6 #include "knowrob/reasoner/Goal.h"
7 #include "knowrob/integration/python/utils.h"
8 #include "knowrob/queries/AnswerYes.h"
9 #include "knowrob/reasoner/RDFGoal.h"
16 bool hasExtraVars = bindings->size() > vars.size();
18 for (
const auto &
var : *bindings) {
19 if (vars.find(
var.first) == vars.end()) {
27 auto filtered = std::make_shared<Bindings>();
28 for (
const auto &
var : vars) {
29 auto it = bindings->find(
var);
30 if (it != bindings->end()) {
31 filtered->set(it->second.first, it->second.second);
41 std::set<std::string_view> vars;
42 for (
const auto &lit :
formula->literals()) {
43 for (
const auto &
var : lit->predicate()->variables()) {
47 return includeOnly(bindings, vars);
53 answerBuffer_(goal.answerBuffer_),
54 outputChannel_(goal.outputChannel_),
61 outputChannel_(
TokenStream::Channel::create(answerBuffer_)),
68 outputChannel_(
TokenStream::Channel::create(answerBuffer_)),
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());
97 class_<Goal, std::shared_ptr<Goal>, boost::noncopyable>
98 (
"Goal", init<TriplePatternPtr, QueryContextPtr>())
99 .def(
"formula", &
Goal::formula, return_value_policy<copy_const_reference>())
100 .def(
"answerBuffer", &
Goal::answerBuffer, return_value_policy<copy_const_reference>())
101 .def(
"ctx", &
Query::ctx, return_value_policy<copy_const_reference>())
102 .def(
"push", with<no_gil>(
static_cast<Push1
>(&
Goal::push)))
103 .def(
"push", with<no_gil>(
static_cast<Push2
>(&
Goal::push)));
std::shared_ptr< TokenStream::Channel > outputChannel_
auto & answerBuffer() const
void push(const AnswerPtr &answer)
Goal(SimpleConjunctionPtr formula, QueryContextPtr ctx=DefaultQueryContext())
std::shared_ptr< SimpleConjunction > formula_
void createType< RDFGoal >()
void createType< Goal >()
std::shared_ptr< SimpleConjunction > SimpleConjunctionPtr
std::shared_ptr< const Bindings > BindingsPtr
std::shared_ptr< const QueryContext > QueryContextPtr
std::shared_ptr< const Answer > AnswerPtr
FirstOrderLiteralPtr applyBindings(const FirstOrderLiteralPtr &lit, const Bindings &bindings)
std::shared_ptr< FirstOrderLiteral > FirstOrderLiteralPtr