Search in sources :

Example 66 with Quad

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

the class AbstractDatasetGraphTests method quad_02.

@Test
public void quad_02() {
    DatasetGraph dsg = emptyDataset();
    assertNotNull(dsg);
    Quad quad = SSE.parseQuad("(quad <g> <s> <p> <o>)");
    dsg.add(quad);
    dsg.containsGraph(NodeFactory.createURI("g"));
    dsg.delete(quad);
    assertTrue(dsg.isEmpty());
    assertTrue(dsg.getDefaultGraph().isEmpty());
    assertTrue(dsg.getGraph(NodeFactory.createURI("g")).isEmpty());
}
Also used : Quad(org.apache.jena.sparql.core.Quad) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) Test(org.junit.Test)

Example 67 with Quad

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

the class AbstractDatasetGraphTests method deleteAny_01.

@Test
public void deleteAny_01() {
    DatasetGraph dsg = emptyDataset();
    Node subject = NodeFactory.createURI("http://example/s");
    Node predicate = NodeFactory.createURI("http://example/p");
    Node object = NodeFactory.createBlankNode();
    dsg.add(new Quad(Quad.defaultGraphIRI, subject, predicate, object));
    dsg.deleteAny(Node.ANY, subject, null, null);
}
Also used : Quad(org.apache.jena.sparql.core.Quad) Node(org.apache.jena.graph.Node) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) Test(org.junit.Test)

Example 68 with Quad

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

the class AbstractDatasetGraphTests method graph_01.

// Graph centric operations
@Test
public void graph_01() {
    DatasetGraph dsg = emptyDataset();
    assertNotNull(dsg);
    Node g = NodeFactory.createURI("g");
    Triple t = SSE.parseTriple("(<s> <p> <o>)");
    dsg.getGraph(g).add(t);
    assertTrue(dsg.getGraph(g).contains(t));
    Quad quad = SSE.parseQuad("(quad <g> <s> <p> <o>)");
    Iterator<Quad> iter = dsg.find(null, null, null, null);
    assertTrue(iter.hasNext());
    Quad quad2 = iter.next();
    assertFalse(iter.hasNext());
    assertEquals(quad, quad2);
    assertTrue(dsg.getDefaultGraph().isEmpty());
    assertFalse(dsg.getGraph(NodeFactory.createURI("g")).isEmpty());
}
Also used : Triple(org.apache.jena.graph.Triple) Quad(org.apache.jena.sparql.core.Quad) Node(org.apache.jena.graph.Node) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) Test(org.junit.Test)

Example 69 with Quad

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

the class UpdateBuilderTest method testInsertAndDeleteWithVar.

@Test
public void testInsertAndDeleteWithVar() {
    UpdateBuilder builder = new UpdateBuilder();
    Var v = Var.alloc("v");
    builder.addInsert(new Quad(g, s, v, o));
    builder.addDelete(new Triple(s, v, o));
    builder.addWhere(null, v, "foo");
    builder.setVar(v, p);
    Update update = builder.build();
    assertTrue(update instanceof UpdateModify);
    UpdateModify um = (UpdateModify) update;
    List<Quad> quads = um.getInsertQuads();
    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());
    quads = um.getDeleteQuads();
    assertEquals(1, quads.size());
    q = quads.get(0);
    assertEquals(Quad.defaultGraphNodeGenerated, q.getGraph());
    assertEquals(s, q.getSubject());
    assertEquals(p, q.getPredicate());
    assertEquals(o, q.getObject());
    Element e = um.getWherePattern();
    assertTrue(e instanceof ElementGroup);
    ElementGroup eg = (ElementGroup) e;
    assertEquals(1, eg.getElements().size());
    ElementPathBlock epb = (ElementPathBlock) eg.getElements().get(0);
    Triple t = epb.getPattern().get(0).asTriple();
    assertEquals(Node.ANY, t.getSubject());
    assertEquals(p, t.getPredicate());
    assertEquals(builder.makeNode("foo"), t.getObject());
}
Also used : Triple(org.apache.jena.graph.Triple) Quad(org.apache.jena.sparql.core.Quad) UpdateModify(org.apache.jena.sparql.modify.request.UpdateModify) Var(org.apache.jena.sparql.core.Var) Element(org.apache.jena.sparql.syntax.Element) UpdateBuilder(org.apache.jena.arq.querybuilder.UpdateBuilder) Update(org.apache.jena.update.Update) ElementGroup(org.apache.jena.sparql.syntax.ElementGroup) ElementPathBlock(org.apache.jena.sparql.syntax.ElementPathBlock) Test(org.junit.Test)

Example 70 with Quad

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

the class UpdateBuilderTest method testDelete_Triple.

@Test
public void testDelete_Triple() {
    Triple t = new Triple(s, p, o);
    UpdateBuilder builder = new UpdateBuilder();
    builder.addDelete(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(Quad.defaultGraphNodeGenerated, 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)

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