22
22
from .dict_parser import DictReader
23
23
from .parser_utils import ParserException , RDF_CONVERSION_FORMATS
24
24
25
- try :
26
- unicode = unicode
27
- except NameError :
28
- unicode = str
29
-
30
25
ODML_NS = Format .namespace ()
31
26
32
27
@@ -129,7 +124,7 @@ def save_odml_values(self, parent_node, rdf_predicate, values):
129
124
to the current parent node.
130
125
:param values: list of odml values.
131
126
"""
132
- seq = URIRef (ODML_NS + unicode (uuid .uuid4 ()))
127
+ seq = URIRef (ODML_NS + str (uuid .uuid4 ()))
133
128
self .graph .add ((seq , RDF .type , RDF .Seq ))
134
129
self .graph .add ((parent_node , rdf_predicate , seq ))
135
130
@@ -138,14 +133,14 @@ def save_odml_values(self, parent_node, rdf_predicate, values):
138
133
# Once rdflib upgrades this should be reversed to RDF:li again!
139
134
# see https://github.com/RDFLib/rdflib/issues/280
140
135
# -- keep until supported
141
- # bag = URIRef(ODML_NS + unicode (uuid.uuid4()))
136
+ # bag = URIRef(ODML_NS + str (uuid.uuid4()))
142
137
# self.graph.add((bag, RDF.type, RDF.Bag))
143
138
# self.graph.add((curr_node, fmt.rdf_map(k), bag))
144
139
# for curr_val in values:
145
140
# self.graph.add((bag, RDF.li, Literal(curr_val)))
146
141
counter = 1
147
142
for curr_val in values :
148
- custom_predicate = "%s_%s" % (unicode (RDF ), counter )
143
+ custom_predicate = "%s_%s" % (str (RDF ), counter )
149
144
self .graph .add ((seq , URIRef (custom_predicate ), Literal (curr_val )))
150
145
counter = counter + 1
151
146
@@ -160,7 +155,7 @@ def save_odml_list(self, parent_node, rdf_predicate, odml_list):
160
155
:param odml_list: list of odml entities.
161
156
"""
162
157
for curr_item in odml_list :
163
- node = URIRef (ODML_NS + unicode (curr_item .id ))
158
+ node = URIRef (ODML_NS + str (curr_item .id ))
164
159
self .graph .add ((parent_node , rdf_predicate , node ))
165
160
166
161
fmt = curr_item .format ()
@@ -185,7 +180,7 @@ def save_repository_node(self, parent_node, rdf_predicate, leaf_value):
185
180
if not terminology_node :
186
181
# adding terminology url value to the graph and linking it
187
182
# to the current RDF node.
188
- terminology_node = URIRef (ODML_NS + unicode (uuid .uuid4 ()))
183
+ terminology_node = URIRef (ODML_NS + str (uuid .uuid4 ()))
189
184
self .graph .add ((terminology_node , RDF .type , URIRef (leaf_value )))
190
185
self .graph .add ((self .hub_root , ODML_NS .hasTerminology , terminology_node ))
191
186
@@ -203,7 +198,7 @@ def save_document(self, doc, curr_node=None):
203
198
fmt = doc .format ()
204
199
205
200
if not curr_node :
206
- curr_node = URIRef (ODML_NS + unicode (doc .id ))
201
+ curr_node = URIRef (ODML_NS + str (doc .id ))
207
202
208
203
self .graph .add ((curr_node , RDF .type , URIRef (fmt .rdf_type )))
209
204
self .graph .add ((self .hub_root , ODML_NS .hasDocument , curr_node ))
@@ -478,7 +473,7 @@ def parse_document(self, doc_uri):
478
473
elif attr [0 ] == "id" :
479
474
doc_attrs [attr [0 ]] = doc_uri .split ("#" , 1 )[1 ]
480
475
elif elems :
481
- doc_attrs [attr [0 ]] = unicode (elems [0 ].toPython ())
476
+ doc_attrs [attr [0 ]] = str (elems [0 ].toPython ())
482
477
483
478
return {'Document' : doc_attrs , 'odml-version' : FORMAT_VERSION }
484
479
@@ -503,7 +498,7 @@ def parse_section(self, sec_uri):
503
498
elif attr [0 ] == "id" :
504
499
sec_attrs [attr [0 ]] = sec_uri .split ("#" , 1 )[1 ]
505
500
elif elems :
506
- sec_attrs [attr [0 ]] = unicode (elems [0 ].toPython ())
501
+ sec_attrs [attr [0 ]] = str (elems [0 ].toPython ())
507
502
508
503
self ._check_mandatory_attrs (sec_attrs )
509
504
return sec_attrs
@@ -537,7 +532,7 @@ def parse_property(self, prop_uri):
537
532
elif attr [0 ] == "id" :
538
533
prop_attrs [attr [0 ]] = prop_uri .split ("#" , 1 )[1 ]
539
534
elif elems :
540
- prop_attrs [attr [0 ]] = unicode (elems [0 ].toPython ())
535
+ prop_attrs [attr [0 ]] = str (elems [0 ].toPython ())
541
536
542
537
self ._check_mandatory_attrs (prop_attrs )
543
538
return prop_attrs
0 commit comments