Menu

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

Download this file

87 lines (75 with data), 2.6 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
/** @file "/owlcpp/binding/python/terms.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"
namespace bp = boost::python;
#include "boost/mpl/for_each.hpp"
namespace bmp = boost::mpl;
#include <map>
#include "rdf/iri_tag_vector.hpp"
#include "rdf/node_tag_vector_system.hpp"
#include "rdf/node_tag_vector_owl.hpp"
namespace t = owlcpp::terms;
template<class T> struct Ns_tag_name {
static std::string get() {return T::prefix();}
};
template<> struct Ns_tag_name<t::empty> {
static std::string get() {return "empty";}
};
template<> struct Ns_tag_name<t::blank> {
static std::string get() {return "blank";}
};
typedef std::map<owlcpp::Ns_id, bp::object> map_t;
class Ns_tag_inserter {
public:
explicit Ns_tag_inserter(map_t& map) : map_(&map){}
template<class Ns> static std::string iri() {return Ns::iri();}
template<class Ns> static std::string pref() {return Ns::prefix();}
template<class T> void operator()(T const& t) const {
(*map_)[T::id()] =
bp::class_<T>(Ns_tag_name<T>::get().c_str())
.add_static_property("id", &T::id)
.add_static_property("iri", &iri<T>)
.add_static_property("prefix", &pref<T>)
;
}
private:
mutable map_t* map_;
};
template<class T> struct Term_tag_name {
static std::string get() {
return
Ns_tag_name<typename T::ns_type>::get() +
"_" +
T::fragment()
;
}
};
class Term_tag_inserter {
public:
Term_tag_inserter(map_t const& map) : map_(map) {}
template<class T> static char const* fragment() {return T::fragment().c_str();}
template<class T> void operator()(T const& t) const {
bp::class_<T>(Term_tag_name<T>::get().c_str())
.add_static_property("id", &T::id)
.add_static_property("fragment", &fragment<T>)
.add_static_property("ns_type", map_.find(T::ns_type::id())->second)
;
}
private:
map_t const& map_;
};
BOOST_PYTHON_MODULE(terms) {
map_t map;
Ns_tag_inserter nti(map);
bmp::for_each<t::mpl_vector_iris_t>(nti);
Term_tag_inserter tti(map);
bmp::for_each<t::mpl_vector_terms_system_t>(tti);
bmp::for_each<t::mpl_vector_terms_rdfs_t>(tti);
bmp::for_each<t::mpl_vector_terms_rdf_t>(tti);
bmp::for_each<t::mpl_vector_terms_xsd_t>(tti);
bmp::for_each<t::mpl_vector_terms_owl1_t>(tti);
bmp::for_each<t::mpl_vector_terms_owl2_t>(tti);
}
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.