6 #include "knowrob/semweb/GraphQuery.h"
7 #include "knowrob/semweb/GraphPattern.h"
8 #include "knowrob/semweb/GraphSequence.h"
9 #include "knowrob/formulas/Negation.h"
10 #include "knowrob/formulas/Disjunction.h"
11 #include "knowrob/semweb/GraphUnion.h"
12 #include "knowrob/formulas/Conjunction.h"
13 #include "knowrob/integration/python/utils.h"
18 auto ctx = std::make_shared<QueryContext>();
20 query->getTripleFrame(ctx->selector);
30 :
Query(createQueryContext(query)),
42 auto sequence = std::static_pointer_cast<GraphSequence>(
term_);
43 for (
auto &p: query) {
44 sequence->addPattern(p);
49 switch (
term->termType()) {
53 return std::make_shared<Negation>(
pattern->predicate());
60 std::vector<FormulaPtr> formulae;
61 for (
const auto &t: terms) {
62 auto phi = toFormula_recursive(t.get());
64 formulae.push_back(phi);
67 return std::make_shared<Disjunction>(formulae);
71 std::vector<FormulaPtr> formulae;
72 for (
const auto &t: terms) {
73 auto phi = toFormula_recursive(t.get());
75 formulae.push_back(phi);
78 return std::make_shared<Conjunction>(formulae);
87 return toFormula_recursive(
term_.get());
101 class_<GraphQuery, std::shared_ptr<GraphQuery>, boost::noncopyable>
102 (
"GraphQuery", init<const std::shared_ptr<GraphTerm> &>())
103 .def(init<
const std::shared_ptr<GraphTerm> &,
const QueryContextPtr &>())
104 .def(init<const TriplePatternPtr &>())
105 .def(init<const TriplePatternPtr &, const QueryContextPtr &>())
106 .def(init<
const std::vector<TriplePatternPtr> &,
const QueryContextPtr &>())
FormulaPtr toFormula() const
std::shared_ptr< GraphTerm > term_
GraphQuery(const std::shared_ptr< GraphTerm > &query, const QueryContextPtr &ctx=DefaultQueryContext())
void write(std::ostream &os) const override
GraphTermRule & pattern()
void createType< GraphQuery >()
void createType< GraphTerm >()
std::shared_ptr< TriplePattern > TriplePatternPtr
@ QUERY_FLAG_ALL_SOLUTIONS
std::shared_ptr< Formula > FormulaPtr
std::shared_ptr< const QueryContext > QueryContextPtr