📄 testbugs.java
字号:
Resource B = m.createResource(NS + "B");
Statement s = m.createStatement(r, RDF.type, A);
m.add(s);
String rules = "(?r rdf:type eg:A) -> (?r rdf:type eg:B).";
GenericRuleReasoner grr = new GenericRuleReasoner(Rule.parseRules(rules));
InfModel im = ModelFactory.createInfModel(grr, m);
assertTrue(im.contains(r, RDF.type, B));
assertTrue(im.getDeductionsModel().contains(r, RDF.type, B));
im.remove(s);
assertFalse(im.contains(r, RDF.type, B));
assertFalse(im.getDeductionsModel().contains(r, RDF.type, B));
}
/**
* Test looping on recursive someValuesFrom.
*/
public void hiddenTestOWLLoop() {
Model data = FileManager.get().loadModel("file:testing/reasoners/bugs/loop.owl");
InfModel infmodel = ModelFactory.createInfModel(ReasonerRegistry.getOWLReasoner(), data);
((FBRuleInfGraph)infmodel.getGraph()).setTraceOn(true);
String baseURI = "http://jena.hpl.hp.com/eg#";
Resource C = infmodel.getResource(baseURI + "C");
Resource I = infmodel.getResource(baseURI + "i");
Property R = infmodel.getProperty(baseURI, "R");
// ((FBRuleInfGraph)infmodel.getGraph()).setTraceOn(true);
System.out.println("Check that the instance does have an R property");
Statement s = I.getProperty(R);
System.out.println(" - " + s);
System.out.println("And that the type of the R property is C");
Statement s2 = ((Resource)s.getObject()).getProperty(RDF.type);
System.out.println(" - " + s2);
System.out.println("But does that have an R property?");
Statement s3 = ((Resource)s.getObject()).getProperty(R);
System.out.println(" - " + s3);
System.out.println("List all instances of C");
int count = 0;
for (Iterator i = infmodel.listStatements(null, RDF.type, C); i.hasNext(); ) {
Statement st = (Statement)i.next();
System.out.println(" - " + st);
count++;
}
System.out.println("OK");
// infmodel.write(System.out);
// System.out.flush();
}
/**
* Test bug with leaking variables which results in an incorrect "range = Nothing" deduction.
*/
public void testRangeBug() {
Model model = FileManager.get().loadModel("file:testing/reasoners/bugs/rangeBug.owl");
Model m = ModelFactory.createDefaultModel();
Reasoner r = ReasonerRegistry.getOWLReasoner();
InfModel omodel = ModelFactory.createInfModel(r, model);
String baseuri = "http://decsai.ugr.es/~ontoserver/bacarex2.owl#";
Resource js = omodel.getResource(baseuri + "JS");
Resource surname = omodel.getResource(baseuri + "surname");
Statement s = omodel.createStatement(surname, RDFS.range, OWL.Nothing);
assertTrue(! omodel.contains(s));
}
/**
* Test change of RDF specs to allow plain literals w/o lang and XSD string to be the same.
*/
public void testLiteralBug() {
Model model = FileManager.get().loadModel("file:testing/reasoners/bugs/dtValidation.owl");
Model m = ModelFactory.createDefaultModel();
Reasoner r = ReasonerRegistry.getOWLReasoner();
InfModel infmodel = ModelFactory.createInfModel(r, model);
ValidityReport validity = infmodel.validate();
assertTrue (validity.isValid());
}
/**
* Test that prototype nodes are now hidden
*/
public void testHide() {
String NS = "http://jena.hpl.hp.com/bugs#";
OntModel m = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM_RULE_INF, null);
OntClass c = m.createClass(NS + "C");
OntResource i = m.createIndividual(c);
Iterator res = m.listStatements(null, RDF.type, c);
TestUtil.assertIteratorValues(this, res, new Statement[] {
m.createStatement(i, RDF.type, c)
});
}
/**
* Also want to have hidden rb:xsdRange
*/
public void testHideXSDRange() {
OntModelSpec[] specs = new OntModelSpec[] {
OntModelSpec.OWL_MEM_RULE_INF,
OntModelSpec.OWL_MEM_RDFS_INF,
OntModelSpec.OWL_MEM_MINI_RULE_INF,
OntModelSpec.OWL_MEM_MICRO_RULE_INF
};
for (int os = 0; os < specs.length; os++) {
OntModelSpec spec = specs[os];
OntModel m = ModelFactory.createOntologyModel(spec, null);
Iterator i = m.listOntProperties();
while (i.hasNext()) {
Resource r = (Resource)i.next();
if (r.getURI() != null && r.getURI().startsWith(ReasonerVocabulary.RBNamespace)) {
assertTrue("Rubrik internal property leaked out: " + r + "(" + os + ")", false);
}
}
}
}
/**
* Test problem with bindSchema not interacting properly with validation.
*/
public void testBindSchemaValidate() {
Reasoner reasoner = ReasonerRegistry.getOWLReasoner();
Model schema = FileManager.get().loadModel("file:testing/reasoners/bugs/sbug.owl");
Model data = FileManager.get().loadModel("file:testing/reasoners/bugs/sbug.rdf");
// Union version
InfModel infu = ModelFactory.createInfModel(reasoner, data.union(schema));
ValidityReport validity = infu.validate();
assertTrue( ! validity.isValid());
// debug print
// for (Iterator i = validity.getReports(); i.hasNext(); ) {
// System.out.println(" - " + i.next());
// }
// bindSchema version
InfModel inf = ModelFactory.createInfModel(reasoner.bindSchema(schema), data);
validity = inf.validate();
assertTrue( ! validity.isValid());
}
/**
* Delete bug in generic rule reasoner.
*/
public void testGenericDeleteBug() {
Model data = ModelFactory.createDefaultModel();
String NS = "urn:x-hp:eg/";
Property p = data.createProperty(NS, "p");
Resource x = data.createResource(NS + "x");
Resource y = data.createResource(NS + "y");
Statement sy = data.createStatement(y, p, "foo");
data.add(sy);
data.add(x, p, "foo");
// String rule = "[(?x eg:p ?m) -> (?x eg:same ?x)]";
String rule = "[(?x eg:p ?m) (?y eg:p ?m) -> (?x eg:same ?y) (?y eg:same ?x)]";
GenericRuleReasoner reasoner = (GenericRuleReasoner) GenericRuleReasonerFactory.theInstance().create(null);
reasoner.setMode(GenericRuleReasoner.FORWARD_RETE);
reasoner.setRules(Rule.parseRules(rule));
InfModel inf = ModelFactory.createInfModel(reasoner, data);
TestUtil.assertIteratorLength(inf.listStatements(y, null, (RDFNode)null), 3);
inf.remove(sy);
TestUtil.assertIteratorLength(inf.listStatements(y, null, (RDFNode)null), 0);
}
/**
* RETE incremental processing bug.
*/
public void testRETEInc() {
String rule = "(?x ?p ?y) -> (?p rdf:type rdf:Property) .";
Reasoner r = new GenericRuleReasoner(Rule.parseRules(rule));
InfModel m = ModelFactory.createInfModel(r, ModelFactory.createDefaultModel());
Resource source = m.createResource("urn:alfie:testResource");
Property prop = m.createProperty("urn:alfie:testProperty");
Statement s1=m.createStatement(source, prop, "value1");
Statement s2=m.createStatement(source, prop, "value2");
m.add(s1);
assertIsProperty(m, prop);
m.add(s2);
m.remove(s1);
assertIsProperty(m, prop);
}
/**
* RETE incremental processing bug.
*/
public void testRETEDec() {
String rule = "(?x ?p ?y) -> (?p rdf:type rdf:Property) .";
Reasoner r = new GenericRuleReasoner(Rule.parseRules(rule));
InfModel m = ModelFactory.createInfModel(r, ModelFactory.createDefaultModel());
Resource source = m.createResource("urn:alfie:testResource");
Property prop = m.createProperty("urn:alfie:testProperty");
Statement s1=m.createStatement(source, prop, "value1");
Statement s2=m.createStatement(source, prop, "value2");
m.add(prop, RDF.type, RDF.Property);
m.add(s1);
m.prepare();
m.remove(s1);
assertIsProperty(m, prop);
}
private void assertIsProperty(Model m, Property prop) {
assertTrue(m.contains(prop, RDF.type, RDF.Property));
}
/**
* Bug that exposed prototypes of owl:Thing despite hiding being switched on.
*/
public void testHideOnOWLThing() {
Reasoner r = ReasonerRegistry.getOWLReasoner();
Model data = ModelFactory.createDefaultModel();
InfModel inf = ModelFactory.createInfModel(r, data);
StmtIterator things = inf.listStatements(null, RDF.type, OWL.Thing);
TestUtil.assertIteratorLength(things, 0);
}
/**
* Limitation of someValuesFrom applied to datatype properties.
*/
public void testSomeDatatype() throws IOException {
String uri = "http://www.daml.org/2001/03/daml+oil-ex-dt";
String filename = "testing/xsd/daml+oil-ex-dt.xsd";
TypeMapper tm = TypeMapper.getInstance();
XSDDatatype.loadUserDefined(uri, new FileReader(filename), null, tm);
Model data = ModelFactory.createDefaultModel();
data.read("file:testing/reasoners/bugs/userDatatypes.owl");
InfModel inf = ModelFactory.createInfModel(ReasonerRegistry.getOWLReasoner(), data);
String egNS = "http://jena.hpl.hp.com/eg#";
Resource meR = inf.getResource(egNS + "me");
Resource TestR = inf.getResource(egNS + "Test");
assertTrue("somevalues inf for datatypes", inf.contains(meR, RDF.type, TestR));
Resource Test2R = inf.getResource(egNS + "Test2");
Resource me2R = inf.getResource(egNS + "me2");
assertTrue("somevalues inf for datatypes", inf.contains(me2R, RDF.type, Test2R));
assertTrue("somevalues inf for user datatypes", inf.contains(meR, RDF.type, Test2R));
}
/* Report on jena-dev that DAMLMicroReasoner infmodels don't support daml:subClassOf, etc */
public void testDAMLMicroReasonerSupports() {
Reasoner r = DAMLMicroReasonerFactory.theInstance().create( null );
assertTrue( "Should support daml:subClassOf", r.supportsProperty( DAML_OIL.subClassOf ));
assertTrue( "Should support daml:subPropertyOf", r.supportsProperty( DAML_OIL.subPropertyOf));
assertTrue( "Should support daml:domain", r.supportsProperty( DAML_OIL.domain ));
assertTrue( "Should support daml:range", r.supportsProperty( DAML_OIL.range ));
}
/**
* Utility function.
* Create a model from an N3 string with OWL and EG namespaces defined.
*/
public static Model modelFromN3(String src) {
String fullSource = "@prefix owl: <http://www.w3.org/2002/07/owl#> .\n" +
"@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .\n" +
"@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .\n" +
"@prefix eg: <http://jena.hpl.hp.com/eg#> .\n" +
"@prefix : <#> .\n"+ src + "\n";
Model result = ModelFactory.createDefaultModel();
result.read(new StringReader(fullSource), "", "N3");
return result;
}
/** Bug report from Ole Hjalmar - direct subClassOf not reporting correct result with rule reasoner */
public void test_oh_01() {
String NS = "http://www.idi.ntnu.no/~herje/ja/";
Resource[] expected = new Resource[] {
ResourceFactory.createResource( NS+"reiseliv.owl#Reiseliv" ),
ResourceFactory.createResource( NS+"hotell.owl#Hotell" ),
ResourceFactory.createResource( NS+"restaurant.owl#Restaurant" ),
ResourceFactory.createResource( NS+"restaurant.owl#UteRestaurant" ),
ResourceFactory.createResource( NS+"restaurant.owl#UteBadRestaurant" ),
ResourceFactory.createResource( NS+"restaurant.owl#UteDoRestaurant" ),
ResourceFactory.createResource( NS+"restaurant.owl#SkogRestaurant" ),
};
test_oh_01scan( OntModelSpec.OWL_MEM, "No inf", expected );
test_oh_01scan( OntModelSpec.OWL_MEM_MINI_RULE_INF, "Mini rule inf", expected );
test_oh_01scan( OntModelSpec.OWL_MEM_MICRO_RULE_INF, "Micro rule inf", expected );
test_oh_01scan( OntModelSpec.OWL_MEM_RULE_INF, "Full rule inf", expected );
}
/** Problem with bindSchema and validation rules */
public void test_der_validation() {
Model abox = FileManager.get().loadModel("file:testing/reasoners/owl/nondetbug.rdf");
List rules = FBRuleReasoner.loadRules("testing/reasoners/owl/nondetbug.rules");
GenericRuleReasoner r = new GenericRuleReasoner(rules);
// r.setTraceOn(true);
for (int i = 0; i < 10; i++) {
InfModel im = ModelFactory.createInfModel(r, abox);
assertTrue("failed on count " + i, im.contains(null, ReasonerVocabulary.RB_VALIDATION_REPORT, (RDFNode)null));
}
}
// Temporary for debug
private void test_oh_01scan( OntModelSpec s, String prompt, Resource[] expected ) {
String NS = "http://www.idi.ntnu.no/~herje/ja/reiseliv.owl#";
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -