knowrob  2.1.0
A Knowledge Base System for Cognition-enabled Robots
knowrob::py Namespace Reference

Classes

struct  DictToMapConverter
 
struct  dict_map_converter
 
struct  list_to_pylist
 
struct  python_optional
 
struct  PairToTupleConverter
 
struct  string_view_to_python_str
 
struct  python_str_to_string_view
 
struct  custom_vector_from_seq
 
struct  no_gil
 
class  gil_lock
 
class  PyObj_wrap
 
class  guarded_function
 
struct  mpl_signature
 
struct  mpl_signature< boost::function< Signature > >
 

Functions

boost::any python_to_boost_any (const boost::python::object &obj)
 
std::unordered_map< std::string, boost::any > dict_to_map (const boost::python::dict &py_dict)
 
void register_dict_to_map_converter ()
 
void register_list_converter ()
 
void register_pair_converter ()
 
void register_string_view_converter ()
 
template<typename R , typename... Args>
call_method (PyObject *self, const char *method, Args... args)
 
template<typename R >
call (const std::function< R()> &goal)
 
template<typename R >
call_with_gil (const std::function< R()> &goal)
 
std::string resolveModulePath (std::string_view modulePath)
 
std::string addToSysPath (const std::filesystem::path &modulePath)
 
template<typename T >
void createType ()
 
template<typename Guard , typename Fn , typename Policy >
boost::python::object with_aux (Fn fn, const Policy &policy)
 
template<typename Guard , typename Fn , typename Policy >
boost::python::object with (const Fn &fn, const Policy &policy)
 
template<typename Guard , typename Fn >
boost::python::object with (const Fn &fn)
 Create a callable object with guards. More...
 
void staticKnowRobModuleInit ()
 
template<>
void createType< DataSource > ()
 
template<>
void createType< DataSourceHandler > ()
 
template<>
void createType< Bottom > ()
 
template<>
void createType< CompoundFormula > ()
 
template<>
void createType< Conjunction > ()
 
template<>
void createType< Disjunction > ()
 
template<>
void createType< FirstOrderLiteral > ()
 
template<>
void createType< Formula > ()
 
template<>
void createType< Implication > ()
 
template<>
void createType< ModalFormula > ()
 
template<>
void createType< ModalOperator > ()
 
template<>
void createType< Negation > ()
 
template<>
void createType< Predicate > ()
 
template<>
void createType< PredicateIndicator > ()
 
template<>
void createType< SimpleConjunction > ()
 
template<>
void createType< Top > ()
 
template<>
void createType< InterfaceUtils > ()
 
template<>
void createType< KnowledgeBase > ()
 
template<>
void createType< Logger > ()
 
template<>
void createType< PropertyTree > ()
 
template<>
void createType< Answer > ()
 
template<>
void createType< AnswerDontKnow > ()
 
template<>
void createType< AnswerNo > ()
 
template<>
void createType< AnswerYes > ()
 
template<>
void createType< ConjunctiveQuery > ()
 
template<>
void createType< QueryContext > ()
 
template<>
void createType< QueryParser > ()
 
template<>
void createType< Token > ()
 
template<>
void createType< TokenBroadcaster > ()
 
template<>
void createType< TokenBuffer > ()
 
template<>
void createType< TokenQueue > ()
 
template<>
void createType< TokenStream > ()
 
template<>
void createType< DataDrivenReasoner > ()
 
template<>
void createType< Goal > ()
 
template<>
void createType< GoalDrivenReasoner > ()
 
template<>
void createType< RDFGoal > ()
 
template<>
void createType< RDFGoalReasoner > ()
 
template<>
void createType< Reasoner > ()
 
template<>
void createType< reasoner::Event > ()
 
template<>
void createType< semweb::Class > ()
 
template<>
void createType< GraphBuiltin > ()
 
template<>
void createType< GraphQuery > ()
 
template<>
void createType< GraphSelector > ()
 
template<>
void createType< GraphSequence > ()
 
std::shared_ptr< GraphTermapplyBindings_graph (const std::shared_ptr< GraphTerm > &term, const Bindings &bindings)
 
template<>
void createType< GraphTerm > ()
 
template<>
void createType< GraphUnion > ()
 
template<>
void createType< ImportHierarchy > ()
 
template<>
void createType< Perspective > ()
 
template<>
void createType< semweb::Property > ()
 
template<>
void createType< semweb::Resource > ()
 
template<>
void createType< Triple > ()
 
template<>
void createType< TripleContainer > ()
 
template<>
void createType< TriplePattern > ()
 
template<>
void createType< Vocabulary > ()
 
template<>
void createType< Observer > ()
 
template<>
void createType< QueryableStorage > ()
 
template<>
void createType< Storage > ()
 
template<>
void createType< Atom > ()
 
template<>
void createType< Atomic > ()
 
TermPtr applyBindings_t (const TermPtr &t, const Bindings &bindings)
 
FormulaPtr applyBindings_phi (const FormulaPtr &phi, const Bindings &bindings)
 
template<>
void createType< Bindings > ()
 
template<>
void createType< Blank > ()
 
template<>
void createType< Function > ()
 
template<>
void createType< IRIAtom > ()
 
template<>
void createType< ListTerm > ()
 
template<>
void createType< Numeric > ()
 
template<>
void createType< RDFNode > ()
 
template<>
void createType< String > ()
 
template<>
void createType< Term > ()
 
template<>
void createType< Variable > ()
 
template<>
void createType< XSDAtomic > ()
 

Function Documentation

◆ addToSysPath()

std::string knowrob::py::addToSysPath ( const std::filesystem::path &  modulePath)

Make sure that a Python file at path can be imported.

Parameters
modulePaththe path to add.
Returns
the import string needed to import the module.

Definition at line 25 of file utils.cpp.

25  {
26  static std::set<std::filesystem::path> moduleDirectories;
27 
28  auto topmostPythonPath = modulePath.parent_path();
29  std::list<std::string> modulePathParts;
30  modulePathParts.push_front(modulePath.stem().string());
31  while(!topmostPythonPath.empty() && std::filesystem::exists(topmostPythonPath / "__init__.py")) {
32  modulePathParts.push_front(topmostPythonPath.stem().string());
33  topmostPythonPath = topmostPythonPath.parent_path();
34  }
35  std::stringstream ss;
36  for (auto it = modulePathParts.begin(); it != modulePathParts.end(); ++it) {
37  ss << *it;
38  if (it != --modulePathParts.end()) {
39  ss << ".";
40  }
41  }
42  auto relativeModulePath = ss.str();
43 
44  // make sure that the module directory is only added once
45  if (moduleDirectories.count(topmostPythonPath) == 0) {
46  moduleDirectories.insert(topmostPythonPath);
47  // >>> sys.path.append(moduleDir)
48  auto py_sys = boost::python::import("sys");
49  auto py_path = py_sys.attr("path");
50  auto sysPathAppend = py_path.attr("append");
51  sysPathAppend(topmostPythonPath.string());
52  KB_DEBUG("[python] Added '{}' to sys.path.", topmostPythonPath.string().c_str());
53  }
54 
55  return relativeModulePath;
56  }
#define KB_DEBUG
Definition: Logger.h:25

◆ applyBindings_graph()

std::shared_ptr<GraphTerm> knowrob::py::applyBindings_graph ( const std::shared_ptr< GraphTerm > &  term,
const Bindings bindings 
)

Definition at line 85 of file GraphTerm.cpp.

85  {
86  return applyBindings(term, bindings);
87  }
TermRule & term()
Definition: terms.cpp:136
FirstOrderLiteralPtr applyBindings(const FirstOrderLiteralPtr &lit, const Bindings &bindings)

◆ applyBindings_phi()

FormulaPtr knowrob::py::applyBindings_phi ( const FormulaPtr phi,
const Bindings bindings 
)

Definition at line 290 of file Bindings.cpp.

290  {
291  return applyBindings(phi, bindings);
292  }

◆ applyBindings_t()

TermPtr knowrob::py::applyBindings_t ( const TermPtr t,
const Bindings bindings 
)

Definition at line 286 of file Bindings.cpp.

286  {
287  return applyBindings(t, bindings);
288  }

◆ call()

template<typename R >
R knowrob::py::call ( const std::function< R()> &  goal)

Call a function and translate boost::python::error_already_set exceptions into PythonError.

Parameters
goalthe function to call.

Definition at line 29 of file utils.h.

29  {
30  try {
31  return goal();
32  } catch(const boost::python::error_already_set&) {
33  throw PythonError();
34  }
35  }

◆ call_method()

template<typename R , typename... Args>
R knowrob::py::call_method ( PyObject *  self,
const char *  method,
Args...  args 
)

Definition at line 17 of file utils.h.

17  {
18  try {
19  return boost::python::call_method<R>(self, method, boost::python::object(args)...);
20  } catch(const boost::python::error_already_set&) {
21  throw PythonError();
22  }
23  }

◆ call_with_gil()

template<typename R >
R knowrob::py::call_with_gil ( const std::function< R()> &  goal)

Same as call but locks the GIL before performing the call.

Parameters
goalthe function to call.

Definition at line 41 of file utils.h.

41  {
42  py::gil_lock lock;
43  return call(goal);
44  }
R call(const std::function< R()> &goal)
Definition: utils.h:29

◆ createType()

template<typename T >
void knowrob::py::createType ( )

A template function to create a new type in Python.

Template Parameters
TThe C++ type to map into Python.

◆ createType< Answer >()

template<>
void knowrob::py::createType< Answer > ( )

Definition at line 163 of file Answer.cpp.

163  {
164  using namespace boost::python;
165  class_<Answer, std::shared_ptr<Answer>, boost::noncopyable, bases<Token>>
166  ("Answer", no_init)
167  .def("__str__", &AnswerYes::humanReadableForm)
168  .def("isPositive", &Answer::isPositive)
169  .def("isNegative", &Answer::isNegative)
170  .def("isCertain", &Answer::isCertain)
171  .def("isUncertain", &Answer::isUncertain)
172  .def("isOccasionallyTrue", &Answer::isOccasionallyTrue)
173  .def("setIsOccasionallyTrue", &Answer::setIsOccasionallyTrue)
174  .def("setIsUncertain", &Answer::setIsUncertain)
175  .def("setFrame", &Answer::setFrame)
176  .def("frame", &Answer::frame, return_value_policy<copy_const_reference>())
177  .def("reasonerTerm", &Answer::reasonerTerm, return_value_policy<copy_const_reference>());
178  // Allow implicit conversion from shared_ptr<Answer> to shared_ptr<const Answer>
179  register_ptr_to_python<std::shared_ptr<const Answer> >();
180  implicitly_convertible<std::shared_ptr<Answer>, std::shared_ptr<const Answer> >();
181  // Create subtypes
185  }
void createType< AnswerNo >()
Definition: AnswerNo.cpp:101
void createType< AnswerYes >()
Definition: AnswerYes.cpp:193
void createType< AnswerDontKnow >()
const IRIAtomPtr isUncertain
Definition: reification.h:18

◆ createType< AnswerDontKnow >()

template<>
void knowrob::py::createType< AnswerDontKnow > ( )

Definition at line 42 of file AnswerDontKnow.cpp.

42  {
43  using namespace boost::python;
44  class_<AnswerDontKnow, std::shared_ptr<AnswerDontKnow>, bases<Answer>>
45  ("AnswerDontKnow", init<>());
46  // Allow implicit conversion of shared_ptr< AnswerDontKnow > to shared_ptr< const AnswerDontKnow >
47  register_ptr_to_python<std::shared_ptr<const AnswerDontKnow> >();
48  implicitly_convertible<std::shared_ptr<AnswerDontKnow>, std::shared_ptr<const AnswerDontKnow> >();
49  }

