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®

Reply via email to