You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by David Jordan <Da...@sas.com> on 2013/03/29 15:08:00 UTC

testing assignment of invalid range

I am writing a small test to check whether assignment of an invalid value is caught and how long it takes.

Here is the relevant part of the ontology:

:Sex rdf:type rdfs:Class ;
       rdfs:label "Sex" .

:Male rdfs:subClassOf :Sex ;
       rdfs:label "Male" .

:Female rdfs:subClassOf :Sex ;
       rdfs:label "Female" .

:Individual rdf:type owl:Class .

:hasSex rdf:type  owl:ObjectProperty ;
       rdfs:domain :Individual ;
       rdf:type owl:FunctionalProperty ;
       rdfs:range :Sex .


Here is the relevant Java code:

From base class TestBase:
       public OntModel getGenealogyOntologyModel(){
              if( genealogyOntModel == null ){
                     Model model = getGenealogyModel();
                     OntModelSpec spec = new OntModelSpec(OntModelSpec.OWL_MEM_MICRO_RULE_INF);
                     genealogyOntModel = ModelFactory.createOntologyModel(spec, model);
              }
              return genealogyOntModel;
       }


public class InvalidPropertyValueTest extends TestBase {
       private static final String P1 = GENEALOGY_MODEL_NAME + "P1";
       private static final String P2 = GENEALOGY_MODEL_NAME + "P2";
       private static final String HAS_SEX = GENEALOGY_MODEL_NAME + "hasSex";

       @Test
       public void testSetInvalidRange(){
              OntModel omodel = getGenealogyOntologyModel();
              Individual p1 = omodel.getIndividual(P1);
              Individual p2 = omodel.getIndividual(P2);
              Property hasSex = omodel.getProperty(HAS_SEX);
              omodel.add(omodel.createStatement(p1, hasSex, p2));
              omodel.rebind();
              ValidityReport validity = omodel.validate();
              boolean isValid = validity.isValid();
              if( !isValid ){
                     Iterator<ValidityReport.Report> iter = validity.getReports();
                     while( iter.hasNext() ){
                           ValidityReport.Report report = iter.next();
                           System.out.println(report.toString());
                     }
              }
       }
}

The problem is that isValid is returning true, I expected false. What am I doing wrong?
Am I using the wrong OntModelSpec?

David Jordan
Senior Software Developer
SAS Institute Inc.
Health & Life Sciences, Research & Development
Bldg R ▪ Office 4467
600 Research Drive ▪ Cary, NC 27513
Tel: 919 531 1233 ▪ david.jordan@sas.com<ma...@sas.com>
www.sas.com<http://www.sas.com/>
SAS® … THE POWER TO KNOW®


Re: testing assignment of invalid range

Posted by Joshua TAYLOR <jo...@gmail.com>.
I know there are some documents out there about common pitfalls that
people fall into when they start working with OWL and RDF,
particularly coming from other programming backgrounds, but the best I
could find at the moment are

http://protege.stanford.edu/conference/2004/slides/6.1_Horridge_CommonErrorsInOWL.pdf
http://www.co-ode.org/resources/papers/ekaw2004.pdf

These does cover some of the issues that are coming up here, though.