◆ createType< AnswerNo >()

template<>
void knowrob::py::createType< AnswerNo > ( )

Definition at line 101 of file AnswerNo.cpp.

101  {
102  using namespace boost::python;
103  class_<AnswerNo, std::shared_ptr<AnswerNo>, bases<Answer>>
104  ("AnswerNo", init<>())
105  .def("addUngrounded", &AnswerNo::addUngrounded)
106  .def("positiveUngrounded", &AnswerNo::positiveUngrounded, return_value_policy<copy_const_reference>())
107  .def("negativeUngrounded", &AnswerNo::negativeUngrounded, return_value_policy<copy_const_reference>())
108  .def("mergeWith", &AnswerNo::mergeWith);
109  // Allow implicit conversion from AnswerNo to const AnswerNo
110  register_ptr_to_python<std::shared_ptr<const AnswerNo> >();
111  implicitly_convertible<std::shared_ptr<AnswerNo>, std::shared_ptr<const AnswerNo> >();
112  }

◆ createType< AnswerYes >()

template<>
void knowrob::py::createType< AnswerYes > ( )

Definition at line 193 of file AnswerYes.cpp.

193  {
194  using namespace boost::python;
195 
196  class_<AnswerYes, std::shared_ptr<AnswerYes>, bases<Answer>>
197  ("AnswerYes", init<>())
198  .def(init<BindingsPtr>())
199  .def("hasGrounding", &AnswerYes::hasGrounding)
200  .def("addGrounding", +[](AnswerYes &self, const PredicatePtr &predicate) {
201  return self.addGrounding(predicate);
202  })
203  .def("addGrounding", +[](AnswerYes &self, const PredicatePtr &predicate, bool isNegated) {
204  return self.addGrounding(predicate, isNegated);
205  })
206  .def("addGrounding", +[](AnswerYes &self, const PredicatePtr &predicate, bool isNegated, const GraphSelectorPtr &frame) {
207  return self.addGrounding(predicate, isNegated, frame);
208  })
209  .def("substitution", &AnswerYes::substitution, return_value_policy<copy_const_reference>())
210  .def("positiveGroundings", &AnswerYes::positiveGroundings, return_value_policy<copy_const_reference>())
211  .def("negativeGroundings", &AnswerYes::negativeGroundings, return_value_policy<copy_const_reference>())
212  .def("mergeWith", &AnswerYes::mergeWith)
213  .def("isRicherThan", &AnswerYes::isRicherThan)
214  .def("isGenericYes", &AnswerYes::isGenericYes);
215  // Allow implicit conversion from AnswerYes to const AnswerYes
216  register_ptr_to_python<std::shared_ptr<const AnswerYes> >();
217  implicitly_convertible<std::shared_ptr<AnswerYes>, std::shared_ptr<const AnswerYes> >();
218  }
PredicateRule & predicate()
Definition: formula.cpp:221
std::shared_ptr< Predicate > PredicatePtr
Definition: Predicate.h:77
std::shared_ptr< const GraphSelector > GraphSelectorPtr
Definition: GraphSelector.h:76

◆ createType< Atom >()

template<>
void knowrob::py::createType< Atom > ( )

Definition at line 63 of file Atom.cpp.

63  {
64  using namespace boost::python;
65  enum_<AtomType>("AtomType")
66  .value("IRI", AtomType::IRI)
67  .value("REGULAR", AtomType::REGULAR)
68  .export_values();
69  class_<Atom, std::shared_ptr<Atom>, bases<Atomic>>("Atom", no_init)
70  .def("__init__", make_constructor(&Atom::Tabled))
71  .def("Tabled", &Atom::Tabled).staticmethod("Tabled")
72  .def("__repr__", &Atom::stringForm)
73  .def("atomType", &Atom::atomType)
74  .def("isSameAtom", &Atom::isSameAtom);
75  }

◆ createType< Atomic >()

template<>
void knowrob::py::createType< Atomic > ( )

Definition at line 68 of file Atomic.cpp.

68  {
69  using namespace boost::python;
70  enum_<AtomicType>("AtomicType")
71  .value("ATOM", AtomicType::ATOM)
72  .value("STRING", AtomicType::STRING)
73  .value("NUMERIC", AtomicType::NUMERIC)
74  .export_values();
75  class_<Atomic, std::shared_ptr<Atomic>, bases<Term>, boost::noncopyable>
76  ("Atomic", no_init)
77  .def("atomicType", &Atomic::atomicType)
78  .def("isSameAtomic", &Atomic::isSameAtomic);
79  }

◆ createType< Bindings >()

template<>
void knowrob::py::createType< Bindings > ( )

Definition at line 295 of file Bindings.cpp.

295  {
296  using namespace boost::python;
297 
298  class_<Bindings, std::shared_ptr<Bindings>>("Bindings", init<>())
299  .def(init<std::map<VariablePtr, TermPtr>>())
300  .def("__eq__", &Bindings::operator==)
301  .def("__iter__", range(&Bindings::begin, &Bindings::end))
302  .def("__len__", &Bindings::size)
303  .def("__hash__", &Bindings::hash)
304  .def("empty", &Bindings::empty)
305  .def("set", &Bindings::set)
306  .def("get", &Bindings::get, return_value_policy<copy_const_reference>())
307  .def("contains", &Bindings::contains)
308  .def("unifyWith", &Bindings::unifyWith)
309  .def("isConsistentWith", &Bindings::isConsistentWith);
310 
311  // define global functions
312  def("applyBindings", applyBindings_t);
313  def("applyBindings", applyBindings_phi);
314  // Allow implicit conversion from shared_ptr<Bindings> to shared_ptr<const Bindings>
315  register_ptr_to_python<std::shared_ptr<const Bindings> >();
316  implicitly_convertible<std::shared_ptr<Bindings>, std::shared_ptr<const Bindings> >();
317  // Allow conversion from python dict to std::map
318  dict_map_converter<std::shared_ptr<Variable>,std::shared_ptr<Term>>::register_from_python_converter();
319  }
FormulaPtr applyBindings_phi(const FormulaPtr &phi, const Bindings &bindings)
Definition: Bindings.cpp:290
TermPtr applyBindings_t(const TermPtr &t, const Bindings &bindings)
Definition: Bindings.cpp:286
const IRIAtomPtr range
Definition: rdfs.h:20

◆ createType< Blank >()

template<>
void knowrob::py::createType< Blank > ( )

Definition at line 35 of file Blank.cpp.

35  {
36  using namespace boost::python;
37  class_<Blank, std::shared_ptr<Blank>, bases<Atom, RDFNode>>
38  ("Blank", init<std::string_view>());
39  }

◆ createType< Bottom >()

template<>
void knowrob::py::createType< Bottom > ( )

Definition at line 31 of file Bottom.cpp.

31  {
32  using namespace boost::python;
33  class_<Bottom, std::shared_ptr<Bottom>, bases<Predicate>>
34  ("Bottom", no_init)
35  .def("get", &Bottom::get, return_value_policy<copy_const_reference>());
36  }

◆ createType< CompoundFormula >()

template<>
void knowrob::py::createType< CompoundFormula > ( )

Definition at line 42 of file CompoundFormula.cpp.

42  {
43  using namespace boost::python;
44  class_<CompoundFormula, std::shared_ptr<CompoundFormula>, boost::noncopyable, bases<Formula>>
45  ("CompoundFormula", no_init)
46  .def("formulae", &CompoundFormula::formulae, return_value_policy<copy_const_reference>());
47  }

◆ createType< Conjunction >()

template<>
void knowrob::py::createType< Conjunction > ( )

Definition at line 61 of file Conjunction.cpp.

61  {
62  using namespace boost::python;
63  class_<Conjunction, std::shared_ptr<Conjunction>, bases<CompoundFormula>>
64  ("Conjunction", init<const std::vector<FormulaPtr> &>());
65 
67  }
void createType< SimpleConjunction >()

◆ createType< ConjunctiveQuery >()

template<>
void knowrob::py::createType< ConjunctiveQuery > ( )

Definition at line 29 of file ConjunctiveQuery.cpp.

29  {
30  using namespace boost::python;
31 
33 
34  class_<ConjunctiveQuery, std::shared_ptr<ConjunctiveQuery>, boost::noncopyable>
35  ("GraphQuery", init<const FirstOrderLiteralPtr &, const QueryContextPtr &>())
36  .def(init<const std::vector<FirstOrderLiteralPtr> &, const QueryContextPtr &>())
37  .def("formula", &ConjunctiveQuery::formula, return_value_policy<copy_const_reference>())
38  .def("literals", &ConjunctiveQuery::literals, return_value_policy<copy_const_reference>());
39  }
FormulaRule & formula()
Definition: formula.cpp:283
void createType< GraphTerm >()
Definition: GraphTerm.cpp:90
std::shared_ptr< const QueryContext > QueryContextPtr
Definition: QueryContext.h:41

◆ createType< DataDrivenReasoner >()

Definition at line 229 of file DataDrivenReasoner.cpp.

229  {
230  using namespace boost::python;
231  enum_<DataDrivenReasoner::Feature>("DataDrivenReasonerFeature")
232  .value("NothingSpecial", DataDrivenReasoner::NothingSpecial)
233  .value("UpdatesItself", DataDrivenReasoner::UpdatesItself)
234  .value("InvalidatesItself", DataDrivenReasoner::InvalidatesItself)
235  .export_values();
236 
237  py::createType<reasoner::Event>();
238 
239  class_<DataDrivenReasoner, std::shared_ptr<DataDrivenReasonerWrap>, bases<Reasoner>, boost::noncopyable>
240  ("DataDrivenReasoner", init<>())
241  .def("enableFeature", &DataDrivenReasonerWrap::enableFeature)
242  .def("hasFeature", &DataDrivenReasonerWrap::hasFeature)
243  .def("emit", &DataDrivenReasonerWrap::emit)
244  .def("observe", +[](DataDrivenReasoner &x, const std::shared_ptr<GraphQuery> &query, object &handler) {
245  no_gil unlock;
246  x.observe(query, [handler](const BindingsPtr &bindings) {
247  py::gil_lock lock;
248  handler(bindings);
249  });
250  })
251  .def("observe", +[](DataDrivenReasoner &x, const std::string &queryString, object &handler) {
252  no_gil unlock;
253  x.observe(queryString, [handler](const BindingsPtr &bindings) {
254  py::gil_lock lock;
255  handler(bindings);
256  });
257  })
258  .def("setUpdateInterval", &DataDrivenReasonerWrap::setUpdateInterval)
259  .def("updateInterval", &DataDrivenReasonerWrap::updateInterval)
260  // methods that must be implemented by reasoner plugins
261  .def("update", &DataDrivenReasonerWrap::update)
262  .def("start", &DataDrivenReasonerWrap::start, &DataDrivenReasonerWrap::start_default)
263  .def("stop", &DataDrivenReasonerWrap::stop, &DataDrivenReasonerWrap::stop_default);
264  }
void observe(const std::shared_ptr< GraphQuery > &query, const BindingsHandler &handler)
TermRule & string()
Definition: terms.cpp:63
std::shared_ptr< const Bindings > BindingsPtr
Definition: Bindings.h:151

◆ createType< DataSource >()

template<>
void knowrob::py::createType< DataSource > ( )

