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

#include <UnReificationContainer.h>

Inheritance diagram for knowrob::UnReificationContainer:
Collaboration diagram for knowrob::UnReificationContainer:

Public Member Functions

void add (const Triple &triple)
 
ConstGenerator cgenerator () const override
 
void add (const Triple &triple)
 
ConstGenerator cgenerator () const override
 
- Public Member Functions inherited from knowrob::TripleContainer
virtual ~TripleContainer ()=default
 
iterator begin () const
 
bool empty () const
 
virtual bool isMutable () const
 
virtual ~TripleContainer ()=default
 
iterator begin () const
 
bool empty () const
 
virtual bool isMutable () const
 

Protected Member Functions

TriplePtrgetUnReifiedTriple (std::string_view subject)
 
TriplePtrgetUnReifiedTriple (std::string_view subject)
 

Protected Attributes

std::map< std::string_view, TriplePtrtriples_
 

Additional Inherited Members

- Public Types inherited from knowrob::TripleContainer
using ConstGenerator = std::function< const TriplePtr *()>
 
using ConstGenerator = std::function< const TriplePtr *()>
 
- Static Public Member Functions inherited from knowrob::TripleContainer
static iterator end ()
 
static iterator end ()
 

Detailed Description

A container that reverses the reification of input triples.

Definition at line 16 of file UnReificationContainer.h.

Member Function Documentation

◆ add() [1/2]

void UnReificationContainer::add ( const Triple triple)

Add a triple to the container.

Parameters
triplethe triple to add.

Definition at line 32 of file UnReificationContainer.cpp.

32  {
33  using PropertyHandler = std::function<void(const Triple &triple, TriplePtr &unReified)>;
34  static std::map<std::string_view, PropertyHandler> propertyHandler = {
35  {rdf::type->stringForm(), [](auto &triple, auto &unReified) {
36  unReified->setPredicate(semweb::Property::unReifiedIRI(triple.valueAsString())->stringForm());
37  }},
38  {reification::hasSubject->stringForm(), [](auto &triple, auto &unReified) {
40  unReified->setSubjectBlank(triple.valueAsString());
41  } else {
42  unReified->setSubject(triple.valueAsString());
43  }
44  }},
45  {reification::hasObject->stringForm(), [](auto &triple, auto &unReified) {
47  unReified->setObjectBlank(triple.valueAsString());
48  } else {
49  unReified->setObjectIRI(triple.valueAsString());
50  }
51  }},
52  {reification::hasLiteral->stringForm(), [](auto &triple, auto &unReified) {
53  unReified->setXSDValue(triple.valueAsString(), triple.xsdType().value());
54  }},
55  {reification::hasPerspective->stringForm(), [](auto &triple, auto &unReified) {
56  unReified->setPerspective(triple.valueAsString());
57  }},
58  {reification::isUncertain->stringForm(), [](auto &triple, auto &unReified) {
59  unReified->setIsUncertain(triple.valueAsBoolean());
60  }},
61  {reification::isOccasional->stringForm(), [](auto &triple, auto &unReified) {
62  unReified->setIsOccasional(triple.valueAsBoolean());
63  }},
64  {reification::hasConfidence->stringForm(), [](auto &triple, auto &unReified) {
65  unReified->setConfidence(triple.valueAsDouble());
66  }},
67  {reification::hasBeginTime->stringForm(), [](auto &triple, auto &unReified) {
68  unReified->setBegin(triple.valueAsDouble());
69  }},
70  {reification::hasEndTime->stringForm(), [](auto &triple, auto &unReified) {
71  unReified->setEnd(triple.valueAsDouble());
72  }}
73  };
74 
75  auto it = propertyHandler.find(triple.predicate());
76  if (it == propertyHandler.end()) {
77  KB_WARN("No property handler for {}.", triple.predicate());
78  return;
79  }
80  auto &handler = it->second;
81  handler(triple, getUnReifiedTriple(triple.subject()));
82 }
#define KB_WARN
Definition: Logger.h:27
virtual std::string_view valueAsString() const =0
auto xsdType() const
Definition: Triple.h:64
virtual double valueAsDouble() const =0
virtual std::string_view subject() const =0
virtual std::string_view predicate() const =0
virtual bool valueAsBoolean() const =0
TriplePtr & getUnReifiedTriple(std::string_view subject)
static knowrob::IRIAtomPtr unReifiedIRI(std::string_view iri)
Definition: Property.cpp:43
FunctionRule & function()
Definition: terms.cpp:140
const IRIAtomPtr type
Definition: rdf.h:15
const IRIAtomPtr hasSubject
Definition: reification.h:15
const IRIAtomPtr isUncertain
Definition: reification.h:18
const IRIAtomPtr hasConfidence
Definition: reification.h:21
const IRIAtomPtr isOccasional
Definition: reification.h:19
const IRIAtomPtr hasEndTime
Definition: reification.h:23
const IRIAtomPtr hasLiteral
Definition: reification.h:17
const IRIAtomPtr hasBeginTime
Definition: reification.h:22
const IRIAtomPtr hasPerspective
Definition: reification.h:20
const IRIAtomPtr hasObject
Definition: reification.h:16
RDFNodeType rdfNodeTypeGuess(std::string_view str)
Definition: RDFNode.cpp:11

◆ add() [2/2]

void knowrob::UnReificationContainer::add ( const Triple triple)

Add a triple to the container.

Parameters
triplethe triple to add.

◆ cgenerator() [1/2]

TripleContainer::ConstGenerator UnReificationContainer::cgenerator ( ) const
overridevirtual
Returns
a generator function that returns a const pointer to a triple.

Implements knowrob::TripleContainer.

Definition at line 14 of file UnReificationContainer.cpp.

14  {
15  return [this, it = triples_.begin()]() mutable -> const TriplePtr * {
16  if (it == triples_.end()) return nullptr;
17  auto &triple = it->second;
18  ++it;
19  return &triple;
20  };
21 }
std::map< std::string_view, TriplePtr > triples_

◆ cgenerator() [2/2]

ConstGenerator knowrob::UnReificationContainer::cgenerator ( ) const
overridevirtual
Returns
a generator function that returns a const pointer to a triple.

Implements knowrob::TripleContainer.

◆ getUnReifiedTriple() [1/2]

TriplePtr & UnReificationContainer::getUnReifiedTriple ( std::string_view  subject)
protected

Definition at line 23 of file UnReificationContainer.cpp.

23  {
24  auto it = triples_.find(subject);
25  if (it == triples_.end()) {
26  auto [jt, success] = triples_.emplace(subject, new TripleView());
27  return jt->second;
28  }
29  return it->second;
30 }
TripleTemplate< std::string_view > TripleView
Definition: Triple.h:581

◆ getUnReifiedTriple() [2/2]

TriplePtr& knowrob::UnReificationContainer::getUnReifiedTriple ( std::string_view  subject)
protected

Member Data Documentation

◆ triples_

std::map< std::string_view, TriplePtr > knowrob::UnReificationContainer::triples_
protected

Definition at line 28 of file UnReificationContainer.h.


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