On Fri, Mar 29, 2013 at 11:42 AM, Joshua TAYLOR <jo...@gmail.com> wrote:
>> -----Original Message-----
>> From: Joshua TAYLOR [mailto:joshuaaaron@gmail.com]
>> Sent: Friday, March 29, 2013 11:19 AM
>> To: users@jena.apache.org
>> Subject: Re: testing assignment of invalid range
>>
>> I don't see anything that would make anything invalid. There's no declaration that the classes Male and Female are disjoint.  By adding [p1 hasSex p2] to the model, you'll be able to infer that [p2 rdf:type Sex], though, and that's expected.  Since the domain of hasSex is p2, anything that appears as the object of a hasSex statement is inferred to be a Sex.
>>
>> If you can elaborate on what invalidity/inconsistency you expected to observe, someone can probably tell you what changes you'll need to make to the model to get it.
>>
>> //JT
>>
>>
>> On Fri, Mar 29, 2013 at 10:08 AM, David Jordan <Da...@sas.com> wrote:
>>
>> >
>> > I am writing a small test to check whether assignment of an invalid
>> > value is caught and how long it takes.
>> >
>> > Here is the relevant part of the ontology:
>> >
>> > :Sex rdf:type rdfs:Class ;
>> >        rdfs:label "Sex" .
>> >
>> > :Male rdfs:subClassOf :Sex ;
>> >        rdfs:label "Male" .
>> >
>> > :Female rdfs:subClassOf :Sex ;
>> >        rdfs:label "Female" .
>> >
>> > :Individual rdf:type owl:Class .
>> >
>> > :hasSex rdf:type  owl:ObjectProperty ;
>> >        rdfs:domain :Individual ;
>> >        rdf:type owl:FunctionalProperty ;
>> >        rdfs:range :Sex .
>> >
>> >
>> > Here is the relevant Java code:
>> >
>> > From base class TestBase:
>> >        public OntModel getGenealogyOntologyModel(){
>> >               if( genealogyOntModel == null ){
>> >                      Model model = getGenealogyModel();
>> >                      OntModelSpec spec = new
>> > OntModelSpec(OntModelSpec.OWL_MEM_MICRO_RULE_INF);
>> >                      genealogyOntModel =
>> > ModelFactory.createOntologyModel(spec, model);
>> >               }
>> >               return genealogyOntModel;
>> >        }
>> >
>> >
>> > public class InvalidPropertyValueTest extends TestBase {
>> >        private static final String P1 = GENEALOGY_MODEL_NAME + "P1";
>> >        private static final String P2 = GENEALOGY_MODEL_NAME + "P2";
>> >        private static final String HAS_SEX = GENEALOGY_MODEL_NAME +
>> > "hasSex";
>> >
>> >        @Test
>> >        public void testSetInvalidRange(){
>> >               OntModel omodel = getGenealogyOntologyModel();
>> >               Individual p1 = omodel.getIndividual(P1);
>> >               Individual p2 = omodel.getIndividual(P2);
>> >               Property hasSex = omodel.getProperty(HAS_SEX);
>> >               omodel.add(omodel.createStatement(p1, hasSex, p2));
>> >               omodel.rebind();
>> >               ValidityReport validity = omodel.validate();
>> >               boolean isValid = validity.isValid();
>> >               if( !isValid ){
>> >                      Iterator<ValidityReport.Report> iter =
>> > validity.getReports();
>> >                      while( iter.hasNext() ){
>> >                            ValidityReport.Report report = iter.next();
>> >                            System.out.println(report.toString());
>> >                      }
>> >               }
>> >        }
>> > }
>> >
>> > The problem is that isValid is returning true, I expected false. What
>> > am I doing wrong?
>> > Am I using the wrong OntModelSpec?
>> >
>> > David Jordan
>> > Senior Software Developer
>> > SAS Institute Inc.
>> > Health & Life Sciences, Research & Development Bldg R ▪ Office 4467
>> > 600 Research Drive ▪ Cary, NC 27513
>> > Tel: 919 531 1233 ▪ david.jordan@sas.com<ma...@sas.com>
>> > www.sas.com<http://www.sas.com/>
>> > SAS® … THE POWER TO KNOW®
>> >
> On Fri, Mar 29, 2013 at 11:33 AM, David Jordan <Da...@sas.com> wrote:
>>
>> Then maybe I don't understand use of domain and range.
>>
>> :hasSex has a range of :Sex
>> I am assigning an :Individual for the range value, which I thought would be flagged as invalid.
>>
>> Is there another way to do this? I want to do a constraint check that will prevent the hasSex property from being given a value of anything other than a :Sex (or :Male, :Female).
>
> rdfs:[domain,range] state that subjects and objects triples using the
> property are members of the declared domains and ranges.
> Specifically,
>
> if [P rdfs:domain D] and [X P Y]
> then [X rdf:type D]
>
> if [P rdfs:range R] and [X P Y]
> then [Y rdf:type R]
>
> In your example, you created individuals p1 and p2, and asserted [p1
> hasSex p2] [hasSex rdfs:range Sex] so it can be inferred that [p2
> rdf:type Sex].
>
> I expect that what you want is that p2 should not have type Sex, so
> define some class, say, Person, that is disjoint from Sex, assert that
> p2 is a Person, and then there will be an inconsistency.
>
> //JT
> --
> Joshua Taylor, http://www.cs.rpi.edu/~tayloj/