Definition at line 144 of file DataSource.cpp.

144  {
145  using namespace boost::python;
146  class_<DataSource, std::shared_ptr<DataSource>>
147  ("DataSource", no_init)
148  .def("format", &DataSource::format, return_value_policy<copy_const_reference>())
149  .def("uri", &DataSource::uri, return_value_policy<copy_const_reference>())
150  .def("path", &DataSource::path, return_value_policy<copy_const_reference>())
151  .def("version", &DataSource::version)
152  .def("name", &DataSource::name)
153  .def("dataSourceType", &DataSource::dataSourceType)
154  .def("isVersionString", &DataSource::isVersionString)
155  .staticmethod("isVersionString")
156  .def("getNameFromURI", &DataSource::getNameFromURI)
157  .staticmethod("getNameFromURI")
158  .def("getVersionFromURI", &DataSource::getVersionFromURI)
159  .staticmethod("getVersionFromURI")
160  .def("create", &DataSource::create)
161  .staticmethod("create");
162  }

◆ createType< DataSourceHandler >()

Definition at line 30 of file DataSourceHandler.cpp.

30  {
31  using namespace boost::python;
32  class_<DataSourceHandler, std::shared_ptr<DataSourceHandler>>("DataSourceHandler", init<>())
33  .def("addDataHandler", +[]
34  (DataSourceHandler &x, const std::string &format, object &fn) {
35  // when KnowRob calls the data handler, it does not hold the GIL
36  // so we need to acquire it before calling fn.
37  x.addDataHandler(format, [fn](const DataSourcePtr &dataSource) {
38  gil_lock lock;
39  return fn(dataSource);
40  });
41  })
42  .def("loadDataSource", &DataSourceHandler::loadDataSource);
43  }
void addDataHandler(const std::string &format, const DataSourceLoader &fn)
std::shared_ptr< DataSource > DataSourcePtr
Definition: DataSource.h:107

◆ createType< Disjunction >()

template<>
void knowrob::py::createType< Disjunction > ( )

Definition at line 82 of file Disjunction.cpp.

82  {
83  using namespace boost::python;
84  class_<Disjunction, std::shared_ptr<Disjunction>, bases<CompoundFormula>>
85  ("Disjunction", init<const std::vector<FormulaPtr> &>());
86  }

◆ createType< FirstOrderLiteral >()

Definition at line 43 of file FirstOrderLiteral.cpp.

43  {
44  using namespace boost::python;
45  class_<FirstOrderLiteral, std::shared_ptr<FirstOrderLiteral>>
46  ("FirstOrderLiteral", init<const PredicatePtr &, bool>())
47  .def("predicate", &FirstOrderLiteral::predicate, return_value_policy<copy_const_reference>())
48  .def("isNegated", &FirstOrderLiteral::isNegated)
49  .def("functor", &FirstOrderLiteral::functor, return_value_policy<copy_const_reference>())
50  .def("arity", &FirstOrderLiteral::arity)
51  .def("numVariables", &FirstOrderLiteral::numVariables);
52  }

◆ createType< Formula >()

template<>
void knowrob::py::createType< Formula > ( )

Definition at line 48 of file Formula.cpp.

48  {
49  using namespace boost::python;
50  enum_<FormulaType>("FormulaType")
51  .value("PREDICATE", FormulaType::PREDICATE)
52  .value("CONJUNCTION", FormulaType::CONJUNCTION)
53  .value("DISJUNCTION", FormulaType::DISJUNCTION)
54  .value("NEGATION", FormulaType::NEGATION)
55  .value("IMPLICATION", FormulaType::IMPLICATION)
56  .value("MODAL", FormulaType::MODAL)
57  .export_values();
58  class_<Formula, std::shared_ptr<Formula>, boost::noncopyable>
59  ("Formula", no_init)
60  .def("type", &Formula::type)
61  .def("__eq__", &Formula::operator==)
62  .def("__repr__", &Formula::format)
63  .def("isGround", &Formula::isGround)
64  .def("isAtomic", &Formula::isAtomic)
65  .def("isTop", &Formula::isTop)
66  .def("isBottom", &Formula::isBottom);
67 
79  }
PREDICATE(mng_collections, 2)
Definition: mongo_kb.cpp:48
void createType< PredicateIndicator >()
void createType< Bottom >()
Definition: Bottom.cpp:31
void createType< FirstOrderLiteral >()
void createType< CompoundFormula >()
void createType< Predicate >()
Definition: Predicate.cpp:95
void createType< Negation >()
Definition: Negation.cpp:39
void createType< Top >()
Definition: Top.cpp:30
void createType< Implication >()
Definition: Implication.cpp:23
void createType< Disjunction >()
Definition: Disjunction.cpp:82
void createType< ModalFormula >()
void createType< Conjunction >()
Definition: Conjunction.cpp:61
const IRIAtomPtr type
Definition: rdf.h:15

◆ createType< Function >()

template<>
void knowrob::py::createType< Function > ( )

Definition at line 69 of file Function.cpp.

69  {
70  using namespace boost::python;
71  class_<Function, std::shared_ptr<Function>, bases<Term>>
72  ("Function", init<std::string_view, const std::vector<TermPtr> &>())
73  .def(init<const AtomPtr &, const std::vector<TermPtr> &>())
74  .def("functor", &Function::functor, return_value_policy<copy_const_reference>())
75  .def("arguments", &Function::arguments, return_value_policy<copy_const_reference>());
76  }
std::shared_ptr< Atom > AtomPtr
Definition: Atom.h:69

◆ createType< Goal >()

template<>
void knowrob::py::createType< Goal > ( )

Definition at line 91 of file Goal.cpp.

91  {
92  using namespace boost::python;
93 
94  using Push1 = void (Goal::*)(const AnswerPtr &);
95  using Push2 = void (Goal::*)(const BindingsPtr &);
96 
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)));
105  }
void createType< RDFGoal >()
Definition: RDFGoal.cpp:36
std::shared_ptr< const Answer > AnswerPtr
Definition: Answer.h:129

◆ createType< GoalDrivenReasoner >()

Definition at line 98 of file GoalDrivenReasoner.cpp.

98  {
99  using namespace boost::python;
100 
101  using Define1 = void (GoalDrivenReasoner::*)(const PredicateIndicator &);
102  using Define2 = void (GoalDrivenReasoner::*)(const IRIAtomPtr &);
103 
104  // export the GoalDrivenReasonerFeature enum
105  enum_<GoalDrivenReasonerFeature>("GoalDrivenReasonerFeature")
106  .value("SupportsSimpleConjunctions", GoalDrivenReasonerFeature::SupportsSimpleConjunctions)
107  .value("SupportsExtensionalGrounding", GoalDrivenReasonerFeature::SupportsExtensionalGrounding);
108 
109  // export the GoalDrivenReasoner class
110  class_<GoalDrivenReasoner, std::shared_ptr<GoalDrivenReasonerWrap>, bases<Reasoner>, boost::noncopyable>
111  ("GoalDrivenReasoner", init<>())
112  .def("hasFeature", &GoalDrivenReasoner::hasFeature)
113  .def("enableFeature", &GoalDrivenReasoner::enableFeature)
114  .def("isRelationDefined", &GoalDrivenReasoner::isRelationDefined)
115  .def("isClassDefined", &GoalDrivenReasoner::isClassDefined)
116  .def("defineRelation", static_cast<Define1>(&GoalDrivenReasoner::defineRelation))
117  .def("defineRelation", static_cast<Define2>(&GoalDrivenReasoner::defineRelation))
118  .def("defineClass", &GoalDrivenReasoner::defineClass)
119  .def("undefineRelation", &GoalDrivenReasoner::undefineRelation)
120  .def("undefineClass", &GoalDrivenReasoner::undefineClass)
121  // methods that must be implemented by reasoner plugins
122  .def("evaluate", &GoalDrivenReasonerWrap::evaluate);
123 
124  // export sub-types
127  }
void createType< RDFGoalReasoner >()
void createType< Goal >()
Definition: Goal.cpp:91
std::shared_ptr< IRIAtom > IRIAtomPtr
Definition: IRIAtom.h:57

◆ createType< GraphBuiltin >()

template<>
void knowrob::py::createType< GraphBuiltin > ( )

Definition at line 97 of file GraphBuiltin.cpp.

97  {
98  using namespace boost::python;
99 
100  class_<GraphBuiltin, bases<GraphTerm, Function>, std::shared_ptr<GraphBuiltin>, boost::noncopyable>
101  ("GraphBuiltin", no_init)
102  .def("setOptional", &GraphBuiltin::setOptional)
103  .def("isOptional", &GraphBuiltin::isOptional)
104  .def("bind", &GraphBuiltin::bind).staticmethod("bind")
105  .def("min", &GraphBuiltin::min).staticmethod("min")
106  .def("max", &GraphBuiltin::max).staticmethod("max")
107  .def("less", &GraphBuiltin::less).staticmethod("less")
108  .def("lessOrEqual", &GraphBuiltin::lessOrEqual).staticmethod("lessOrEqual")
109  .def("greater", &GraphBuiltin::greater).staticmethod("greater")
110  .def("greaterOrEqual", &GraphBuiltin::greaterOrEqual).staticmethod("greaterOrEqual")
111  .def("equal", &GraphBuiltin::equal).staticmethod("equal")
112  .def("notEqual", &GraphBuiltin::notEqual).staticmethod("notEqual");
113  }

◆ createType< GraphQuery >()

template<>
void knowrob::py::createType< GraphQuery > ( )

Definition at line 96 of file GraphQuery.cpp.

96  {
97  using namespace boost::python;
98 
100 
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 &>())
107  .def("term", &GraphQuery::term)
108  .def("toFormula", &GraphQuery::toFormula);
109  }

◆ createType< GraphSelector >()

template<>
void knowrob::py::createType< GraphSelector > ( )

Definition at line 151 of file GraphSelector.cpp.

151  {
152  using namespace boost::python;
153  class_<GraphSelector, std::shared_ptr<GraphSelector>>
154  ("GraphSelector", init<>())
155  .def_readwrite("graph", &GraphSelector::graph)
156  .def_readwrite("uncertain", &GraphSelector::uncertain)
157  .def_readwrite("occasional", &GraphSelector::occasional)
158  .BOOST_PYTHON_ADD_OPTIONAL("perspective", &GraphSelector::perspective)
159  .BOOST_PYTHON_ADD_OPTIONAL("begin", &GraphSelector::begin)
160  .BOOST_PYTHON_ADD_OPTIONAL("end", &GraphSelector::end)
161  .BOOST_PYTHON_ADD_OPTIONAL("confidence", &GraphSelector::confidence);
162  }

◆ createType< GraphSequence >()

template<>
void knowrob::py::createType< GraphSequence > ( )

Definition at line 24 of file GraphSequence.cpp.

24  {
25  using namespace boost::python;
26 
27  class_<GraphSequence, bases<GraphTerm>, std::shared_ptr<GraphSequence>, boost::noncopyable>
28  ("GraphSequence", init<>())
29  .def(init<const std::vector<std::shared_ptr<GraphTerm>> &>());
30  }

◆ createType< GraphTerm >()

template<>
void knowrob::py::createType< GraphTerm > ( )

Definition at line 90 of file GraphTerm.cpp.

