2

I want to read all the Object Properties present in the OWL file. I have created that OWL file using Protege tool. I have loaded the model also but I am not able to fetch the object properties.

For Example: if I have a class in Ontology named as Car and which has several Object and Data properties linked to it, such as hasColor, hasAudioSystem,hasGps.

I want to get all the object properties linked with that particular class through Domain and Range or only through the name of the class. Please help..

  • 1
    Can you clarify how the object properties are "linked" to the class? Are they stated as domain/range? Class restrictions? Instance data? – enridaga May 05 '15 at 11:09

2 Answers2

1

If you want to get the list of object properties having a type declared as domain or range, one way of doing it with Jena is the following:

public void objectPropertiesForType(Model m, final Resource type) {
    StmtIterator i = m.listStatements(new SimpleSelector() {
        @Override
        public boolean test(Statement s) {
            if (s.getPredicate().equals(RDFS.domain)
                    || s.getPredicate().equals(RDFS.range)) {
                return (s.getObject().equals(type));
            }
            return false;
        }
    });
    while (i.hasNext()) {
        Statement s = i.next();
        System.out.println("Property: " + s.getSubject().getURI());
    }
}
enridaga
  • 631
  • 4
  • 9
0

In Jena, you'd probably want to retrieve an instance of OntClass for the class, and then use the listDeclaredProperties method, which will:

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.

Joshua Taylor
  • 84,998
  • 9
  • 154
  • 353