13 # details. |
13 # details. |
14 # |
14 # |
15 # You should have received a copy of the GNU Lesser General Public License |
15 # You should have received a copy of the GNU Lesser General Public License |
16 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
16 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 |
17 |
18 from rdflib import Namespace, ConjunctiveGraph, plugin |
18 from rdflib import ConjunctiveGraph, plugin |
|
19 from rdflib.namespace import Namespace, RDF, FOAF |
19 import rdflib_jsonld # noqa |
20 import rdflib_jsonld # noqa |
20 |
21 |
21 plugin.register("jsonld", plugin.Serializer, "rdflib_jsonld.serializer", "JsonLDSerializer") |
22 plugin.register("jsonld", plugin.Serializer, "rdflib_jsonld.serializer", "JsonLDSerializer") |
22 |
23 |
23 RDF_MIMETYPE_TO_FORMAT = { |
24 RDF_MIMETYPE_TO_FORMAT = { |
28 'application/n-triples': 'nt', |
29 'application/n-triples': 'nt', |
29 'application/trig': 'trig', |
30 'application/trig': 'trig', |
30 'application/ld+json': 'json-ld', |
31 'application/ld+json': 'json-ld', |
31 } |
32 } |
32 |
33 |
33 namespaces = { |
34 NAMESPACES = { |
34 "rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#", |
35 "rdf": RDF, |
35 "schema": "http://schema.org/", |
36 "schema": Namespace("http://schema.org/"), |
|
37 "foaf": FOAF, |
36 } |
38 } |
37 |
|
38 NS_VARS = {ns: Namespace(uri) for ns, uri in namespaces.items()} |
|
39 |
39 |
40 |
40 |
41 # dict: name of CWEType -> list of regid of adapters derived from EntityRDFAdapter |
41 # dict: name of CWEType -> list of regid of adapters derived from EntityRDFAdapter |
42 ETYPES_ADAPTERS = { |
42 ETYPES_ADAPTERS = { |
|
43 "CWUser": ("rdf.foaf",), |
43 } |
44 } |
44 |
45 |
45 |
46 |
46 def conjunctive_graph(): |
47 def conjunctive_graph(): |
47 """factory to build a ``ConjunctiveGraph`` and bind all namespaces |
48 """factory to build a ``ConjunctiveGraph`` and bind all namespaces |
48 """ |
49 """ |
49 graph = ConjunctiveGraph() |
50 graph = ConjunctiveGraph() |
50 for vocab, rdfns in NS_VARS.items(): |
51 for prefix, rdfns in NAMESPACES.items(): |
51 graph.bind(vocab, rdfns) |
52 graph.bind(prefix, rdfns) |
52 return graph |
53 return graph |
53 |
54 |
54 |
55 |
55 def iter_rdf_adapters(entity): |
56 def iter_rdf_adapters(entity): |
56 for adapter_id in ETYPES_ADAPTERS.get(entity.__regid__, ()): |
57 for adapter_id in ETYPES_ADAPTERS.get(entity.__regid__, ()): |