Skip to content

Commit 8172f9e

Browse files
committed
[tools/rdfwriter] Add save_sec method
1 parent 123982e commit 8172f9e

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

odml/tools/rdf_converter.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,42 @@ def save_document(self, doc, curr_node=None):
203203
curr_lit = Literal(curr_val)
204204
self.graph.add((curr_node, curr_pred, curr_lit))
205205

206+
def save_section(self, sec, curr_node):
207+
"""
208+
Add the current odML Section to the RDF graph and handle all child
209+
elements recursively.
210+
211+
:param sec: An odml Section that should be added to the RDF graph.
212+
:param curr_node: An RDF node that is used to append the current odml element
213+
to the current RDF graph.
214+
"""
215+
fmt = sec.format()
216+
217+
# Add type of current node to the RDF graph
218+
curr_type = fmt.rdf_type
219+
# Handle section subclass types
220+
sub_sec = self._get_section_subclass(sec)
221+
if sub_sec:
222+
curr_type = sub_sec
223+
self.graph.add((curr_node, RDF.type, URIRef(curr_type)))
224+
225+
for k in fmt.rdf_map_keys:
226+
curr_pred = fmt.rdf_map(k)
227+
curr_val = getattr(sec, k)
228+
229+
# Ignore an "id" entry, it has already been used to create the node itself.
230+
if k == "id" or not curr_val:
231+
continue
232+
elif k == "repository":
233+
self.save_repository_node(curr_node, curr_pred, curr_val)
234+
235+
# generating nodes for sections and properties
236+
elif k in ["sections", "properties"]:
237+
self.save_odml_list(curr_val, curr_node, curr_pred)
238+
else:
239+
curr_lit = Literal(curr_val)
240+
self.graph.add((curr_node, curr_pred, curr_lit))
241+
206242
def save_element(self, odml_elem, node=None):
207243
"""
208244
Save the current odml element to the RDF graph and handle all child

0 commit comments

Comments
 (0)