knowrob  2.1.0
A Knowledge Base System for Cognition-enabled Robots
knowrob::GoalDrivenReasoner Class Referenceabstract

#include <GoalDrivenReasoner.h>

Inheritance diagram for knowrob::GoalDrivenReasoner:
Collaboration diagram for knowrob::GoalDrivenReasoner:

Public Member Functions

 GoalDrivenReasoner ()
 
bool hasFeature (GoalDrivenReasonerFeature feature) const
 
void enableFeature (GoalDrivenReasonerFeature feature)
 
bool isRelationDefined (const PredicateIndicator &indicator)
 
bool isClassDefined (const std::string_view &iri)
 
void defineRelation (const PredicateIndicator &indicator)
 
void defineRelation (const IRIAtomPtr &iri)
 
void undefineRelation (const PredicateIndicator &indicator)
 
void defineClass (const IRIAtomPtr &iri)
 
void undefineClass (const IRIAtomPtr &iri)
 
const auto & definedRelations () const
 
const auto & definedClasses () const
 
virtual bool evaluate (GoalPtr query)=0
 
 GoalDrivenReasoner ()
 
bool hasFeature (GoalDrivenReasonerFeature feature) const
 
void enableFeature (GoalDrivenReasonerFeature feature)
 
bool isRelationDefined (const PredicateIndicator &indicator)
 
bool isClassDefined (const std::string_view &iri)
 
void defineRelation (const PredicateIndicator &indicator)
 
void defineRelation (const IRIAtomPtr &iri)
 
void undefineRelation (const PredicateIndicator &indicator)
 
void defineClass (const IRIAtomPtr &iri)
 
void undefineClass (const IRIAtomPtr &iri)
 
const auto & definedRelations () const
 
const auto & definedClasses () const
 
virtual bool evaluate (GoalPtr query)=0
 
- Public Member Functions inherited from knowrob::Reasoner
 Reasoner ()
 
virtual ~Reasoner ()=default
 
auto & reasonerName () const
 
auto reasonerLanguage () const
 
auto storage () const
 
template<class T >
std::shared_ptr< T > getTypedStorage () const
 
ReasonerManagerreasonerManager () const
 
void pushWork (const std::function< void(void)> &fn)
 
void setStorage (const StoragePtr &storage)
 
virtual bool initializeReasoner (const PropertyTree &ptree)=0
 
virtual void unload ()
 
 Reasoner ()
 
virtual ~Reasoner ()=default
 
auto & reasonerName () const
 
auto reasonerLanguage () const
 
auto storage () const
 
template<class T >
std::shared_ptr< T > getTypedStorage () const
 
ReasonerManagerreasonerManager () const
 
void pushWork (const std::function< void(void)> &fn)
 
void setStorage (const StoragePtr &storage)
 
virtual bool initializeReasoner (const PropertyTree &ptree)=0
 
virtual void unload ()
 
- Public Member Functions inherited from knowrob::DataSourceHandler
 DataSourceHandler ()=default
 
virtual ~DataSourceHandler ()=default
 
void addDataHandler (const std::string &format, const DataSourceLoader &fn)
 
bool loadDataSource (const DataSourcePtr &dataSource)
 
bool hasDataHandler (const DataSourcePtr &dataSource) const
 
 DataSourceHandler ()=default
 
virtual ~DataSourceHandler ()=default
 
void addDataHandler (const std::string &format, const DataSourceLoader &fn)
 
bool loadDataSource (const DataSourcePtr &dataSource)
 
bool hasDataHandler (const DataSourcePtr &dataSource) const
 

Protected Attributes

std::set< PredicateIndicatordefinedRelations_
 
std::set< PredicateIndicatordefinedClasses_
 
int features_
 
- Protected Attributes inherited from knowrob::DataSourceHandler
std::map< std::string, DataSourceLoaderdataSourceHandler_
 

Additional Inherited Members

- Protected Member Functions inherited from knowrob::DataSourceHandler
virtual bool loadDataSourceWithUnknownFormat (const DataSourcePtr &)
 
virtual bool loadDataSourceWithUnknownFormat (const DataSourcePtr &)
 

Detailed Description

A reasoner that supports goal-driven reasoning. Goal-driven reasoning is a form of reasoning where the reasoner is asked to evaluate a query. This is in contrast to data-driven reasoning, where the reasoner is started and then infers additional knowledge from the data.

Definition at line 40 of file GoalDrivenReasoner.h.

Constructor & Destructor Documentation

◆ GoalDrivenReasoner() [1/2]

knowrob::GoalDrivenReasoner::GoalDrivenReasoner ( )
inline

Definition at line 42 of file GoalDrivenReasoner.h.

◆ GoalDrivenReasoner() [2/2]

knowrob::GoalDrivenReasoner::GoalDrivenReasoner ( )
inline

Definition at line 42 of file GoalDrivenReasoner.h.

42 : Reasoner(), features_(0) {}

Member Function Documentation

◆ defineClass() [1/2]

void GoalDrivenReasoner::defineClass ( const IRIAtomPtr iri)

Add a defined class to the reasoner.

Parameters
irian IRI of a RDF class.

Definition at line 47 of file GoalDrivenReasoner.cpp.

47  {
48  KB_DEBUG("Defining class {} in reasoner {}",
49  iri->stringForm(), *reasonerName());
50  definedClasses_.insert(PredicateIndicator(iri->stringForm(), 1));
51 }
#define KB_DEBUG
Definition: Logger.h:25
std::set< PredicateIndicator > definedClasses_
auto & reasonerName() const
Definition: Reasoner.h:37
IRIAtomPtr iri(std::string_view ns, std::string_view name)
Definition: IRIAtom.cpp:62

◆ defineClass() [2/2]

void knowrob::GoalDrivenReasoner::defineClass ( const IRIAtomPtr iri)

Add a defined class to the reasoner.

Parameters
irian IRI of a RDF class.

◆ definedClasses() [1/2]

const auto& knowrob::GoalDrivenReasoner::definedClasses ( ) const
inline
Returns
the set of defined classes.

Definition at line 110 of file GoalDrivenReasoner.h.

110 { return definedClasses_; }

◆ definedClasses() [2/2]

const auto& knowrob::GoalDrivenReasoner::definedClasses ( ) const
inline
Returns
the set of defined classes.

Definition at line 110 of file GoalDrivenReasoner.h.

110 { return definedClasses_; }

◆ definedRelations() [1/2]

const auto& knowrob::GoalDrivenReasoner::definedRelations ( ) const
inline
Returns
the set of defined relations.

Definition at line 105 of file GoalDrivenReasoner.h.

105 { return definedRelations_; }
std::set< PredicateIndicator > definedRelations_

◆ definedRelations() [2/2]

const auto& knowrob::GoalDrivenReasoner::definedRelations ( ) const
inline
Returns
the set of defined relations.

Definition at line 105 of file GoalDrivenReasoner.h.

105 { return definedRelations_; }

◆ defineRelation() [1/4]

void GoalDrivenReasoner::defineRelation ( const IRIAtomPtr iri)

Add a defined relation to the reasoner.

Parameters
irian IRI of a RDF predicate.

Definition at line 35 of file GoalDrivenReasoner.cpp.

35  {
36  KB_DEBUG("Defining relation {} with arity 2 in reasoner {}",
37  iri->stringForm(), *reasonerName());
38  definedRelations_.insert(PredicateIndicator(iri->stringForm(), 2));
39 }

◆ defineRelation() [2/4]

void knowrob::GoalDrivenReasoner::defineRelation ( const IRIAtomPtr iri)

Add a defined relation to the reasoner.

Parameters
irian IRI of a RDF predicate.

◆ defineRelation() [3/4]

void GoalDrivenReasoner::defineRelation ( const PredicateIndicator indicator)

Add a defined relation to the reasoner.

Parameters
indicatora predicate indicator.

Definition at line 29 of file GoalDrivenReasoner.cpp.

29  {
30  KB_DEBUG("Defining relation {} with arity {} in reasoner {}",
31  *indicator.functor(), indicator.arity(), *reasonerName());
32  definedRelations_.insert(indicator);
33 }

◆ defineRelation() [4/4]

void knowrob::GoalDrivenReasoner::defineRelation ( const PredicateIndicator indicator)

Add a defined relation to the reasoner.

Parameters
indicatora predicate indicator.

◆ enableFeature() [1/2]

void GoalDrivenReasoner::enableFeature ( GoalDrivenReasonerFeature  feature)

Enable a specific feature of the reasoner.

Definition at line 17 of file GoalDrivenReasoner.cpp.

17  {
18  features_ = features_ | static_cast<int>(feature);
19 }

◆ enableFeature() [2/2]

void knowrob::GoalDrivenReasoner::enableFeature ( GoalDrivenReasonerFeature  feature)

Enable a specific feature of the reasoner.

◆ evaluate() [1/2]

virtual bool knowrob::GoalDrivenReasoner::evaluate ( GoalPtr  query)
pure virtual

Evaluate a query with a reasoner. The query is represented by a formula, a context and an answer queue where results of the reasoning process can be added. The evaluation of the query must be performed synchronously, i.e. the answer queue must be filled before the function returns. A reasoner may instead throw an exception if the query cannot be evaluated, or return false to also indicate an error status.

Parameters
querythe query to evaluate.
Returns
true on success, false otherwise.

Implemented in knowrob::RDFGoalReasoner, knowrob::PrologReasoner, knowrob::RDFGoalReasoner, and knowrob::PrologReasoner.

◆ evaluate() [2/2]

virtual bool knowrob::GoalDrivenReasoner::evaluate ( GoalPtr  query)
pure virtual

