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

#include <Resource.h>

Inheritance diagram for knowrob::semweb::Resource:

Classes

struct  AtomComparator
 

Public Member Functions

 Resource (std::string_view iri)
 
 Resource (const IRIAtomPtr &iri)
 
auto iri () const
 
auto iriAtom () const
 
std::string_view name () const
 
std::string_view ns (bool includeDelimiter=false) const
 
 Resource (std::string_view iri)
 
 Resource (const IRIAtomPtr &iri)
 
auto iri () const
 
auto iriAtom () const
 
std::string_view name () const
 
std::string_view ns (bool includeDelimiter=false) const
 

Static Public Member Functions

static IRIAtomPtr unique_iri (std::string_view ns, std::string_view name)
 
static IRIAtomPtr unique_iri (std::string_view type_iri)
 
static std::string_view iri_name (std::string_view iri)
 
static std::string_view iri_ns (std::string_view iri, bool includeDelimiter=false)
 
static AtomPtr graph_atom (std::optional< std::string_view > graph)
 
static IRIAtomPtr unique_iri (std::string_view ns, std::string_view name)
 
static IRIAtomPtr unique_iri (std::string_view type_iri)
 
static std::string_view iri_name (std::string_view iri)
 
static std::string_view iri_ns (std::string_view iri, bool includeDelimiter=false)
 
static AtomPtr graph_atom (std::optional< std::string_view > graph)
 

Protected Attributes

knowrob::AtomPtr iri_
 

Detailed Description

A RDF resource.

Definition at line 17 of file Resource.h.

Constructor & Destructor Documentation

◆ Resource() [1/4]

Resource::Resource ( std::string_view  iri)
explicit

Definition at line 23 of file Resource.cpp.

23  {
24  switch (rdfNodeTypeGuess(iri)) {
25  case RDFNodeType::BLANK:
27  break;
28  case RDFNodeType::IRI:
30  break;
32  KB_WARN("Resource created with guessed literal type: {}. Treating as IRI.", iri);
34  break;
35  }
36 }
#define KB_WARN
Definition: Logger.h:27
static std::shared_ptr< Blank > Tabled(std::string_view stringForm)
Definition: Blank.cpp:12
static std::shared_ptr< IRIAtom > Tabled(std::string_view stringForm)
Definition: IRIAtom.cpp:25
knowrob::AtomPtr iri_
Definition: Resource.h:79
RDFNodeType rdfNodeTypeGuess(std::string_view str)
Definition: RDFNode.cpp:11

◆ Resource() [2/4]

knowrob::semweb::Resource::Resource ( const IRIAtomPtr iri)
inlineexplicit

Definition at line 21 of file Resource.h.

21 : iri_(iri) {}

◆ Resource() [3/4]

knowrob::semweb::Resource::Resource ( std::string_view  iri)
explicit

◆ Resource() [4/4]

knowrob::semweb::Resource::Resource ( const IRIAtomPtr iri)
inlineexplicit

Definition at line 21 of file Resource.h.

21 : iri_(iri) {}

Member Function Documentation

◆ graph_atom() [1/2]

knowrob::AtomPtr Resource::graph_atom ( std::optional< std::string_view >  graph)
static

Obtain an atom from an optional string.

Parameters
graphan optional string
Returns
an atom

Definition at line 82 of file Resource.cpp.

82  {
83  return graph ? IRIAtom::Tabled(graph.value()) : IRIAtom::Tabled(ImportHierarchy::ORIGIN_SESSION);
84 }

◆ graph_atom() [2/2]

static AtomPtr knowrob::semweb::Resource::graph_atom ( std::optional< std::string_view >  graph)
static

Obtain an atom from an optional string.

Parameters
graphan optional string
Returns
an atom

◆ iri() [1/2]

auto knowrob::semweb::Resource::iri ( ) const
inline
Returns
the IRI string of this resource

Definition at line 26 of file Resource.h.

26 { return iri_->stringForm(); }

◆ iri() [2/2]

auto knowrob::semweb::Resource::iri ( ) const
inline
Returns
the IRI string of this resource

Definition at line 26 of file Resource.h.

26 { return iri_->stringForm(); }

◆ iri_name() [1/2]

std::string_view Resource::iri_name ( std::string_view  iri)
static
Parameters
iria IRI
Returns
the name part of the IRI

Definition at line 57 of file Resource.cpp.

57  {
58  auto pos = iri.find('#');
59  if (pos != std::string::npos) {
60  return iri.substr(pos + 1);
61  }
62  return {iri.data()};
63 }

◆ iri_name() [2/2]