-- 
Joshua Taylor, http://www.cs.rpi.edu/~tayloj/

Re: testing assignment of invalid range

Posted by Joshua TAYLOR <jo...@gmail.com>.
> -----Original Message-----
> From: Joshua TAYLOR [mailto:joshuaaaron@gmail.com]
> Sent: Friday, March 29, 2013 11:19 AM
> To: users@jena.apache.org
> Subject: Re: testing assignment of invalid range
>
> I don't see anything that would make anything invalid. There's no declaration that the classes Male and Female are disjoint.  By adding [p1 hasSex p2] to the model, you'll be able to infer that [p2 rdf:type Sex], though, and that's expected.  Since the domain of hasSex is p2, anything that appears as the object of a hasSex statement is inferred to be a Sex.
>
> If you can elaborate on what invalidity/inconsistency you expected to observe, someone can probably tell you what changes you'll need to make to the model to get it.
>
> //JT
>
>
> On Fri, Mar 29, 2013 at 10:08 AM, David Jordan <Da...@sas.com> wrote:
>
> >
> > I am writing a small test to check whether assignment of an invalid
> > value is caught and how long it takes.
> >
> > Here is the relevant part of the ontology:
> >
> > :Sex rdf:type rdfs:Class ;
> >        rdfs:label "Sex" .
> >
> > :Male rdfs:subClassOf :Sex ;
> >        rdfs:label "Male" .
> >
> > :Female rdfs:subClassOf :Sex ;
> >        rdfs:label "Female" .
> >
> > :Individual rdf:type owl:Class .
> >
> > :hasSex rdf:type  owl:ObjectProperty ;
> >        rdfs:domain :Individual ;
> >        rdf:type owl:FunctionalProperty ;
> >        rdfs:range :Sex .
> >
> >
> > Here is the relevant Java code:
> >
> > From base class TestBase:
> >        public OntModel getGenealogyOntologyModel(){
> >               if( genealogyOntModel == null ){
> >                      Model model = getGenealogyModel();
> >                      OntModelSpec spec = new
> > OntModelSpec(OntModelSpec.OWL_MEM_MICRO_RULE_INF);
> >                      genealogyOntModel =
> > ModelFactory.createOntologyModel(spec, model);
> >               }
> >               return genealogyOntModel;
> >        }
> >
> >
> > public class InvalidPropertyValueTest extends TestBase {
> >        private static final String P1 = GENEALOGY_MODEL_NAME + "P1";
> >        private static final String P2 = GENEALOGY_MODEL_NAME + "P2";
> >        private static final String HAS_SEX = GENEALOGY_MODEL_NAME +
> > "hasSex";
> >
> >        @Test
> >        public void testSetInvalidRange(){
> >               OntModel omodel = getGenealogyOntologyModel();
> >               Individual p1 = omodel.getIndividual(P1);
> >               Individual p2 = omodel.getIndividual(P2);
> >               Property hasSex = omodel.getProperty(HAS_SEX);
> >               omodel.add(omodel.createStatement(p1, hasSex, p2));
> >               omodel.rebind();
> >               ValidityReport validity = omodel.validate();
> >               boolean isValid = validity.isValid();
> >               if( !isValid ){
> >                      Iterator<ValidityReport.Report> iter =
> > validity.getReports();
> >                      while( iter.hasNext() ){
> >                            ValidityReport.Report report = iter.next();
> >                            System.out.println(report.toString());
> >                      }
> >               }
> >        }
> > }
> >
> > The problem is that isValid is returning true, I expected false. What
> > am I doing wrong?
> > Am I using the wrong OntModelSpec?
> >
> > David Jordan
> > Senior Software Developer
> > SAS Institute Inc.
> > Health & Life Sciences, Research & Development Bldg R ▪ Office 4467
> > 600 Research Drive ▪ Cary, NC 27513
> > Tel: 919 531 1233 ▪ david.jordan@sas.com<ma...@sas.com>
> > www.sas.com<http://www.sas.com/>
> > SAS® … THE POWER TO KNOW®
> >
On Fri, Mar 29, 2013 at 11:33 AM, David Jordan <Da...@sas.com> wrote:
>
> Then maybe I don't understand use of domain and range.
>
> :hasSex has a range of :Sex
> I am assigning an :Individual for the range value, which I thought would be flagged as invalid.
>
> Is there another way to do this? I want to do a constraint check that will prevent the hasSex property from being given a value of anything other than a :Sex (or :Male, :Female).

