Skip to content

Commit 70cc940

Browse files
committed
[doc/rdf] Add RDFWriter description
1 parent 6f2d43e commit 70cc940

File tree

1 file changed

+42
-1
lines changed

1 file changed

+42
-1
lines changed

doc/odmltordf.rst

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Opening odML to the Semantic Web and graph database searches
88
Searches within odML documents are part of the library implementation and imports from linked, external sources into odML documents can be easily done with the core library functionality.
99
With the option to export odML documents to the RDF format, users also gain the option to search across multiple documents using tools from the Semantic Web technology.
1010

11-
If you are unfamiliar with it, we linked additional information to the `Semantic web<https://www.w3.org/standards/semanticweb>`_ and `RDF<https://www.w3.org/TR/rdf11-concepts>`_ for your convenience and give the briefest introduction below.
11+
If you are unfamiliar with it, we linked additional information to the `Semantic web <https://www.w3.org/standards/semanticweb>`_ and `RDF <https://www.w3.org/TR/rdf11-concepts>`_ for your convenience and give the briefest introduction below.
1212

1313
RDF was designed by the World Wide Web Consortium (W3C) as a standard model for data representation and exchange on the web with the heterogeneity of data in mind. Even tough the RDF file format might vary, the underlying concept features two key points. The first is that information is structured in subject-predicate-object triples e.g. "apple hasColor red". The second key point is that multiple subjects and objects can be connected to form a graph e.g. "tree hasFruit apple" can be combined with the previous example to form a minimal graph. These graphs can contain very heterogeneous data, but can still be queried due to the semantic structure of the underlying data.
1414

@@ -61,3 +61,44 @@ The content of the file will look something like this (the UUIDs of the individu
6161
<odml:hasDocument rdf:resource="https://g-node.org/odml-rdf#08c6e31a-533f-443b-acd2-8e961215d38e"/>
6262
</rdf:Description>
6363
</rdf:RDF>
64+
65+
Using the RDFWriter class to export to a specific RDF format
66+
************************************************************
67+
68+
The RDFWriter class is used to convert odML documents to one of the supported RDF formats:
69+
70+
``xml, pretty-xml, trix, n3, turtle, ttl, ntriples, nt, nt11, trig``
71+
72+
``turtle`` is the format that is best suited for storage and human readability which is why we will use it in our tutorial. For cross-tool usage, saving RDF in its ``XML`` variant is probably the safest choice.
73+
74+
The output can also be returned as a string instead of saving it to a file::
75+
76+
from odml.tools.rdf_converter import RDFWriter
77+
78+
print(RDFWriter(doc).get_rdf_str('turtle'))
79+
80+
This will print the content of the odML document in the Turtle flavor of RDF::
81+
82+
@prefix odml: <https://g-node.org/odml-rdf#> .
83+
84+
odml:Hub odml:hasDocument odml:08c6e31a-533f-443b-acd2-8e961215d38e .
85+
86+
odml:08c6e31a-533f-443b-acd2-8e961215d38e a odml:Document ;
87+
odml:hasFileName "None" ;
88+
odml:hasSection odml:eebe4bf7-af10-4321-87ec-2cdf77289478 .
89+
90+
odml:281c5aa7-8fea-4852-85ec-db127f753647 a odml:Property ;
91+
odml:hasName "rdf_export_property" .
92+
93+
odml:eebe4bf7-af10-4321-87ec-2cdf77289478 a odml:Section ;
94+
odml:hasName "rdf_export_section" ;
95+
odml:hasProperty odml:281c5aa7-8fea-4852-85ec-db127f753647 ;
96+
odml:hasType "n.s." .
97+
98+
The output can of course also be written to a file with a specified RDF output format; the output file will autmatically be assigned the appropriate file ending.::
99+
100+
from odml.tools.rdf_converter import RDFWriter
101+
102+
RDFWriter(doc).write_file("./rdf_export_turtle", "turtle")
103+
104+
All available RDF output formats can be viewed via ``odml.tools.parser_utils.RDF_CONVERSION_FORMATS.keys()``.

0 commit comments

Comments
 (0)