90  {
91  using namespace boost::python;
92 
93  enum_<GraphTermType>("GraphTermType")
94  .value("Sequence", GraphTermType::Sequence)
95  .value("Union", GraphTermType::Union)
96  .value("Pattern", GraphTermType::Pattern)
97  .value("Builtin", GraphTermType::Builtin)
98  .export_values();
99 
100  class_<GraphTerm, std::shared_ptr<GraphTerm>, boost::noncopyable>
101  ("GraphTerm", no_init)
102  .def("isPattern", &GraphTerm::isPattern)
103  .def("isBuiltin", &GraphTerm::isBuiltin)
104  .def("termType", &GraphTerm::termType);
105 
106  class_<GraphPattern, bases<GraphTerm>, std::shared_ptr<GraphPattern>, boost::noncopyable>
107  ("GraphPattern", init<TriplePatternPtr>())
108  .def(init<const TermPtr &, const TermPtr &, const TermPtr &>())
109  .def("value", &GraphPattern::value, return_value_policy<copy_const_reference>());
110 
114 
115  def("applyBindings", applyBindings_graph);
116  // allow conversion between std::vector and python::list for FirstOrderLiteral objects.
117  typedef std::vector<std::shared_ptr<GraphTerm>> GraphTermList;
119  boost::python::class_<GraphTermList>("GraphTermList").def(
120  boost::python::vector_indexing_suite<GraphTermList, true>());
121  }
void createType< GraphUnion >()
Definition: GraphUnion.cpp:24
std::shared_ptr< GraphTerm > applyBindings_graph(const std::shared_ptr< GraphTerm > &term, const Bindings &bindings)
Definition: GraphTerm.cpp:85
void createType< GraphBuiltin >()
void createType< GraphSequence >()

◆ createType< GraphUnion >()

template<>
void knowrob::py::createType< GraphUnion > ( )

Definition at line 24 of file GraphUnion.cpp.

24  {
25  using namespace boost::python;
26 
27  class_<GraphUnion, bases<GraphTerm>, std::shared_ptr<GraphUnion>, boost::noncopyable>
28  ("GraphUnion", init<>())
29  .def(init<const std::vector<std::shared_ptr<GraphTerm>> &>());
30  }

◆ createType< Implication >()

template<>
void knowrob::py::createType< Implication > ( )

Definition at line 23 of file Implication.cpp.

23  {
24  using namespace boost::python;
25  class_<Implication, std::shared_ptr<Implication>, bases<CompoundFormula>>
26  ("Implication", init<const FormulaPtr &, const FormulaPtr &>())
27  .def("antecedent", &Implication::antecedent, return_value_policy<copy_const_reference>())
28  .def("consequent", &Implication::consequent, return_value_policy<copy_const_reference>());
29  }

◆ createType< ImportHierarchy >()

template<>
void knowrob::py::createType< ImportHierarchy > ( )

Definition at line 131 of file ImportHierarchy.cpp.

131  {
132  using namespace boost::python;
133 
134  class_<ImportHierarchy, std::shared_ptr<ImportHierarchy>, boost::noncopyable>
135  ("ImportHierarchy", init<>())
136  .def("isCurrentGraph", &ImportHierarchy::isCurrentGraph)
137  .def("isReservedOrigin", &ImportHierarchy::isReservedOrigin)
138  .def("clear", &ImportHierarchy::clear)
139  .def("setDefaultGraph", &ImportHierarchy::setDefaultGraph)
140  .def("defaultGraph", &ImportHierarchy::defaultGraph, return_value_policy<copy_const_reference>())
141  .def("addCurrentGraph", &ImportHierarchy::addCurrentGraph)
142  .def("removeCurrentGraph", &ImportHierarchy::removeCurrentGraph)
143  .def("addDirectImport", &ImportHierarchy::addDirectImport)
144  .def("getImports", &ImportHierarchy::getImports, return_value_policy<copy_const_reference>());
145  }

◆ createType< InterfaceUtils >()

template<>
void knowrob::py::createType< InterfaceUtils > ( )

Definition at line 175 of file InterfaceUtils.cpp.

175  {
176  using namespace boost::python;
177 
178  // Expose InterfaceUtils class and its methods
179  class_<InterfaceUtils>("InterfaceUtils")
180  .def("assertStatements", &InterfaceUtils::assertStatements).staticmethod("assertStatements")
181  .def("applyModality", &InterfaceUtils::applyModality).staticmethod("applyModality");
182 
183  // Expose enums
184  enum_<EpistemicOperator>("EpistemicOperator")
185  .value("KNOWLEDGE", KNOWLEDGE)
186  .value("BELIEF", BELIEF);
187  enum_<TemporalOperator>("TemporalOperator")
188  .value("CURRENTLY", CURRENTLY)
189  .value("ALL_PAST", ALL_PAST)
190  .value("SOME_PAST", SOME_PAST);
191  }
@ SOME_PAST
@ CURRENTLY
@ ALL_PAST

◆ createType< IRIAtom >()

template<>
void knowrob::py::createType< IRIAtom > ( )

Definition at line 76 of file IRIAtom.cpp.

76  {
77  using namespace boost::python;
78  class_<IRIAtom, std::shared_ptr<IRIAtom>, bases<Atom, RDFNode>>("IRIAtom", no_init)
79  .def("__init__", make_constructor(&IRIAtom::Tabled));
80  def("iri", &iri);
81  }
StringRule & iri()
Definition: strings.cpp:49

◆ createType< KnowledgeBase >()

template<>
void knowrob::py::createType< KnowledgeBase > ( )

Definition at line 666 of file KnowledgeBase.cpp.

666  {
667  using namespace boost::python;
668 
669  // these typedefs are necessary to resolve functions with duplicate names which is
670  // fine in C++ but not in Python, so they need special handling here.
671  // The typedefs are used to explicitly select the mapped method.
672  using QueryPredicate = TokenBufferPtr (KnowledgeBase::*)(const FirstOrderLiteralPtr &, const QueryContextPtr &);
673  using QueryFormula = TokenBufferPtr (KnowledgeBase::*)(const FormulaPtr &, const QueryContextPtr &);
674  using QueryGraph = TokenBufferPtr (KnowledgeBase::*)(const ConjunctiveQueryPtr &);
675  using ContainerAction = bool (KnowledgeBase::*)(const TripleContainerPtr &);
676  using ListAction = bool (KnowledgeBase::*)(const std::vector<TriplePtr> &);
677 
680 
681  class_<KnowledgeBase, std::shared_ptr<KnowledgeBase>, boost::noncopyable>
682  ("KnowledgeBase", no_init)
683  // hide the "create" functions in Python
684  .def("__init__", make_constructor(&makeKB1))
685  .def("__init__", make_constructor(&makeKB2))
686  .def("__init__", make_constructor(&makeKB3))
687  .def("setDefaultGraph", &KnowledgeBase::setDefaultGraph)
688  .def("vocabulary", &KnowledgeBase::vocabulary, return_value_policy<copy_const_reference>())
689  .def("loadCommon", with<no_gil>(&KnowledgeBase::loadCommon))
690  .def("loadDataSource", with<no_gil>(&KnowledgeBase::loadDataSource))
691  .def("submitQuery", with<no_gil>(static_cast<QueryFormula>(&KnowledgeBase::submitQuery)))
692  .def("submitQuery", with<no_gil>(static_cast<QueryPredicate>(&KnowledgeBase::submitQuery)))
693  .def("submitQuery", with<no_gil>(static_cast<QueryGraph>(&KnowledgeBase::submitQuery)))
694  .def("observe", +[](KnowledgeBase &kb, const GraphQueryPtr &query, object &fn) {
695  no_gil unlock;
696  return kb.observe(query, [fn](const BindingsPtr &bindings) {
697  // make sure to lock the GIL before calling the Python function
698  gil_lock lock;
699  fn(bindings);
700  });
701  })
702  .def("insertOne", with<no_gil>(&KnowledgeBase::insertOne))
703  .def("insertAll", with<no_gil>(static_cast<ContainerAction>(&KnowledgeBase::insertAll)))
704  .def("insertAll", with<no_gil>(static_cast<ListAction>(&KnowledgeBase::insertAll)))
705  .def("removeOne", with<no_gil>(&KnowledgeBase::removeOne))
706  .def("removeAll", with<no_gil>(static_cast<ContainerAction>(&KnowledgeBase::removeAll)))
707  .def("removeAll", with<no_gil>(static_cast<ListAction>(&KnowledgeBase::removeAll)))
708  .def("removeAllWithOrigin", with<no_gil>(&KnowledgeBase::removeAllWithOrigin));
709  }
ObserverPtr observe(const GraphQueryPtr &query, const BindingsHandler &callback)
void createType< Vocabulary >()
Definition: Vocabulary.cpp:271
void createType< GraphQuery >()
Definition: GraphQuery.cpp:96
std::shared_ptr< TripleContainer > TripleContainerPtr
std::shared_ptr< Formula > FormulaPtr
Definition: Formula.h:99
std::shared_ptr< ConjunctiveQuery > ConjunctiveQueryPtr
std::shared_ptr< TokenBuffer > TokenBufferPtr
Definition: TokenBuffer.h:43
std::shared_ptr< GraphQuery > GraphQueryPtr
Definition: GraphQuery.h:65
std::shared_ptr< FirstOrderLiteral > FirstOrderLiteralPtr

◆ createType< ListTerm >()

template<>
void knowrob::py::createType< ListTerm > ( )

Definition at line 45 of file ListTerm.cpp.

45  {
46  using namespace boost::python;
47  class_<ListTerm, std::shared_ptr<ListTerm>, bases<Function>>
48  ("ListTerm", init<const std::vector<TermPtr> &>())
49  .def("__iter__", range(&ListTerm::begin, &ListTerm::end))
50  .def("isNIL", &ListTerm::isNIL)
51  .def("elements", &ListTerm::elements, return_value_policy<copy_const_reference>());
52  }

◆ createType< Logger >()

template<>
void knowrob::py::createType< Logger > ( )

Definition at line 164 of file Logger.cpp.

164  {
165  using namespace boost::python;
166  def("logInfo", +[](const std::string &msg) { KB_INFO(msg); });
167  def("logWarn", +[](const std::string &msg) { KB_WARN(msg); });
168  def("logError", +[](const std::string &msg) { KB_ERROR(msg); });
169  def("logDebug", +[](const std::string &msg) { KB_DEBUG(msg); });
170  def("logCritical", +[](const std::string &msg) { KB_CRITICAL(msg); });
171  }
#define KB_INFO
Definition: Logger.h:26
#define KB_CRITICAL
Definition: Logger.h:29
#define KB_ERROR
Definition: Logger.h:28
#define KB_WARN
Definition: Logger.h:27

◆ createType< ModalFormula >()

template<>
void knowrob::py::createType< ModalFormula > ( )

Definition at line 114 of file ModalFormula.cpp.

114  {
115  using namespace boost::python;
116  class_<ModalFormula, std::shared_ptr<ModalFormula>, bases<CompoundFormula>>
117  ("ModalFormula", init<const ModalOperatorPtr &, const FormulaPtr &>())
118  .def("modalOperator", &ModalFormula::modalOperator, return_value_policy<copy_const_reference>())
119  .def("modalFormula", &ModalFormula::modalFormula, return_value_policy<copy_const_reference>())
120  .def("isModalPossibility", &ModalFormula::isModalPossibility)
121  .def("isModalNecessity", &ModalFormula::isModalNecessity);
122  }

◆ createType< ModalOperator >()

template<>
void knowrob::py::createType< ModalOperator > ( )

Definition at line 179 of file ModalOperator.cpp.