rdfs:[domain,range] state that subjects and objects triples using the
property are members of the declared domains and ranges.
Specifically,

if [P rdfs:domain D] and [X P Y]
then [X rdf:type D]

if [P rdfs:range R] and [X P Y]
then [Y rdf:type R]

In your example, you created individuals p1 and p2, and asserted [p1
hasSex p2] [hasSex rdfs:range Sex] so it can be inferred that [p2
rdf:type Sex].

I expect that what you want is that p2 should not have type Sex, so
define some class, say, Person, that is disjoint from Sex, assert that
p2 is a Person, and then there will be an inconsistency.

//JT
--
Joshua Taylor, http://www.cs.rpi.edu/~tayloj/

RE: testing assignment of invalid range

Posted by David Jordan <Da...@sas.com>.
Then maybe I don't understand use of domain and range.

:hasSex has a range of :Sex
I am assigning an :Individual for the range value, which I thought would be flagged as invalid.

Is there another way to do this? I want to do a constraint check that will prevent the hasSex property from being given a value of anything other than a :Sex (or :Male, :Female).

-----Original Message-----
From: Joshua TAYLOR [mailto:joshuaaaron@gmail.com] 
Sent: Friday, March 29, 2013 11:19 AM
To: users@jena.apache.org
Subject: Re: testing assignment of invalid range

I don't see anything that would make anything invalid. There's no declaration that the classes Male and Female are disjoint.  By adding [p1 hasSex p2] to the model, you'll be able to infer that [p2 rdf:type Sex], though, and that's expected.  Since the domain of hasSex is p2, anything that appears as the object of a hasSex statement is inferred to be a Sex.

If you can elaborate on what invalidity/inconsistency you expected to observe, someone can probably tell you what changes you'll need to make to the model to get it.

//JT


On Fri, Mar 29, 2013 at 10:08 AM, David Jordan <Da...@sas.com> wrote:

>
> I am writing a small test to check whether assignment of an invalid 
> value is caught and how long it takes.
>
> Here is the relevant part of the ontology:
>
> :Sex rdf:type rdfs:Class ;
>        rdfs:label "Sex" .
>
> :Male rdfs:subClassOf :Sex ;
>        rdfs:label "Male" .
>
> :Female rdfs:subClassOf :Sex ;
>        rdfs:label "Female" .
>
> :Individual rdf:type owl:Class .
>
> :hasSex rdf:type  owl:ObjectProperty ;
>        rdfs:domain :Individual ;
>        rdf:type owl:FunctionalProperty ;
>        rdfs:range :Sex .
>
>
> Here is the relevant Java code:
>
> From base class TestBase:
>        public OntModel getGenealogyOntologyModel(){
>               if( genealogyOntModel == null ){
>                      Model model = getGenealogyModel();
>                      OntModelSpec spec = new 
> OntModelSpec(OntModelSpec.OWL_MEM_MICRO_RULE_INF);
>                      genealogyOntModel = 
> ModelFactory.createOntologyModel(spec, model);
>               }
>               return genealogyOntModel;
>        }
>
>
> public class InvalidPropertyValueTest extends TestBase {
>        private static final String P1 = GENEALOGY_MODEL_NAME + "P1";
>        private static final String P2 = GENEALOGY_MODEL_NAME + "P2";
>        private static final String HAS_SEX = GENEALOGY_MODEL_NAME + 
> "hasSex";
>
>        @Test
>        public void testSetInvalidRange(){
>               OntModel omodel = getGenealogyOntologyModel();
>               Individual p1 = omodel.getIndividual(P1);
>               Individual p2 = omodel.getIndividual(P2);
>               Property hasSex = omodel.getProperty(HAS_SEX);
>               omodel.add(omodel.createStatement(p1, hasSex, p2));
>               omodel.rebind();
>               ValidityReport validity = omodel.validate();
>               boolean isValid = validity.isValid();
>               if( !isValid ){
>                      Iterator<ValidityReport.Report> iter = 
> validity.getReports();
>                      while( iter.hasNext() ){
>                            ValidityReport.Report report = iter.next();
>                            System.out.println(report.toString());
>                      }
>               }
>        }
> }
>
> The problem is that isValid is returning true, I expected false. What 
> am I doing wrong?
> Am I using the wrong OntModelSpec?
>
> David Jordan
> Senior Software Developer
> SAS Institute Inc.
> Health & Life Sciences, Research & Development Bldg R ▪ Office 4467
> 600 Research Drive ▪ Cary, NC 27513
> Tel: 919 531 1233 ▪ david.jordan@sas.com<ma...@sas.com>
> www.sas.com<http://www.sas.com/>
> SAS® … THE POWER TO KNOW®
>
>


