@Override public Reasoner create( Resource configuration ) { return rf.create( configuration ).bindSchema( schema ); }
@Override public Reasoner create( Resource configuration ) { return rf.create( configuration ).bindSchema( schema ); }
/** Answer a Reasoner created according to the underlying factory, and then loaded with this Wrapper's rules (if the Reasoner is a RuleReasoner) and bound to this Wrapper's schemas (in an unspecified order). */ @Override public Reasoner create( Resource ignored ) { Reasoner result = factory.create( config ); return schemaUnion.isEmpty() ? result : result.bindSchema( schemaUnion ); }
/** Answer a Reasoner created according to the underlying factory, and then loaded with this Wrapper's rules (if the Reasoner is a RuleReasoner) and bound to this Wrapper's schemas (in an unspecified order). */ @Override public Reasoner create( Resource ignored ) { Reasoner result = factory.create( config ); return schemaUnion.isEmpty() ? result : result.bindSchema( schemaUnion ); }
/** * Build an inferred model by attaching the given RDF model to the given reasoner. * This form of the call allows two data sets to be merged and reasoned over - * conventionally one contains schema data and one instance data but this is not * a formal requirement. * * @param reasoner the reasoner to use to process the data * @param schema a Model containing RDFS schema data * @param model a Model containing instance data assertions, any statements added to the InfModel * will be added to this underlying data model. */ public static InfModel createInfModel(Reasoner reasoner, Model schema, Model model) { InfGraph graph = reasoner.bindSchema(schema.getGraph()).bind(model.getGraph()); return new InfModelImpl( graph ); }
/** * Build an inferred model by attaching the given RDF model to the given reasoner. * This form of the call allows two data sets to be merged and reasoned over - * conventionally one contains schema data and one instance data but this is not * a formal requirement. * * @param reasoner the reasoner to use to process the data * @param schema a Model containing RDFS schema data * @param model a Model containing instance data assertions, any statements added to the InfModel * will be added to this underlying data model. */ public static InfModel createInfModel(Reasoner reasoner, Model schema, Model model) { InfGraph graph = reasoner.bindSchema(schema.getGraph()).bind(model.getGraph()); return new InfModelImpl( graph ); }
public static void main(String[] args) { FileManager.get().addLocatorClassLoader(ExampleONT_02.class.getClassLoader()); Model tbox = FileManager.get().loadModel("data/inference/tbox.owl", null, "RDF/XML"); // http://en.wikipedia.org/wiki/Tbox Reasoner reasoner = ReasonerRegistry.getOWLReasoner().bindSchema(tbox.getGraph()); Model abox = FileManager.get().loadModel("data/inference/abox.owl", null, "RDF/XML"); // http://en.wikipedia.org/wiki/Abox InfModel inf = ModelFactory.createInfModel(reasoner, abox); ValidityReport validityReport = inf.validate(); if ( !validityReport.isValid() ) { System.out.println("Inconsistent"); Iterator<Report> iter = validityReport.getReports(); while ( iter.hasNext() ) { Report report = iter.next(); System.out.println(report); } } else { System.out.println("Valid"); } }
/** * Return a Model through which all the RDFS entailments * derivable from the given data and schema models are accessible. * There is no strict requirement to separate schema and instance data between the two * arguments. * * @param model a Model containing instance data assertions * @param schema a Model containing RDFS schema data */ public static InfModel createRDFSModel( Model schema, Model model ) { Reasoner reasoner = ReasonerRegistry.getRDFSReasoner(); InfGraph graph = reasoner.bindSchema(schema.getGraph()).bind(model.getGraph()); return new InfModelImpl( graph ); }
/** * Return a Model through which all the RDFS entailments * derivable from the given data and schema models are accessible. * There is no strict requirement to separate schema and instance data between the two * arguments. * * @param model a Model containing instance data assertions * @param schema a Model containing RDFS schema data */ public static InfModel createRDFSModel( Model schema, Model model ) { Reasoner reasoner = ReasonerRegistry.getRDFSReasoner(); InfGraph graph = reasoner.bindSchema(schema.getGraph()).bind(model.getGraph()); return new InfModelImpl( graph ); }
/** * Create, or retrieve from cache, an OWL reasoner already bound * to the test tbox. */ public Reasoner makeReasoner() { if (reasonerCache == null) { Model tbox = FileManager.get().loadModel(testTbox); reasonerCache = ReasonerRegistry.getOWLReasoner().bindSchema(tbox.getGraph()); } return reasonerCache; }
/** * Create, or retrieve from cache, an OWL reasoner already bound * to the test tbox. */ public Reasoner makeReasoner() { if (reasonerCache == null) { Model tbox = FileManager.get().loadModel(testTbox); reasonerCache = ReasonerRegistry.getOWLReasoner().bindSchema(tbox.getGraph()); } return reasonerCache; }
/** * Time a trial list of results from an inf graph. */ private static void doTiming(Reasoner r, Model tbox, Model data, String name, int loop) { Resource C1 = ResourceFactory.createResource("http://www.hpl.hp.com/semweb/2003/eg#C1"); Resource C2 = ResourceFactory.createResource("http://www.hpl.hp.com/semweb/2003/eg#C2"); long t1 = System.currentTimeMillis(); int count = 0; for (int lp = 0; lp < loop; lp++) { Model m = ModelFactory.createModelForGraph(r.bindSchema(tbox.getGraph()).bind(data.getGraph())); count = 0; for (Iterator<Statement> i = m.listStatements(null, RDF.type, C1); i.hasNext(); i.next()) count++; } long t2 = System.currentTimeMillis(); long time10 = (t2-t1)*10/loop; long time = time10/10; long timeFraction = time10 - (time*10); System.out.println(name + ": " + count +" results in " + time + "." + timeFraction +"ms"); // t1 = System.currentTimeMillis(); // for (int j = 0; j < 10; j++) { // count = 0; // for (Iterator i = m.listStatements(null, RDF.type, C1); i.hasNext(); i.next()) count++; // } // t2 = System.currentTimeMillis(); // System.out.println(name + ": " + count + " results in " + (t2-t1)/10 +"ms"); } }
/** * Time a trial list of results from an inf graph. */ private static void doTiming(Reasoner r, Model tbox, Model data, String name, int loop) { Resource C1 = ResourceFactory.createResource("http://www.hpl.hp.com/semweb/2003/eg#C1"); Resource C2 = ResourceFactory.createResource("http://www.hpl.hp.com/semweb/2003/eg#C2"); long t1 = System.currentTimeMillis(); int count = 0; for (int lp = 0; lp < loop; lp++) { Model m = ModelFactory.createModelForGraph(r.bindSchema(tbox.getGraph()).bind(data.getGraph())); count = 0; for (Iterator<Statement> i = m.listStatements(null, RDF.type, C1); i.hasNext(); i.next()) count++; } long t2 = System.currentTimeMillis(); long time10 = (t2-t1)*10/loop; long time = time10/10; long timeFraction = time10 - (time*10); System.out.println(name + ": " + count +" results in " + time + "." + timeFraction +"ms"); // t1 = System.currentTimeMillis(); // for (int j = 0; j < 10; j++) { // count = 0; // for (Iterator i = m.listStatements(null, RDF.type, C1); i.hasNext(); i.next()) count++; // } // t2 = System.currentTimeMillis(); // System.out.println(name + ": " + count + " results in " + (t2-t1)/10 +"ms"); } }
/** * 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()); }
/** * 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()); }
/** * Test schema partial binding machinery */ public void testSchemaBinding() { String rules = "[testRule1: (n1 p ?a) -> (n2, p, ?a)]" + "[testRule2: (n1 q ?a) -> (n2, q, ?a)]" + "[testRule3: (n2 p ?a), (n2 q ?a) -> (res p ?a)]"; List<Rule> ruleList = Rule.parseRules(rules); Graph schema = Factory.createGraphMem(); schema.add(new Triple(n1, p, n3)); Graph data = Factory.createGraphMem(); data.add(new Triple(n1, q, n4)); data.add(new Triple(n1, q, n3)); Reasoner reasoner = new BasicForwardRuleReasoner(ruleList); Reasoner boundReasoner = reasoner.bindSchema(schema); InfGraph infgraph = boundReasoner.bind(data); TestUtil.assertIteratorValues(this, infgraph.find(null, null, null), new Triple[] { new Triple(n1, p, n3), new Triple(n2, p, n3), new Triple(n1, q, n4), new Triple(n2, q, n4), new Triple(n1, q, n3), new Triple(n2, q, n3), new Triple(res, p, n3) }); }
/** * Test schema partial binding machinery */ public void testSchemaBinding() { String rules = "[testRule1: (n1 p ?a) -> (n2, p, ?a)]" + "[testRule2: (n1 q ?a) -> (n2, q, ?a)]" + "[testRule3: (n2 p ?a), (n2 q ?a) -> (res p ?a)]"; List<Rule> ruleList = Rule.parseRules(rules); Graph schema = Factory.createGraphMem(); schema.add(new Triple(n1, p, n3)); Graph data = Factory.createGraphMem(); data.add(new Triple(n1, q, n4)); data.add(new Triple(n1, q, n3)); Reasoner reasoner = new BasicForwardRuleReasoner(ruleList); Reasoner boundReasoner = reasoner.bindSchema(schema); InfGraph infgraph = boundReasoner.bind(data); TestUtil.assertIteratorValues(this, infgraph.find(null, null, null), new Triple[] { new Triple(n1, p, n3), new Triple(n2, p, n3), new Triple(n1, q, n4), new Triple(n2, q, n4), new Triple(n1, q, n3), new Triple(n2, q, n3), new Triple(res, p, n3) }); }
Reasoner boundReasoner = reasoner.bindSchema(schema); InfGraph infgraph = boundReasoner.bind(data);
Reasoner boundReasoner = reasoner.bindSchema(schema); InfGraph infgraph = boundReasoner.bind(data);
reasoner = reasoner.bindSchema(tBox); Model model = ModelFactory.createDefaultModel(); InfModel aBox = ModelFactory.createInfModel(reasoner, model);