use of org.apache.jena.graph.Triple in project jena by apache.
the class TestReasoners method doTestMetaLevel.
/**
* Test metalevel add/remove subproperty operations for a reasoner.
*/
public void doTestMetaLevel(ReasonerFactory rf) {
Graph data = Factory.createGraphMem();
Node c1 = NodeFactory.createURI("C1");
Node c2 = NodeFactory.createURI("C2");
Node c3 = NodeFactory.createURI("C3");
Node p = NodeFactory.createURI("p");
Node q = NodeFactory.createURI("q");
Node sC = RDFS.subClassOf.asNode();
Node sP = RDFS.subPropertyOf.asNode();
data.add(new Triple(c2, sC, c3));
data.add(new Triple(c1, p, c2));
Reasoner reasoner = rf.create(null);
InfGraph infgraph = reasoner.bind(data);
TestUtil.assertIteratorValues(this, infgraph.find(c1, sC, null), new Object[] {});
infgraph.add(new Triple(p, q, sC));
TestUtil.assertIteratorValues(this, infgraph.find(c1, sC, null), new Object[] {});
infgraph.add(new Triple(q, sP, sP));
TestUtil.assertIteratorValues(this, infgraph.find(c1, sC, null), new Object[] { new Triple(c1, sC, c1), new Triple(c1, sC, c2), new Triple(c1, sC, c3) });
infgraph.delete(new Triple(p, q, sC));
TestUtil.assertIteratorValues(this, infgraph.find(c1, sC, null), new Object[] {});
}
use of org.apache.jena.graph.Triple in project jena by apache.
the class ReasonerTester method runTest.
/**
* Run a single designated test.
* @param uri the uri of the test, as defined in the manifest file
* @param reasoner the reasoner to be tested
* @param testcase the JUnit test case which is requesting this test
* @return true if the test passes
* @throws IOException if one of the test files can't be found
* @throws JenaException if the test can't be found or fails internally
*/
public boolean runTest(String uri, Reasoner reasoner, TestCase testcase) throws IOException {
// Find the specification for the named test
Resource test = testManifest.getResource(uri);
if (!test.hasProperty(RDF.type, testClass)) {
throw new JenaException("Can't find test: " + uri);
}
String description = test.getRequiredProperty(descriptionP).getObject().toString();
logger.debug("Reasoner test " + test.getURI() + " - " + description);
// Construct the inferred graph
Graph tbox = loadTestFile(test, tboxP);
Graph data = loadTestFile(test, dataP);
InfGraph graph = reasoner.bindSchema(tbox).bind(data);
// Run each query triple and accumulate the results
Graph queryG = loadTestFile(test, queryP);
Graph resultG = Factory.createGraphMem();
Iterator<Triple> queries = queryG.find(null, null, null);
while (queries.hasNext()) {
TriplePattern query = tripleToPattern(queries.next());
logger.debug("Query: " + query);
Iterator<Triple> answers = graph.find(query.asTripleMatch());
while (answers.hasNext()) {
Triple ans = answers.next();
logger.debug("ans: " + TriplePattern.simplePrintString(ans));
resultG.add(ans);
}
}
// Check the total result set against the correct answer
Graph correctG = loadTestFile(test, resultP);
boolean correct = correctG.isIsomorphicWith(resultG);
// ... end of debugging hack
if (testcase != null) {
Assert.assertTrue(description, correct);
}
return correct;
}
use of org.apache.jena.graph.Triple in project jena by apache.
the class Matcher method remap.
private static Triple remap(Map<Node, Node> bnodeMapping, Triple t, Allocator alloc) {
Node s = t.getSubject();
Node p = t.getPredicate();
Node o = t.getObject();
return new Triple(remap(bnodeMapping, s, alloc), remap(bnodeMapping, p, alloc), remap(bnodeMapping, o, alloc));
}
use of org.apache.jena.graph.Triple in project jena by apache.
the class TestTransitiveGraphCache method testEquivalencesSimple.
/**
* Test simple equivalences case
*/
public void testEquivalencesSimple() {
TransitiveGraphCache cache = new TransitiveGraphCache(directP, closedP);
cache.addRelation(new Triple(a, closedP, b));
cache.addRelation(new Triple(b, closedP, a));
TestUtil.assertIteratorValues(this, cache.find(new TriplePattern(null, closedP, null)), new Object[] { new Triple(a, closedP, b), new Triple(b, closedP, a), new Triple(b, closedP, b), new Triple(a, closedP, a) });
TestUtil.assertIteratorLength(cache.find(new TriplePattern(null, closedP, null)), 4);
}
use of org.apache.jena.graph.Triple in project jena by apache.
the class TestTransitiveGraphCache method testCycle.
/**
* Test cycle detection.
*/
public void testCycle() {
TransitiveGraphCache cache = new TransitiveGraphCache(directP, closedP);
cache.addRelation(new Triple(a, closedP, b));
cache.addRelation(new Triple(b, closedP, c));
cache.addRelation(new Triple(a, closedP, c));
cache.addRelation(new Triple(c, closedP, b));
TestUtil.assertIteratorValues(this, cache.find(new TriplePattern(a, directP, null)), new Object[] { new Triple(a, closedP, a), new Triple(a, closedP, b), new Triple(a, closedP, c) });
}
Aggregations