Search in sources :

Example 56 with Quad

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

the class TestDatasetGraphInMemoryBasic method orderingOfNodesFromFindIsCorrect.

@Test
public void orderingOfNodesFromFindIsCorrect() {
    final DatasetGraph dsg = DatasetGraphFactory.createTxnMem();
    final Node p = parseNode(":p");
    final Triple triple = parseTriple("(:s :p :o)");
    dsg.getDefaultGraph().add(triple);
    final Iterator<Triple> iter = dsg.getDefaultGraph().find(null, p, null);
    assertTrue(some(iter, triple::equals));
    final Node p1 = parseNode(":p1");
    final Quad quad = parseQuad("(:g1 :s1 :p1 :o1)");
    dsg.add(quad);
    final Iterator<Quad> iter2 = dsg.find(null, null, p1, null);
    assertTrue(some(iter2, quad::equals));
    Iter.print(err, iter2);
}
Also used : Triple(org.apache.jena.graph.Triple) SSE.parseTriple(org.apache.jena.sparql.sse.SSE.parseTriple) SSE.parseQuad(org.apache.jena.sparql.sse.SSE.parseQuad) Quad(org.apache.jena.sparql.core.Quad) SSE.parseNode(org.apache.jena.sparql.sse.SSE.parseNode) NodeFactory.createBlankNode(org.apache.jena.graph.NodeFactory.createBlankNode) Node(org.apache.jena.graph.Node) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) Test(org.junit.Test)

Example 57 with Quad

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

the class TestHexTable method checkConcreteQueries.

@Test
public void checkConcreteQueries() {
    queryPatterns().filter(p -> !allWildcardQuery.equals(p)).map(TestHexTable::exampleFrom).forEach(testQuery -> {
        final HexTable index = new HexTable();
        index.begin(null);
        index.add(testTuple());
        final Node node = createBlankNode();
        final Quad noiseQuad = Quad.create(node, node, node, node);
        index.add(noiseQuad);
        index.commit();
        index.begin(null);
        Set<Quad> contents = index.find(testQuery.getGraph(), testQuery.getSubject(), testQuery.getPredicate(), testQuery.getObject()).collect(toSet());
        assertEquals(of(testTuple()), contents);
        contents = index.find(null, ANY, null, ANY).collect(toSet());
        assertEquals(of(testTuple(), noiseQuad), contents);
        index.end();
    });
}
Also used : Quad(org.apache.jena.sparql.core.Quad) Node(org.apache.jena.graph.Node) NodeFactory.createBlankNode(org.apache.jena.graph.NodeFactory.createBlankNode) Test(org.junit.Test)

Example 58 with Quad

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

the class AbstractDatasetGraphTests method quad_04.

@Test
public void quad_04() {
    DatasetGraph dsg = emptyDataset();
    assertNotNull(dsg);
    Quad quad1 = SSE.parseQuad("(quad <g> <s> <p> <o1>)");
    Quad quad2 = SSE.parseQuad("(quad <g> <s> <p> <o2>)");
    dsg.add(quad1);
    dsg.add(quad2);
    Iterator<Quad> iter = dsg.find(NodeFactory.createURI("g"), NodeFactory.createURI("s"), null, null);
    assertTrue(iter.hasNext());
    Set<Quad> x = Iter.iter(iter).toSet();
    assertEquals(2, x.size());
    assertTrue(x.contains(quad1));
    assertTrue(x.contains(quad2));
}
Also used : Quad(org.apache.jena.sparql.core.Quad) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) Test(org.junit.Test)

Example 59 with Quad

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

the class AbstractDatasetGraphFindPatterns method find_pattern_s.

@Test
public void find_pattern_s() {
    DatasetGraph dsg = create(dataPattern);
    List<Quad> quads1 = Iter.toList(dsg.find(null, node(":sx"), null, null));
    List<Quad> quads2 = Arrays.asList(q_s, q_gs, q_sp, q_so, q_gsp, q_gso, q_spo, q_gspo);
    BaseTest.assertEqualsUnordered("find(s)", quads1, quads2);
}
Also used : Quad(org.apache.jena.sparql.core.Quad) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) BaseTest(org.apache.jena.atlas.junit.BaseTest) Test(org.junit.Test)

Example 60 with Quad

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

the class AbstractDatasetGraphFindPatterns method find_pattern_p.

@Test
public void find_pattern_p() {
    DatasetGraph dsg = create(dataPattern);
    List<Quad> quads1 = Iter.toList(dsg.find(null, null, node(":px"), null));
    List<Quad> quads2 = Arrays.asList(q_p, q_gp, q_sp, q_po, q_gsp, q_gpo, q_spo, q_gspo);
    BaseTest.assertEqualsUnordered("find(p)", quads1, quads2);
}
Also used : Quad(org.apache.jena.sparql.core.Quad) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) BaseTest(org.apache.jena.atlas.junit.BaseTest) 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