9 #include <unordered_map>
10 #include <boost/any.hpp>
11 #include <boost/property_tree/json_parser.hpp>
12 #include "knowrob/integration/InterfaceUtils.h"
13 #include "knowrob/formulas/ModalFormula.h"
14 #include "knowrob/semweb/Triple.h"
15 #include "knowrob/queries/QueryTree.h"
16 #include "knowrob/queries/QueryError.h"
17 #include "knowrob/KnowledgeBase.h"
38 if (std::getenv(
"KNOWROB_SETTINGS")) {
39 config_path = std::getenv(
"KNOWROB_SETTINGS");
43 boost::property_tree::ptree config;
44 boost::property_tree::read_json(
53 std::vector<TriplePtr> data(args.size());
54 std::vector<TriplePatternPtr> buf(args.size());
55 uint32_t dataIndex = 0;
57 for (
auto &phi: args) {
60 throw QueryError(
"Disjunctions are not allowed in assertions. "
61 "Appears in statement {}.", *phi);
63 throw QueryError(
"Invalid assertion: '{}'", *phi);
65 for (
auto &psi: qt.
begin()->nodes()) {
66 switch (psi->type()) {
68 buf[dataIndex] = std::make_shared<TriplePattern>(
69 std::static_pointer_cast<Predicate>(psi),
false);
71 data[dataIndex].owned =
true;
72 buf[dataIndex]->instantiateInto(*data[dataIndex].ptr);
76 throw QueryError(
"Invalid assertion: '{}'", *phi);
80 if (kb_->insertAll(data)) {
81 std::cout <<
"success, " << dataIndex <<
" statement(s) were asserted." <<
"\n";
84 std::cout <<
"assertion failed." <<
"\n";
95 auto epistemicOperator = boost::any_cast<int>(
options.at(
"epistemicOperator"));
98 auto aboutAgentIRI = boost::any_cast<std::string>(
options.at(
"aboutAgentIRI"));
99 auto confidence = boost::any_cast<double>(
options.at(
"confidence"));
100 if (!aboutAgentIRI.empty()) {
101 if (confidence != 1.0) {
102 mFormula = std::make_shared<ModalFormula>(
103 modals::B(aboutAgentIRI, confidence), mFormula);
105 mFormula = std::make_shared<ModalFormula>(
111 auto aboutAgentIRI = boost::any_cast<std::string>(
options.at(
"aboutAgentIRI"));
112 if (!aboutAgentIRI.empty()) {
113 mFormula = std::make_shared<ModalFormula>(
118 auto temporalOperator = boost::any_cast<int>(
options.at(
"temporalOperator"));
121 auto minPastTimestamp = boost::any_cast<double>(
options.at(
"minPastTimestamp"));
122 auto maxPastTimestamp = boost::any_cast<double>(
options.at(
"maxPastTimestamp"));
124 auto minPastTimePoint =
127 auto maxPastTimePoint =
132 if (minPastTimestamp != -1 || maxPastTimestamp != -1) {
133 if (minPastTimestamp == -1) {
134 mFormula = std::make_shared<ModalFormula>(
136 maxPastTimePoint)), mFormula);
137 }
else if (maxPastTimestamp == -1) {
138 mFormula = std::make_shared<ModalFormula>(
140 std::nullopt)), mFormula);
142 mFormula = std::make_shared<ModalFormula>(
144 maxPastTimePoint)), mFormula);
147 mFormula = std::make_shared<ModalFormula>(
151 if (minPastTimestamp != -1 || maxPastTimestamp != -1) {
152 if (minPastTimestamp == -1) {
153 mFormula = std::make_shared<ModalFormula>(
155 maxPastTimePoint)), mFormula);
156 }
else if (maxPastTimestamp == -1) {
157 mFormula = std::make_shared<ModalFormula>(
159 std::nullopt)), mFormula);
161 mFormula = std::make_shared<ModalFormula>(
163 maxPastTimePoint)), mFormula);
166 mFormula = std::make_shared<ModalFormula>(
179 class_<InterfaceUtils>(
"InterfaceUtils")
184 enum_<EpistemicOperator>(
"EpistemicOperator")
187 enum_<TemporalOperator>(
"TemporalOperator")
static boost::property_tree::ptree loadSettings()
static FormulaPtr applyModality(const std::unordered_map< std::string, boost::any > &options, FormulaPtr phi)
static bool assertStatements(const KnowledgeBasePtr &kb, const std::vector< FormulaPtr > &args)
std::shared_ptr< ModalFormula > K(const FormulaPtr &phi)
std::shared_ptr< ModalFormula > P(const FormulaPtr &phi)
std::shared_ptr< ModalFormula > B(const FormulaPtr &phi)
std::shared_ptr< ModalFormula > H(const FormulaPtr &phi)
void createType< InterfaceUtils >()
TimePoint fromSeconds(double seconds)
std::shared_ptr< KnowledgeBase > KnowledgeBasePtr
TripleTemplate< std::string > TripleCopy
std::shared_ptr< Formula > FormulaPtr