1 19 20 package com.hp.hpl.jena.reasoner.dig.test; 23 24 25 26 import java.util.Iterator ; 29 30 import org.apache.commons.logging.LogFactory; 31 32 import com.hp.hpl.jena.ontology.*; 33 import com.hp.hpl.jena.rdf.model.*; 34 import com.hp.hpl.jena.reasoner.ReasonerRegistry; 35 import com.hp.hpl.jena.reasoner.ValidityReport; 36 import com.hp.hpl.jena.reasoner.dig.*; 37 import com.hp.hpl.jena.vocabulary.OWL; 38 39 import junit.framework.*; 40 41 42 43 51 public class TestConsistency 52 extends TestCase 53 { 54 57 60 63 66 69 public void testConsistent0() { 70 String NS = "http://example.org/foo#"; 71 72 OntModel base = ModelFactory.createOntologyModel( OntModelSpec.OWL_DL_MEM, null ); 73 OntClass F0 = base.createClass( NS + "F0" ); 74 OntClass F1 = base.createClass( NS + "F1" ); 75 F0.addDisjointWith( F1 ); 76 Individual i0 = base.createIndividual( NS + "i0", OWL.Thing ); 77 i0.setRDFType( F0 ); 78 79 DIGReasoner r = (DIGReasoner) ReasonerRegistry.theRegistry().create( DIGReasonerFactory.URI, null ); 80 81 OntModelSpec spec = new OntModelSpec( OntModelSpec.OWL_DL_MEM ); 82 spec.setReasoner( r ); 83 OntModel m = ModelFactory.createOntologyModel( spec, base ); 84 assertTrue( "KB should be consistent", m.validate().isValid() ); 85 } 86 87 public void testConsistent1() { 88 String NS = "http://example.org/foo#"; 89 90 OntModel base = ModelFactory.createOntologyModel( OntModelSpec.OWL_DL_MEM, null ); 91 OntClass F0 = base.createClass( NS + "F0" ); 92 OntClass F1 = base.createClass( NS + "F1" ); 93 F0.addDisjointWith( F1 ); 94 Individual i0 = base.createIndividual( NS + "i0", OWL.Thing ); 95 i0.setRDFType( F0 ); 96 i0.addRDFType( F1 ); 97 98 DIGReasoner r = (DIGReasoner) ReasonerRegistry.theRegistry().create( DIGReasonerFactory.URI, null ); 99 100 OntModelSpec spec = new OntModelSpec( OntModelSpec.OWL_DL_MEM ); 101 spec.setReasoner( r ); 102 OntModel m = ModelFactory.createOntologyModel( spec, base ); 103 ValidityReport report = m.validate(); 104 105 if (!report.isValid()) { 106 for (Iterator i = report.getReports(); i.hasNext(); ) { 107 ValidityReport.Report rp = (ValidityReport.Report) i.next(); 108 LogFactory.getLog( getClass() ).debug( "Problem report: " + rp.type + " - " + rp.description ); 109 } 110 } 111 assertFalse( "KB should not be consistent", m.validate().isValid() ); 112 } 113 114 public void testConsistent2() { 115 String NS = "http://example.org/foo#"; 116 117 OntModel base = ModelFactory.createOntologyModel( OntModelSpec.OWL_DL_MEM, null ); 118 OntClass F0 = base.createClass( NS + "F0" ); 119 OntClass F1 = base.createClass( NS + "F1" ); 120 OntClass F2 = base.createClass( NS + "F2" ); 121 122 F0.addDisjointWith( F1 ); 123 F2.addSuperClass( F0 ); 124 F2.addSuperClass( F1 ); 125 126 DIGReasoner r = (DIGReasoner) ReasonerRegistry.theRegistry().create( DIGReasonerFactory.URI, null ); 127 128 OntModelSpec spec = new OntModelSpec( OntModelSpec.OWL_DL_MEM ); 129 spec.setReasoner( r ); 130 OntModel m = ModelFactory.createOntologyModel( spec, base ); 131 ValidityReport report = m.validate(); 132 133 if (!report.isValid()) { 134 for (Iterator i = report.getReports(); i.hasNext(); ) { 135 ValidityReport.Report rp = (ValidityReport.Report) i.next(); 136 LogFactory.getLog( getClass() ).debug( "Problem report: " + rp.type + " - " + rp.description ); 137 } 138 } 139 assertFalse( "KB should not be consistent", m.validate().isValid() ); 140 } 141 142 145 149 } 150 151 152 178 | Popular Tags |