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

#include <Goal.h>

Inheritance diagram for knowrob::Goal:
Collaboration diagram for knowrob::Goal:

Public Member Functions

 Goal (SimpleConjunctionPtr formula, QueryContextPtr ctx=DefaultQueryContext())
 
 Goal (const FirstOrderLiteralPtr &literal, QueryContextPtr ctx=DefaultQueryContext())
 
 Goal (SimpleConjunctionPtr formula, const Goal &goal)
 
 ~Goal () override
 
auto & formula () const
 
void push (const AnswerPtr &answer)
 
void push (const BindingsPtr &bindings)
 
void finish ()
 
auto & answerBuffer () const
 
auto & outputChannel () const
 
 Goal (SimpleConjunctionPtr formula, QueryContextPtr ctx=DefaultQueryContext())
 
 Goal (const FirstOrderLiteralPtr &literal, QueryContextPtr ctx=DefaultQueryContext())
 
 Goal (SimpleConjunctionPtr formula, const Goal &goal)
 
 ~Goal () override
 
auto & formula () const
 
void push (const AnswerPtr &answer)
 
void push (const BindingsPtr &bindings)
 
void finish ()
 
auto & answerBuffer () const
 
auto & outputChannel () const
 
- Public Member Functions inherited from knowrob::Query
 Query (QueryContextPtr ctx=DefaultQueryContext())
 
virtual ~Query ()=default
 
auto & ctx () const
 
void setContext (QueryContextPtr ctx)
 
 Query (QueryContextPtr ctx=DefaultQueryContext())
 
virtual ~Query ()=default
 
auto & ctx () const
 
void setContext (QueryContextPtr ctx)
 
- Public Member Functions inherited from knowrob::Printable
virtual ~Printable ()=default
 
virtual std::string format () const
 
virtual ~Printable ()=default
 
virtual std::string format () const
 

Protected Member Functions

void write (std::ostream &os) const override
 
void write (std::ostream &os) const override
 

Protected Attributes

std::shared_ptr< const QueryContextctx_
 
std::shared_ptr< TokenBufferanswerBuffer_
 
std::shared_ptr< TokenStream::ChanneloutputChannel_
 
std::shared_ptr< SimpleConjunctionformula_
 
- Protected Attributes inherited from knowrob::Query
QueryContextPtr ctx_
 

Detailed Description

A query that can be submitted to a reasoner.

Definition at line 20 of file Goal.h.

Constructor & Destructor Documentation

◆ Goal() [1/6]

Goal::Goal ( SimpleConjunctionPtr  formula,
QueryContextPtr  ctx = DefaultQueryContext() 
)
explicit
Parameters
formulaa formula.
ctxa query context.

Definition at line 57 of file Goal.cpp.

58  : Query(ctx),
59  ctx_(std::move(ctx)),
60  answerBuffer_(std::make_shared<TokenBuffer>()),
62  formula_(std::move(formula)) {}
std::shared_ptr< const QueryContext > ctx_
Definition: Goal.h:75
std::shared_ptr< TokenStream::Channel > outputChannel_
Definition: Goal.h:77
auto & formula() const
Definition: Goal.h:45
std::shared_ptr< TokenBuffer > answerBuffer_
Definition: Goal.h:76
std::shared_ptr< SimpleConjunction > formula_
Definition: Goal.h:78
auto & ctx() const
Definition: Query.h:41
Query(QueryContextPtr ctx=DefaultQueryContext())
Definition: Query.h:34
static std::shared_ptr< Channel > create(const std::shared_ptr< TokenStream > &stream)
Definition: TokenStream.cpp:88

◆ Goal() [2/6]

Goal::Goal ( const FirstOrderLiteralPtr literal,
QueryContextPtr  ctx = DefaultQueryContext() 
)
explicit
Parameters
literala literal.
ctxa query context.

Definition at line 64 of file Goal.cpp.

65  : Query(ctx),
66  ctx_(std::move(ctx)),
67  answerBuffer_(std::make_shared<TokenBuffer>()),
69  formula_(std::make_shared<SimpleConjunction>(literal)) {}

◆ Goal() [3/6]

Goal::Goal ( SimpleConjunctionPtr  formula,
const Goal goal 
)
Parameters
formulaa formula.
goala goal.

Definition at line 50 of file Goal.cpp.

51  : Query(goal.ctx_),
52  ctx_(goal.ctx_),
55  formula_(std::move(formula)) {}

◆ ~Goal() [1/2]

Goal::~Goal ( )
override

Definition at line 71 of file Goal.cpp.

71  {
72  outputChannel_->close();
73 }

◆ Goal() [4/6]

knowrob::Goal::Goal ( SimpleConjunctionPtr  formula,
QueryContextPtr  ctx = DefaultQueryContext() 
)
explicit
Parameters
formulaa formula.
ctxa query context.

