Menu

[ccc612]: / binding / python / rdf_objects.cpp  Maximize  Restore  History

Download this file

138 lines (116 with data), 3.7 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/** @file "/owlcpp/binding/python/rdf_objects.cpp"
part of owlcpp project.
@n @n Distributed under the Boost Software License, Version 1.0; see doc/license.txt.
@n Copyright Mikhail K Levin 2013
*******************************************************************************/
#include "boost/python.hpp"
#include "boost/static_assert.hpp"
namespace bp = boost::python;
#include "owlcpp/rdf/triple.hpp"
#include "owlcpp/rdf/ns_iri.hpp"
#include "owlcpp/rdf/node.hpp"
#include "owlcpp/rdf/print_node.hpp"
#include "owlcpp/rdf/triple_store.hpp"
using owlcpp::Triple;
using owlcpp::Node_id;
using owlcpp::Doc_id;
using owlcpp::Ns_iri;
using owlcpp::Node;
using owlcpp::Triple_store;
namespace {
Triple* make_triple(
const Node_id subj, const Node_id pred,
const Node_id obj, const Doc_id doc
) {
Triple* t = new Triple();
t->subj_ = subj;
t->pred_ = pred;
t-> obj_ = obj;
t-> doc_ = doc;
return t;
}
std::string to_string_1(Node const& node, Triple_store const& ts) {
return to_string(node, ts);
}
std::string to_string_2(const Node_id nid, Triple_store const& ts) {
return to_string(nid, ts);
}
std::string to_string_full_1(Node const& node, Triple_store const& ts) {
return to_string_full(node, ts);
}
std::string to_string_full_2(const Node_id nid, Triple_store const& ts) {
return to_string_full(nid, ts);
}
std::string to_string_pref_1(Node const& node, Triple_store const& ts) {
return to_string_pref(node, ts);
}
std::string to_string_pref_2(const Node_id nid, Triple_store const& ts) {
return to_string_pref(nid, ts);
}
}//namespace anonymous
void export_objects() {
bp::class_<Triple>(
"Triple",
"IDs for subject, predicate, object, and document"
)
.def(
"__init__",
bp::make_constructor(&make_triple)/*,
(bp::arg("subj"), bp::arg("pred"), bp::arg("obj"), bp::arg("doc"))*/
)
.def(str(bp::self))
.def(bp::self == bp::self)
.def(bp::self != bp::self)
.def_readonly("subj_", &Triple::subj_)
.def_readonly("pred_", &Triple::pred_)
.def_readonly( "obj_", &Triple:: obj_)
.def_readonly( "doc_", &Triple:: doc_)
;
bp::class_<Ns_iri>("Ns_iri", "namespace IRI", bp::init<std::string>())
.def(str(bp::self))
.def("str", &Ns_iri::str, bp::return_internal_reference<>())
.def(bp::self == bp::self)
.def(bp::self == std::string())
;
bp::class_<Node, boost::noncopyable>("Node", "RDF node", bp::no_init)
.def(str(bp::self))
.def(bp::self == bp::self)
.def(bp::self != bp::self)
;
bp::def(
"to_string",
&to_string_1,
(bp::arg("node"), bp::arg("store")),
"return string representation of a node"
);
bp::def(
"to_string",
&to_string_2,
(bp::arg("node_id"), bp::arg("store")),
"return string representation of a node"
);
bp::def(
"to_string_full",
&to_string_full_1,
(bp::arg("node"), bp::arg("store")),
"return node string with complete namespace"
);
bp::def(
"to_string_full",
&to_string_full_2,
(bp::arg("node_id"), bp::arg("store")),
"return node string with complete namespace"
);
bp::def(
"to_string_pref",
&to_string_pref_1,
(bp::arg("node"), bp::arg("store")),
"return node string with namespace prefix"
);
bp::def(
"to_string_pref",
&to_string_pref_2,
(bp::arg("node_id"), bp::arg("store")),
"return node string with namespace prefix"
);
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.