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

#include <IRIAtom.h>

Inheritance diagram for knowrob::IRIAtom:
Collaboration diagram for knowrob::IRIAtom:

Public Member Functions

 IRIAtom (std::string_view stringForm)
 
PredicatePtr operator() (const TermPtr &s, const TermPtr &o) const
 
PredicatePtr operator() (const TermPtr &s) const
 
void write (std::ostream &os) const override
 
 IRIAtom (std::string_view stringForm)
 
PredicatePtr operator() (const TermPtr &s, const TermPtr &o) const
 
PredicatePtr operator() (const TermPtr &s) const
 
void write (std::ostream &os) const override
 
- Public Member Functions inherited from knowrob::Atom
 Atom (std::string_view stringForm, AtomType atomType=AtomType::REGULAR)
 
bool isSameAtom (const Atom &other) const
 
AtomType atomType () const
 
std::string_view stringForm () const final
 
 Atom (std::string_view stringForm, AtomType atomType=AtomType::REGULAR)
 
bool isSameAtom (const Atom &other) const
 
AtomType atomType () const
 
std::string_view stringForm () const final
 
- Public Member Functions inherited from knowrob::Atomic
 Atomic (AtomicType atomicType)
 
 ~Atomic () override=default
 
bool isSameAtomic (const Atomic &other) const
 
AtomicType atomicType () const
 
size_t hashOfAtomic () const
 
const std::set< std::string_view > & variables () const final
 
 Atomic (AtomicType atomicType)
 
 ~Atomic () override=default
 
bool isSameAtomic (const Atomic &other) const
 
AtomicType atomicType () const
 
size_t hashOfAtomic () const
 
const std::set< std::string_view > & variables () const final
 
- Public Member Functions inherited from knowrob::Term
 Term (TermType termType)
 
 ~Term () override=default
 
bool operator== (const Term &other) const
 
bool operator!= (const Term &other) const
 
TermType termType () const
 
bool isGround () const
 
bool isAtomic () const
 
bool isAtom () const
 
bool isVariable () const
 
bool isFunction () const
 
bool isNumeric () const
 
bool isString () const
 
bool isIRI () const
 
bool isBlank () const
 
size_t hash () const
 
 Term (TermType termType)
 
 ~Term () override=default
 
bool operator== (const Term &other) const
 
bool operator!= (const Term &other) const
 
TermType termType () const
 
bool isGround () const
 
bool isAtomic () const
 
bool isAtom () const
 
bool isVariable () const
 
bool isFunction () const
 
bool isNumeric () const
 
bool isString () const
 
bool isIRI () const
 
bool isBlank () const
 
size_t hash () const
 
- Public Member Functions inherited from knowrob::Printable
virtual ~Printable ()=default
 
virtual std::string format () const
 
virtual ~Printable ()=default
 
virtual std::string format () const
 
- Public Member Functions inherited from knowrob::RDFNode
 RDFNode (RDFNodeType rdfNodeType)
 
auto rdfNodeType () const
 
 RDFNode (RDFNodeType rdfNodeType)
 
auto rdfNodeType () const
 

Static Public Member Functions

static std::shared_ptr< IRIAtomTabled (std::string_view stringForm)
 
static std::shared_ptr< IRIAtomTabled (std::string_view stringForm)
 
- Static Public Member Functions inherited from knowrob::Atom
static std::shared_ptr< knowrob::AtomTabled (std::string_view stringForm)
 
static std::shared_ptr< knowrob::AtomTabled (std::string_view stringForm)
 
- Static Public Member Functions inherited from knowrob::Atomic
static std::shared_ptr< AtomicmakeTripleValue (const Triple &triple)
 
static std::shared_ptr< AtomicmakeTripleValue (const Triple &triple)
 

Additional Inherited Members

- Protected Types inherited from knowrob::Atom
using AtomTable = std::map< std::string, std::optional< std::weak_ptr< Atom > >, std::less<> >
 
using AtomTable = std::map< std::string, std::optional< std::weak_ptr< Atom > >, std::less<> >
 
- Static Protected Member Functions inherited from knowrob::Atom
static AtomTabletable ()
 
static AtomTabletable ()
 
- Protected Attributes inherited from knowrob::Atom
std::string_view stringForm_
 
const AtomType atomType_
 
- Protected Attributes inherited from knowrob::Atomic
const AtomicType atomicType_
 
- Protected Attributes inherited from knowrob::Term
const TermType termType_
 
bool isBlank_ = false
 
bool isIRI_ = false
 
- Protected Attributes inherited from knowrob::RDFNode
const RDFNodeType rdfNodeType_
 
- Static Protected Attributes inherited from knowrob::Term
static const std::set< std::string_view > noVariables_ = {}
 

Detailed Description

An IRI (Internationalized Resource Identifier) within an RDF graph is a Unicode string that conforms to the syntax defined in RFC 3987.

Definition at line 18 of file IRIAtom.h.

Constructor & Destructor Documentation

◆ IRIAtom() [1/2]

knowrob::IRIAtom::IRIAtom ( std::string_view  stringForm)
inlineexplicit

