How can I determine object properties for a class in Jena . I can get the all objects properties, but I want to get the object properties for a particular class.
Code
You might find enough information in this answer to Parsing schema.org ttl/owl file using Jena to solve your problem, but if not, some discussion is in order.
First, note that properties in OWL are not the same kind of thing as "properties" in an object-oriented programming languages. What it means we we say that a property P has a domain D is that when we see a statement whose property is P, we can infer that the subject is of type D. As a rule, this is:
x P y P rdfs:domain D
--------------------------
x rdf:type D
But consider what this means. If D is a subclass of C, then we can infer from x rdf:type D
that x rdf:type C
. This means that C
is also a domain of P. (This is the case in OWL, but pure RDF has a slightly different semantics.) Thus, if you're asking "what properties have class C as a domain", you'll get the properties that have subclasses of C as domains, in addition to properties that have C as a domain.
If you do want a sort of "object-oriented" view of the classes and properties, you can use the Jena method OntClass#listDeclaredProperties.
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][2] 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.