Search in sources :

Example 1 with Tuple

use of org.apache.jena.atlas.lib.tuple.Tuple 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 2 with Tuple

use of org.apache.jena.atlas.lib.tuple.Tuple in project jena by apache.

the class TestIsoMatcher method tuples.

private List<Tuple<Node>> tuples(String[] strings) {
    List<Tuple<Node>> tuples = new ArrayList<>();
    for (String s : strings) {
        Item item = SSE.parse(s);
        List<Node> list = BuilderNode.buildNodeList(item);
        Tuple<Node> tuple = TupleFactory.tuple(list.toArray(T));
        tuples.add(tuple);
    }
    return tuples;
}
Also used : Item(org.apache.jena.sparql.sse.Item) BuilderNode(org.apache.jena.sparql.sse.builders.BuilderNode) Node(org.apache.jena.graph.Node) ArrayList(java.util.ArrayList) Tuple(org.apache.jena.atlas.lib.tuple.Tuple)

Example 3 with Tuple

use of org.apache.jena.atlas.lib.tuple.Tuple in project jena by apache.

the class SolverLib method graphNames.

/** Find all the graph names in the quads table. */
public static QueryIterator graphNames(DatasetGraphTDB ds, Node graphNode, QueryIterator input, Predicate<Tuple<NodeId>> filter, ExecutionContext execCxt) {
    List<Abortable> killList = new ArrayList<>();
    Iterator<Tuple<NodeId>> iter1 = ds.getQuadTable().getNodeTupleTable().find(NodeId.NodeIdAny, NodeId.NodeIdAny, NodeId.NodeIdAny, NodeId.NodeIdAny);
    if (filter != null)
        iter1 = Iter.filter(iter1, filter);
    Iterator<NodeId> iter2 = Iter.map(iter1, (t) -> t.get(0));
    iter2 = makeAbortable(iter2, killList);
    Iterator<NodeId> iter3 = Iter.distinct(iter2);
    iter3 = makeAbortable(iter3, killList);
    Iterator<Node> iter4 = NodeLib.nodes(ds.getQuadTable().getNodeTupleTable().getNodeTable(), iter3);
    final Var var = Var.alloc(graphNode);
    Iterator<Binding> iterBinding = Iter.map(iter4, node -> BindingFactory.binding(var, node));
    // Not abortable.
    return new QueryIterTDB(iterBinding, killList, input, execCxt);
}
Also used : Binding(org.apache.jena.sparql.engine.binding.Binding) Var(org.apache.jena.sparql.core.Var) Node(org.apache.jena.graph.Node) NodeId(org.apache.jena.tdb.store.NodeId) Tuple(org.apache.jena.atlas.lib.tuple.Tuple)

Example 4 with Tuple

use of org.apache.jena.atlas.lib.tuple.Tuple in project jena by apache.

the class SolverLib method testForGraphName.

/** Find whether a specific graph name is in the quads table. */
public static QueryIterator testForGraphName(DatasetGraphTDB ds, Node graphNode, QueryIterator input, Predicate<Tuple<NodeId>> filter, ExecutionContext execCxt) {
    NodeId nid = TDBInternal.getNodeId(ds, graphNode);
    boolean exists = !NodeId.isDoesNotExist(nid);
    if (exists) {
        // Node exists but is it used in the quad position?
        NodeTupleTable ntt = ds.getQuadTable().getNodeTupleTable();
        // Don't worry about abortable - this iterator should be fast
        // (with normal indexing - at least one G???).
        // Either it finds a starting point, or it doesn't.  We are only 
        // interested in the first .hasNext.
        Iterator<Tuple<NodeId>> iter1 = ntt.find(nid, NodeId.NodeIdAny, NodeId.NodeIdAny, NodeId.NodeIdAny);
        if (filter != null)
            iter1 = Iter.filter(iter1, filter);
        exists = iter1.hasNext();
    }
    if (exists)
        return input;
    else {
        input.close();
        return QueryIterNullIterator.create(execCxt);
    }
}
Also used : NodeTupleTable(org.apache.jena.tdb.store.nodetupletable.NodeTupleTable) NodeId(org.apache.jena.tdb.store.NodeId) Tuple(org.apache.jena.atlas.lib.tuple.Tuple)

Example 5 with Tuple

use of org.apache.jena.atlas.lib.tuple.Tuple in project jena by apache.

the class AbstractTestTupleIndex method TupleIndexRecordFindNot_2.

@Test
public void TupleIndexRecordFindNot_2() {
    TupleIndex index = createIndex("SPO");
    add(index, n1, n2, n3);
    Tuple<NodeId> tuple2 = TupleFactory.tuple(n1, n5, n6);
    Iterator<Tuple<NodeId>> iter = index.find(tuple2);
    assertFalse(iter.hasNext());
}
Also used : NodeId(org.apache.jena.tdb.store.NodeId) TupleIndex(org.apache.jena.tdb.store.tupletable.TupleIndex) Tuple(org.apache.jena.atlas.lib.tuple.Tuple) BaseTest(org.apache.jena.atlas.junit.BaseTest) Test(org.junit.Test)

Aggregations

Tuple (org.apache.jena.atlas.lib.tuple.Tuple)75 NodeId (org.apache.jena.tdb.store.NodeId)35 Node (org.apache.jena.graph.Node)22 TupleIndex (org.apache.jena.tdb.store.tupletable.TupleIndex)19 Test (org.junit.Test)19 BaseTest (org.apache.jena.atlas.junit.BaseTest)17 Quad (org.apache.jena.sparql.core.Quad)13 NodeId (org.apache.jena.tdb2.store.NodeId)10 Predicate (java.util.function.Predicate)8 Triple (org.apache.jena.graph.Triple)7 Iterator (java.util.Iterator)6 Binding (org.apache.jena.sparql.engine.binding.Binding)6 ArrayList (java.util.ArrayList)5 Iter (org.apache.jena.atlas.iterator.Iter)5 NodeTable (org.apache.jena.tdb.store.nodetable.NodeTable)5 NodeTupleTable (org.apache.jena.tdb.store.nodetupletable.NodeTupleTable)5 NodeTable (org.apache.jena.tdb2.store.nodetable.NodeTable)5 Function (java.util.function.Function)4 InternalErrorException (org.apache.jena.atlas.lib.InternalErrorException)4 TupleFactory (org.apache.jena.atlas.lib.tuple.TupleFactory)4