179  {
180  using namespace boost::python;
181  enum_<ModalType>("ModalType")
182  .value("KNOWLEDGE", ModalType::KNOWLEDGE)
183  .value("BELIEF", ModalType::BELIEF)
184  .value("ALWAYS", ModalType::ALWAYS)
185  .value("SOMETIMES", ModalType::SOMETIMES)
186  .export_values();
187  class_<ModalOperator, std::shared_ptr<ModalOperator>>
188  ("ModalOperator", init<ModalType>())
189  .def("isModalNecessity", &ModalOperator::isModalNecessity)
190  .def("isModalPossibility", &ModalOperator::isModalPossibility)
191  .def("modalType", &ModalOperator::modalType)
192  .def("symbol", &ModalOperator::symbol);
193  class_<ModalIteration, std::shared_ptr<ModalIteration>>
194  ("ModalIteration", init<>())
195  .def("__eq__", &ModalIteration::operator==)
196  .def("__iter__", range(&ModalIteration::begin, &ModalIteration::end))
197  .def("numOperators", &ModalIteration::numOperators)
198  .def("emptyIteration", &ModalIteration::emptyIteration, return_value_policy<copy_const_reference>());
199  }
@ KNOWLEDGE
@ BELIEF

◆ createType< Negation >()

template<>
void knowrob::py::createType< Negation > ( )

Definition at line 39 of file Negation.cpp.

39  {
40  using namespace boost::python;
41  class_<Negation, std::shared_ptr<Negation>, bases<CompoundFormula>>
42  ("Negation", init<const FormulaPtr &>())
43  .def("negatedFormula", &Negation::negatedFormula, return_value_policy<copy_const_reference>());
44  }

◆ createType< Numeric >()

template<>
void knowrob::py::createType< Numeric > ( )

Definition at line 27 of file Numeric.cpp.

27  {
28  using namespace boost::python;
29  class_<Numeric, std::shared_ptr<Numeric>, bases<XSDAtomic>, boost::noncopyable>
30  ("Numeric", no_init)
31  .def("isFloatingNumber", &Numeric::isFloatingNumber)
32  .def("isSameNumeric", &Numeric::isSameNumeric);
33  class_<Double, std::shared_ptr<Double>, bases<Numeric>>
34  ("Double", init<double>())
35  .def(init<std::string_view>())
36  .def("__repr__", &Double::stringForm)
37  .def("numericForm", &Double::numericForm);
38  class_<Float, std::shared_ptr<Float>, bases<Numeric>>
39  ("Float", init<float>())
40  .def(init<std::string_view>())
41  .def("__repr__", &Float::stringForm)
42  .def("numericForm", &Float::numericForm);
43  class_<Integer, std::shared_ptr<Integer>, bases<Numeric>>
44  ("Integer", init<int>())
45  .def(init<std::string_view>())
46  .def("__repr__", &Integer::stringForm)
47  .def("numericForm", &Integer::numericForm);
48  class_<Long, std::shared_ptr<Long>, bases<Numeric>>
49  ("Long", init<long>())
50  .def(init<std::string_view>())
51  .def("__repr__", &Long::stringForm)
52  .def("numericForm", &Long::numericForm);
53  class_<Short, std::shared_ptr<Short>, bases<Numeric>>
54  ("Short", init<short>())
55  .def(init<std::string_view>())
56  .def("__repr__", &Short::stringForm)
57  .def("numericForm", &Short::numericForm);
58  }

◆ createType< Observer >()

template<>
void knowrob::py::createType< Observer > ( )

Definition at line 30 of file Observer.cpp.

30  {
31  using namespace boost::python;
32 
33  class_<Observer, std::shared_ptr<Observer>, boost::noncopyable>
34  ("Observer", no_init)
35  .def("stopObservation", &Observer::stopObservation);
36  }

◆ createType< Perspective >()

template<>
void knowrob::py::createType< Perspective > ( )

Definition at line 44 of file Perspective.cpp.

44  {
45  using namespace boost::python;
46  class_<Perspective, std::shared_ptr<Perspective>>("Perspective", no_init)
47  .def("iri", &Perspective::iri)
48  .def("atom", &Perspective::atom)
49  .def("getEgoPerspective", &Perspective::getEgoPerspective)
50  .def("isEgoPerspective", &Perspective::isEgoPerspective)
51  .def("get", &Perspective::get);
52  }
StringRule & atom()
Definition: strings.cpp:54

◆ createType< Predicate >()

template<>
void knowrob::py::createType< Predicate > ( )

Definition at line 95 of file Predicate.cpp.

95  {
96  using namespace boost::python;
97  class_<Predicate, std::shared_ptr<Predicate>, bases<Formula>>
98  ("Predicate", init<std::string_view, const std::vector<TermPtr> &>())
99  .def(init<const AtomPtr &, const std::vector<TermPtr> &>())
100  .def("arguments", &Predicate::arguments, return_value_policy<copy_const_reference>())
101  .def("functor", &Predicate::functor, return_value_policy<copy_const_reference>());
102  }

◆ createType< PredicateIndicator >()

Definition at line 37 of file PredicateIndicator.cpp.

37  {
38  using namespace boost::python;
39  class_<PredicateIndicator, std::shared_ptr<PredicateIndicator>>
40  ("PredicateIndicator", init<const std::string &, unsigned int>())
41  .def(init<AtomPtr, unsigned int>())
42  .def("__eq__", &PredicateIndicator::operator==)
43  .def(self < self)
44  .def("name", &PredicateIndicator::functor, return_value_policy<copy_const_reference>())
45  .def("arity", &PredicateIndicator::arity)
46  .def("toTerm", &PredicateIndicator::toTerm);
47  }

◆ createType< PropertyTree >()

template<>
void knowrob::py::createType< PropertyTree > ( )

Definition at line 160 of file PropertyTree.cpp.

160  {
161  using namespace boost::python;
162  class_<PropertyTree, std::shared_ptr<PropertyTree>>("PropertyTree", init<>())
163  .def(init<const std::string &>())
164  .def("__iter__", range(&PropertyTree::begin, &PropertyTree::end))
165  .def("get", &PropertyTree::get)
166  .def("dataSources", &PropertyTree::dataSources, return_value_policy<copy_const_reference>());
167  }

◆ createType< QueryableStorage >()

template<>
void knowrob::py::createType< QueryableStorage > ( )

Definition at line 462 of file QueryableStorage.cpp.

462  {
463  using namespace boost::python;
464  class_<QueryableStorage, std::shared_ptr<QueryableStorageWrap>, bases<Storage>, boost::noncopyable>
465  ("QueryableStorage", init<StorageFeatures>())
466  .def("setVersionOfOrigin", &QueryableStorage::setVersionOfOrigin)
467  .def("getVersionOfOrigin", &QueryableStorage::getVersionOfOrigin)
468  .def("dropSessionOrigins", &QueryableStorage::dropSessionOrigins)
469  .def("yes", &QueryableStorage::yes).staticmethod("yes")
470  .def("no", &QueryableStorage::no).staticmethod("no")
471  // methods that must be implemented by backend plugins
472  .def("foreach", &QueryableStorageWrap::foreach, &QueryableStorageWrap::foreach_default)
473  .def("contains", &QueryableStorageWrap::contains, &QueryableStorageWrap::contains_default)
474  .def("match", &QueryableStorageWrap::match, &QueryableStorageWrap::match_default)
475  .def("isPersistent", pure_virtual(&QueryableStorageWrap::isPersistent))
476  .def("batch", pure_virtual(&QueryableStorageWrap::batch))
477  .def("batchOrigin", pure_virtual(&QueryableStorageWrap::batchOrigin))
478  .def("query", +[](QueryableStorage &x, const GraphQueryPtr &query, object &fn) { x.query(query, fn); })
479  .def("count", pure_virtual(&QueryableStorageWrap::count));
480  register_ptr_to_python< std::shared_ptr< QueryableStorage > >();
481  }
virtual void query(const GraphQueryPtr &query, const BindingsHandler &callback)=0

◆ createType< QueryContext >()

template<>
void knowrob::py::createType< QueryContext > ( )

Definition at line 14 of file QueryContext.cpp.

14  {
15  using namespace boost::python;
16 
17  enum_<QueryFlag>("QueryFlag")
18  .value("QUERY_FLAG_ALL_SOLUTIONS", QUERY_FLAG_ALL_SOLUTIONS)
19  .value("QUERY_FLAG_ONE_SOLUTION", QUERY_FLAG_ONE_SOLUTION)
20  .value("QUERY_FLAG_PERSIST_SOLUTIONS", QUERY_FLAG_PERSIST_SOLUTIONS)
21  .value("QUERY_FLAG_UNIQUE_SOLUTIONS", QUERY_FLAG_UNIQUE_SOLUTIONS)
22  .export_values();
23 
24  class_<QueryContext, std::shared_ptr<QueryContext>>
25  ("QueryContext", init<int>())
26  .def(init<const QueryContext &, const ModalOperatorPtr &>())
27  .def_readwrite("queryFlags", &QueryContext::queryFlags)
28  .def_readwrite("modalIteration", &QueryContext::modalIteration)
29  .def_readwrite("selector", &QueryContext::selector);
30 
31  // QueryContextPtr uses `const QueryContext` which currently requires
32  // a custom converter to be defined in order to be used in Python.
33  register_ptr_to_python<std::shared_ptr<const QueryContext> >();
34  implicitly_convertible<std::shared_ptr<QueryContext>, std::shared_ptr<const QueryContext> >();
35  }
@ QUERY_FLAG_ONE_SOLUTION
Definition: QueryFlag.h:17
@ QUERY_FLAG_ALL_SOLUTIONS
Definition: QueryFlag.h:15
@ QUERY_FLAG_UNIQUE_SOLUTIONS
Definition: QueryFlag.h:21
@ QUERY_FLAG_PERSIST_SOLUTIONS
Definition: QueryFlag.h:19

◆ createType< QueryParser >()

template<>
void knowrob::py::createType< QueryParser > ( )

Definition at line 62 of file QueryParser.cpp.

62  {
63  using namespace boost::python;
64  class_<QueryParser, boost::noncopyable>
65  ("QueryParser", no_init)
66  .def("parse", &QueryParser::parse).staticmethod("parse")
67  .def("parsePredicate", &QueryParser::parsePredicate).staticmethod("parsePredicate")
68  .def("parseGraphTerm", &QueryParser::parseGraphTerm).staticmethod("parseGraphTerm")
69  .def("parseFunction", &QueryParser::parseFunction).staticmethod("parseFunction")
70  .def("parseConstant", &QueryParser::parseConstant).staticmethod("parseConstant")
71  .def("parseRawAtom", &QueryParser::parseRawAtom).staticmethod("parseRawAtom");
72  }

◆ createType< RDFGoal >()

template<>
void knowrob::py::createType< RDFGoal > ( )

Definition at line 36 of file RDFGoal.cpp.

36  {
37  using namespace boost::python;
38 
39  class_<RDFGoal, std::shared_ptr<RDFGoal>, bases<Goal>>
40  ("RDFGoal", init<const std::vector<TriplePatternPtr> &, QueryContextPtr>())
41  .def(init<const TriplePatternPtr &, QueryContextPtr>())
42  .def("rdfLiterals", &RDFGoal::rdfLiterals, return_value_policy<copy_const_reference>());
43  }

◆ createType< RDFGoalReasoner >()

template<>
void knowrob::py::createType< RDFGoalReasoner > ( )

Definition at line 44 of file RDFGoalReasoner.cpp.

