knowrob  2.1.0
A Knowledge Base System for Cognition-enabled Robots
knowrob::GraphSelector Struct Reference

#include <GraphSelector.h>

Inheritance diagram for knowrob::GraphSelector:
Collaboration diagram for knowrob::GraphSelector:

Public Member Functions

 GraphSelector ()=default
 
size_t hash () const
 
bool mergeWith (const GraphSelector &other)
 
void set (const boost::property_tree::ptree &config)
 
void write (std::ostream &os) const override
 
 GraphSelector ()=default
 
size_t hash () const
 
bool mergeWith (const GraphSelector &other)
 
void set (const boost::property_tree::ptree &config)
 
void write (std::ostream &os) const override
 
- Public Member Functions inherited from knowrob::Printable
virtual ~Printable ()=default
 
virtual std::string format () const
 
virtual ~Printable ()=default
 
virtual std::string format () const
 

Public Attributes

AtomPtr graph
 
PerspectivePtr perspective
 
bool occasional = false
 
bool uncertain = false
 
std::optional< double > begin
 
std::optional< double > end
 
std::optional< double > confidence
 

Detailed Description

The data base can contain multiple graphs, and this selector is used to select a subset of them. For example, each point in time is conceptually a separate graph, and a query may only address a specific point in time, or time interval.

Definition at line 20 of file GraphSelector.h.

Constructor & Destructor Documentation

◆ GraphSelector() [1/2]

knowrob::GraphSelector::GraphSelector ( )
default

◆ GraphSelector() [2/2]

knowrob::GraphSelector::GraphSelector ( )
default

Member Function Documentation

◆ hash() [1/2]

size_t GraphSelector::hash ( ) const

Compute the hash value of this selector.

Returns
the hash value

Definition at line 54 of file GraphSelector.cpp.

54  {
55  size_t val = 0;
56  if (graph) {
57  hashCombine(val, graph->hash());
58  } else {
59  hashCombine(val, 0);
60  }
61  if (perspective) {
62  hashCombine(val, std::hash<std::string_view>{}(perspective->iri()));
63  } else {
64  hashCombine(val, 0);
65  }
66  hashCombine(val, std::hash<bool>{}(occasional));
67  hashCombine(val, std::hash<bool>{}(uncertain));
68  hashCombine(val, std::hash<std::optional<double>>{}(end));
69  hashCombine(val, std::hash<std::optional<double>>{}(begin));
70  hashCombine(val, std::hash<std::optional<double>>{}(confidence));
71  return val;
72 }
void hashCombine(std::size_t &seed, const std::size_t &v)
Definition: knowrob.cpp:39
std::optional< double > confidence
Definition: GraphSelector.h:50
std::optional< double > end
Definition: GraphSelector.h:46
PerspectivePtr perspective
Definition: GraphSelector.h:30
std::optional< double > begin
Definition: GraphSelector.h:42

◆ hash() [2/2]

size_t knowrob::GraphSelector::hash ( ) const

Compute the hash value of this selector.

Returns
the hash value

◆ mergeWith() [1/2]

bool GraphSelector::mergeWith ( const GraphSelector other)

Merge this selector with another selector.

Parameters
otheranother selector.
Returns
true if the merge was successful.

Definition at line 13 of file GraphSelector.cpp.

13  {
14  uncertain = uncertain || other.uncertain;
15  occasional = occasional || other.occasional;
16 
17  // graph selector changes to wildcard if graph of the other selector is different
18  if (!graph || !other.graph || *graph != *other.graph) {
19  graph = nullptr;
20  }
21 
22  // agent cannot be changed in merge operation.
23  // So GraphSelector can only be merged within a modal in which both are embedded.
24  if (perspective) {
25  if (other.perspective) {
26  if (perspective->iri() != other.perspective->iri()) {
27  return false;
28  }
29  } else {
30  return false;
31  }
32  } else if (other.perspective) {
33  return false;
34  }
35 
36  // later begin time is more restrictive
37  if (other.begin.has_value() && (!begin.has_value() || other.begin.value() > begin.value())) {
38  begin = other.begin;
39  }
40 
41  // earlier end time is more restrictive
42  if (other.end.has_value() && (!end.has_value() || other.end.value() > end.value())) {
43  end = other.end;
44  }
45 
46  // smaller confidence is more restrictive
47  if (other.confidence.has_value() && (!confidence.has_value() || other.confidence.value() < confidence.value())) {
48  confidence = other.confidence;
49  }
50 
51  return true;
52 }

