Skip to content

Commit 81493a8

Browse files
committed
[odmlparser] Support writing different RDF formats
1 parent c91bd8b commit 81493a8

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

odml/tools/odmlparser.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,23 +89,29 @@ def write_file(self, odml_document, filename, **kwargs):
8989
custom_template=custom_template)
9090
else:
9191
with open(filename, 'w') as file:
92-
file.write(self.to_string(odml_document))
92+
file.write(self.to_string(odml_document, **kwargs))
9393

94-
def to_string(self, odml_document):
94+
def to_string(self, odml_document, **kwargs):
9595
"""
9696
Parses an odml.Document to a string in the file format
9797
defined in the ODMLWriter.parser property. Supported formats are
9898
JSON, YAML and RDF.
9999
100100
:param odml_document: odml.Document.
101+
:param kwargs: Writer backend keyword arguments. Refer to the documentation
102+
of the available parsers to check which arguments are supported.
103+
101104
:return: string containing the content of the odml.Document in the
102105
specified format.
103106
"""
104107
string_doc = ''
105108

106109
if self.parser == "RDF":
107-
# Use XML as default output format for now.
108-
string_doc = RDFWriter(odml_document).get_rdf_str("xml")
110+
rdf_format = "xml"
111+
if "rdf_format" in kwargs and isinstance(kwargs["rdf_format"], str):
112+
rdf_format = kwargs["rdf_format"]
113+
114+
string_doc = RDFWriter(odml_document).get_rdf_str(rdf_format)
109115
else:
110116
self.parsed_doc = DictWriter().to_dict(odml_document)
111117

0 commit comments

Comments
 (0)