44  {
45  using namespace boost::python;
46 
47  // export the GoalDrivenReasoner class
48  class_<RDFGoalReasoner, std::shared_ptr<RDFGoalReasonerWrap>, bases<GoalDrivenReasoner>, boost::noncopyable>
49  ("RDFGoalReasoner", init<>())
50  // methods that must be implemented by reasoner plugins
51  .def("evaluate", &RDFGoalReasonerWrap::evaluate);
52  }

◆ createType< RDFNode >()

template<>
void knowrob::py::createType< RDFNode > ( )

Definition at line 25 of file RDFNode.cpp.

25  {
26  using namespace boost::python;
27  enum_<RDFNodeType>("RDFNodeType")
28  .value("BLANK", RDFNodeType::BLANK)
29  .value("IRI", RDFNodeType::IRI)
30  .value("LITERAL", RDFNodeType::LITERAL)
31  .export_values();
32  class_<RDFNode, std::shared_ptr<RDFNode>, boost::noncopyable>("RDFNode", no_init)
33  .def("rdfNodeType", &RDFNode::rdfNodeType);
34  }

◆ createType< Reasoner >()

template<>
void knowrob::py::createType< Reasoner > ( )

Definition at line 65 of file Reasoner.cpp.

65  {
66  using namespace boost::python;
67  class_<Reasoner, std::shared_ptr<ReasonerWrap>, bases<DataSourceHandler>, boost::noncopyable>
68  ("Reasoner", init<>())
69  .def("pushWork", +[](Reasoner &x, object &fn) {
70  auto fn_wrap = std::make_shared<PyObj_wrap>(fn);
71  x.pushWork([fn_wrap] {
72  (*fn_wrap)();
73  });
74  })
75  .def("reasonerLanguage", &Reasoner::reasonerLanguage)
76  .def("storage", &Reasoner::storage)
77  // methods that must be implemented by reasoner plugins
78  .def("initializeReasoner", &ReasonerWrap::initializeReasoner);
81  }
void pushWork(const std::function< void(void)> &fn)
Definition: Reasoner.cpp:44
void createType< GoalDrivenReasoner >()
void createType< DataDrivenReasoner >()

◆ createType< reasoner::Event >()

template<>
void knowrob::py::createType< reasoner::Event > ( )

Definition at line 31 of file ReasonerEvent.cpp.

31  {
32  using namespace boost::python;
33  using ReasonerEvent = reasoner::Event;
39  using ReasonerEventType = reasoner::Event::Type;
40 
41  enum_<ReasonerEventType>("ReasonerEventType")
42  .value("Assertion", ReasonerEventType::Assertion)
43  .value("Retraction", ReasonerEventType::Retraction)
44  .value("Replacement", ReasonerEventType::Replacement)
45  .value("Invalidation", ReasonerEventType::Invalidation)
46  .export_values();
47 
48  class_<ReasonerEvent, std::shared_ptr<ReasonerEvent>, boost::noncopyable>
49  ("ReasonerEvent", no_init)
50  .def("eventType", &ReasonerEvent::eventType);
51 
52  class_<TripleEvent, bases<ReasonerEvent>, std::shared_ptr<TripleEvent>, boost::noncopyable>
53  ("TripleEvent", no_init)
54  .def("triples", &TripleEvent::triples, return_value_policy<copy_const_reference>())
55  .def("triple", &TripleEvent::triple, return_value_policy<reference_existing_object>());
56 
57  class_<AssertionEvent, std::shared_ptr<AssertionEvent>, bases<TripleEvent>, boost::noncopyable>
58  ("AssertionEvent", init<uint32_t, bool>())
59  .def(init<uint32_t>());
60 
61  class_<RetractionEvent, std::shared_ptr<RetractionEvent>, bases<TripleEvent>, boost::noncopyable>
62  ("RetractionEvent", init<uint32_t, bool>())
63  .def(init<uint32_t>());
64 
65  class_<ReplacementEvent, std::shared_ptr<ReplacementEvent>, bases<TripleEvent>, boost::noncopyable>
66  ("ReplacementEvent", init<uint32_t, bool>())
67  .def(init<uint32_t>());
68 
69  class_<InvalidationEvent, std::shared_ptr<InvalidationEvent>, bases<ReasonerEvent>, boost::noncopyable>
70  ("InvalidationEvent", init<>());
71  }

◆ createType< semweb::Class >()

template<>
void knowrob::py::createType< semweb::Class > ( )

Definition at line 145 of file Class.cpp.

145  {
146  using namespace boost::python;
147 
148  class_<semweb::Class, bases<semweb::Resource>, std::shared_ptr<semweb::Class>, boost::noncopyable>
149  ("Class", init<std::string_view>())
150  .def(init<const IRIAtomPtr &>())
151  .def("addDirectParent", &semweb::Class::addDirectParent)
152  .def("removeDirectParent", &semweb::Class::removeDirectParent)
153  .def("directParents", &semweb::Class::directParents, return_value_policy<copy_const_reference>())
154  .def("isDirectSubClassOf", &semweb::Class::isDirectSubClassOf)
155  .def("isSubClassOf", &semweb::Class::isSubClassOf)
156  .def("forallParents", &semweb::Class::forallParents);
157  }

◆ createType< semweb::Property >()

template<>
void knowrob::py::createType< semweb::Property > ( )

Definition at line 196 of file Property.cpp.

196  {
197  using namespace boost::python;
198 
199  enum_<PropertyFlag>("PropertyFlag")
200  .value("DATATYPE_PROPERTY", DATATYPE_PROPERTY)
201  .value("ANNOTATION_PROPERTY", ANNOTATION_PROPERTY)
202  .value("OBJECT_PROPERTY", OBJECT_PROPERTY)
203  .value("TRANSITIVE_PROPERTY", TRANSITIVE_PROPERTY)
204  .value("REFLEXIVE_PROPERTY", REFLEXIVE_PROPERTY)
205  .value("SYMMETRIC_PROPERTY", SYMMETRIC_PROPERTY)
206  .export_values();
207 
208  class_<semweb::Property, bases<semweb::Resource>, std::shared_ptr<semweb::Property>, boost::noncopyable>
209  ("Property", init<std::string_view>())
210  .def(init<const IRIAtomPtr &>())
211  .def("addDirectParent", &semweb::Property::addDirectParent)
212  .def("removeDirectParent", &semweb::Property::removeDirectParent)
213  .def("directParents", &semweb::Property::directParents, return_value_policy<copy_const_reference>())
214  .def("setInverse", &semweb::Property::setInverse)
215  .def("inverse", &semweb::Property::inverse, return_value_policy<copy_const_reference>())
216  .def("hasFlag", &semweb::Property::hasFlag)
217  .def("setFlag", &semweb::Property::setFlag)
218  .def("isDatatypeProperty", &semweb::Property::isDatatypeProperty)
219  .def("isAnnotationProperty", &semweb::Property::isAnnotationProperty)
220  .def("isObjectProperty", &semweb::Property::isObjectProperty)
221  .def("isTransitiveProperty", &semweb::Property::isTransitiveProperty)
222  .def("isReflexiveProperty", &semweb::Property::isReflexiveProperty)
223  .def("isSymmetricProperty", &semweb::Property::isSymmetricProperty)
224  .def("forallParents", &semweb::Property::forallParents)
225  .def("reification", &semweb::Property::reification)
226  .def("reifiedIRI", &semweb::Property::reifiedIRI)
227  .def("unReifiedIRI", &semweb::Property::unReifiedIRI);
228  }
@ SYMMETRIC_PROPERTY
Definition: Property.h:26
@ TRANSITIVE_PROPERTY
Definition: Property.h:24
@ ANNOTATION_PROPERTY
Definition: Property.h:22
@ REFLEXIVE_PROPERTY
Definition: Property.h:25

◆ createType< semweb::Resource >()

template<>
void knowrob::py::createType< semweb::Resource > ( )

Definition at line 88 of file Resource.cpp.

88  {
89  using namespace boost::python;
90 
91  using IRIArg1 = IRIAtomPtr (*)(std::string_view);
92  using IRIArg2 = IRIAtomPtr (*)(std::string_view, std::string_view);
93 
94  class_<semweb::Resource, std::shared_ptr<semweb::Resource>, boost::noncopyable>
95  ("Resource", no_init)
96  .def("iri", &semweb::Resource::iri)
97  .def("iriAtom", &semweb::Resource::iriAtom)
98  .def("name", &semweb::Resource::name)
99  .def("ns", &semweb::Resource::ns)
100  .def("unique_iri", static_cast<IRIArg1>(&semweb::Resource::unique_iri))
101  .def("unique_iri", static_cast<IRIArg2>(&semweb::Resource::unique_iri))
102  .def("iri_name", &semweb::Resource::iri_name)
103  .def("iri_ns", &semweb::Resource::iri_ns);
104  }
StringRule & iri_ns()
Definition: strings.cpp:41

◆ createType< SimpleConjunction >()

Definition at line 34 of file SimpleConjunction.cpp.

34  {
35  using namespace boost::python;
36  class_<SimpleConjunction, std::shared_ptr<SimpleConjunction>, bases<Conjunction>>
37  ("SimpleConjunction", init<const std::vector<FirstOrderLiteralPtr> &>()).
38  def("literals", &SimpleConjunction::literals, return_value_policy<copy_const_reference>());
39  }

◆ createType< Storage >()

template<>
void knowrob::py::createType< Storage > ( )

Definition at line 49 of file Storage.cpp.

49  {
50  using namespace boost::python;
51  enum_<StorageFeature>("StorageFeature")
52  .value("NothingSpecial", StorageFeature::NothingSpecial)
53  .value("ReAssignment", StorageFeature::ReAssignment)
54  .value("TripleContext", StorageFeature::TripleContext)
55  .export_values();
56  class_<Storage, std::shared_ptr<StorageWrap>, bases<DataSourceHandler>, boost::noncopyable>
57  ("Storage", init<>())
58  .def("vocabulary", &Storage::vocabulary, return_value_policy<copy_const_reference>())
59  .def("supports", &Storage::supports)
60  .def("getVersionOfOrigin", &Storage::getVersionOfOrigin)
61  .def("setVersionOfOrigin", &Storage::setVersionOfOrigin)
62  // methods that must be implemented by backend plugins
63  .def("initializeBackend", pure_virtual(&Storage::initializeBackend))
64  .def("insertOne", pure_virtual(&Storage::insertOne))
65  .def("insertAll", pure_virtual(&Storage::insertAll))
66  .def("removeAll", pure_virtual(&Storage::removeAll))
67  .def("removeOne", pure_virtual(&Storage::removeOne))
68  .def("removeAllWithOrigin", pure_virtual(&Storage::removeAllWithOrigin));
69  register_ptr_to_python< std::shared_ptr< Storage > >();
72  }
void createType< QueryableStorage >()
void createType< Observer >()
Definition: Observer.cpp:30

◆ createType< String >()

template<>
void knowrob::py::createType< String > ( )

Definition at line 21 of file String.cpp.

21  {
22  using namespace boost::python;
23  class_<StringBase, std::shared_ptr<StringBase>, bases<XSDAtomic>, boost::noncopyable>
24  ("StringTerm", no_init)
25  .def("isSameString", &StringBase::isSameString);
26  class_<String, std::shared_ptr<String>, bases<StringBase>>
27  ("String", init<std::string_view>())
28  .def("__str__", &String::stringForm)
29  .def("__repr__", &String::stringForm);
30  class_<StringView, std::shared_ptr<StringView>, bases<StringBase>>
31  ("StringView", init<std::string_view>())
32  .def("__str__", &StringView::stringForm)
33  .def("__repr__", &StringView::stringForm);
34  }

