knowrob  2.1.0
A Knowledge Base System for Cognition-enabled Robots
knowrob::PrefixRegistry Class Reference

#include <PrefixRegistry.h>

Public Types

using Iterator = std::map< std::string, std::string >::iterator
 
using Iterator = std::map< std::string, std::string >::iterator
 

Public Member Functions

Iterator begin ()
 
Iterator end ()
 
Iterator begin ()
 
Iterator end ()
 

Static Public Member Functions

static PrefixRegistryget ()
 
static void registerPrefix (std::string_view prefix, std::string_view uri)
 
static OptionalStringRef uriToAlias (std::string_view uri)
 
static OptionalStringRef aliasToUri (std::string_view alias)
 
static std::optional< std::string > createIRI (std::string_view alias, std::string_view entityName)
 
static std::vector< std::string_view > getAliasesWithPrefix (std::string_view prefix)
 
static PrefixRegistryget ()
 
static void registerPrefix (std::string_view prefix, std::string_view uri)
 
static OptionalStringRef uriToAlias (std::string_view uri)
 
static OptionalStringRef aliasToUri (std::string_view alias)
 
static std::optional< std::string > createIRI (std::string_view alias, std::string_view entityName)
 
static std::vector< std::string_view > getAliasesWithPrefix (std::string_view prefix)
 

Detailed Description

Stores short names of IRI prefixes.

Definition at line 20 of file PrefixRegistry.h.

Member Typedef Documentation

◆ Iterator [1/2]

using knowrob::PrefixRegistry::Iterator = std::map<std::string, std::string>::iterator

An iterator of the registry map.

Definition at line 66 of file PrefixRegistry.h.

◆ Iterator [2/2]

using knowrob::PrefixRegistry::Iterator = std::map<std::string, std::string>::iterator

An iterator of the registry map.

Definition at line 66 of file PrefixRegistry.h.

Member Function Documentation

◆ aliasToUri() [1/2]

OptionalStringRef PrefixRegistry::aliasToUri ( std::string_view  alias)
static

Maps alias to URI.

Parameters
aliasa URI alias
Returns
the corresponding URI, or nullopt if alias is unknown.

Definition at line 61 of file PrefixRegistry.cpp.

61  {
62  if (alias.empty()) {
63  return std::nullopt;
64  } else {
65  auto it = get().aliasToURI_.find(alias);
66  return it == get().aliasToURI_.end() ? std::nullopt : OptionalStringRef(it->second);
67  }
68 }
static PrefixRegistry & get()
std::optional< std::reference_wrapper< const std::string > > OptionalStringRef

◆ aliasToUri() [2/2]

static OptionalStringRef knowrob::PrefixRegistry::aliasToUri ( std::string_view  alias)
static

Maps alias to URI.

Parameters
aliasa URI alias
Returns
the corresponding URI, or nullopt if alias is unknown.

◆ begin() [1/2]

Iterator knowrob::PrefixRegistry::begin ( )
inline
Returns
begin iterator over the registry map.

Definition at line 71 of file PrefixRegistry.h.

71 { return uriToAlias_.begin(); }

◆ begin() [2/2]

Iterator knowrob::PrefixRegistry::begin ( )
inline
Returns
begin iterator over the registry map.

Definition at line 71 of file PrefixRegistry.h.

71 { return uriToAlias_.begin(); }

◆ createIRI() [1/2]

std::optional< std::string > PrefixRegistry::createIRI ( std::string_view  alias,
std::string_view  entityName 
)
static

Construct a full IRI from alias and entity name.

Parameters
aliasnamespace alias
entityNamethe name of an entity in the namespace identified by alias
Returns
a full IRI if namespace alias is known

Definition at line 70 of file PrefixRegistry.cpp.

70  {
71  auto uri = aliasToUri(alias);
72  if (uri.has_value()) {
73  std::stringstream os;
74  os << uri.value().get() << entityName;
75  return os.str();
76  } else {
77  return std::nullopt;
78  }
79 }
static OptionalStringRef aliasToUri(std::string_view alias)