-- 
Joshua Taylor, http://www.cs.rpi.edu/~tayloj/

Re: testing assignment of invalid range

Posted by Joshua TAYLOR <jo...@gmail.com>.
I don't see anything that would make anything invalid. There's no
declaration that the classes Male and Female are disjoint.  By adding [p1
hasSex p2] to the model, you'll be able to infer that [p2 rdf:type Sex],
though, and that's expected.  Since the domain of hasSex is p2, anything
that appears as the object of a hasSex statement is inferred to be a Sex.

If you can elaborate on what invalidity/inconsistency you expected to
observe, someone can probably tell you what changes you'll need to make to
the model to get it.

//JT


On Fri, Mar 29, 2013 at 10:08 AM, David Jordan <Da...@sas.com> wrote:

>
> I am writing a small test to check whether assignment of an invalid value
> is caught and how long it takes.
>
> Here is the relevant part of the ontology:
>
> :Sex rdf:type rdfs:Class ;
>        rdfs:label "Sex" .
>
> :Male rdfs:subClassOf :Sex ;
>        rdfs:label "Male" .
>
> :Female rdfs:subClassOf :Sex ;
>        rdfs:label "Female" .
>
> :Individual rdf:type owl:Class .
>
> :hasSex rdf:type  owl:ObjectProperty ;
>        rdfs:domain :Individual ;
>        rdf:type owl:FunctionalProperty ;
>        rdfs:range :Sex .
>
>
> Here is the relevant Java code:
>
> From base class TestBase:
>        public OntModel getGenealogyOntologyModel(){
>               if( genealogyOntModel == null ){
>                      Model model = getGenealogyModel();
>                      OntModelSpec spec = new
> OntModelSpec(OntModelSpec.OWL_MEM_MICRO_RULE_INF);
>                      genealogyOntModel =
> ModelFactory.createOntologyModel(spec, model);
>               }
>               return genealogyOntModel;
>        }
>
>
> public class InvalidPropertyValueTest extends TestBase {
>        private static final String P1 = GENEALOGY_MODEL_NAME + "P1";
>        private static final String P2 = GENEALOGY_MODEL_NAME + "P2";
>        private static final String HAS_SEX = GENEALOGY_MODEL_NAME +
> "hasSex";
>
>        @Test
>        public void testSetInvalidRange(){
>               OntModel omodel = getGenealogyOntologyModel();
>               Individual p1 = omodel.getIndividual(P1);
>               Individual p2 = omodel.getIndividual(P2);
>               Property hasSex = omodel.getProperty(HAS_SEX);
>               omodel.add(omodel.createStatement(p1, hasSex, p2));
>               omodel.rebind();
>               ValidityReport validity = omodel.validate();
>               boolean isValid = validity.isValid();
>               if( !isValid ){
>                      Iterator<ValidityReport.Report> iter =
> validity.getReports();
>                      while( iter.hasNext() ){
>                            ValidityReport.Report report = iter.next();
>                            System.out.println(report.toString());
>                      }
>               }
>        }
> }
>
> The problem is that isValid is returning true, I expected false. What am I
> doing wrong?
> Am I using the wrong OntModelSpec?
>
> David Jordan
> Senior Software Developer
> SAS Institute Inc.
> Health & Life Sciences, Research & Development
> Bldg R ▪ Office 4467
> 600 Research Drive ▪ Cary, NC 27513
> Tel: 919 531 1233 ▪ david.jordan@sas.com<ma...@sas.com>
> www.sas.com<http://www.sas.com/>
> SAS® … THE POWER TO KNOW®
>
>


-- 
Joshua Taylor, http://www.cs.rpi.edu/~tayloj/