knowrob  2.1.0
A Knowledge Base System for Cognition-enabled Robots
semweb.cpp File Reference
#include <SWI-cpp.h>
#include "knowrob/reasoner/prolog/semweb.h"
#include "knowrob/reasoner/prolog/PrologReasoner.h"
#include "knowrob/reasoner/ReasonerManager.h"
#include "knowrob/semweb/ImportHierarchy.h"
#include "knowrob/semweb/OntologyFile.h"
#include "knowrob/URI.h"
Include dependency graph for semweb.cpp:

Go to the source code of this file.

Namespaces

 knowrob
 
 knowrob::prolog
 

Macros

#define PL_SAFE_ARG_MACROS
 

Functions

foreign_t sw_current_graph3 (term_t t_manager, term_t t_reasoner, term_t t_graph)
 
foreign_t sw_set_current_graph3 (term_t t_manager, term_t t_reasoner, term_t t_graph)
 
foreign_t sw_unset_current_graph3 (term_t t_manager, term_t t_reasoner, term_t t_origin)
 
foreign_t sw_graph_add_direct_import4 (term_t t_manager, term_t t_reasoner, term_t t_importer, term_t t_imported)
 
foreign_t sw_graph_get_imports4 (term_t t_manager, term_t t_reasoner, term_t t_importer, term_t t_importedList)
 
foreign_t sw_set_default_graph3 (term_t t_manager, term_t t_reasoner, term_t t_graph)
 
foreign_t sw_default_graph3 (term_t t_manager, term_t t_reasoner, term_t t_graph)
 
foreign_t sw_origin_any1 (term_t t_origin)
 
foreign_t sw_origin_system1 (term_t t_origin)
 
foreign_t sw_origin_session1 (term_t t_origin)
 
foreign_t sw_origin_user1 (term_t t_origin)
 
foreign_t sw_origin_reasoner1 (term_t t_origin)
 
foreign_t sw_origin_test1 (term_t t_origin)
 
foreign_t sw_url_graph2 (term_t t_url, term_t t_graph)
 
foreign_t sw_url_version2 (term_t t_url, term_t t_version)
 
foreign_t sw_load_rdf_xml4 (term_t t_manager, term_t t_reasoner, term_t t_url, term_t t_parentGraph)
 

Macro Definition Documentation

◆ PL_SAFE_ARG_MACROS

#define PL_SAFE_ARG_MACROS

Definition at line 6 of file semweb.cpp.

Function Documentation

◆ sw_current_graph3()

foreign_t sw_current_graph3 ( term_t  t_manager,
term_t  t_reasoner,
term_t  t_graph 
)

Definition at line 36 of file semweb.cpp.

36  {
37  auto hierarchy = getImportHierarchy(t_manager, t_reasoner);
38 
39  char *graph;
40  if (hierarchy && PL_get_atom_chars(t_graph, &graph)) {
41  return hierarchy->isCurrentGraph(graph);
42  } else {
43  return false;
44  }
45 }

◆ sw_default_graph3()

foreign_t sw_default_graph3 ( term_t  t_manager,
term_t  t_reasoner,
term_t  t_graph 
)

Definition at line 109 of file semweb.cpp.

109  {
110  auto hierarchy = getImportHierarchy(t_manager, t_reasoner);
111  return hierarchy && PL_unify_atom_chars(t_graph, hierarchy->defaultGraph().c_str());
112 }

◆ sw_graph_add_direct_import4()

foreign_t sw_graph_add_direct_import4 ( term_t  t_manager,
term_t  t_reasoner,
term_t  t_importer,
term_t  t_imported 
)

Definition at line 71 of file semweb.cpp.

71  {
72  auto hierarchy = getImportHierarchy(t_manager, t_reasoner);
73 
74  char *importer, *imported;
75  if (hierarchy &&
76  PL_get_atom_chars(t_importer, &importer) &&
77  PL_get_atom_chars(t_imported, &imported)) {
78  hierarchy->addDirectImport(importer, imported);
79  return true;
80  } else {
81  return false;
82  }
83 }

◆ sw_graph_get_imports4()

foreign_t sw_graph_get_imports4 ( term_t  t_manager,
term_t  t_reasoner,
term_t  t_importer,
term_t  t_importedList 
)

Definition at line 85 of file semweb.cpp.

85  {
86  auto hierarchy = getImportHierarchy(t_manager, t_reasoner);
87  char *importer;
88  if (hierarchy && PL_get_atom_chars(t_importer, &importer)) {
89  PlTail l(t_importedList);
90  for (auto &x: hierarchy->getImports(importer))
91  l.append(x->name().c_str());
92  l.close();
93  return true;
94  }
95  return false;
96 }

◆ sw_load_rdf_xml4()

foreign_t sw_load_rdf_xml4 ( term_t  t_manager,
term_t  t_reasoner,
term_t  t_url,
term_t  t_parentGraph 
)

Definition at line 156 of file semweb.cpp.

156  {
157  auto kb = getKnowledgeBase(t_manager, t_reasoner);
158  char *url, *parentGraph;
159  if (kb && PL_get_atom_chars(t_url, &url) && PL_get_atom_chars(t_parentGraph, &parentGraph)) {
160  URI ontologyURI(url);
161  auto ontologyFile = std::make_shared<OntologyFile>(kb->vocabulary(), ontologyURI, "rdf-xml");
162  ontologyFile->setParentOrigin(parentGraph);
163  if (kb->loadDataSource(ontologyFile)) {
164  return true;
165  }
166  }
167  return false;
168 }

◆ sw_origin_any1()

foreign_t sw_origin_any1 ( term_t  t_origin)

Definition at line 114 of file semweb.cpp.

114  {
115  return PL_unify_atom_chars(t_origin, ImportHierarchy::ORIGIN_ANY.data());
116 }

◆ sw_origin_reasoner1()

foreign_t sw_origin_reasoner1 ( term_t  t_origin)

Definition at line 130 of file semweb.cpp.

130  {
131  return PL_unify_atom_chars(t_origin, ImportHierarchy::ORIGIN_REASONER.data());
132 }

◆ sw_origin_session1()

foreign_t sw_origin_session1 ( term_t  t_origin)

Definition at line 122 of file semweb.cpp.

122  {
123  return PL_unify_atom_chars(t_origin, ImportHierarchy::ORIGIN_SESSION.data());
124 }

◆ sw_origin_system1()

foreign_t sw_origin_system1 ( term_t  t_origin)

Definition at line 118 of file semweb.cpp.

118  {
119  return PL_unify_atom_chars(t_origin, ImportHierarchy::ORIGIN_SYSTEM.data());
120 }

◆ sw_origin_test1()

foreign_t sw_origin_test1 ( term_t  t_origin)

Definition at line 134 of file semweb.cpp.

134  {
135  return PL_unify_atom_chars(t_origin, ImportHierarchy::ORIGIN_TEST.data());
136 }

◆ sw_origin_user1()

foreign_t sw_origin_user1 ( term_t  t_origin)

Definition at line 126 of file semweb.cpp.

126  {
127  return PL_unify_atom_chars(t_origin, ImportHierarchy::ORIGIN_USER.data());
128 }

◆ sw_set_current_graph3()

foreign_t sw_set_current_graph3 ( term_t  t_manager,
term_t  t_reasoner,
term_t  t_graph 
)

Definition at line 47 of file semweb.cpp.

47  {
48  auto hierarchy = getImportHierarchy(t_manager, t_reasoner);
49 
50  char *graph;
51  if (hierarchy && PL_get_atom_chars(t_graph, &graph)) {
52  hierarchy->addCurrentGraph(graph);
53  return true;
54  } else {
55  return false;
56  }
57 }

◆ sw_set_default_graph3()

foreign_t sw_set_default_graph3 ( term_t  t_manager,
term_t  t_reasoner,
term_t  t_graph 
)

Definition at line 98 of file semweb.cpp.

98  {
99  auto hierarchy = getImportHierarchy(t_manager, t_reasoner);
100  char *graph;
101  if (hierarchy && PL_get_atom_chars(t_graph, &graph)) {
102  hierarchy->setDefaultGraph(graph);
103  return true;
104  }
105  return false;
106 
107 }

◆ sw_unset_current_graph3()

foreign_t sw_unset_current_graph3 ( term_t  t_manager,
term_t  t_reasoner,
term_t  t_origin 
)

Definition at line 59 of file semweb.cpp.

59  {
60  auto kb = getKnowledgeBase(t_manager, t_reasoner);
61  if(!kb) return false;
62 
63  char *origin;
64  if (PL_get_atom_chars(t_origin, &origin)) {
65  return kb->removeAllWithOrigin(origin);
66  } else {
67  return false;
68  }
69 }

◆ sw_url_graph2()

foreign_t sw_url_graph2 ( term_t  t_url,
term_t  t_graph 
)

Definition at line 138 of file semweb.cpp.

138  {
139  char *url;
140  if (PL_get_atom_chars(t_url, &url)) {
141  auto name = DataSource::getNameFromURI(url);
142  return PL_unify_atom_chars(t_graph, name.c_str());
143  }
144  return false;
145 }

◆ sw_url_version2()

foreign_t sw_url_version2 ( term_t  t_url,
term_t  t_version 
)

Definition at line 147 of file semweb.cpp.

147  {
148  char *url;
149  if (PL_get_atom_chars(t_url, &url)) {
150  auto version = DataSource::getVersionFromURI(url);
151  return PL_unify_atom_chars(t_version, version.c_str());
152  }
153  return false;
154 }