The notion of "apply to a class" in OWL is not like it is in object oriented languages.

For discussion on this see:
http://jena.apache.org/documentation/notes/rdf-frames.html

In particular see the listDeclaredProperties helper function which is mentioned therein.

Dave

On 19/03/13 15:07, Ed Swing wrote:
On to my next unexplainable thing in Jena – Property domains. The code
below is trying to identify what properties apply to a class based on
the property domain. Here’s the code:

*package*ontology;

*import*java.io.FileInputStream;

*import*java.io.IOException;

*import*java.util.Iterator;

*import*com.hp.hpl.jena.ontology.*;

*import*com.hp.hpl.jena.rdf.model.ModelFactory;

/**

* *@author*<a _href_="http://www.ganae.com/edswing";>Edward Swing</a>

*/

*public**class*PropTest {

/**

      * *TODO*: DOCUMENT ME

      *

      * *@param*args

      * *@throws*IOException

      */

*public**static**void*main(String[] args) *throws*IOException {

         OntModel model =


ModelFactory./createOntologyModel/(OntModelSpec./OWL_DL_MEM_RULE_INF/);

         FileInputStream inStream =

*new*FileInputStream("ontology/terrorism.xml");

         model.read(inStream, *null*);

         inStream.close();

         String uriBase = model.getNsPrefixURI("");

         OntClass cls = model.getOntClass(uriBase + "TerrorAttack");

         System./out/.println(cls);

*for*(Iterator<OntProperty> iter = model.listAllOntProperties(); iter

            .hasNext();) {

             OntProperty prop = iter.next();

             OntResource res = prop.getDomain();

*if*(res != *null*&& res.isURIResource() && res.isClass()) {

*try*{

                     OntClass dom = res.asClass();

*if*(cls.hasSuperClass(dom)) {

                         System./out/.println("Prop: "+ prop + "  (domain: "

                             + dom + ")");

                     }

                 } *catch*(ConversionException exc) {

                 }

             }

         }

     }

}

Here’s what is printed:

http://blsdev1.vsticorp.com/terrorism#TerrorAttack

Prop: http://blsdev1.vsticorp.com/terrorism#numberKilled  (domain:
http://blsdev1.vsticorp.com/terrorism#Killing)

Prop: http://blsdev1.vsticorp.com/terrorism#isSuicide  (domain:
http://blsdev1.vsticorp.com/terrorism#TerrorAttack)

Prop: http://blsdev1.vsticorp.com/terrorism#eventType  (domain:
http://blsdev1.vsticorp.com/terrorism#Event)

Prop: http://blsdev1.vsticorp.com/terrorism#numberInjured  (domain:
http://blsdev1.vsticorp.com/terrorism#Killing)

Prop: http://blsdev1.vsticorp.com/terrorism#weaponType  (domain:
http://blsdev1.vsticorp.com/terrorism#Killing)

Prop: http://blsdev1.vsticorp.com/terrorism#destination  (domain:
http://www.w3.org/2002/07/owl#Thing)

Prop: http://blsdev1.vsticorp.com/terrorism#relatedEvent  (domain:
http://www.w3.org/2002/07/owl#Thing)

Prop: http://blsdev1.vsticorp.com/terrorism#victim  (domain:
http://www.w3.org/2002/07/owl#Thing)

Prop: http://blsdev1.vsticorp.com/terrorism#inCountry  (domain:
http://www.w3.org/2002/07/owl#Thing)

Prop: http://blsdev1.vsticorp.com/terrorism#forCountry  (domain:
http://www.w3.org/2002/07/owl#Thing)

Prop: http://blsdev1.vsticorp.com/terrorism#regionOfInfluence  (domain:
http://www.w3.org/2002/07/owl#Thing)

Prop: http://blsdev1.vsticorp.com/terrorism#actor  (domain:
http://www.w3.org/2002/07/owl#Thing)

Prop: http://blsdev1.vsticorp.com/terrorism#organizationsInBody
(domain: http://www.w3.org/2002/07/owl#Thing)

Prop: http://blsdev1.vsticorp.com/terrorism#eventDate  (domain:
http://www.w3.org/2002/07/owl#Thing)

Prop: http://blsdev1.vsticorp.com/terrorism#isNearTo  (domain:
http://www.w3.org/2002/07/owl#Thing)

Prop: http://blsdev1.vsticorp.com/terrorism#personsInBody  (domain:
http://www.w3.org/2002/07/owl#Thing)

Prop: http://blsdev1.vsticorp.com/terrorism#responsibleFor  (domain:
http://www.w3.org/2002/07/owl#Thing)

Prop: http://blsdev1.vsticorp.com/terrorism#hasLocation  (domain:
http://www.w3.org/2002/07/owl#Thing)

Prop: http://blsdev1.vsticorp.com/terrorism#locatedIn  (domain:
http://www.w3.org/2002/07/owl#Thing)

Prop: http://blsdev1.vsticorp.com/terrorism#reportedBy  (domain:
http://www.w3.org/2002/07/owl#Thing)

Prop: http://blsdev1.vsticorp.com/terrorism#hasTopic  (domain:
http://www.w3.org/2002/07/owl#Thing)

Prop: http://blsdev1.vsticorp.com/terrorism#isPartOf  (domain:
http://www.w3.org/2002/07/owl#Thing)

Prop: http://blsdev1.vsticorp.com/terrorism#locationsInBody  (domain:
http://www.w3.org/2002/07/owl#Thing)

Prop: http://blsdev1.vsticorp.com/terrorism#hasMember  (domain:
http://www.w3.org/2002/07/owl#Thing)

Several of these are incorrect. For instance, organizationsInBody
explicitly has a domain of NewsArticle:

        <owl:ObjectProperty rdf:ID="organizationsInBody">

               <rdfs:domain rdf:resource="#NewsArticle" />

               <rdfs:range rdf:resource="#Organization" />

        </owl:ObjectProperty>

The Javadoc description for getDomain() is “Answer a resource that
represents the domain class of this property. If there is more than one
such resource, an arbitrary selection is made.”

If the domain of a property can be generalized into Thing (trivially
true) then this method is useless – all it has to do is return Thing
every time to be technically correct.

*Edward Swing*

*Applied Research Technologist*

*Vision Systems + Technology, Inc., a SAS Company*

6021 University Boulevard • Suite 360 • Ellicott City • Maryland • 21043

*Tel:*410.418.5555 *Ext:*919 • *Fax:*410.418.8580

*Email*:[email protected] <mailto:[email protected]>

*Web:*http://www.vsticorp.com <http://www.vsticorp.com/>


Reply via email to