Skip to content

Commit 63e3765

Browse files
committed
[doc/rdf] Graph example
1 parent e713fc8 commit 63e3765

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

doc/odmltordf.rst

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,3 +241,36 @@ The following section gives a basic example how multiple odML RDF files can be l
241241

242242
Please note, that the `rdflib <https://rdflib.readthedocs.io/en/stable/>`_ library provides just basic implementation of a triple store and query features via SPARQL. To make full use of SPARQL additional RDF reasoning libraries are required. In our case the `owlrl <https://owl-rl.readthedocs.io/en/latest/>`_ library is used to provide proper reasoning and enable searches for the RDF subclassing feature.
243243

244+
The following is a basic example how to load odML RDF documents into a single graph and provide the required to namespace to make the odml specific content of the graph accessible::
245+
246+
import odml
247+
248+
file_A = "./rdf_recordings.rdf"
249+
file_B = "./rdf_protocols.rdf"
250+
251+
doc_A = odml.Document(author="MS")
252+
sec_A = odml.Section(name="recording_A", type="paradigm_A", parent=doc_A)
253+
_ = odml.Property(name="protocol", values="recording_protocol_A", parent=sec_A)
254+
sec_B = odml.Section(name="recording_B", type="paradigm_A", parent=doc_A)
255+
_ = odml.Property(name="protocol", values="recording_protocol_B", parent=sec_B)
256+
_ = odml.Section(name="analysis_A", type="paradigm_A", parent=doc_A)
257+
258+
odml.save(doc_A, file_A, "RDF")
259+
260+
doc_B = odml.Document(author="MS")
261+
_ = odml.Section(name="recording_protocol_A", type="protocol", parent=doc_B)
262+
_ = odml.Section(name="recording_protocol_B", type="protocol", parent=doc_B)
263+
264+
odml.save(doc_B, file_B, "RDF")
265+
266+
Please note, that every odML Document exported to RDF has a special ``odml-rdf:Hub`` node at the very root of the document. This node is identical in every exported odML Document and is used as the root Node connecting all individual odML RDF documents into a single graph.
267+
268+
The documents saved above can now be loaded into single graph::
269+
270+
from rdflib import Graph
271+
272+
curr_graph = Graph()
273+
curr_graph.parse(file_A)
274+
curr_graph.parse(file_B)
275+
276+

0 commit comments

Comments
 (0)