You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by Ed Swing <Ed...@sas.com> on 2013/03/19 16:07:29 UTC

Property Domains

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: Ed.Swing@vsticorp.com<ma...@vsticorp.com>
Web: http://www.vsticorp.com<http://www.vsticorp.com/>


Re: Property Domains

Posted by Dave Reynolds <da...@gmail.com>.
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*:Ed.Swing@vsticorp.com <ma...@vsticorp.com>
>
> *Web:*http://www.vsticorp.com <http://www.vsticorp.com/>
>


Re: Property Domains

Posted by Chris Dollin <ch...@epimorphics.com>.
On Tuesday, March 19, 2013 03:07:29 PM 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;

(fx:snip)

> 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>

That doesn't make the printed answer incorrect ...

> 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."

... because if there are multiple domain classes, /somehow/ Jena has to
choose one. (It chooses the first one that turns up when doing whatever
the code "naturally" does.)

> 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.

Whether or not the range generalises to Thing is going to depend
on how much inference the model has been asked to do and whether
the Jena implementors are trying to be more than just "technically correct".

It looks like getDomain() isn't the method you're looking for; something
based on listDomain() (exactly what I don't know) may be more useful.

Chris

-- 
"I know it was late, but Mountjoy never bothers,                /Archer's Goon/
 so long as it's the full two thousand words."

Epimorphics Ltd, http://www.epimorphics.com
Registered address: Court Lodge, 105 High Street, Portishead, Bristol BS20 6PT
Epimorphics Ltd. is a limited company registered in England (number 7016688)


Re: Property Domains

Posted by Joshua TAYLOR <jo...@gmail.com>.
On Tue, Mar 19, 2013 at 11:07 AM, Ed Swing <Ed...@sas.com> 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.

There is a rule in owl-fb.rules that says:

[objectProperty: (?P rdf:type owl:ObjectProperty) ->
						(?P rdfs:domain owl:Thing) (?P rdfs:range owl:Thing) ]

so there would be rdfs:domain owl:Thing for every property.  So, since
OntProperty#getDomain can return an arbitrary domain of the property,
returning owl:Thing is acceptable.  Dave Reynolds wrote a reply
linking to more discussion, so I'll just respond as before that you
might get what you want by querying the base model via RDF, or by
having a non inferencing OntModel to work with (perhaps as a submodel
of the inferencing OntModel).  For instance:

import java.io.IOException;
import java.io.InputStream;
import java.util.Iterator;

import com.hp.hpl.jena.ontology.OntClass;
import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.ontology.OntModelSpec;
import com.hp.hpl.jena.ontology.OntProperty;
import com.hp.hpl.jena.rdf.model.ModelFactory;

public class PropTest {
	public static void main(String[] args) throws IOException {
        OntModel base =
ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM );
        InputStream inStream = PropTest.class.getResourceAsStream(
"terrorism.xml" );
        base.read(inStream, null);
        inStream.close();
        OntModel model = ModelFactory.createOntologyModel(
OntModelSpec.OWL_DL_MEM_RULE_INF );
        model.addSubModel( base );

        String uriBase = base.getNsPrefixURI("");
        OntClass cls = model.getOntClass(uriBase + "TerrorAttack");
        System.out.println(cls);

        for ( OntModel m : new OntModel[] { base, model } ) {
        	System.out.println( "*****" );
        	for (Iterator<OntProperty> iter = m.listAllOntProperties();
iter.hasNext();) {
        		OntProperty prop = iter.next();
        		System.out.println( "prop: "+prop+"; domain: "+prop.getDomain() );
        	}
        }
    }
}

Output includes:

...
prop: http://blsdev1.vsticorp.com/terrorism#organizationsInBody;
domain: http://blsdev1.vsticorp.com/terrorism#NewsArticle
...
prop: http://blsdev1.vsticorp.com/terrorism#organizationsInBody;
domain: http://www.w3.org/2002/07/owl#Thing
...
-- 
Joshua Taylor, http://www.cs.rpi.edu/~tayloj/