Constructs an IRI atom from a string.

Parameters
stringFormthe string form of the IRI

Definition at line 24 of file IRIAtom.h.

27  isIRI_ = true;
28  }
Atom(std::string_view stringForm, AtomType atomType=AtomType::REGULAR)
Definition: Atom.cpp:16
std::string_view stringForm() const final
Definition: Atom.h:55
RDFNode(RDFNodeType rdfNodeType)
Definition: RDFNode.h:29
bool isIRI_
Definition: Term.h:113

◆ IRIAtom() [2/2]

knowrob::IRIAtom::IRIAtom ( std::string_view  stringForm)
inlineexplicit

Constructs an IRI atom from a string.

Parameters
stringFormthe string form of the IRI

Definition at line 24 of file IRIAtom.h.

27  isIRI_ = true;
28  }

Member Function Documentation

◆ operator()() [1/4]

PredicatePtr IRIAtom::operator() ( const TermPtr s) const

Constructs a predicate from this IRI atom and the given term.

Parameters
sthe subject term
Returns
a shared pointer to a predicate

Definition at line 20 of file IRIAtom.cpp.

20  {
21  auto functor = IRIAtom::Tabled(stringForm());
22  return std::make_shared<Predicate>(functor, std::vector<TermPtr>{s});
23 }
static std::shared_ptr< IRIAtom > Tabled(std::string_view stringForm)
Definition: IRIAtom.cpp:25

◆ operator()() [2/4]

PredicatePtr knowrob::IRIAtom::operator() ( const TermPtr s) const

Constructs a predicate from this IRI atom and the given term.

Parameters
sthe subject term
Returns
a shared pointer to a predicate

◆ operator()() [3/4]

PredicatePtr IRIAtom::operator() ( const TermPtr s,
const TermPtr o 
) const

Constructs a predicate from this IRI atom and the given terms.

Parameters
sthe subject term
othe object term
Returns
a shared pointer to a predicate

Definition at line 15 of file IRIAtom.cpp.

15  {
16  auto functor = IRIAtom::Tabled(stringForm());
17  return std::make_shared<Predicate>(functor, std::vector<TermPtr>{s, o});
18 }

◆ operator()() [4/4]

PredicatePtr knowrob::IRIAtom::operator() ( const TermPtr s,
const TermPtr o 
) const

Constructs a predicate from this IRI atom and the given terms.

Parameters
sthe subject term
othe object term
Returns
a shared pointer to a predicate

◆ Tabled() [1/2]

std::shared_ptr< knowrob::IRIAtom > IRIAtom::Tabled ( std::string_view  stringForm)
static
Parameters
stringFormthe string form of the IRI
Returns
a shared pointer to an IRI atom

Definition at line 25 of file IRIAtom.cpp.

25  {
26  auto it = Atom::table().find(name);
27  if (it != table().end()) {
28  if (auto atomPtr = it->second.value().lock()) {
29  if (atomPtr->isIRI()) {
30  return std::static_pointer_cast<IRIAtom>(atomPtr);
31  }
32  }
33  }
34  // Atom does not exist or was destroyed, create a new one
35  auto inserted = table().emplace(name, std::nullopt);
36  auto &jt = inserted.first;
37  auto atom = std::make_shared<knowrob::IRIAtom>(jt->first);
38  jt->second = atom;
39  auto locked = jt->second.value().lock();
40  if (!locked) {
41  throw std::runtime_error("Failed to lock IRIAtom");
42  }
43  return std::static_pointer_cast<IRIAtom>(locked);
44 }
static AtomTable & table()
Definition: Atom.cpp:11
StringRule & atom()
Definition: strings.cpp:54

◆ Tabled() [2/2]

static std::shared_ptr<IRIAtom> knowrob::IRIAtom::Tabled ( std::string_view  stringForm)
static
Parameters
stringFormthe string form of the IRI
Returns
a shared pointer to an IRI atom

◆ write() [1/2]

void IRIAtom::write ( std::ostream &  os) const
overridevirtual

Print this object to a stream.

Parameters
osthe stream to print to.

Reimplemented from knowrob::Atom.

Definition at line 46 of file IRIAtom.cpp.

46  {
48  if (!ns.empty()) {
49  auto alias = PrefixRegistry::uriToAlias(ns);
50  if (alias.has_value()) {
52  if (!name.empty()) {
53  os << alias.value().get() << ":" << name;
54  return;
55  }
56  }
57  }
58  Atom::write(os);
59 }
void write(std::ostream &os) const override
Definition: Atom.cpp:28
std::string_view stringForm_
Definition: Atom.h:61
static OptionalStringRef uriToAlias(std::string_view uri)
static std::string_view iri_name(std::string_view iri)
Definition: Resource.cpp:57
static std::string_view iri_ns(std::string_view iri, bool includeDelimiter=false)
Definition: Resource.cpp:69

◆ write() [2/2]

void knowrob::IRIAtom::write ( std::ostream &  os) const
overridevirtual

Print this object to a stream.

Parameters
osthe stream to print to.

Reimplemented from knowrob::Atom.


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