private Set<String> getObjectsOfProperty(final Model model, final String subject, final String property) { final InfModel infModel = createInfModel(getOWLMicroReasoner(), createDefaultModel()); infModel.add(model.listStatements()); infModel.add(pcdmModel.listStatements()); return asStream(infModel.listObjectsOfProperty(createResource(subject), createProperty(property))) .filter(RDFNode::isURIResource).map(RDFNode::asResource).map(Resource::getURI).collect(toSet()); } }
private Set<String> getObjectsOfProperty(final Model model, final String subject, final String property) { final InfModel infModel = createInfModel(getOWLMicroReasoner(), createDefaultModel()); infModel.add(model.listStatements()); infModel.add(oreModel.listStatements()); return asStream(infModel.listObjectsOfProperty(createResource(subject), createProperty(property))) .filter(RDFNode::isURIResource).map(RDFNode::asResource).map(Resource::getURI).collect(toSet()); } }
public static void usageWithDefaultModel() { System.out.println("Results with plain RDF Model"); System.out.println("----------------------------"); System.out.println(); // ontology that will be used final String ont = "http://protege.cim3.net/file/pub/ontologies/koala/koala.owl#"; final String ns = "http://protege.stanford.edu/plugins/owl/owl-library/koala.owl#"; // create Pellet reasoner final Reasoner reasoner = PelletReasonerFactory.theInstance().create(); // create an empty model final Model emptyModel = ModelFactory.createDefaultModel(); // create an inferencing model using Pellet reasoner final InfModel model = ModelFactory.createInfModel(reasoner, emptyModel); // read the file model.read(ont); // print validation report final ValidityReport report = model.validate(); printIterator(report.getReports(), "Validation Results"); // print superclasses final Resource c = model.getResource(ns + "MaleStudentWith3Daughters"); printIterator(model.listObjectsOfProperty(c, RDFS.subClassOf), "All super classes of " + c.getLocalName()); System.out.println(); }
public static void usageWithDefaultModel() { System.out.println("Results with plain RDF Model"); System.out.println("----------------------------"); System.out.println(); // ontology that will be used final String ont = "http://protege.cim3.net/file/pub/ontologies/koala/koala.owl#"; final String ns = "http://protege.stanford.edu/plugins/owl/owl-library/koala.owl#"; // create Pellet reasoner final Reasoner reasoner = PelletReasonerFactory.theInstance().create(); // create an empty model final Model emptyModel = ModelFactory.createDefaultModel(); // create an inferencing model using Pellet reasoner final InfModel model = ModelFactory.createInfModel(reasoner, emptyModel); // read the file model.read(ont); // print validation report final ValidityReport report = model.validate(); printIterator(report.getReports(), "Validation Results"); // print superclasses final Resource c = model.getResource(ns + "MaleStudentWith3Daughters"); printIterator(model.listObjectsOfProperty(c, RDFS.subClassOf), "All super classes of " + c.getLocalName()); System.out.println(); }
/** * Test that a transitive reduction is complete. * Assumes test graph has no cycles (other than the trivial * identity ones). */ public void doTestTransitiveReduction(Model model, Property dp) { InfModel im = ModelFactory.createInfModel(ReasonerRegistry.getTransitiveReasoner(), model); for (ResIterator i = im.listSubjects(); i.hasNext();) { Resource base = i.nextResource(); List<RDFNode> directLinks = new ArrayList<>(); for (NodeIterator j = im.listObjectsOfProperty(base, dp); j.hasNext(); ) { directLinks.add(j.next()); } for (int n = 0; n < directLinks.size(); n++) { Resource d1 = (Resource)directLinks.get(n); for (int m = n+1; m < directLinks.size(); m++) { Resource d2 = (Resource)directLinks.get(m); if (im.contains(d1, dp, d2) && ! base.equals(d1) && !base.equals(d2)) { assertTrue("Triangle discovered in transitive reduction", false); } } } } }
/** * Test that a transitive reduction is complete. * Assumes test graph has no cycles (other than the trivial * identity ones). */ public void doTestTransitiveReduction(Model model, Property dp) { InfModel im = ModelFactory.createInfModel(ReasonerRegistry.getTransitiveReasoner(), model); for (ResIterator i = im.listSubjects(); i.hasNext();) { Resource base = i.nextResource(); List<RDFNode> directLinks = new ArrayList<>(); for (NodeIterator j = im.listObjectsOfProperty(base, dp); j.hasNext(); ) { directLinks.add(j.next()); } for (int n = 0; n < directLinks.size(); n++) { Resource d1 = (Resource)directLinks.get(n); for (int m = n+1; m < directLinks.size(); m++) { Resource d2 = (Resource)directLinks.get(m); if (im.contains(d1, dp, d2) && ! base.equals(d1) && !base.equals(d2)) { assertTrue("Triangle discovered in transitive reduction", false); } } } } }
/** * Bug report on bad conflict resolution between two non-monotonic rules. */ public void testNonmonotonicCR() { String ruleSrc = "(eg:IndA eg:scoreA ?score), sum(?score 40 ?total), noValue(eg:IndA eg:flag_1 'true') -> drop(0), (eg:IndA eg:scoreA ?total), (eg:IndA eg:flag_1 'true')." + "(eg:IndA eg:scoreA ?score), sum(?score 33 ?total), noValue(eg:IndA eg:flag_2 'true') -> drop(0), (eg:IndA eg:scoreA ?total), (eg:IndA eg:flag_2 'true')."; List<Rule> rules = Rule.parseRules(ruleSrc); Model data = ModelFactory.createDefaultModel(); String NS = PrintUtil.egNS; Resource i = data.createResource(NS + "IndA"); Property scoreA = data.createProperty(NS, "scoreA"); i.addProperty(scoreA, data.createTypedLiteral(100)); GenericRuleReasoner reasoner = new GenericRuleReasoner(rules); InfModel inf = ModelFactory.createInfModel(reasoner, data); Iterator<RDFNode> values = inf.listObjectsOfProperty(i, scoreA); TestUtil.assertIteratorValues(this, values, new Object[] { data.createTypedLiteral(173)}); }
/** * Bug report on bad conflict resolution between two non-monotonic rules. */ public void testNonmonotonicCR() { String ruleSrc = "(eg:IndA eg:scoreA ?score), sum(?score 40 ?total), noValue(eg:IndA eg:flag_1 'true') -> drop(0), (eg:IndA eg:scoreA ?total), (eg:IndA eg:flag_1 'true')." + "(eg:IndA eg:scoreA ?score), sum(?score 33 ?total), noValue(eg:IndA eg:flag_2 'true') -> drop(0), (eg:IndA eg:scoreA ?total), (eg:IndA eg:flag_2 'true')."; List<Rule> rules = Rule.parseRules(ruleSrc); Model data = ModelFactory.createDefaultModel(); String NS = PrintUtil.egNS; Resource i = data.createResource(NS + "IndA"); Property scoreA = data.createProperty(NS, "scoreA"); i.addProperty(scoreA, data.createTypedLiteral(100)); GenericRuleReasoner reasoner = new GenericRuleReasoner(rules); InfModel inf = ModelFactory.createInfModel(reasoner, data); Iterator<RDFNode> values = inf.listObjectsOfProperty(i, scoreA); TestUtil.assertIteratorValues(this, values, new Object[] { data.createTypedLiteral(173)}); }