◆ mergeWith() [2/2]

bool knowrob::GraphSelector::mergeWith ( const GraphSelector other)

Merge this selector with another selector.

Parameters
otheranother selector.
Returns
true if the merge was successful.

◆ set() [1/2]

void GraphSelector::set ( const boost::property_tree::ptree &  config)

Set the selector from a property tree.

Parameters
configthe property tree

Definition at line 117 of file GraphSelector.cpp.

117  {
118  uncertain = config.get<bool>("uncertain", false);
119  occasional = config.get<bool>("occasional", false);
120  if (config.count("graph")) {
121  graph = Atom::Tabled(config.get<std::string>("graph"));
122  }
123  if (config.count("perspective")) {
124  perspective = std::make_shared<Perspective>(config.get<std::string>("perspective"));
125  }
126  if (config.count("begin")) {
127  begin = config.get<double>("begin");
128  }
129  if (config.count("end")) {
130  end = config.get<double>("end");
131  }
132  if (config.count("confidence")) {
133  confidence = config.get<double>("confidence");
134  }
135 }
static std::shared_ptr< knowrob::Atom > Tabled(std::string_view stringForm)
Definition: Atom.cpp:40
TermRule & string()
Definition: terms.cpp:63

◆ set() [2/2]

void knowrob::GraphSelector::set ( const boost::property_tree::ptree &  config)

Set the selector from a property tree.

Parameters
configthe property tree

◆ write() [1/2]

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

Print this object to a stream.

Parameters
osthe stream to print to.

Implements knowrob::Printable.

Definition at line 74 of file GraphSelector.cpp.

74  {
75  os << std::setprecision(1);
76 
77  bool hasEpistemicOperator = false;
78  if (confidence.has_value()) {
79  hasEpistemicOperator = true;
80  if (confidence.value() > 0.999) {
81  os << 'K';
82  } else {
83  os << "B[" << confidence.value() << "]";
84  }
85  } else if (uncertain) {
86  hasEpistemicOperator = true;
87  os << 'B';
88  }
90  if (!hasEpistemicOperator) {
91  os << 'K';
92  }
93  os << '[' << perspective->iri() << ']';
94  }
95 
96  bool hasTemporalOperator = false;
97  if (occasional) {
98  hasTemporalOperator = true;
99  os << 'P';
100  }
101  if (begin.has_value() || end.has_value()) {
102  if (!hasTemporalOperator) {
103  os << 'H';
104  }
105  os << '[';
106  if (begin.has_value()) {
107  os << begin.value();
108  }
109  os << '-';
110  if (end.has_value()) {
111  os << end.value();
112  }
113  os << ']';
114  }
115 }
static bool isEgoPerspective(std::string_view iri)
Definition: Perspective.cpp:27

◆ write() [2/2]

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

Print this object to a stream.

Parameters
osthe stream to print to.

Implements knowrob::Printable.

Member Data Documentation

◆ begin

std::optional< double > knowrob::GraphSelector::begin

The begin of the time interval of consideration.

Definition at line 42 of file GraphSelector.h.

◆ confidence

std::optional< double > knowrob::GraphSelector::confidence

The minimum confidence threshold for statements.

Definition at line 50 of file GraphSelector.h.

◆ end

std::optional< double > knowrob::GraphSelector::end

The end of the time interval of consideration.

Definition at line 46 of file GraphSelector.h.

◆ graph

AtomPtr knowrob::GraphSelector::graph

The name of the graph, usually reflects the name of an ontology.

Definition at line 26 of file GraphSelector.h.

◆ occasional

bool knowrob::GraphSelector::occasional = false

True if occasional triples are considered.

Definition at line 34 of file GraphSelector.h.

◆ perspective

PerspectivePtr knowrob::GraphSelector::perspective

The perspective of statement.

Definition at line 30 of file GraphSelector.h.

◆ uncertain

bool knowrob::GraphSelector::uncertain = false

True if uncertain triples are considered.

Definition at line 38 of file GraphSelector.h.


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