static std::string_view knowrob::semweb::Resource::iri_name ( std::string_view  iri)
static
Parameters
iria IRI
Returns
the name part of the IRI

◆ iri_ns() [1/2]

std::string_view Resource::iri_ns ( std::string_view  iri,
bool  includeDelimiter = false 
)
static
Parameters
iria IRI
includeDelimiterif true, the delimiter is included in the result
Returns
the namespace part of the IRI

Definition at line 69 of file Resource.cpp.

69  {
70  auto pos = iri.rfind('#');
71  if (pos != std::string::npos) {
72  auto pos_x = (includeDelimiter ? pos + 1 : pos);
73  return iri.substr(0, pos_x);
74  }
75  return {};
76 }

◆ iri_ns() [2/2]

static std::string_view knowrob::semweb::Resource::iri_ns ( std::string_view  iri,
bool  includeDelimiter = false 
)
static
Parameters
iria IRI
includeDelimiterif true, the delimiter is included in the result
Returns
the namespace part of the IRI

◆ iriAtom() [1/2]

auto knowrob::semweb::Resource::iriAtom ( ) const
inline
Returns
the IRI string of this resource as an atom

Definition at line 31 of file Resource.h.

31 { return iri_; }

◆ iriAtom() [2/2]

auto knowrob::semweb::Resource::iriAtom ( ) const
inline
Returns
the IRI string of this resource as an atom

Definition at line 31 of file Resource.h.

31 { return iri_; }

◆ name() [1/2]

std::string_view Resource::name ( ) const
Returns
the name of this resource

Definition at line 65 of file Resource.cpp.

65  {
66  return iri_name(iri_->stringForm());
67 }
static std::string_view iri_name(std::string_view iri)
Definition: Resource.cpp:57

◆ name() [2/2]

std::string_view knowrob::semweb::Resource::name ( ) const
Returns
the name of this resource

◆ ns() [1/2]

std::string_view Resource::ns ( bool  includeDelimiter = false) const
Returns
the namespace of this resource.

Definition at line 78 of file Resource.cpp.

78  {
79  return iri_ns(iri_->stringForm(), includeDelimiter);
80 }
static std::string_view iri_ns(std::string_view iri, bool includeDelimiter=false)
Definition: Resource.cpp:69

◆ ns() [2/2]

std::string_view knowrob::semweb::Resource::ns ( bool  includeDelimiter = false) const
Returns
the namespace of this resource.

◆ unique_iri() [1/4]

knowrob::IRIAtomPtr Resource::unique_iri ( std::string_view  ns,
std::string_view  name 
)
static

Generate a unique IRI for a resource.

Parameters
nsthe namespace of the IRI.
namethe name prefix of the IRI.
Returns
a unique IRI.

Definition at line 38 of file Resource.cpp.

38  {
39  std::stringstream ss;
40  ss << ns;
41  if (!ns.empty() && ns.back() != '#') {
42  ss << "#";
43  }
44  ss << name << '_';
45  insertUnique(ss);
46  return IRIAtom::Tabled(ss.str());
47 }
std::string_view name() const
Definition: Resource.cpp:65
std::string_view ns(bool includeDelimiter=false) const
Definition: Resource.cpp:78
void insertUnique(std::ostream &os)
Definition: knowrob.cpp:44

◆ unique_iri() [2/4]

static IRIAtomPtr knowrob::semweb::Resource::unique_iri ( std::string_view  ns,
std::string_view  name 
)
static

Generate a unique IRI for a resource.

Parameters
nsthe namespace of the IRI.
namethe name prefix of the IRI.
Returns
a unique IRI.

◆ unique_iri() [3/4]

knowrob::IRIAtomPtr Resource::unique_iri ( std::string_view  type_iri)
static

Generate a unique IRI for a resource.

Parameters
type_irithe type IRI of the resource used as a prefix.
Returns
a unique IRI.

Definition at line 49 of file Resource.cpp.

49  {
50  std::stringstream ss;
51  ss << type_iri;
52  ss << '_';
53  insertUnique(ss);
54  return IRIAtom::Tabled(ss.str());
55 }

◆ unique_iri() [4/4]

static IRIAtomPtr knowrob::semweb::Resource::unique_iri ( std::string_view  type_iri)
static

Generate a unique IRI for a resource.

Parameters
type_irithe type IRI of the resource used as a prefix.
Returns
a unique IRI.

Member Data Documentation

◆ iri_

knowrob::AtomPtr knowrob::semweb::Resource::iri_
protected

Definition at line 79 of file Resource.h.


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