◆ createType< Term >()

template<>
void knowrob::py::createType< Term > ( )

Definition at line 82 of file Term.cpp.

82  {
83  using namespace boost::python;
84  enum_<TermType>("TermType")
85  .value("FUNCTION", TermType::FUNCTION)
86  .value("ATOMIC", TermType::ATOMIC)
87  .value("VARIABLE", TermType::VARIABLE)
88  .export_values();
89  class_<Term, std::shared_ptr<TermWrap>, boost::noncopyable>
90  ("Term", no_init)
91  .def("__eq__", &Term::operator==)
92  .def("__str__", &Term::format)
93  .def("__repr__", &Term::format)
94  .def("__hash__", &Term::hash)
95  .def("termType", &Term::termType)
96  .def("isAtomic", &Term::isAtomic)
97  .def("isAtom", &Term::isAtom)
98  .def("isVariable", &Term::isVariable)
99  .def("isFunction", &Term::isFunction)
100  .def("isNumeric", &Term::isNumeric)
101  .def("isString", &Term::isString)
102  .def("isIRI", &Term::isIRI)
103  .def("isBlank", &Term::isBlank)
104  .def("isGround", &Term::isGround)
105  .def("variables", pure_virtual(&Term::variables), return_value_policy<copy_const_reference>());
106  // register shared_ptr to Term
107  register_ptr_to_python<std::shared_ptr<Term> >();
108  }

◆ createType< Token >()

template<>
void knowrob::py::createType< Token > ( )

Definition at line 42 of file Token.cpp.

42  {
43  using namespace boost::python;
44  enum_<TokenType>("TokenType")
45  .value("CONTROL_TOKEN", TokenType::CONTROL_TOKEN)
46  .value("ANSWER_TOKEN", TokenType::ANSWER_TOKEN)
47  .export_values();
48  class_<Token, std::shared_ptr<Token>, boost::noncopyable>
49  ("Token", no_init)
50  .def("__repr__", &Token::stringForm)
51  .def("__hash__", &Token::hash)
52  .def("tokenType", &Token::tokenType)
53  .def("indicatesEndOfEvaluation", &Token::indicatesEndOfEvaluation);
54  class_<EndOfEvaluation, bases<Token>, std::shared_ptr<EndOfEvaluation>>
55  ("EndOfEvaluation", no_init)
56  .def("get", &EndOfEvaluation::get, return_value_policy<reference_existing_object>())
57  .staticmethod("get");
58  // allow implicit conversion from shared_ptr<Token> to shared_ptr<const Token>
59  register_ptr_to_python<std::shared_ptr<const Token> >();
60  implicitly_convertible<std::shared_ptr<Token>, std::shared_ptr<const Token> >();
61  // create subtypes
63  }
void createType< Answer >()
Definition: Answer.cpp:163

◆ createType< TokenBroadcaster >()

template<>
void knowrob::py::createType< TokenBroadcaster > ( )

Definition at line 59 of file TokenBroadcaster.cpp.

59  {
60  using namespace boost::python;
61  class_<TokenBroadcaster, std::shared_ptr<TokenBroadcaster>, bases<TokenStream>, boost::noncopyable>
62  ("TokenBroadcaster", init<>())
63  .def("addSubscriber", &TokenBroadcaster::addSubscriber)
64  .def("removeSubscriber", &TokenBroadcaster::removeSubscriber);
65  }

◆ createType< TokenBuffer >()

template<>
void knowrob::py::createType< TokenBuffer > ( )

Definition at line 59 of file TokenBuffer.cpp.

59  {
60  using namespace boost::python;
61  class_<TokenBuffer, std::shared_ptr<TokenBuffer>, bases<TokenBroadcaster>, boost::noncopyable>
62  ("TokenBuffer", init<>())
63  .def("stopBuffering", with<no_gil>(&TokenBuffer::stopBuffering))
64  .def("createQueue", &TokenBuffer::createQueue);
65  }

◆ createType< TokenQueue >()

template<>
void knowrob::py::createType< TokenQueue > ( )

Definition at line 51 of file TokenQueue.cpp.

51  {
52  using namespace boost::python;
53  class_<TokenQueue, std::shared_ptr<TokenQueue>, bases<TokenStream>, boost::noncopyable>
54  ("TokenQueue", init<>())
55  .def("front", with<no_gil>(&TokenQueue::front, return_value_policy<reference_existing_object>()))
56  .def("pop", &TokenQueue::pop)
57  .def("pop_front", with<no_gil>(&TokenQueue::pop_front))
58  .def("empty", &TokenQueue::empty)
59  .def("size", &TokenQueue::size);
60  }

◆ createType< TokenStream >()

template<>
void knowrob::py::createType< TokenStream > ( )

Definition at line 142 of file TokenStream.cpp.

142  {
143  using namespace boost::python;
145  class_<TokenStream, std::shared_ptr<TokenStream>, boost::noncopyable>
146  ("TokenStream", no_init)
147  .def("isOpened", &TokenStream::isOpened);
148  class_<TokenStream::Channel, std::shared_ptr<TokenStream::Channel>, boost::noncopyable>
149  ("TokenChannel", no_init)
150  .def("create", &TokenStream::Channel::create).staticmethod("create")
151  .def("push", with<no_gil>(&TokenStream::Channel::push))
152  .def("close", with<no_gil>(&TokenStream::Channel::close))
153  .def("isOpened", &TokenStream::Channel::isOpened)
154  .def("id", &TokenStream::Channel::id);
158  }
void createType< TokenBroadcaster >()
void createType< Token >()
Definition: Token.cpp:42
void createType< TokenQueue >()
Definition: TokenQueue.cpp:51
void createType< TokenBuffer >()
Definition: TokenBuffer.cpp:59

◆ createType< Top >()

template<>
void knowrob::py::createType< Top > ( )

Definition at line 30 of file Top.cpp.

30  {
31  using namespace boost::python;
32  class_<Top, std::shared_ptr<Top>, bases<Predicate>>("Top", no_init)
33  .def("get", &Top::get, return_value_policy<copy_const_reference>());
34  }

◆ createType< Triple >()

template<>
void knowrob::py::createType< Triple > ( )

Definition at line 395 of file Triple.cpp.

395  {
396  using namespace boost::python;
397  class_<Triple, std::shared_ptr<TripleWrap>, boost::noncopyable>
398  ("Triple", no_init)
399  .def("__eq__", &Triple::operator==)
400  .def("isObjectIRI", &Triple::isObjectIRI)
401  .def("isSubjectIRI", &Triple::isSubjectIRI)
402  .def("isObjectBlank", &Triple::isObjectBlank)
403  .def("isSubjectBlank", &Triple::isSubjectBlank)
404  .def("isXSDLiteral", &Triple::isXSDLiteral)
405  .def("setSubject", pure_virtual(&Triple::setSubject))
406  .def("setPredicate", pure_virtual(&Triple::setPredicate))
407  .def("setSubjectBlank", pure_virtual(&Triple::setSubjectBlank))
408  .def("setObjectIRI", pure_virtual(&Triple::setObjectIRI))
409  .def("setObjectBlank", pure_virtual(&Triple::setObjectBlank))
410  .def("valueAsString", pure_virtual(&Triple::valueAsString))
411  .def("createStringValue", &Triple::createStringValue)
412  .def("setXSDValue", &Triple::setXSDValue)
413  .def("xsdTypeIRI", &Triple::xsdTypeIRI)
414  .def("setGraph", pure_virtual(&Triple::setGraph))
415  .def("setPerspective", pure_virtual(&Triple::setPerspective))
416  .def("setIsOccasional", &Triple::setIsOccasional)
417  .def("setIsUncertain", &Triple::setIsUncertain)
418  .def("setBegin", &Triple::setBegin)
419  .def("setEnd", &Triple::setEnd)
420  .def("setConfidence", &Triple::setConfidence)
421  .def("xsdType", &Triple::xsdType)
422  .def("subject", pure_virtual(&Triple::subject))
423  .def("predicate", pure_virtual(&Triple::predicate))
424  .def("graph", pure_virtual(&Triple::graph))
425  .def("perspective", pure_virtual(&Triple::perspective))
426  .def("isOccasional", &Triple::isOccasional)
427  .def("isUncertain", &Triple::isUncertain)
428  .def("begin", &Triple::begin)
429  .def("end", &Triple::end)
430  .def("confidence", &Triple::confidence);
431  class_<TripleCopy, std::shared_ptr<TripleCopy>, bases<Triple>>
432  ("TripleCopy", init<>())
433  .def(init<std::string_view, std::string_view, std::string_view>());
434  class_<TripleView, std::shared_ptr<TripleView>, bases<Triple>>
435  ("TripleView", init<>())
436  .def(init<std::string_view, std::string_view, std::string_view>());
437  class_<TriplePtr>("TriplePtr", init<>())
438  .def("get", &TriplePtr::get, return_value_policy<reference_existing_object>());
439  }
const IRIAtomPtr isOccasional
Definition: reification.h:19

◆ createType< TripleContainer >()

template<>
void knowrob::py::createType< TripleContainer > ( )

Definition at line 75 of file TripleContainer.cpp.

75  {
76  using namespace boost::python;
77  class_<TripleContainer, std::shared_ptr<TripleContainer>, boost::noncopyable>
78  ("TripleContainer", no_init)
79  .def("__iter__",
80  boost::python::iterator<TripleContainer, boost::python::return_value_policy<boost::python::copy_const_reference>>{});
81  }

◆ createType< TriplePattern >()

template<>
void knowrob::py::createType< TriplePattern > ( )

Definition at line 498 of file TriplePattern.cpp.

498  {
499  using namespace boost::python;
500  class_<TriplePattern, std::shared_ptr<TriplePattern>, bases<FirstOrderLiteral>>
501  ("TriplePattern", init<const Triple &, bool>())
502  .def(init<const Triple &>())
503  .def("subjectTerm", &TriplePattern::subjectTerm, return_value_policy<return_by_value>())
504  .def("propertyTerm", &TriplePattern::propertyTerm, return_value_policy<return_by_value>())
505  .def("objectTerm", &TriplePattern::objectTerm, return_value_policy<return_by_value>())
506  .def("graphTerm", &TriplePattern::graphTerm, return_value_policy<return_by_value>())
507  .def("perspectiveTerm", &TriplePattern::perspectiveTerm, return_value_policy<return_by_value>())
508  .def("beginTerm", &TriplePattern::beginTerm, return_value_policy<return_by_value>())
509  .def("endTerm", &TriplePattern::endTerm, return_value_policy<return_by_value>())
510  .def("confidenceTerm", &TriplePattern::confidenceTerm, return_value_policy<return_by_value>())
511  .def("objectOperator", &TriplePattern::objectOperator)
512  .def("isOccasionalTerm", &TriplePattern::isOccasionalTerm, return_value_policy<return_by_value>())
513  .def("isUncertainTerm", &TriplePattern::isUncertainTerm, return_value_policy<return_by_value>())
514  .def("setGraphName", &TriplePattern::setGraphName)
515  .def("setPerspectiveTerm", &TriplePattern::setPerspectiveTerm)
516  .def("setBeginTerm", &TriplePattern::setBeginTerm)
517  .def("setEndTerm", &TriplePattern::setEndTerm)
518  .def("setConfidenceTerm", &TriplePattern::setConfidenceTerm)
519  .def("setObjectOperator", &TriplePattern::setObjectOperator)
520  .def("setIsOccasionalTerm", &TriplePattern::setIsOccasionalTerm)
521  .def("setIsUncertainTerm", &TriplePattern::setIsUncertainTerm)
522  .def("filter", &TriplePattern::filter)
523  .def("instantiateInto", &TriplePattern::instantiateInto)
524  .def("getVariables", &TriplePattern::getVariables)
525  .def("numVariables", &TriplePattern::numVariables)
526  .def("getTripleFrame", &TriplePattern::getTripleFrame)
527  .def("setTripleFrame", &TriplePattern::setTripleFrame);
528 
529  // allow conversion between std::vector and python::list for TriplePattern objects.
530  typedef std::vector<std::shared_ptr<TriplePattern>> GoalList;
532  boost::python::class_<GoalList>("GoalList").def(boost::python::vector_indexing_suite<GoalList, true>());
533  }
GraphTermRule & graphTerm()
Definition: graph.cpp:77

