public void setUp() { model = getModel(); Resource S2 = model.createResource(anchor + "subject2"); S = model.createResource(anchor + "subject"); P = model.createProperty(anchor + "predicate"); O = model.createLiteral(anchor + "object"); SPO = model.createStatement(S, P, O); SPO2 = model.createStatement(S2, P, O); }
/** * Example the conclusions graph for introduction of restrictions which require a comprehension * rewrite and declare new (anon) classes for those restrictions. */ public void comprehensionAxioms(Model premises, Model conclusions) { // Comprehend all restriction declarations and note them in a map Map<Resource, Resource> comprehension = new HashMap<>(); StmtIterator ri = conclusions.listStatements(null, RDF.type, OWL.Restriction); while (ri.hasNext()) { Resource restriction = ri.nextStatement().getSubject(); StmtIterator pi = restriction.listProperties(OWL.onProperty); while (pi.hasNext()) { Resource prop = (Resource) pi.nextStatement().getObject(); StmtIterator vi = restriction.listProperties(); while (vi.hasNext()) { Statement rs = vi.nextStatement(); if (!rs.getPredicate().equals(OWL.onProperty)) { // Have a restriction on(prop) of type rs in the conclusions // So assert a premise that such a restriction could exisit Resource comp = premises .createResource() .addProperty(RDF.type, OWL.Restriction) .addProperty(OWL.onProperty, prop) .addProperty(rs.getPredicate(), rs.getObject()); comprehension.put(restriction, comp); } } } } // Comprehend any intersectionOf lists. Introduce anon class which has the form // of the intersection expression. // Rewrite queries of the form (X intersectionOf Y) to the form // (X equivalentClass ?CC) (?CC intersectionOf Y) StmtIterator ii = conclusions.listStatements(null, OWL.intersectionOf, (RDFNode) null); List<Statement> intersections = new ArrayList<>(); while (ii.hasNext()) { intersections.add(ii.nextStatement()); } for (Statement is : intersections) { // Declare in the premises that such an intersection exists Resource comp = premises .createResource() .addProperty(RDF.type, OWL.Class) .addProperty( OWL.intersectionOf, mapList(premises, (Resource) is.getObject(), comprehension)); // Rewrite the conclusions to be a test for equivalence between the class being // queried and the comprehended interesection conclusions.remove(is); conclusions.add(is.getSubject(), OWL.equivalentClass, comp); } // Comprehend any oneOf lists StmtIterator io = conclusions.listStatements(null, OWL.oneOf, (RDFNode) null); while (io.hasNext()) { Statement s = io.nextStatement(); Resource comp = premises.createResource().addProperty(OWL.oneOf, s.getObject()); } }
public void testQuintetOfQuadlets() { Resource rs = model.createResource(); rs.addProperty(RDF.type, RDF.Statement); model.createResource().addProperty(RDF.value, rs); rs.addProperty(RDF.subject, model.createResource()); rs.addProperty(RDF.predicate, model.createProperty("http://example.org/foo")); rs.addProperty(RDF.object, model.createResource()); rs.addProperty(RDF.object, model.createResource()); StmtIterator it = model.listStatements(); while (it.hasNext()) { Statement s = it.nextStatement(); assertFalse(s.getObject().equals(s.getSubject())); } }
/** "dirty" reifications - those with conflicting quadlets - should fail. */ public void testDirtyReification() { Resource R = model.createResource(aURI); model.add(R, RDF.type, RDF.Statement); model.add(R, RDF.subject, S); model.add(R, RDF.subject, P); testDoesNotReify("boo", R); }
private void testNotReifying(Model m, String uri) { try { m.createResource(uri).as(ReifiedStatement.class); fail("there should be no reifiedStatement for " + uri); } catch (DoesNotReifyException e) { /* that's what we require */ } }
/** * check that, from a model with any combination of the statements given, we can convert R into a * ReifiedStatement iff the four components of the quad are in the model. */ public void testReificationCombinations() { Resource RR = model.createResource(aURI), SS = model.createResource(anotherURI); Property PP = (Property) RR.as(Property.class); Object[][] statements = { {model.createStatement(RR, RDF.type, RDF.Statement), new Integer(1)}, {model.createStatement(RR, RDF.subject, SS), new Integer(2)}, {model.createStatement(RR, RDF.predicate, PP), new Integer(4)}, {model.createStatement(RR, RDF.object, O), new Integer(8)}, {model.createStatement(SS, PP, O), new Integer(16)}, {model.createStatement(RR, PP, O), new Integer(32)}, {model.createStatement(SS, RDF.subject, SS), new Integer(64)}, {model.createStatement(SS, RDF.predicate, PP), new Integer(128)}, {model.createStatement(SS, RDF.object, O), new Integer(256)}, {model.createStatement(SS, RDF.type, RDF.Statement), new Integer(512)} }; if (model.getReificationStyle() != ModelFactory.Minimal) testCombinations(model, RR, 0, statements, statements.length); }
/** * the simplest case: if we assert all the components of a reification quad, we can get a * ReifiedStatement that represents the reified statement. */ public void testBasicReification() { if (model.getReificationStyle() != ModelFactory.Minimal) { Resource R = model.createResource(aURI); model.add(R, RDF.type, RDF.Statement); model.add(R, RDF.subject, S); model.add(R, RDF.predicate, P); model.add(R, RDF.object, O); RDFNode rs = R.as(ReifiedStatement.class); assertEquals("can recover statement", SPO, ((ReifiedStatement) rs).getStatement()); } }
public void testIsReified() { ReifiedStatement rs = model.createReifiedStatement(aURI, SPO); Resource BS = model.createResource(anchor + "BS"); Property BP = model.createProperty(anchor + "BP"); RDFNode BO = model.createProperty(anchor + "BO"); model.add(rs, P, O); assertTrue("st should be reified now", SPO.isReified()); assertTrue("m should have st reified now", model.isReified(SPO)); assertFalse( "this new statement should not be reified", model.createStatement(BS, BP, BO).isReified()); }
/** Initialize the result model. */ public void initResults() { testResults = ModelFactory.createDefaultModel(); jena2 = testResults.createResource(BASE_RESULTS_URI + "#jena2"); jena2.addProperty( RDFS.comment, testResults.createLiteral( "<a xmlns=\"http://www.w3.org/1999/xhtml\" href=\"http://jena.sourceforce.net/\">Jena2</a> includes a rule-based inference engine for RDF processing, " + "supporting both forward and backward chaining rules. Its OWL rule set is designed to provide sound " + "but not complete instance resasoning for that fragment of OWL/Full limited to the OWL/lite vocabulary. In" + "particular it does not support unionOf/complementOf.", true)); jena2.addProperty(RDFS.label, "Jena2"); testResults.setNsPrefix("results", OWLResults.NS); }
/** * Helper. Adds to the target model a translation of the given RDF list with each element replaced * according to the map. */ private Resource mapList(Model target, Resource list, Map<Resource, Resource> map) { if (list.equals(RDF.nil)) { return RDF.nil; } else { Resource head = (Resource) list.getRequiredProperty(RDF.first).getObject(); Resource rest = (Resource) list.getRequiredProperty(RDF.rest).getObject(); Resource mapElt = target.createResource(); Resource mapHead = map.get(head); if (mapHead == null) mapHead = head; mapElt.addProperty(RDF.first, mapHead); mapElt.addProperty(RDF.rest, mapList(target, rest, map)); return mapElt; } }
/** * Check that a predicate for which no shortnames are defined in name map still gets a term * binding in the metadata. */ @Test public void testTermBindingsCoverAllPredicates() throws URISyntaxException { Resource thisPage = ResourceFactory.createResource("elda:thisPage"); String pageNumber = "1"; Bindings cc = new Bindings(); URI reqURI = new URI(""); // EndpointDetails spec = new EndpointDetails() { @Override public boolean isListEndpoint() { return true; } @Override public boolean hasParameterBasedContentNegotiation() { return false; } }; EndpointMetadata em = new EndpointMetadata(spec, thisPage, pageNumber, cc, reqURI); // PrefixMapping pm = PrefixMapping.Factory.create().setNsPrefix("this", "http://example.com/root#"); Model toScan = ModelIOUtils.modelFromTurtle(":a <http://example.com/root#predicate> :b."); toScan.setNsPrefixes(pm); Resource predicate = toScan.createProperty("http://example.com/root#predicate"); Model meta = ModelFactory.createDefaultModel(); Resource exec = meta.createResource("fake:exec"); ShortnameService sns = new StandardShortnameService(); // APIEndpoint.Request r = new APIEndpoint.Request( new Controls(), reqURI, cc ); CompleteContext c = new CompleteContext(CompleteContext.Mode.PreferPrefixes, sns.asContext(), pm) .include(toScan); em.addTermBindings(toScan, meta, exec, c); @SuppressWarnings("unused") Map<String, String> termBindings = c.Do(); Resource tb = meta.listStatements(null, API.termBinding, Any).nextStatement().getResource(); assertTrue(meta.contains(tb, API.label, "this_predicate")); assertTrue(meta.contains(tb, API.property, predicate)); }
/** Run a single test of any sort, performing any appropriate logging and error reporting. */ public void runTest(Resource test) { System.out.println("Running " + test); boolean success = false; boolean fail = false; try { success = doRunTest(test); } catch (Exception e) { fail = true; System.out.print("\nException: " + e); e.printStackTrace(); } testCount++; if (success) { System.out.print((testCount % 40 == 0) ? ".\n" : "."); System.out.flush(); passCount++; } else { System.out.println("\nFAIL: " + test); } Resource resultType = null; if (fail) { resultType = OWLResults.FailingRun; } else { if (test.hasProperty(RDF.type, OWLTest.NegativeEntailmentTest) || test.hasProperty(RDF.type, OWLTest.ConsistencyTest)) { resultType = success ? OWLResults.PassingRun : OWLResults.FailingRun; } else { resultType = success ? OWLResults.PassingRun : OWLResults.IncompleteRun; } } // log to the rdf result format Resource result = testResults .createResource() .addProperty(RDF.type, OWLResults.TestRun) .addProperty(RDF.type, resultType) .addProperty(OWLResults.test, test) .addProperty(OWLResults.system, jena2); }
public void testThisWillBreak() { Resource R = model.createResource(aURI); SPO.createReifiedStatement(aURI); model.add(R, RDF.subject, R); }
private Resource createMetadata(final boolean isListEndpoint, Integer totalResults) throws URISyntaxException { Model objectModel = ModelFactory.createDefaultModel(); MergedModels mergedModels = new MergedModels(objectModel); // Model meta = mergedModels.getMetaModel(); // Resource thisMetaPage = meta.createResource("eh:/thisMetaPage"); Resource SEP = meta.createResource("eh:/sparqlEndpoint"); thisMetaPage.addProperty(API.sparqlEndpoint, SEP); Bindings bindings = new Bindings(); URI ru = new URI(thisMetaPage.getURI()); Resource uriForDefinition = objectModel.createResource(thisMetaPage.getURI()); boolean suppressIPTO = true; int page = 1, perPage = 10; boolean hasMorePages = true; Context context = new Context(); CompleteContext cc = new CompleteContext(Mode.PreferLocalnames, context, objectModel); // SetsMetadata setsMeta = new SetsMetadata() { @Override public void setMetadata(String type, Model meta) {} }; WantsMetadata wantsMeta = new WantsMetadata() { @Override public boolean wantsMetadata(String name) { return true; } }; // Map<String, View> views = new HashMap<String, View>(); Set<FormatNameAndType> formats = new HashSet<FormatNameAndType>(); // EndpointDetails details = new EndpointDetails() { @Override public boolean isListEndpoint() { return isListEndpoint; } @Override public boolean hasParameterBasedContentNegotiation() { return false; } }; // EndpointMetadata.addAllMetadata( mergedModels, ru, uriForDefinition, bindings, cc, suppressIPTO, thisMetaPage, page, perPage, totalResults, hasMorePages, CollectionUtils.list(objectModel.createResource("eh:/item/_1")), setsMeta, wantsMeta, "SELECT", "VIEW", new TestCaches.FakeSource("Nemos"), views, formats, details); return thisMetaPage; }
public void testConversion() { final String uri = "spoo:handle"; model.createReifiedStatement(uri, SPO); ReifiedStatement rs2 = (ReifiedStatement) model.createResource(uri).as(ReifiedStatement.class); assertEquals("recover statement", SPO, rs2.getStatement()); }
public void testDoesNotReifyUnknown() { testDoesNotReify("model should not reify rubbish", model.createResource("spoo:rubbish")); }
public void testDoesNotReifyElsewhere() { final String uri = "spoo:rubbish"; Model m2 = getModel(); model.createReifiedStatement(uri, SPO); testDoesNotReify("blue model should not reify rubbish", m2.createResource(uri)); }