Skip to content

Commit 8f490e1

Browse files
committed
[rdf_converter.py] Get File Extension
Extract file extension if given in full file name. Related to issue #213.
1 parent b754b3c commit 8f490e1

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

odml/tools/rdf_converter.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,21 @@ def __init__(self, odml_documents):
5656
print(err)
5757
return
5858

59+
_conversion_formats = {
60+
# rdflib version "4.2.2" serialization formats
61+
'xml': '.rdf',
62+
'pretty-xml': '.rdf',
63+
'trix': '.rdf',
64+
'n3': '.n3',
65+
'turtle': '.ttl',
66+
'ttl': '.ttl',
67+
'ntriples': '.nt',
68+
'nt': '.nt',
69+
'nt11': '.nt',
70+
'trig': '.trig',
71+
'json-ld': '.jsonld'
72+
}
73+
5974
def convert_to_rdf(self):
6075
self.hub_root = URIRef(odmlns.Hub)
6176
if self.docs:
@@ -193,7 +208,10 @@ def get_rdf_str(self, rdf_format):
193208

194209
def write_file(self, filename, rdf_format):
195210
data = self.get_rdf_str(rdf_format)
196-
with open(filename, "w") as file:
211+
filename_ext = filename
212+
if not filename.find("." + rdf_format):
213+
filename_ext += "." + rdf_format
214+
with open(filename_ext, "w") as file:
197215
file.write(data)
198216

199217

0 commit comments

Comments
 (0)