6 #ifndef COPY_TRIPLES_HPP_
7 #define COPY_TRIPLES_HPP_
8 #include "boost/foreach.hpp"
9 #include "boost/unordered_map.hpp"
10 #include "boost/assert.hpp"
13 #include "owlcpp/rdf/detail/map_traits.hpp"
17 namespace owlcpp{
namespace detail{
20 typedef boost::unordered_map<Node_id,Node_id> node_map_t;
21 typedef node_map_t::const_iterator node_iter_t;
22 typedef boost::unordered_map<Doc_id,Doc_id> doc_map_t;
23 typedef doc_map_t::const_iterator doc_iter_t;
24 typedef boost::unordered_map<Ns_id,Ns_id> ns_map_t;
25 typedef ns_map_t::const_iterator ns_iter_t;
27 typedef detail::Map_traits<Src> traits;
28 typedef typename traits::doc_type doc_type;
32 : src_(src), dest_(dest)
35 void operator()(
Triple const& t) {
36 const Node_id subj = cp(t.subj_);
37 const Node_id pred = cp(t.pred_);
39 const Doc_id doc = cp(t.doc_);
40 dest_.insert_triple(subj, pred, obj, doc);
44 const node_iter_t i = nm_.find(nid0);
45 if( i != nm_.end() )
return i->second;
46 Node const& node = src_[nid0];
48 nm_.emplace(nid0, last_inserted_id_);
49 return last_inserted_id_;
53 const doc_iter_t i = dm_.find(did0);
54 if( i != dm_.end() )
return i->second;
55 doc_type
const& doc = src_[did0];
56 const Node_id iri_id = cp(doc.ontology_iri);
57 const Node_id vers_id = cp(doc.version_iri);
58 const std::pair<Doc_id, bool> p =
71 dm_.emplace(did0, p.first);
76 const ns_iter_t i = nsm_.find(nsid0);
77 if( i != nsm_.end() )
return i->second;
78 const Ns_id nsid1 = dest_.insert(src_[nsid0]);
79 std::string
const& pref = src_.prefix(nsid0);
82 dest_.prefix(nsid1).empty() &&
83 ! dest_.find_prefix(pref)
85 dest_.insert_prefix(nsid1, pref);
87 nsm_.emplace(nsid0, nsid1);
99 void visit_impl(
Node_iri const& node) {
100 const Ns_id nsid = cp(node.ns_id());
101 last_inserted_id_ = dest_.insert_node_iri(nsid, node.fragment());
105 const Doc_id did = cp(node.document());
111 last_inserted_id_ = dest_.insert_blank(node.index(), did);
115 const Node_id dt = cp(node.datatype());
116 last_inserted_id_ = dest_.insert_literal(node.value_str(), dt);
119 void visit_impl(
Node_int const& node) {
120 const Node_id dt = cp(node.datatype());
121 last_inserted_id_ = dest_.insert_literal(node.value_str(), dt);
125 const Node_id dt = cp(node.datatype());
126 last_inserted_id_ = dest_.insert_literal(node.value_str(), dt);
130 const Node_id dt = cp(node.datatype());
131 last_inserted_id_ = dest_.insert_literal(node.value_str(), dt);
135 const Node_id dt = cp(node.datatype());
136 last_inserted_id_ = dest_.insert_literal(
137 node.value(), dt, node.language()
157 BOOST_FOREACH(
Triple const& t, r) copier(t);
166 template<
class Src,
class Dest>
inline void copy_triples(Src
const& src, Dest& dest) {