ObjectSpokenNames.h
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * ArmarX is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * ArmarX is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * @package RobotAPI::ArmarXObjects::OpossumLogger
17 * @author Joana Plewnia ( joana dot plewnia at kit dot edu )
18 * @date 2026
19 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22
23#pragma once
24
25#include <map>
26#include <mutex>
27#include <optional>
28#include <string>
29#include <utility>
30
32
33#include "SkillEventRenderer.h"
34
35namespace armarx::opossum
36{
37
38 /**
39 * @brief Spoken object names from PriorKnowledgeData, for use as a
40 * `SpokenNameLookup`.
41 *
42 * Looks up `<dataset>/<className>/<className>_names.json` via
43 * `ObjectFinder`; if that yields nothing (the dataset is unknown to
44 * PriorKnowledgeData, as for `MobileKitchen/mobile-fridge`), the class name
45 * is searched in all datasets. Results, including misses, are cached: only
46 * about a quarter of the known classes carry a names file, so misses are
47 * common and re-checking the filesystem for them would be wasteful.
48 *
49 * Thread-safe.
50 */
52 {
53 public:
54 ObjectSpokenNames() = default;
55
56 /// The spoken name of an object class, or `std::nullopt` if it has none.
57 std::optional<std::string> operator()(const std::string& dataset,
58 const std::string& className);
59
60 /// This resolver as a `SpokenNameLookup`. Must not outlive this object.
62
63 private:
64 std::optional<std::string> load(const std::string& dataset, const std::string& className);
65
67
68 std::mutex mutex;
69 std::map<std::pair<std::string, std::string>, std::optional<std::string>> cache;
70 };
71
72} // namespace armarx::opossum
Used to find objects in the ArmarX objects repository [1] (formerly [2]).
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.
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.