Parsing schema.org ttl/owl file using Jena

末鹿安然 提交于 2019-11-28 14:30:42

Note that the documentation on listDeclaredProperties is (emphasis added):

listDeclaredProperties

com.hp.hpl.jena.util.iterator.ExtendedIterator<OntProperty> listDeclaredProperties(boolean direct)

Return an iterator over the properties associated with a frame-like view of this class. This captures an intuitive notion of the properties of a class. This can be useful in presenting an ontology class in a user interface, for example by automatically constructing a form to instantiate instances of the class. The properties in the frame-like view of the class are determined by comparing the domain of properties in this class's OntModel with the class itself. See: Presenting RDF as frames for more details.

Note that many cases of determining whether a property is associated with a class depends on RDFS or OWL reasoning. This method may therefore return complete results only in models that have an attached reasoner.

Parameters:

  • direct - If true, restrict the properties returned to those directly associated with this class. If false, the properties of super-classes of this class will not be listed among the declared properties of this class.

Returns:

An iteration of the properties that are associated with this class by their domain.

So, even before looking at the particular schema, it's important to note that unless you're using a reasoner, you might not get all the results you expect. Then, notice how the address property is declared:

schema:address a rdf:Property;
    rdfs:label "Address"@en;
    rdfs:comment "Physical address of the item."@en;
    rdfs:domain [ a owl:Class; owl:unionOf (schema:Person schema:Place schema:Organization) ];
    rdfs:range schema:PostalAddress;
    rdfs:isDefinedBy <http://schema.org/Person>;
    rdfs:isDefinedBy <http://schema.org/Place>;
    rdfs:isDefinedBy <http://schema.org/Organization>;

The domain of address is a union class: Person or Place or Organization. That's a superclass of Person, but it's a complex class expression, not just a simple named class, so you'll probably need a reasoner, as the documentation mentions, to get Jena to recognize that it's a superclass of Person.

Comparison with OWL semantics

I think that using a reasoner will allow Jena to recognize that the domain of address is a superclass of Person, and thus include it in the result of listDeclaredProperties. It's worth noting how this differs from OWL semantics, though.

In OWL, what it means for a class D to be the domain of a property P means that whenever we have a triple with the property P, we can infer that the subject is a D. This can be expressed by the rule

P rdfs:domain D     X P Y
-------------------------
    X rdf:type D

So, even though a Person might have an address, just because something has an address isn't enough to tell us that that something is a Person; it could still be a Place or Organization.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!