Search in sources :

Example 66 with Tuple

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

the class StoragePrefixesTDB method get.

@Override
public String get(Node graphNode, String prefix) {
    requireTxn();
    graphNode = canonicalGraphName(graphNode);
    Node p = NodeFactory.createLiteral(prefix);
    Iterator<Tuple<Node>> iter = prefixTable.find(graphNode, p, null);
    if (!iter.hasNext())
        return null;
    Node x = iter.next().get(2);
    Iter.close(iter);
    return x.getURI();
}
Also used : Node(org.apache.jena.graph.Node) Tuple(org.apache.jena.atlas.lib.tuple.Tuple)

Example 67 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 68 with Tuple

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

the class TestIsoMatcher method testGraphVar$.

private void testGraphVar$(String s1, String s2, boolean expected) {
    s1 = "(graph " + s1 + ")";
    s2 = "(graph " + s2 + ")";
    Graph g1 = SSE.parseGraph(s1);
    Graph g2 = SSE.parseGraph(s2);
    Collection<Tuple<Node>> x1 = IsoMatcher.tuplesTriples(g1.find());
    Collection<Tuple<Node>> x2 = IsoMatcher.tuplesTriples(g2.find());
    boolean b = IsoAlg.isIsomorphic(x1, x2, Iso.mappableBlankNodesVariables, NodeUtils.sameRdfTerm);
    if (b != expected) {
        System.out.println("====");
        SSE.write(g1);
        System.out.println("----");
        SSE.write(g2);
        System.out.println("Expected: " + expected + "; got: " + b);
    }
    assertEquals(expected, b);
}
Also used : DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) Graph(org.apache.jena.graph.Graph) Tuple(org.apache.jena.atlas.lib.tuple.Tuple)

Example 69 with Tuple

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

the class TestQuadFilter method createFilter.

/**
 * Create a filter to exclude the graph http://example/g2
 */
private static Predicate<Tuple<NodeId>> createFilter(Dataset dataset) {
    return Txn.calculateRead(dataset, () -> {
        DatasetGraphTDB dsg = TDBInternal.getDatasetGraphTDB(dataset);
        final NodeTable nodeTable = dsg.getQuadTable().getNodeTupleTable().getNodeTable();
        final NodeId target = nodeTable.getNodeIdForNode(NodeFactory.createURI(graphToHide));
        // Check g slot. Exclude graphToHide
        return item -> !(item.len() == 4 && item.get(0).equals(target));
    });
}
Also used : SystemTDB(org.apache.jena.tdb2.sys.SystemTDB) NodeFactory(org.apache.jena.graph.NodeFactory) org.apache.jena.query(org.apache.jena.query) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) Predicate(java.util.function.Predicate) TDBInternal(org.apache.jena.tdb2.sys.TDBInternal) TDB2Factory(org.apache.jena.tdb2.TDB2Factory) Test(org.junit.Test) TDB2(org.apache.jena.tdb2.TDB2) NodeTable(org.apache.jena.tdb2.store.nodetable.NodeTable) SSE(org.apache.jena.sparql.sse.SSE) Txn(org.apache.jena.system.Txn) Quad(org.apache.jena.sparql.core.Quad) Tuple(org.apache.jena.atlas.lib.tuple.Tuple) Assert.assertEquals(org.junit.Assert.assertEquals) NodeTable(org.apache.jena.tdb2.store.nodetable.NodeTable)

Example 70 with Tuple

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

the class TupleIndexRecord method findWorker.

private Iterator<Tuple<NodeId>> findWorker(Tuple<NodeId> patternNaturalOrder, boolean partialScanAllowed, boolean fullScanAllowed) {
    if (Check) {
        if (tupleLength != patternNaturalOrder.len())
            throw new TDBException(String.format("Mismatch: tuple length %d / index for length %d", patternNaturalOrder.len(), tupleLength));
    }
    // Convert to index order.
    Tuple<NodeId> pattern = tupleMap.map(patternNaturalOrder);
    // Canonical form.
    int numSlots = 0;
    // Index of last leading pattern NodeId.  Start less than numSlots-1
    int leadingIdx = -2;
    boolean leading = true;
    // Records.
    Record minRec = factory.createKeyOnly();
    Record maxRec = factory.createKeyOnly();
    // Set the prefixes.
    for (int i = 0; i < pattern.len(); i++) {
        NodeId X = pattern.get(i);
        if (NodeId.isAny(X)) {
            X = null;
            // No longer seting leading key slots.
            leading = false;
            continue;
        }
        // if ( NodeId.isDoesNotExist(X) )
        // return Iter.nullIterator();
        numSlots++;
        if (leading) {
            leadingIdx = i;
            NodeIdFactory.set(X, minRec.getKey(), i * SizeOfNodeId);
            NodeIdFactory.set(X, maxRec.getKey(), i * SizeOfNodeId);
        }
    }
    // Is it a simple existence test?
    if (numSlots == pattern.len()) {
        if (index.contains(minRec))
            return new SingletonIterator<>(pattern);
        else
            return new NullIterator<>();
    }
    if (true) {
        Iterator<Tuple<NodeId>> tuples;
        if (leadingIdx < 0) {
            if (!fullScanAllowed)
                return null;
            // Full scan necessary
            tuples = index.iterator(null, null, recordMapper);
        } else {
            // Adjust the maxRec.
            NodeId X = pattern.get(leadingIdx);
            // Set the max Record to the leading NodeIds, +1.
            // Example, SP? inclusive to S(P+1)? exclusive where ? is zero.
            NodeIdFactory.setNext(X, maxRec.getKey(), leadingIdx * SizeOfNodeId);
            tuples = index.iterator(minRec, maxRec, recordMapper);
        }
        if (leadingIdx < numSlots - 1) {
            if (!partialScanAllowed)
                return null;
            // Didn't match all defined slots in request.
            // Partial or full scan needed.
            // pattern.unmap(colMap);
            tuples = scan(tuples, patternNaturalOrder);
        }
        return tuples;
    }
    Iterator<Record> iter = null;
    if (leadingIdx < 0) {
        if (!fullScanAllowed)
            return null;
        // Full scan necessary
        iter = index.iterator();
    } else {
        // Adjust the maxRec.
        NodeId X = pattern.get(leadingIdx);
        // Set the max Record to the leading NodeIds, +1.
        // Example, SP? inclusive to S(P+1)? exclusive where ? is zero.
        NodeIdFactory.setNext(X, maxRec.getKey(), leadingIdx * SizeOfNodeId);
        iter = index.iterator(minRec, maxRec);
    }
    Iterator<Tuple<NodeId>> tuples = Iter.map(iter, item -> TupleLib.tuple(item, tupleMap));
    if (leadingIdx < numSlots - 1) {
        if (!partialScanAllowed)
            return null;
        // Didn't match all defined slots in request.
        // Partial or full scan needed.
        // pattern.unmap(colMap);
        tuples = scan(tuples, patternNaturalOrder);
    }
    return tuples;
}
Also used : TDBException(org.apache.jena.tdb2.TDBException) SizeOfNodeId(org.apache.jena.tdb2.sys.SystemTDB.SizeOfNodeId) NodeId(org.apache.jena.tdb2.store.NodeId) Record(org.apache.jena.dboe.base.record.Record) Tuple(org.apache.jena.atlas.lib.tuple.Tuple)

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