Skip to content

Commit d1385ea

Browse files
committed
[tools/RDFWriter] Make RDF subclassing optional
Closes #394
1 parent 7a1ca1f commit d1385ea

1 file changed

Lines changed: 20 additions & 4 deletions

File tree

odml/tools/rdf_converter.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,19 @@ class RDFWriter(object):
5757
"""
5858
A writer to parse odML files into RDF documents.
5959
60+
Use the 'rdf_subclassing' flag to disable default usage
61+
of Section type conversion to RDF Subclasses.
62+
6063
Usage:
6164
RDFWriter(odml_docs).get_rdf_str('turtle')
6265
RDFWriter(odml_docs).write_file("/output_path", "rdf_format")
6366
"""
6467

65-
def __init__(self, odml_documents):
68+
def __init__(self, odml_documents, rdf_subclassing=True):
6669
"""
6770
:param odml_documents: list of odML documents
71+
:param rdf_subclassing: Flag whether Section types should be converted to RDF Subclasses
72+
for enhanced SPARQL queries. Default is 'True'.
6873
"""
6974
if not isinstance(odml_documents, list):
7075
odml_documents = [odml_documents]
@@ -75,6 +80,7 @@ def __init__(self, odml_documents):
7580
self.graph.bind("odml", ODML_NS)
7681

7782
self.section_subclasses = load_rdf_subclasses()
83+
self.rdf_subclassing = rdf_subclassing
7884

7985
def convert_to_rdf(self):
8086
"""
@@ -221,16 +227,26 @@ def save_section(self, sec, curr_node):
221227

222228
# Add type of current node to the RDF graph
223229
curr_type = fmt.rdf_type
230+
231+
print(curr_type)
232+
224233
# Handle section subclass types
225-
sub_sec = self._get_section_subclass(sec)
226-
if sub_sec:
227-
curr_type = sub_sec
234+
if self.rdf_subclassing:
235+
print("I'm in here")
236+
sub_sec = self._get_section_subclass(sec)
237+
if sub_sec:
238+
curr_type = sub_sec
239+
240+
print(curr_type)
241+
228242
self.graph.add((curr_node, RDF.type, URIRef(curr_type)))
229243

230244
for k in fmt.rdf_map_keys:
231245
curr_pred = fmt.rdf_map(k)
232246
curr_val = getattr(sec, k)
233247

248+
print("pred: %s; val: %s" % (curr_pred, curr_val))
249+
234250
# Ignore an "id" entry, it has already been used to create the node itself.
235251
if k == "id" or not curr_val:
236252
continue

0 commit comments

Comments
 (0)