Search in sources :

Example 76 with Quad

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

the class UpdateBuilderTest method testInsert_SPO.

@Test
public void testInsert_SPO() {
    UpdateBuilder builder = new UpdateBuilder();
    builder.addInsert(s, p, o);
    Update update = builder.build();
    assertTrue(update instanceof UpdateDataInsert);
    UpdateDataInsert udi = (UpdateDataInsert) update;
    List<Quad> quads = udi.getQuads();
    assertEquals(1, quads.size());
    Quad q = quads.get(0);
    assertEquals(Quad.defaultGraphNodeGenerated, q.getGraph());
    assertEquals(s, q.getSubject());
    assertEquals(p, q.getPredicate());
    assertEquals(o, q.getObject());
}
Also used : Quad(org.apache.jena.sparql.core.Quad) UpdateDataInsert(org.apache.jena.sparql.modify.request.UpdateDataInsert) UpdateBuilder(org.apache.jena.arq.querybuilder.UpdateBuilder) Update(org.apache.jena.update.Update) Test(org.junit.Test)

Example 77 with Quad

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

the class UpdateBuilderTest method testDelete_Quad.

@Test
public void testDelete_Quad() {
    UpdateBuilder builder = new UpdateBuilder();
    builder.addDelete(new Quad(g, s, p, o));
    Update update = builder.build();
    assertTrue(update instanceof UpdateDataDelete);
    UpdateDataDelete udd = (UpdateDataDelete) update;
    List<Quad> quads = udd.getQuads();
    assertEquals(1, quads.size());
    Quad q = quads.get(0);
    assertEquals(g, q.getGraph());
    assertEquals(s, q.getSubject());
    assertEquals(p, q.getPredicate());
    assertEquals(o, q.getObject());
}
Also used : Quad(org.apache.jena.sparql.core.Quad) UpdateDataDelete(org.apache.jena.sparql.modify.request.UpdateDataDelete) UpdateBuilder(org.apache.jena.arq.querybuilder.UpdateBuilder) Update(org.apache.jena.update.Update) Test(org.junit.Test)

Example 78 with Quad

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

the class UpdateBuilderTest method testDelete_NodeTriple.

@Test
public void testDelete_NodeTriple() {
    Triple t = new Triple(s, p, o);
    UpdateBuilder builder = new UpdateBuilder();
    builder.addDelete(g, t);
    Update update = builder.build();
    assertTrue(update instanceof UpdateDataDelete);
    UpdateDataDelete udd = (UpdateDataDelete) update;
    List<Quad> quads = udd.getQuads();
    assertEquals(1, quads.size());
    Quad q = quads.get(0);
    assertEquals(g, q.getGraph());
    assertEquals(s, q.getSubject());
    assertEquals(p, q.getPredicate());
    assertEquals(o, q.getObject());
}
Also used : Triple(org.apache.jena.graph.Triple) UpdateDataDelete(org.apache.jena.sparql.modify.request.UpdateDataDelete) Quad(org.apache.jena.sparql.core.Quad) UpdateBuilder(org.apache.jena.arq.querybuilder.UpdateBuilder) Update(org.apache.jena.update.Update) Test(org.junit.Test)

Example 79 with Quad

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

the class TestQuadFilter method setup.

/** Example setup - in-memory dataset with two graphs, one triple in each */
private static Dataset setup() {
    Dataset ds = TDBFactory.createDataset();
    DatasetGraphTDB dsg = (DatasetGraphTDB) (ds.asDatasetGraph());
    Quad q1 = SSE.parseQuad("(<http://example/g1> <http://example/s> <http://example/p> <http://example/o1>)");
    Quad q2 = SSE.parseQuad("(<http://example/g2> <http://example/s> <http://example/p> <http://example/o2>)");
    dsg.add(q1);
    dsg.add(q2);
    return ds;
}
Also used : Quad(org.apache.jena.sparql.core.Quad) DatasetGraphTDB(org.apache.jena.tdb.store.DatasetGraphTDB)

Example 80 with Quad

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

the class FmtTemplate method format.

@Override
public void format(Template template) {
    out.print("{");
    out.incIndent(INDENT);
    out.pad();
    List<Quad> quads = template.getQuads();
    for (Quad quad : quads) {
        BasicPattern bgp = new BasicPattern();
        bgp.add(quad.asTriple());
        out.newline();
        if (!Quad.defaultGraphNodeGenerated.equals(quad.getGraph())) {
            out.print("GRAPH");
            out.print(" ");
            out.print(slotToString(quad.getGraph()));
            out.print(" ");
            out.newline();
            out.incIndent(INDENT);
            out.pad();
            out.print("{");
            out.incIndent(INDENT);
            out.pad();
        }
        formatTriples(bgp);
        if (!Quad.defaultGraphNodeGenerated.equals(quad.getGraph())) {
            out.decIndent(INDENT);
            out.print("}");
            out.decIndent(INDENT);
        }
    }
    out.newline();
    out.decIndent(INDENT);
    out.print("}");
    out.newline();
}
Also used : Quad(org.apache.jena.sparql.core.Quad) 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