◆ createType< Variable >()

template<>
void knowrob::py::createType< Variable > ( )

Definition at line 37 of file Variable.cpp.

37  {
38  using namespace boost::python;
39  class_<Variable, std::shared_ptr<Variable>, bases<Term>>
40  ("Variable", init<std::string_view>())
41  .def(self < self)
42  .def("name", &Variable::name)
43  .def("isSameVariable", &Variable::isSameVariable);
44  }

◆ createType< Vocabulary >()

template<>
void knowrob::py::createType< Vocabulary > ( )

Definition at line 271 of file Vocabulary.cpp.

271  {
272  using namespace boost::python;
273 
274  using PropertyFun = semweb::PropertyPtr (Vocabulary::*)(const std::string_view &);
275  using SetFlag = void (Vocabulary::*)(const std::string_view &, semweb::PropertyFlag);
276 
277  createType<semweb::Resource>();
278  createType<semweb::Property>();
279  createType<semweb::Class>();
281 
282  class_<Vocabulary, std::shared_ptr<Vocabulary>, boost::noncopyable>
283  ("Vocabulary", init<>())
284  .def("addResourceType", &Vocabulary::addResourceType)
285  .def("isDefinedClass", &Vocabulary::isDefinedClass)
286  .def("getDefinedClass", &Vocabulary::getDefinedClass)
287  .def("getDefinedClassesWithPrefix", &Vocabulary::getDefinedClassesWithPrefix)
288  .def("getDefinedClassNamesWithPrefix", &Vocabulary::getDefinedClassNamesWithPrefix)
289  .def("defineClass", &Vocabulary::defineClass)
290  .def("addSubClassOf", &Vocabulary::addSubClassOf)
291  .def("isSubClassOf", &Vocabulary::isSubClassOf)
292  .def("isDefinedProperty", &Vocabulary::isDefinedProperty)
293  .def("isDefinedReification", &Vocabulary::isDefinedReification)
294  .def("getDefinedProperty", &Vocabulary::getDefinedProperty)
295  .def("getDefinedReification", &Vocabulary::getDefinedReification)
296  .def("getDefinedPropertiesWithPrefix", &Vocabulary::getDefinedPropertiesWithPrefix)
297  .def("getDefinedPropertyNamesWithPrefix", &Vocabulary::getDefinedPropertyNamesWithPrefix)
298  .def("defineProperty", static_cast<PropertyFun>(&Vocabulary::defineProperty))
299  .def("addSubPropertyOf", &Vocabulary::addSubPropertyOf)
300  .def("setInverseOf", &Vocabulary::setInverseOf)
301  .def("setPropertyFlag", static_cast<SetFlag>(&Vocabulary::setPropertyFlag))
302  .def("isAnnotationProperty", &Vocabulary::isAnnotationProperty)
303  .def("isObjectProperty", &Vocabulary::isObjectProperty)
304  .def("isDatatypeProperty", &Vocabulary::isDatatypeProperty)
305  .def("isTaxonomicProperty", &Vocabulary::isTaxonomicProperty)
306  .def("setFrequency", &Vocabulary::setFrequency)
307  .def("increaseFrequency", &Vocabulary::increaseFrequency)
308  .def("frequency", &Vocabulary::frequency)
309  .def("importHierarchy", &Vocabulary::importHierarchy, return_value_policy<copy_const_reference>());
310  }
void createType< ImportHierarchy >()
std::shared_ptr< Property > PropertyPtr
Definition: Property.h:175

◆ createType< XSDAtomic >()

template<>
void knowrob::py::createType< XSDAtomic > ( )

Definition at line 97 of file XSDAtomic.cpp.

97  {
98  using namespace boost::python;
99  enum_<XSDType>("XSDType")
100  .value("STRING", XSDType::STRING)
101  .value("BOOLEAN", XSDType::BOOLEAN)
102  .value("DOUBLE", XSDType::DOUBLE)
103  .value("FLOAT", XSDType::FLOAT)
104  .value("INTEGER", XSDType::INTEGER)
105  .value("LONG", XSDType::LONG)
106  .value("SHORT", XSDType::SHORT)
107  .value("UNSIGNED_LONG", XSDType::UNSIGNED_LONG)
108  .value("UNSIGNED_INT", XSDType::UNSIGNED_INT)
109  .value("UNSIGNED_SHORT", XSDType::UNSIGNED_SHORT)
110  .export_values();
111  class_<XSDAtomic, std::shared_ptr<XSDAtomic>, bases<Atomic, RDFNode>, boost::noncopyable>
112  ("XSDAtomic", no_init)
113  .def("xsdTypeIRI", &XSDAtomic::xsdTypeIRI)
114  .def("xsdType", &XSDAtomic::xsdType)
115  .def("create", &XSDAtomic::create);
116  }

◆ dict_to_map()

std::unordered_map< std::string, boost::any > knowrob::py::dict_to_map ( const boost::python::dict &  py_dict)

Definition at line 32 of file dict.h.

32  {
33  std::unordered_map<std::string, boost::any> map;
34  boost::python::list keys = py_dict.keys();
35  for (int i = 0; i < len(keys); ++i) {
36  std::string key = boost::python::extract<std::string>(keys[i]);
37  boost::python::object value = py_dict[keys[i]];
38  map[key] = python_to_boost_any(value);
39  }
40  return map;
41  }
boost::any python_to_boost_any(const boost::python::object &obj)
Definition: dict.h:13

◆ python_to_boost_any()

boost::any knowrob::py::python_to_boost_any ( const boost::python::object &  obj)

Definition at line 13 of file dict.h.

13  {
14  using namespace boost::python;
15 
16  if (extract<int>(obj).check()) {
17  return boost::any(extract<int>(obj)());
18  } else if (extract<double>(obj).check()) {
19  return boost::any(extract<double>(obj)());
20  } else if (extract<std::string>(obj).check()) {
21  return boost::any(extract<std::string>(obj)());
22  } else {
23  // Add more type checks as needed
24  PyErr_SetString(PyExc_TypeError, "Unsupported type in Python object");
25  throw_error_already_set();
26  }
27 
28  return boost::any(); // This will never be reached
29  }

◆ register_dict_to_map_converter()

void knowrob::py::register_dict_to_map_converter ( )

Definition at line 59 of file dict.h.

59  {
60  boost::python::converter::registry::push_back(
61  &DictToMapConverter::convertible,
62  &DictToMapConverter::construct,
63  boost::python::type_id<std::unordered_map<std::string, boost::any>>());
64  }

◆ register_list_converter()

void knowrob::py::register_list_converter ( )

Definition at line 29 of file list.h.

29  {
30  boost::python::to_python_converter<std::list<std::shared_ptr<knowrob::DataSource>>, list_to_pylist<std::shared_ptr<knowrob::DataSource>>>();
31  }

◆ register_pair_converter()

void knowrob::py::register_pair_converter ( )

Definition at line 24 of file pair.h.

24  {
25  boost::python::to_python_converter<std::pair<std::basic_string_view<char, std::char_traits<char> > const, std::pair<std::shared_ptr<knowrob::Variable>, std::shared_ptr<knowrob::Term> > >, PairToTupleConverter>();
26  }

◆ register_string_view_converter()

void knowrob::py::register_string_view_converter ( )

Definition at line 33 of file string_view.h.

33  {
34  boost::python::to_python_converter<std::string_view, string_view_to_python_str>();
35  boost::python::converter::registry::push_back(
36  &python_str_to_string_view::convertible,
37  &python_str_to_string_view::construct,
38  boost::python::type_id<std::string_view>()
39  );
40  }

◆ resolveModulePath()

std::string knowrob::py::resolveModulePath ( std::string_view  modulePath)

Resolve a module path to a file path.

Parameters
modulePaththe module path.
Returns
the file path.

Definition at line 13 of file utils.cpp.

13  {
14  // guess if '/' or '.' is used as delimiter
15  if (modulePath.find('/') != std::string::npos) {
16  return URI::resolve(modulePath);
17  } else {
18  // replace '.' with '/', assuming dots do not appear in directory names.
19  std::string modulePath_withSlash(modulePath);
20  std::replace(modulePath_withSlash.begin(), modulePath_withSlash.end(), '.', '/');
21  return URI::resolve(modulePath_withSlash);
22  }
23  }

◆ staticKnowRobModuleInit()

void knowrob::py::staticKnowRobModuleInit ( )

Initialize the Python module.

Definition at line 134 of file knowrob.cpp.

134  {
135  using namespace boost::python;
136  using namespace knowrob;
137 
139  // mappings for static functions
140  def("InitKnowRobWithArgs", &py_InitKnowRob1, "Initialize the Knowledge Base with arguments.");
141  def("InitKnowRob", &py_InitKnowRob2, "Initialize the Knowledge Base using sys.argv.");
142  def("ShutdownKnowRob", &ShutdownKnowRob);
143  }
void ShutdownKnowRob()
Definition: knowrob.cpp:123

◆ with() [1/2]

template<typename Guard , typename Fn >
boost::python::object knowrob::py::with ( const Fn &  fn)

Create a callable object with guards.

Definition at line 102 of file with.h.

102  {
103  return with<Guard>(fn, boost::python::default_call_policies());
104  }

◆ with() [2/2]

template<typename Guard , typename Fn , typename Policy >
boost::python::object knowrob::py::with ( const Fn &  fn,
const Policy &  policy 
)

Create a callable object with guards.

Definition at line 96 of file with.h.

96  {
97  return with_aux<Guard>(fn, policy);
98  }

◆ with_aux()

template<typename Guard , typename Fn , typename Policy >
boost::python::object knowrob::py::with_aux ( Fn  fn,
const Policy &  policy 
)

Create a callable object with guards.

Definition at line 71 of file with.h.

71  {
72  // Obtain the components of the Fn. This will decompose non-member
73  // and member functions into an mpl sequence.
74  // R (*)(A1) => R, A1
75  // R (C::*)(A1) => R, C*, A1
76  typedef typename mpl_signature<Fn>::type mpl_signature_type;
77 
78  // Synthesize the components into a function type. This process
79  // causes member functions to require the instance argument.
80  // This is necessary because member functions will be explicitly
81  // provided the 'self' argument.
82  // R, A1 => R (*)(A1)
83  // R, C*, A1 => R (*)(C*, A1)
84  typedef typename boost::function_types::function_type<
85  mpl_signature_type>::type signature_type;
86 
87  // Create a callable boost::python::object that delegates to the
88  // guarded_function.
89  return boost::python::make_function(
90  guarded_function<signature_type, Guard>(fn),
91  policy, mpl_signature_type());
92  }