Search in sources :

Example 76 with Triple

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[] {});
}
Also used : Triple(org.apache.jena.graph.Triple) InfGraph(org.apache.jena.reasoner.InfGraph) InfGraph(org.apache.jena.reasoner.InfGraph) Graph(org.apache.jena.graph.Graph) TransitiveReasoner(org.apache.jena.reasoner.transitiveReasoner.TransitiveReasoner) Reasoner(org.apache.jena.reasoner.Reasoner) RDFNode(org.apache.jena.rdf.model.RDFNode) Node(org.apache.jena.graph.Node)

Example 77 with Triple

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;
}
Also used : Triple(org.apache.jena.graph.Triple) JenaException(org.apache.jena.shared.JenaException) InfGraph(org.apache.jena.reasoner.InfGraph) InfGraph(org.apache.jena.reasoner.InfGraph) Graph(org.apache.jena.graph.Graph) TriplePattern(org.apache.jena.reasoner.TriplePattern)

Example 78 with Triple

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));
}
Also used : Triple(org.apache.jena.graph.Triple) Node(org.apache.jena.graph.Node)

Example 79 with Triple

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);
}
Also used : Triple(org.apache.jena.graph.Triple) TriplePattern(org.apache.jena.reasoner.TriplePattern) TransitiveGraphCache(org.apache.jena.reasoner.transitiveReasoner.TransitiveGraphCache)

Example 80 with Triple

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) });
}
Also used : Triple(org.apache.jena.graph.Triple) TriplePattern(org.apache.jena.reasoner.TriplePattern) TransitiveGraphCache(org.apache.jena.reasoner.transitiveReasoner.TransitiveGraphCache)

Aggregations

Triple (org.apache.jena.graph.Triple)406 Test (org.junit.Test)139 Node (org.apache.jena.graph.Node)95 BaseTest (org.apache.jena.atlas.junit.BaseTest)66 Graph (org.apache.jena.graph.Graph)54 Quad (org.apache.jena.sparql.core.Quad)25 TriplePath (org.apache.jena.sparql.core.TriplePath)22 ArrayList (java.util.ArrayList)20 StatsMatcher (org.apache.jena.sparql.engine.optimizer.StatsMatcher)19 Var (org.apache.jena.sparql.core.Var)17 TripleWritable (org.apache.jena.hadoop.rdf.types.TripleWritable)15 TriplePattern (org.apache.jena.reasoner.TriplePattern)13 Op (org.apache.jena.sparql.algebra.Op)13 BasicPattern (org.apache.jena.sparql.core.BasicPattern)13 Model (org.apache.jena.rdf.model.Model)12 TransitiveGraphCache (org.apache.jena.reasoner.transitiveReasoner.TransitiveGraphCache)11 LongWritable (org.apache.hadoop.io.LongWritable)10 InfGraph (org.apache.jena.reasoner.InfGraph)10 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)10 QuadWritable (org.apache.jena.hadoop.rdf.types.QuadWritable)8