Search in sources :

Example 96 with Quad

use of org.apache.jena.sparql.core.Quad in project jena by apache.

the class TestParserFactory method trig_01.

@Test
public void trig_01() {
    String s = "{ <x> <p> <q> }";
    CatchParserOutput sink = parseCapture(s, Lang.TRIG);
    assertEquals(1, sink.startCalled);
    assertEquals(1, sink.finishCalled);
    assertEquals(0, sink.triples.size());
    assertEquals(1, sink.quads.size());
    Triple t = SSE.parseTriple("(<http://base/x> <http://base/p> <http://base/q>)");
    Quad q = new Quad(Quad.tripleInQuad, t);
    assertEquals(q, last(sink.quads));
}
Also used : Triple(org.apache.jena.graph.Triple) Quad(org.apache.jena.sparql.core.Quad) Test(org.junit.Test) BaseTest(org.apache.jena.atlas.junit.BaseTest)

Example 97 with Quad

use of org.apache.jena.sparql.core.Quad in project jena by apache.

the class TestAPI method testARQConstructQuad_a_2.

// Test a)+2): Quads constructed in the default graph
@Test
public void testARQConstructQuad_a_2() {
    String queryString = "CONSTRUCT { ?s ?p ?o } WHERE { ?s ?p ?o }";
    Query q = QueryFactory.create(queryString, Syntax.syntaxARQ);
    QueryExecution qExec = QueryExecutionFactory.create(q, d);
    Iterator<Quad> ts = qExec.execConstructQuads();
    DatasetGraph result = DatasetGraphFactory.create();
    long count = 0;
    while (ts.hasNext()) {
        count++;
        result.add(ts.next());
    }
    DatasetGraph expected = DatasetGraphFactory.create();
    expected.add(Quad.defaultGraphNodeGenerated, s.asNode(), p.asNode(), o.asNode());
    assertEquals(1, count);
    assertTrue(IsoMatcher.isomorphic(expected, result));
}
Also used : Quad(org.apache.jena.sparql.core.Quad) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) Test(org.junit.Test) BaseTest(org.apache.jena.atlas.junit.BaseTest)

Example 98 with Quad

use of org.apache.jena.sparql.core.Quad in project jena by apache.

the class TestAPI method testARQConstructQuad_b_2.

// Test b)+2)
@Test
public void testARQConstructQuad_b_2() {
    String queryString = "CONSTRUCT { GRAPH ?g1 {?s ?p ?o} } WHERE { ?s ?p ?o. GRAPH ?g1 {?s1 ?p1 'x1'} }";
    Query q = QueryFactory.create(queryString, Syntax.syntaxARQ);
    QueryExecution qExec = QueryExecutionFactory.create(q, d);
    Iterator<Quad> ts = qExec.execConstructQuads();
    DatasetGraph result = DatasetGraphFactory.create();
    long count = 0;
    while (ts.hasNext()) {
        count++;
        Quad qd = ts.next();
        result.add(qd);
    }
    DatasetGraph expected = DatasetGraphFactory.create();
    expected.add(g1.asNode(), s.asNode(), p.asNode(), o.asNode());
    assertEquals(1, count);
    assertTrue(IsoMatcher.isomorphic(expected, result));
}
Also used : Quad(org.apache.jena.sparql.core.Quad) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) Test(org.junit.Test) BaseTest(org.apache.jena.atlas.junit.BaseTest)

Example 99 with Quad

use of org.apache.jena.sparql.core.Quad in project jena by apache.

the class TriGBlankNodeOutputTests method generateTuples.

@Override
protected Iterator<QuadWritable> generateTuples(int num) {
    List<QuadWritable> qs = new ArrayList<QuadWritable>();
    Node subject = NodeFactory.createBlankNode();
    for (int i = 0; i < num; i++) {
        Quad t = new Quad(NodeFactory.createURI("http://example.org/graphs/" + i), subject, NodeFactory.createURI("http://example.org/predicate"), NodeFactory.createLiteral(Integer.toString(i), XSDDatatype.XSDinteger));
        qs.add(new QuadWritable(t));
    }
    return qs.iterator();
}
Also used : Quad(org.apache.jena.sparql.core.Quad) QuadWritable(org.apache.jena.hadoop.rdf.types.QuadWritable) Node(org.apache.jena.graph.Node) ArrayList(java.util.ArrayList)

Example 100 with Quad

use of org.apache.jena.sparql.core.Quad in project jena by apache.

the class Template method getGraphPattern.

public Map<Node, BasicPattern> getGraphPattern() {
    List<Quad> quads = getQuads();
    HashMap<Node, BasicPattern> graphs = new HashMap<>();
    for (Quad q : quads) {
        BasicPattern bgp = graphs.get(q.getGraph());
        if (bgp == null) {
            bgp = new BasicPattern();
            graphs.put(q.getGraph(), bgp);
        }
        bgp.add(q.asTriple());
    }
    return graphs;
}
Also used : Quad(org.apache.jena.sparql.core.Quad) HashMap(java.util.HashMap) Node(org.apache.jena.graph.Node) BasicPattern(org.apache.jena.sparql.core.BasicPattern)

Aggregations

Quad (org.apache.jena.sparql.core.Quad)161 Test (org.junit.Test)91 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)49 Node (org.apache.jena.graph.Node)36 BaseTest (org.apache.jena.atlas.junit.BaseTest)32 Triple (org.apache.jena.graph.Triple)25 UpdateBuilder (org.apache.jena.arq.querybuilder.UpdateBuilder)14 Update (org.apache.jena.update.Update)14 QuadWritable (org.apache.jena.hadoop.rdf.types.QuadWritable)12 ResultSet (java.sql.ResultSet)8 ArrayList (java.util.ArrayList)8 TripleWritable (org.apache.jena.hadoop.rdf.types.TripleWritable)7 Var (org.apache.jena.sparql.core.Var)7 LongWritable (org.apache.hadoop.io.LongWritable)6 UpdateDataDelete (org.apache.jena.sparql.modify.request.UpdateDataDelete)6 UpdateDataInsert (org.apache.jena.sparql.modify.request.UpdateDataInsert)6 Element (org.apache.jena.sparql.syntax.Element)6 Graph (org.apache.jena.graph.Graph)5 BasicPattern (org.apache.jena.sparql.core.BasicPattern)4 IOException (java.io.IOException)3