◆ Goal() [5/6]

knowrob::Goal::Goal ( const FirstOrderLiteralPtr literal,
QueryContextPtr  ctx = DefaultQueryContext() 
)
explicit
Parameters
literala literal.
ctxa query context.

◆ Goal() [6/6]

knowrob::Goal::Goal ( SimpleConjunctionPtr  formula,
const Goal goal 
)
Parameters
formulaa formula.
goala goal.

◆ ~Goal() [2/2]

knowrob::Goal::~Goal ( )
override

Member Function Documentation

◆ answerBuffer() [1/2]

auto& knowrob::Goal::answerBuffer ( ) const
inline
Returns
the answer buffer.

Definition at line 67 of file Goal.h.

67 { return answerBuffer_; }

◆ answerBuffer() [2/2]

auto& knowrob::Goal::answerBuffer ( ) const
inline
Returns
the answer buffer.

Definition at line 67 of file Goal.h.

67 { return answerBuffer_; }

◆ finish() [1/2]

void knowrob::Goal::finish ( )
inline

Indicates that the evaluation has finished.

Definition at line 62 of file Goal.h.

◆ finish() [2/2]

void knowrob::Goal::finish ( )
inline

Indicates that the evaluation has finished.

Definition at line 62 of file Goal.h.

◆ formula() [1/2]

auto& knowrob::Goal::formula ( ) const
inline
Returns
the literal.

Definition at line 45 of file Goal.h.

45 { return formula_; }

◆ formula() [2/2]

auto& knowrob::Goal::formula ( ) const
inline
Returns
the literal.

Definition at line 45 of file Goal.h.

45 { return formula_; }

◆ outputChannel() [1/2]

auto& knowrob::Goal::outputChannel ( ) const
inline
Returns
the output channel.

Definition at line 72 of file Goal.h.

72 { return outputChannel_; }

◆ outputChannel() [2/2]

auto& knowrob::Goal::outputChannel ( ) const
inline
Returns
the output channel.

Definition at line 72 of file Goal.h.

72 { return outputChannel_; }

◆ push() [1/4]

void Goal::push ( const AnswerPtr answer)

Pushes an answer into the output channel.

Parameters
answeran answer.

Definition at line 75 of file Goal.cpp.

75  {
76  outputChannel_->push(answer);
77 }

◆ push() [2/4]

void knowrob::Goal::push ( const AnswerPtr answer)

Pushes an answer into the output channel.

Parameters
answeran answer.

◆ push() [3/4]

void Goal::push ( const BindingsPtr bindings)

Pushes a positive answer into the output channel.

Parameters
bindingsthe bindings under which the query is true.

Definition at line 79 of file Goal.cpp.

79  {
80  auto filteredBindings = includeOnly(bindings, formula_);
81  auto yes = std::make_shared<AnswerYes>(filteredBindings);
82  for (const auto &lit : formula_->literals()) {
83  auto instance = applyBindings(lit->predicate(), *filteredBindings);
84  yes->addGrounding(std::static_pointer_cast<Predicate>(instance), lit->isNegated());
85  }
86  push(yes);
87 }
void push(const AnswerPtr &answer)
Definition: Goal.cpp:75
FirstOrderLiteralPtr applyBindings(const FirstOrderLiteralPtr &lit, const Bindings &bindings)

◆ push() [4/4]

void knowrob::Goal::push ( const BindingsPtr bindings)

Pushes a positive answer into the output channel.

Parameters
bindingsthe bindings under which the query is true.

◆ write() [1/2]

void knowrob::Goal::write ( std::ostream &  os) const
inlineoverrideprotectedvirtual

Print this object to a stream.

Parameters
osthe stream to print to.

Implements knowrob::Printable.

Definition at line 81 of file Goal.h.

81 { os << *formula_; }

◆ write() [2/2]

void knowrob::Goal::write ( std::ostream &  os) const
inlineoverrideprotectedvirtual

Print this object to a stream.

Parameters
osthe stream to print to.

Implements knowrob::Printable.

Definition at line 81 of file Goal.h.

81 { os << *formula_; }

Member Data Documentation

◆ answerBuffer_

std::shared_ptr< TokenBuffer > knowrob::Goal::answerBuffer_
protected

Definition at line 76 of file Goal.h.

◆ ctx_

std::shared_ptr< const QueryContext > knowrob::Goal::ctx_
protected

Definition at line 75 of file Goal.h.

◆ formula_

std::shared_ptr< SimpleConjunction > knowrob::Goal::formula_
protected

Definition at line 78 of file Goal.h.

◆ outputChannel_

std::shared_ptr< TokenStream::Channel > knowrob::Goal::outputChannel_
protected

Definition at line 77 of file Goal.h.


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