77from rdflib .namespace import XSD , RDF
88
99import yaml
10- import odml
1110
1211from ..doc import BaseDocument
1312from ..format import Format , Document , Section , Property
1413from ..info import FORMAT_VERSION
14+ from ..resources import RDF_SUBCLASS_FILE
1515from .dict_parser import DictReader
1616from .parser_utils import ParserException
1717from .utils import RDFConversionFormats
@@ -34,13 +34,11 @@ def load_rdf_subclasses():
3434 """
3535 section_subclasses = {}
3636
37- subclass_file = os .path .join (odml .__path__ [0 ], 'resources' , 'section_subclasses.yaml' )
38-
39- if not os .path .isfile (subclass_file ):
40- print ("[Warning] Could not find subclass file '%s'" % subclass_file )
37+ if not os .path .isfile (RDF_SUBCLASS_FILE ):
38+ print ("[Warning] Could not find subclass file '%s'" % RDF_SUBCLASS_FILE )
4139 return section_subclasses
4240
43- with open (subclass_file , "r" ) as yaml_file :
41+ with open (RDF_SUBCLASS_FILE , "r" ) as yaml_file :
4442 try :
4543 section_subclasses = yaml .load (yaml_file )
4644 except yaml .parser .ParserError as err :
@@ -188,9 +186,11 @@ def save_element(self, odml_elem, node=None):
188186 self .graph .add ((curr_node , ODML_NS .hasFileName , curr_lit ))
189187
190188 for k in fmt .rdf_map_keys :
191- if k == "id" or \
192- (k == "value" and not getattr (odml_elem , fmt .map (k ))) or \
193- (not getattr (odml_elem , k )):
189+ # Ignore "id" and empty values, but make sure the content of "value"
190+ # is only accessed via its non deprecated property "values".
191+ if k == "id" or k == "value" and not getattr (odml_elem , fmt .map (k )):
192+ continue
193+ elif k != "value" and not getattr (odml_elem , k ):
194194 continue
195195
196196 if (is_doc or is_sec ) and k == "repository" :
@@ -207,9 +207,11 @@ def save_element(self, odml_elem, node=None):
207207 # 'value' needs to be mapped to its appropriate odml Property attribute.
208208 self .save_odml_values (curr_node , fmt .rdf_map (k ),
209209 getattr (odml_elem , fmt .map (k )))
210+
210211 elif k == "date" :
211212 curr_lit = Literal (getattr (odml_elem , k ), datatype = XSD .date )
212213 self .graph .add ((curr_node , fmt .rdf_map (k ), curr_lit ))
214+
213215 else :
214216 curr_lit = Literal (getattr (odml_elem , k ))
215217 self .graph .add ((curr_node , fmt .rdf_map (k ), curr_lit ))
0 commit comments