knowrob  2.1.0
A Knowledge Base System for Cognition-enabled Robots
MongologReasoner.cpp File Reference
#include <gtest/gtest.h>
#include "knowrob/Logger.h"
#include "knowrob/reasoner/prolog/PrologTests.h"
#include "knowrob/reasoner/ReasonerManager.h"
#include "knowrob/reasoner/mongolog/MongologReasoner.h"
#include "knowrob/queries/QueryError.h"
#include "knowrob/reasoner/ReasonerError.h"
#include "knowrob/terms/Numeric.h"
#include "knowrob/knowrob.h"
Include dependency graph for MongologReasoner.cpp:

Go to the source code of this file.

Namespaces

 knowrob
 
 knowrob::testing
 

Functions

foreign_t pl_is_readonly2 (term_t, term_t)
 
foreign_t pl_db_name3 (term_t, term_t, term_t)
 
foreign_t pl_uri3 (term_t, term_t, term_t)
 
foreign_t pl_assert_triple_cpp9 (term_t, term_t, term_t, term_t, term_t, term_t, term_t, term_t, term_t)
 
 TEST_F (MongologTests, arithmetic)
 
 TEST_F (MongologTests, atoms)
 
 TEST_F (MongologTests, comparison)
 
 TEST_F (MongologTests, control)
 
 TEST_F (MongologTests, findall)
 
 TEST_F (MongologTests, lists)
 
 TEST_F (MongologTests, meta)
 
 TEST_F (MongologTests, terms)
 
 TEST_F (MongologTests, typecheck)
 
 TEST_F (MongologTests, unification)
 
 TEST_F (MongologTests, database)
 
 TEST_F (MongologTests, fluents)
 
 TEST_F (MongologTests, sgml)
 
 TEST_F (MongologTests, annotation)
 
 TEST_F (MongologTests, triple)
 

Function Documentation

◆ pl_assert_triple_cpp9()

foreign_t pl_assert_triple_cpp9 ( term_t  t_reasonerManager,
term_t  t_reasonerModule,
term_t  t_subjectTerm,
term_t  t_propertyTerm,
term_t  t_objectTerm,
term_t  t_graphTerm,
term_t  t_beginTerm,
term_t  t_endTerm,
term_t  t_confidenceTerm 
)

Definition at line 136 of file MongologReasoner.cpp.

