Search in sources :

Example 46 with Triple

use of org.apache.jena.graph.Triple in project jena by apache.

the class NodeTransformLib method transform.

/** Do a node->node conversion of a BGP - return original BGP for "no change" */
public static BasicPattern transform(NodeTransform nodeTransform, BasicPattern pattern) {
    BasicPattern bgp2 = new BasicPattern();
    boolean changed = false;
    for (Triple triple : pattern) {
        Triple t2 = transform(nodeTransform, triple);
        bgp2.add(t2);
        if (t2 != triple)
            changed = true;
    }
    if (!changed)
        return pattern;
    return bgp2;
}
Also used : Triple(org.apache.jena.graph.Triple)

Example 47 with Triple

use of org.apache.jena.graph.Triple in project jena by apache.

the class ElementTransformSubst method transform.

@Override
public Element transform(ElementTriplesBlock el) {
    ElementTriplesBlock etb = new ElementTriplesBlock();
    boolean changed = false;
    for (Triple t : el.getPattern()) {
        Triple t2 = transform(t);
        changed = changed || t != t2;
        etb.addTriple(t2);
    }
    if (changed)
        return etb;
    return el;
}
Also used : Triple(org.apache.jena.graph.Triple) ElementTriplesBlock(org.apache.jena.sparql.syntax.ElementTriplesBlock)

Example 48 with Triple

use of org.apache.jena.graph.Triple in project jena by apache.

the class FmtUtils method formatPattern.

public static void formatPattern(IndentedWriter out, BasicPattern pattern, SerializationContext sCxt) {
    StringBuilder buffer = new StringBuilder();
    boolean first = true;
    for (Triple triple : pattern) {
        if (!first)
            buffer.append("\n");
        stringForTriple(buffer, triple, sCxt);
        buffer.append(" .");
        out.print(buffer.toString());
        buffer.setLength(0);
        first = false;
    }
}
Also used : Triple(org.apache.jena.graph.Triple)

Example 49 with Triple

use of org.apache.jena.graph.Triple in project jena by apache.

the class IsoMatcher method tuplesTriples.

private static List<Tuple<Node>> tuplesTriples(Iterator<Triple> iter) {
    List<Tuple<Node>> tuples = new ArrayList<>();
    for (; iter.hasNext(); ) {
        Triple t = iter.next();
        Tuple<Node> tuple = tuple(t.getSubject(), t.getPredicate(), t.getObject());
        tuples.add(tuple);
    }
    return tuples;
}
Also used : Triple(org.apache.jena.graph.Triple) Node(org.apache.jena.graph.Node) ArrayList(java.util.ArrayList) Tuple(org.apache.jena.atlas.lib.tuple.Tuple)

Example 50 with Triple

use of org.apache.jena.graph.Triple in project jena by apache.

the class TestAPI method testARQConstructQuad_a_1.

//    // Execute a test both with and without regex optimization enabled
//    // Check the number of results
//    private void XexecRegexTest(int expected, String queryString)
//    {
//        Object b = ARQ.getContext().get(ARQ.enableRegexConstraintsOpt) ;
//        try {
//            ARQ.getContext().set(ARQ.enableRegexConstraintsOpt, "false") ;
//            int count1 = queryAndCount(queryString) ;
//            ARQ.getContext().set(ARQ.enableRegexConstraintsOpt, "true") ;
//            int count2 = queryAndCount(queryString) ;
//            assertEquals("Different number of results", count1, count2) ;
//            if ( expected >= 0 )
//                assertEquals("Unexpected number of results", expected, count1) ;
//        } finally {
//            ARQ.getContext().set(ARQ.enableRegexConstraintsOpt, b) ;
//        }
//    }
// ARQ Construct Quad Tests:
// Two types of query strings: a) construct triple string; b) construct quad string;
// Two kinds of query methods: 1) execTriples(); 2) execQuads();
// Test a)+1)
@Test
public void testARQConstructQuad_a_1() {
    String queryString = "CONSTRUCT { ?s ?p ?o } WHERE { GRAPH ?g { ?s ?p ?o } }";
    Query q = QueryFactory.create(queryString, Syntax.syntaxARQ);
    QueryExecution qExec = QueryExecutionFactory.create(q, d);
    Iterator<Triple> ts = qExec.execConstructTriples();
    Model result = ModelFactory.createDefaultModel();
    while (ts.hasNext()) {
        Triple t = ts.next();
        Statement stmt = ModelUtils.tripleToStatement(result, t);
        if (stmt != null)
            result.add(stmt);
    }
    assertEquals(3, result.size());
    assertTrue(m.isIsomorphicWith(result));
}
Also used : Triple(org.apache.jena.graph.Triple) Test(org.junit.Test) BaseTest(org.apache.jena.atlas.junit.BaseTest)

Aggregations

Triple (org.apache.jena.graph.Triple)407 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 Model (org.apache.jena.rdf.model.Model)13 TriplePattern (org.apache.jena.reasoner.TriplePattern)13 Op (org.apache.jena.sparql.algebra.Op)13 BasicPattern (org.apache.jena.sparql.core.BasicPattern)13 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 Resource (org.apache.jena.rdf.model.Resource)9