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:[email protected]] Sent: Friday, March 29, 2013 11:19 AM To: [email protected] 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 <[email protected]> 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 ▪ [email protected]<mailto:[email protected]> > www.sas.com<http://www.sas.com/> > SAS® … THE POWER TO KNOW® > > -- Joshua Taylor, http://www.cs.rpi.edu/~tayloj/