144  {
145  auto mongolog = getMongologReasoner(t_reasonerManager, t_reasonerModule);
146  if (mongolog) {
147  TripleView tripleData;
148 
149  // "s" field
150  auto subjectTerm = PrologTerm::toKnowRobTerm(t_subjectTerm);
151  if (subjectTerm->termType() != TermType::ATOMIC) throw QueryError("invalid subject term {}", *subjectTerm);
152  tripleData.setSubject(((Atomic *) subjectTerm.get())->stringForm());
153 
154  // "p" field
155  auto propertyTerm = PrologTerm::toKnowRobTerm(t_propertyTerm);
156  if (propertyTerm->termType() != TermType::ATOMIC) throw QueryError("invalid property term {}", *propertyTerm);
157  tripleData.setPredicate(((Atomic *) propertyTerm.get())->stringForm());
158 
159  // "o" field
160  auto objectTerm = PrologTerm::toKnowRobTerm(t_objectTerm);
161  if(objectTerm->termType() == TermType::ATOMIC) {
162  auto atomic = std::static_pointer_cast<Atomic>(objectTerm);
163  if (atomic->isNumeric()) {
164  tripleData.setXSDValue(atomic->stringForm(),
165  std::static_pointer_cast<Numeric>(atomic)->xsdType());
166  } else if (atomic->isIRI()) {
167  tripleData.setObjectIRI(atomic->stringForm());
168  } else if (atomic->isBlank()) {
169  tripleData.setObjectBlank(atomic->stringForm());
170  } else {
171  tripleData.setStringValue(atomic->stringForm());
172  }
173  } else {
174  throw QueryError("object term {} of triple has an invalid type", *objectTerm);
175  }
176 
177  // "g" field
179  if (!PL_is_variable(t_graphTerm)) {
180  graphTerm = PrologTerm::toKnowRobTerm(t_graphTerm);
181  if (graphTerm->termType() != TermType::ATOMIC) throw QueryError("invalid property term {}", *graphTerm);
182  tripleData.setGraph(((Atomic *) graphTerm.get())->stringForm());
183  } else {
184  tripleData.setGraph(mongolog->reasonerManager().backendManager()->vocabulary()->importHierarchy()->defaultGraph());
185  }
186 
187  // "c" field
188  TermPtr confidenceTerm;
189  if (!PL_is_variable(t_confidenceTerm)) {
190  confidenceTerm = PrologTerm::toKnowRobTerm(t_confidenceTerm);
191  if (confidenceTerm->isNumeric()) {
192  tripleData.setConfidence(std::static_pointer_cast<Numeric>(confidenceTerm)->asDouble());
193  } else {
194  throw QueryError("invalid confidence term {}", *confidenceTerm);
195  }
196  }
197 
198  // "b" field
199  TermPtr beginTerm;
200  if (!PL_is_variable(t_beginTerm)) {
201  beginTerm = PrologTerm::toKnowRobTerm(t_beginTerm);
202  if (beginTerm->isNumeric()) {
203  tripleData.setBegin(std::static_pointer_cast<Numeric>(beginTerm)->asDouble());
204  } else {
205  throw QueryError("invalid begin term {}", *beginTerm);
206  }
207  }
208 
209  // "e" field
210  TermPtr endTerm;
211  if (!PL_is_variable(t_endTerm)) {
212  endTerm = PrologTerm::toKnowRobTerm(t_endTerm);
213  if (endTerm->isNumeric()) {
214  tripleData.setEnd(std::static_pointer_cast<Numeric>(endTerm)->asDouble());
215  } else {
216  throw QueryError("invalid end term {}", *endTerm);
217  }
218  }
219 
220  mongolog->reasonerManager().kb()->edb()->mergeInsert(mongolog->knowledgeGraph(), tripleData);
221  //mongolog->kb()->insertOne(tripleData);
222  return true;
223  } else {
224  KB_WARN("[mongolog] unable to assert triple: reasoner not found");
225  return false;
226  }
227 }
#define KB_WARN
Definition: Logger.h:27
void setConfidence(double confidence)
Definition: Triple.h:307
void setBegin(double begin)
Definition: Triple.h:297
void setEnd(double end)
Definition: Triple.h:302
void setXSDValue(std::string_view v, XSDType type)
Definition: Triple.cpp:32
void setStringValue(std::string_view v) override
Definition: Triple.h:464
void setObjectIRI(std::string_view object) override
Definition: Triple.h:452
void setPredicate(std::string_view predicate) override
Definition: Triple.h:449
void setObjectBlank(std::string_view identifier) override
Definition: Triple.h:461
void setGraph(std::string_view graph) override
Definition: Triple.h:497
void setSubject(std::string_view subject) override
Definition: Triple.h:446
GraphTermRule & graphTerm()
Definition: graph.cpp:77
TermRule & atomic()
Definition: terms.cpp:79
std::shared_ptr< Term > TermPtr
Definition: Term.h:117

◆ pl_db_name3()

foreign_t pl_db_name3 ( term_t  t_reasonerManager,
term_t  t_reasonerModule,
term_t  t_dbName 
)

Definition at line 118 of file MongologReasoner.cpp.

118  {
119  auto mongolog = getMongologReasoner(t_reasonerManager, t_reasonerModule);
120  if (mongolog) {
121  auto &dbName = mongolog->knowledgeGraph()->dbName();
122  return PL_unify_atom_chars(t_dbName, dbName.c_str());
123  }
124  return false;
125 }

◆ pl_is_readonly2()

foreign_t pl_is_readonly2 ( term_t  t_reasonerManager,
term_t  t_reasonerModule 
)

Definition at line 110 of file MongologReasoner.cpp.

110  {
111  auto mongolog = getMongologReasoner(t_reasonerManager, t_reasonerModule);
112  if (mongolog) {
113  return mongolog->knowledgeGraph()->isReadOnly();
114  }
115  return false;
116 }

◆ pl_uri3()

foreign_t pl_uri3 ( term_t  t_reasonerManager,
term_t  t_reasonerModule,
term_t  t_uri 
)

Definition at line 127 of file MongologReasoner.cpp.

127  {
128  auto mongolog = getMongologReasoner(t_reasonerManager, t_reasonerModule);
129  if (mongolog) {
130  auto &uri = mongolog->knowledgeGraph()->dbURI();
131  return PL_unify_atom_chars(t_uri, uri.c_str());
132  }
133  return false;
134 }

◆ TEST_F() [1/15]

TEST_F ( MongologTests  ,
annotation   
)

Definition at line 338 of file MongologReasoner.cpp.

338 { runTests(getPath("annotation.pl")); }

◆ TEST_F() [2/15]

TEST_F ( MongologTests  ,
arithmetic   
)

Definition at line 312 of file MongologReasoner.cpp.

312 { runTests(getPath("iso/arithmetic.pl")); }

◆ TEST_F() [3/15]

TEST_F ( MongologTests  ,
atoms   
)

Definition at line 314 of file MongologReasoner.cpp.

314 { runTests(getPath("iso/atoms.pl")); }

◆ TEST_F() [4/15]

TEST_F ( MongologTests  ,
comparison   
)

Definition at line 316 of file MongologReasoner.cpp.

316 { runTests(getPath("iso/comparison.pl")); }

◆ TEST_F() [5/15]

TEST_F ( MongologTests  ,
control   
)

Definition at line 318 of file MongologReasoner.cpp.

318 { runTests(getPath("iso/control.pl")); }

◆ TEST_F() [6/15]

TEST_F ( MongologTests  ,
database   
)

Definition at line 332 of file MongologReasoner.cpp.

332 { runTests(getPath("database.pl")); }

◆ TEST_F() [7/15]

TEST_F ( MongologTests  ,
findall   
)

Definition at line 320 of file MongologReasoner.cpp.

320 { runTests(getPath("iso/findall.pl")); }

◆ TEST_F() [8/15]

TEST_F ( MongologTests  ,
fluents   
)

Definition at line 334 of file MongologReasoner.cpp.

334 { runTests(getPath("fluents.pl")); }

◆ TEST_F() [9/15]

TEST_F ( MongologTests  ,
lists   
)

Definition at line 322 of file MongologReasoner.cpp.

322 { runTests(getPath("iso/lists.pl")); }

◆ TEST_F() [10/15]

TEST_F ( MongologTests  ,
meta   
)

Definition at line 324 of file MongologReasoner.cpp.

324 { runTests(getPath("iso/meta.pl")); }

◆ TEST_F() [11/15]

TEST_F ( MongologTests  ,
sgml   
)

Definition at line 336 of file MongologReasoner.cpp.

336 { runTests(getPath("sgml.pl")); }

◆ TEST_F() [12/15]

TEST_F ( MongologTests  ,
terms   
)

Definition at line 326 of file MongologReasoner.cpp.

326 { runTests(getPath("iso/terms.pl")); }

◆ TEST_F() [13/15]

TEST_F ( MongologTests  ,
triple   
)

Definition at line 340 of file MongologReasoner.cpp.

340 { runTests(getPath("triple.plt")); }

◆ TEST_F() [14/15]

TEST_F ( MongologTests  ,
typecheck   
)

Definition at line 328 of file MongologReasoner.cpp.

328 { runTests(getPath("iso/typecheck.pl")); }

◆ TEST_F() [15/15]

TEST_F ( MongologTests  ,
unification   
)

Definition at line 330 of file MongologReasoner.cpp.

330 { runTests(getPath("iso/unification.pl")); }