◆ createIRI() [2/2]

static std::optional<std::string> knowrob::PrefixRegistry::createIRI ( std::string_view  alias,
std::string_view  entityName 
)
static

Construct a full IRI from alias and entity name.

Parameters
aliasnamespace alias
entityNamethe name of an entity in the namespace identified by alias
Returns
a full IRI if namespace alias is known

◆ end() [1/2]

Iterator knowrob::PrefixRegistry::end ( )
inline
Returns
end iterator over the registry map.

Definition at line 76 of file PrefixRegistry.h.

76 { return uriToAlias_.end(); }

◆ end() [2/2]

Iterator knowrob::PrefixRegistry::end ( )
inline
Returns
end iterator over the registry map.

Definition at line 76 of file PrefixRegistry.h.

76 { return uriToAlias_.end(); }

◆ get() [1/2]

PrefixRegistry & PrefixRegistry::get ( )
static
Returns
the singleton instance of the registry.

Definition at line 23 of file PrefixRegistry.cpp.

23  {
24  static PrefixRegistry singleton;
25  return singleton;
26 }

◆ get() [2/2]

static PrefixRegistry& knowrob::PrefixRegistry::get ( )
static
Returns
the singleton instance of the registry.

◆ getAliasesWithPrefix() [1/2]

std::vector< std::string_view > PrefixRegistry::getAliasesWithPrefix ( std::string_view  prefix)
static
Parameters
prefixa alias prefix
Returns
all aliases with matching prefix

Definition at line 81 of file PrefixRegistry.cpp.

81  {
82  auto range_it = get().aliasToURI_.equal_range(PrefixProbe{prefix});
83  std::vector<std::string_view> result;
84  for (auto it = range_it.first; it != range_it.second; ++it) {
85  result.emplace_back(it->first.c_str());
86  }
87  return result;
88 }
constexpr std::string_view prefix
Definition: owl.h:14

◆ getAliasesWithPrefix() [2/2]

static std::vector<std::string_view> knowrob::PrefixRegistry::getAliasesWithPrefix ( std::string_view  prefix)
static
Parameters
prefixa alias prefix
Returns
all aliases with matching prefix

◆ registerPrefix() [1/2]

void PrefixRegistry::registerPrefix ( std::string_view  prefix,
std::string_view  uri 
)
static

Register a namespace prefix. This will overwrite any existing prefix registered for given URI.

Parameters
prefixa short name for the URI.
uria full URI.

Definition at line 44 of file PrefixRegistry.cpp.

44  {
45  get().registerPrefix_(prefix, uri);
46 }

◆ registerPrefix() [2/2]

static void knowrob::PrefixRegistry::registerPrefix ( std::string_view  prefix,
std::string_view  uri 
)
static

Register a namespace prefix. This will overwrite any existing prefix registered for given URI.

Parameters
prefixa short name for the URI.
uria full URI.

◆ uriToAlias() [1/2]

OptionalStringRef PrefixRegistry::uriToAlias ( std::string_view  uri)
static

Maps URI to alias.

Parameters
uria URI
Returns
an alias, or nullopt if no alias is known.

Definition at line 48 of file PrefixRegistry.cpp.

48  {
49  if (uri.empty()) {
50  return std::nullopt;
51  } else if (isDelimiter(uri[uri.size() - 1])) {
52  auto it = get().uriToAlias_.find(uri);
53  return it == get().uriToAlias_.end() ? std::nullopt : OptionalStringRef(it->second);
54  } else {
55  auto withDelimiter = std::string(uri) + '#';
56  auto it = get().uriToAlias_.find(withDelimiter);
57  return it == get().uriToAlias_.end() ? std::nullopt : OptionalStringRef(it->second);
58  }
59 }
TermRule & string()
Definition: terms.cpp:63

◆ uriToAlias() [2/2]

static OptionalStringRef knowrob::PrefixRegistry::uriToAlias ( std::string_view  uri)
static

Maps URI to alias.

Parameters
uria URI
Returns
an alias, or nullopt if no alias is known.

The documentation for this class was generated from the following files: