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

#include <Term.h>

Inheritance diagram for knowrob::Term:
Collaboration diagram for knowrob::Term:

Public Member Functions

 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
 
virtual const std::set< std::string_view > & variables () const =0
 
 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
 
virtual const std::set< std::string_view > & variables () const =0
 
- Public Member Functions inherited from knowrob::Printable
virtual ~Printable ()=default
 
virtual void write (std::ostream &os) const =0
 
virtual std::string format () const
 
virtual ~Printable ()=default
 
virtual void write (std::ostream &os) const =0
 
virtual std::string format () const
 

Protected Attributes

const TermType termType_
 
bool isBlank_ = false
 
bool isIRI_ = false
 

Static Protected Attributes

static const std::set< std::string_view > noVariables_ = {}
 

Detailed Description

Terms are used as components of formulas and are recursively constructed over the set of constants, variables, and function symbols.

Definition at line 31 of file Term.h.

Constructor & Destructor Documentation

◆ Term() [1/2]

knowrob::Term::Term ( TermType  termType)
inlineexplicit

Definition at line 33 of file Term.h.

33 : termType_(termType) {};
const TermType termType_
Definition: Term.h:111
TermType termType() const
Definition: Term.h:52

◆ ~Term() [1/2]

knowrob::Term::~Term ( )
overridedefault

◆ Term() [2/2]

knowrob::Term::Term ( TermType  termType)
inlineexplicit

Definition at line 33 of file Term.h.

33 : termType_(termType) {};

◆ ~Term() [2/2]

knowrob::Term::~Term ( )
overridedefault

Member Function Documentation

◆ hash() [1/2]

size_t Term::hash ( ) const
Returns
the hash of this.

Definition at line 38 of file Term.cpp.

38  {
39  size_t val = 0;
40  hashCombine(val, uint8_t(termType()));
41  switch (termType()) {
42  case TermType::ATOMIC:
43  hashCombine(val, ((Atomic *) this)->hashOfAtomic());
44  break;
45  case TermType::FUNCTION:
46  hashCombine(val, ((Function *) this)->hashOfFunction());
47  break;
48  case TermType::VARIABLE:
49  hashCombine(val, std::hash<std::string_view>{}(((Variable *) this)->name()));
50  break;
51  }
52  return val;
53 }
void hashCombine(std::size_t &seed, const std::size_t &v)
Definition: knowrob.cpp:39

◆ hash() [2/2]

size_t knowrob::Term::hash ( ) const
Returns
the hash of this.

◆ isAtom() [1/2]

bool Term::isAtom ( ) const
Returns
true if this term is an atom.

Definition at line 18 of file Term.cpp.

18  {
19  return termType() == TermType::ATOMIC && ((Atomic *) this)->atomicType() == AtomicType::ATOM;
20 }

◆ isAtom() [2/2]

bool knowrob::Term::isAtom ( ) const
Returns
true if this term is an atom.

◆ isAtomic() [1/2]

bool knowrob::Term::isAtomic ( ) const
inline
Returns
true if this term is bound and not compound.

Definition at line 62 of file Term.h.

62 { return termType_ == TermType::ATOMIC; }

◆ isAtomic() [2/2]

bool knowrob::Term::isAtomic ( ) const
inline
Returns
true if this term is bound and not compound.

Definition at line 62 of file Term.h.

62 { return termType_ == TermType::ATOMIC; }

◆ isBlank() [1/2]

bool knowrob::Term::isBlank ( ) const
inline
Returns
true if this term is a blank node.

Definition at line 97 of file Term.h.

97 { return isBlank_; }
bool isBlank_
Definition: Term.h:112

◆ isBlank() [2/2]

bool knowrob::Term::isBlank ( ) const
inline
Returns
true if this term is a blank node.

Definition at line 97 of file Term.h.

97 { return isBlank_; }

◆ isFunction() [1/2]

bool Term::isFunction ( ) const
Returns
true if this term is a function.

Definition at line 26 of file Term.cpp.

26  {
27  return termType() == TermType::FUNCTION;
28 }

◆ isFunction() [2/2]

bool knowrob::Term::isFunction ( ) const
Returns
true if this term is a function.

◆ isGround() [1/2]

bool knowrob::Term::isGround ( ) const
inline
Returns
true if this term has no variables.

Definition at line 57 of file Term.h.

57 { return variables().empty(); }
virtual const std::set< std::string_view > & variables() const =0

◆ isGround() [2/2]

bool knowrob::Term::isGround ( ) const
inline
Returns
true if this term has no variables.