Evaluate a query with a reasoner. The query is represented by a formula, a context and an answer queue where results of the reasoning process can be added. The evaluation of the query must be performed synchronously, i.e. the answer queue must be filled before the function returns. A reasoner may instead throw an exception if the query cannot be evaluated, or return false to also indicate an error status.

Parameters
querythe query to evaluate.
Returns
true on success, false otherwise.

Implemented in knowrob::RDFGoalReasoner, knowrob::PrologReasoner, knowrob::RDFGoalReasoner, and knowrob::PrologReasoner.

◆ hasFeature() [1/2]

bool GoalDrivenReasoner::hasFeature ( GoalDrivenReasonerFeature  feature) const
Returns
true if the reasoner supports a specific feature.

Definition at line 13 of file GoalDrivenReasoner.cpp.

13  {
14  return (features_ & static_cast<int>(feature)) != 0;
15 }

◆ hasFeature() [2/2]

bool knowrob::GoalDrivenReasoner::hasFeature ( GoalDrivenReasonerFeature  feature) const
Returns
true if the reasoner supports a specific feature.

◆ isClassDefined() [1/2]

bool GoalDrivenReasoner::isClassDefined ( const std::string_view &  iri)

Find out if the class is defined by this reasoner. A defined class is a class that is known to the reasoner, and for which the reasoner can provide additional groundings when being queried.

Parameters
iria class IRI.
Returns
true if the class is currently defined by this reasoner.

Definition at line 25 of file GoalDrivenReasoner.cpp.

25  {
26  return definedClasses_.find(PredicateIndicator(iri, 1)) != definedClasses_.end();
27 }

◆ isClassDefined() [2/2]

bool knowrob::GoalDrivenReasoner::isClassDefined ( const std::string_view &  iri)

Find out if the class is defined by this reasoner. A defined class is a class that is known to the reasoner, and for which the reasoner can provide additional groundings when being queried.

Parameters
iria class IRI.
Returns
true if the class is currently defined by this reasoner.

◆ isRelationDefined() [1/2]

bool GoalDrivenReasoner::isRelationDefined ( const PredicateIndicator indicator)

Find out if the relation is defined by this reasoner. A defined relation is a relation that is known to the reasoner, and for which the reasoner can provide additional groundings when being queried.

Parameters
indicatora predicate indicator.
Returns
true if the relation is currently defined by this reasoner.

Definition at line 21 of file GoalDrivenReasoner.cpp.

21  {
22  return definedRelations_.count(indicator) > 0;
23 }

◆ isRelationDefined() [2/2]

bool knowrob::GoalDrivenReasoner::isRelationDefined ( const PredicateIndicator indicator)

Find out if the relation is defined by this reasoner. A defined relation is a relation that is known to the reasoner, and for which the reasoner can provide additional groundings when being queried.

Parameters
indicatora predicate indicator.
Returns
true if the relation is currently defined by this reasoner.

◆ undefineClass() [1/2]

void GoalDrivenReasoner::undefineClass ( const IRIAtomPtr iri)

Remove a defined class from the reasoner.

Parameters
irian IRI of a RDF class.

Definition at line 53 of file GoalDrivenReasoner.cpp.

53  {
54  KB_DEBUG("Undefining class {} in reasoner {}",
55  iri->stringForm(), *reasonerName());
56  definedClasses_.erase(PredicateIndicator(iri->stringForm(), 1));
57 }

◆ undefineClass() [2/2]

void knowrob::GoalDrivenReasoner::undefineClass ( const IRIAtomPtr iri)

Remove a defined class from the reasoner.

Parameters
irian IRI of a RDF class.

◆ undefineRelation() [1/2]

void GoalDrivenReasoner::undefineRelation ( const PredicateIndicator indicator)

Remove a defined relation from the reasoner.

Parameters
indicatora predicate indicator.

Definition at line 41 of file GoalDrivenReasoner.cpp.

41  {
42  KB_DEBUG("Undefining relation {} with arity {} in reasoner {}",
43  *indicator.functor(), indicator.arity(), *reasonerName());
44  definedRelations_.erase(indicator);
45 }

◆ undefineRelation() [2/2]

void knowrob::GoalDrivenReasoner::undefineRelation ( const PredicateIndicator indicator)

Remove a defined relation from the reasoner.

Parameters
indicatora predicate indicator.

Member Data Documentation

◆ definedClasses_

std::set< PredicateIndicator > knowrob::GoalDrivenReasoner::definedClasses_
protected

Definition at line 127 of file GoalDrivenReasoner.h.

◆ definedRelations_

std::set< PredicateIndicator > knowrob::GoalDrivenReasoner::definedRelations_
protected

Definition at line 126 of file GoalDrivenReasoner.h.

◆ features_

int knowrob::GoalDrivenReasoner::features_
protected

Definition at line 128 of file GoalDrivenReasoner.h.


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