I created ontology in desctop Protege. It consists of two classes - test1 and test2. Then I declared labels for them. First label with no datatype, second - literal. The OWL-file content is below. The dif is presense of string 'rdf:datatype="&rdfs;Literal"' While trying to get labels via owlready2, got an error 'ValueError: Cannot read literal of datatype 305!' for literal-type label.
Here is OWL-file content:
<?xml version="1.0"?>
<!DOCTYPE rdf:RDF [
<!ENTITY owl "http://www.w3.org/2002/07/owl#" >
<!ENTITY xsd "http://www.w3.org/2001/XMLSchema#" >
<!ENTITY rdfs "http://www.w3.org/2000/01/rdf-schema#" >
<!ENTITY rdf "http://www.w3.org/1999/02/22-rdf-syntax-ns#" >
]>
<rdf:RDF xmlns="http://www.semanticweb.org/jdrey/ontologies/2020/11/test#"
xml:base="http://www.semanticweb.org/jdrey/ontologies/2020/11/test"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:owl="http://www.w3.org/2002/07/owl#"
xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">
<owl:Ontology rdf:about="http://www.semanticweb.org/jdrey/ontologies/2020/11/test"/>
<!--
///////////////////////////////////////////////////////////////////////////////////////
//
// Classes
//
///////////////////////////////////////////////////////////////////////////////////////
-->
<!-- http://www.semanticweb.org/jdrey/ontologies/2020/11/test:test1 -->
<owl:Class rdf:about="http://www.semanticweb.org/jdrey/ontologies/2020/11/test:test1">
<rdfs:label>label_test1</rdfs:label>
</owl:Class>
<!-- http://www.semanticweb.org/jdrey/ontologies/2020/11/test:test2 -->
<owl:Class rdf:about="http://www.semanticweb.org/jdrey/ontologies/2020/11/test:test2">
<rdfs:label rdf:datatype="&rdfs;Literal">label_test2</rdfs:label>
</owl:Class>
</rdf:RDF>
This is code for printing labels for subclasses:
from owlready2 import *
owlready2.JAVA_EXE = r'c:\Users\JDrey\AppData\Local\JetBrains\PyCharm Community Edition with Anaconda plugin 2020.1.2\jbr\bin\java.exe'
my_world = World()
onto = my_world.get_ontology(r'd:\temp\OWL\test_owl.owl').load()
for elem in list(Thing.subclasses(world = my_world)):
print(elem.label)
Here is output with error message:
['label_test1']
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-6-5e6c14d62ea5> in <module>
5 onto = my_world.get_ontology(r'd:\temp\OWL\test_owl.owl').load()
6 for elem in list(Thing.subclasses(world = my_world)):
----> 7 print(elem.label)
D:\anaconda\envs\new_env\lib\site-packages\owlready2\entity.py in __getattr__(Class, attr)
561 values = Class.__dict__.get(attr)
562 if values is None:
--> 563 values = Prop._get_values_for_class(Class)
564 type.__setattr__(Class, attr, values)
565 return values
D:\anaconda\envs\new_env\lib\site-packages\owlready2\prop.py in _get_values_for_individual(Prop, entity)
309 def _get_values_for_individual(Prop, entity):
310 return IndividualValueList((entity.namespace.ontology._to_python(o, d) for o, d in entity.namespace.world._get_triples_sp_od(entity.storid, Prop.storid)),
--> 311 entity, Prop)
312
313 _get_value_for_class = _get_value_for_individual
D:\anaconda\envs\new_env\lib\site-packages\owlready2\prop.py in __init__(self, l, obj, Prop)
1045 __slots__ = ["_Prop"]
1046 def __init__(self, l, obj, Prop):
-> 1047 list.__init__(self, l)
1048 self._obj = obj
1049 self._Prop = Prop
D:\anaconda\envs\new_env\lib\site-packages\owlready2\prop.py in <genexpr>(.0)
308
309 def _get_values_for_individual(Prop, entity):
--> 310 return IndividualValueList((entity.namespace.ontology._to_python(o, d) for o, d in entity.namespace.world._get_triples_sp_od(entity.storid, Prop.storid)),
311 entity, Prop)
312
D:\anaconda\envs\new_env\lib\site-packages\owlready2\namespace.py in _to_python(self, o, d, main_type, main_onto, default_to_none)
260 if o in _universal_abbrev_2_datatype: return _universal_abbrev_2_datatype[o]
261 else: return self.world._get_by_storid(o, None, main_type, main_onto, None, default_to_none)
--> 262 else: return from_literal(o, d)
263 raise ValueError
264
D:\anaconda\envs\new_env\lib\site-packages\owlready2\base.py in from_literal(o, d)
56 if d == 0: return o
57 datatype, parser = _universal_abbrev_2_datatype_parser.get(d) or (None, None)
---> 58 if parser is None: raise ValueError("Cannot read literal of datatype %s!" % repr(d))
59 return parser(o)
60
ValueError: Cannot read literal of datatype 305!
How can I get the label value for test2?