Definition at line 57 of file Term.h.

57 { return variables().empty(); }

◆ isIRI() [1/2]

bool knowrob::Term::isIRI ( ) const
inline
Returns
true if this term is an IRI.

Definition at line 92 of file Term.h.

92 { return isIRI_; }
bool isIRI_
Definition: Term.h:113

◆ isIRI() [2/2]

bool knowrob::Term::isIRI ( ) const
inline
Returns
true if this term is an IRI.

Definition at line 92 of file Term.h.

92 { return isIRI_; }

◆ isNumeric() [1/2]

bool Term::isNumeric ( ) const
Returns
true if this term is a numeric.

Definition at line 30 of file Term.cpp.

30  {
31  return termType() == TermType::ATOMIC && ((Atomic *) this)->atomicType() == AtomicType::NUMERIC;
32 }

◆ isNumeric() [2/2]

bool knowrob::Term::isNumeric ( ) const
Returns
true if this term is a numeric.

◆ isString() [1/2]

bool Term::isString ( ) const
Returns
true if this term is a string.

Definition at line 34 of file Term.cpp.

34  {
35  return termType() == TermType::ATOMIC && ((Atomic *) this)->atomicType() == AtomicType::STRING;
36 }

◆ isString() [2/2]

bool knowrob::Term::isString ( ) const
Returns
true if this term is a string.

◆ isVariable() [1/2]

bool Term::isVariable ( ) const
Returns
true if this term is a variable.

Definition at line 22 of file Term.cpp.

22  {
23  return termType() == TermType::VARIABLE;
24 }

◆ isVariable() [2/2]

bool knowrob::Term::isVariable ( ) const
Returns
true if this term is a variable.

◆ operator!=() [1/2]

bool knowrob::Term::operator!= ( const Term other) const
inline
Parameters
otheranother term
Returns
true if both terms are not equal

Definition at line 47 of file Term.h.

47 { return !this->operator==(other); }
bool operator==(const Term &other) const
Definition: Term.cpp:55

◆ operator!=() [2/2]

bool knowrob::Term::operator!= ( const Term other) const
inline
Parameters
otheranother term
Returns
true if both terms are not equal

Definition at line 47 of file Term.h.

47 { return !this->operator==(other); }

◆ operator==() [1/2]

bool Term::operator== ( const Term other) const
Parameters
otheranother term
Returns
true if both terms are equal

Definition at line 55 of file Term.cpp.

55  {
56  if (this == &other) return true;
57  if (termType() != other.termType()) return false;
58  switch (termType()) {
59  case TermType::ATOMIC:
60  return ((Atomic *) this)->isSameAtomic(*((Atomic *) &other));
61  case TermType::VARIABLE:
62  return ((Variable *) this)->isSameVariable(*((Variable *) &other));
63  case TermType::FUNCTION:
64  return ((Function *) this)->isSameFunction(*((Function *) &other));
65  }
66  return false;
67 }

◆ operator==() [2/2]

bool knowrob::Term::operator== ( const Term other) const
Parameters
otheranother term
Returns
true if both terms are equal

◆ termType() [1/2]

TermType knowrob::Term::termType ( ) const
inline
Returns
the type of this term.

Definition at line 52 of file Term.h.

52 { return termType_; }

◆ termType() [2/2]

TermType knowrob::Term::termType ( ) const
inline
Returns
the type of this term.

Definition at line 52 of file Term.h.

52 { return termType_; }

◆ variables() [1/2]

virtual const std::set<std::string_view>& knowrob::Term::variables ( ) const
pure virtual
Returns
set of variables of this term.

Implemented in knowrob::Variable, knowrob::Function, knowrob::Variable, knowrob::Function, knowrob::Atomic, and knowrob::Atomic.

◆ variables() [2/2]

virtual const std::set<std::string_view>& knowrob::Term::variables ( ) const
pure virtual
Returns
set of variables of this term.

Implemented in knowrob::Variable, knowrob::Function, knowrob::Variable, knowrob::Function, knowrob::Atomic, and knowrob::Atomic.

Member Data Documentation

◆ isBlank_

bool knowrob::Term::isBlank_ = false
protected

Definition at line 112 of file Term.h.

◆ isIRI_

bool knowrob::Term::isIRI_ = false
protected

Definition at line 113 of file Term.h.

◆ noVariables_

const std::set< std::string_view > Term::noVariables_ = {}
staticprotected

Definition at line 110 of file Term.h.

◆ termType_

const TermType knowrob::Term::termType_
protected

Definition at line 111 of file Term.h.


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