如何使用Owlready2在DBpedia中读取OntoProperty的域和范围?

时间:2019-03-28 07:57:02

标签: dbpedia owlready

我浏览了Owlready2文档,但没有说明执行此操作的方法。我加载dbpedia.owl文件并遍历所有属性。我只能读取子属性,但不能读取域或范围。下面显示了一个OntoProperty记录。

<owl:ObjectProperty rdf:about="http://dbpedia.org/ontology/artist">
  <rdfs:domain rdf:resource="http://dbpedia.org/ontology/MusicalWork"/> 
  <rdfs:range rdf:resource="http://dbpedia.org/ontology/Agent"/>
</owl:ObjectProperty>

from owlready2 import *
onto_path.append("../")
onto = get_ontology("dbpedia.owl")
onto.load()

propertiesGen = onto.properties()

# getting propery and sub property relationships
propertyToSubProperties = {}
propertiesCount = 0

for ontoProperty in propertiesGen:
    subPropertiesList = list(ontoProperty.subclasses())
    print(ontoProperty.rdf_label)
    # print (list(ontoProperty.subclasses()))
    if len(subPropertiesList) > 0:
        propertyToSubProperties[ontoProperty] = subPropertiesList
        print (ontoProperty, subPropertiesList, "\n")
    propertiesCount += 1

0 个答案:

没有答案