32 std::optional<std::string>
35 const auto key = std::make_pair(dataset, className);
37 std::scoped_lock lock(mutex);
38 if (
const auto cached = cache.find(key); cached != cache.end())
40 return cached->second;
43 std::optional<std::string> spokenName;
46 spokenName = load(dataset, className);
48 catch (
const std::exception& e)
51 << dataset <<
"/" << className <<
"': " << e.what()
52 <<
". Falling back to the class name.";
55 cache.emplace(key, spokenName);
59 std::optional<std::string>
60 ObjectSpokenNames::load(
const std::string& dataset,
const std::string& className)
65 for (
const std::string& datasetToTry : {dataset, std::string()})
67 const std::optional<ObjectInfo> info = finder.
findObject(datasetToTry, className);
68 if (not info.has_value())
72 const std::optional<std::vector<std::string>> spokenNames = info->loadSpokenNames();
73 if (spokenNames.has_value() and not spokenNames->empty())
75 return spokenNames->front();
77 if (datasetToTry.empty())
88 return [
this](
const std::string& dataset,
const std::string& className)
89 {
return (*
this)(dataset, className); };
SpamFilterDataPtr deactivateSpam(SpamFilterDataPtr const &spamFilter, float deactivationDurationSec, const std::string &identifier, bool deactivate)
std::optional< ObjectInfo > findObject(const std::string &dataset, const std::string &name) const
std::optional< std::string > operator()(const std::string &dataset, const std::string &className)
The spoken name of an object class, or std::nullopt if it has none.
SpokenNameLookup asLookup()
This resolver as a SpokenNameLookup. Must not outlive this object.
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
std::function< std::optional< std::string >( const std::string &dataset, const std::string &className)> SpokenNameLookup
Resolves an object class to its natural-language ("spoken") name.