Search in sources :

Example 36 with NodeTable

use of org.apache.jena.tdb2.store.nodetable.NodeTable in project jena by apache.

the class NodeTableOps method bulkNodeToNodeIdImpl.

/**
 * Convert a bulk operation into a loop
 */
public static List<NodeId> bulkNodeToNodeIdImpl(NodeTable nt, List<Node> nodes, boolean withAllocation) {
    List<NodeId> nodeIds = new ArrayList<>(nodes.size());
    for (Node node : nodes) {
        NodeId nid = withAllocation ? nt.getAllocateNodeId(node) : nt.getNodeIdForNode(node);
        nodeIds.add(nid);
    }
    return nodeIds;
}
Also used : Node(org.apache.jena.graph.Node) NodeId(org.apache.jena.tdb2.store.NodeId) ArrayList(java.util.ArrayList)

Example 37 with NodeTable

use of org.apache.jena.tdb2.store.nodetable.NodeTable 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 38 with NodeTable

use of org.apache.jena.tdb2.store.nodetable.NodeTable in project jena by apache.

the class NodeTableLib method printNodeTable.

/**
 * Print the main node table - development helper
 */
public static void printNodeTable(DatasetGraph dsg, long limit) {
    dsg.executeRead(() -> {
        DatasetGraphTDB dsgtdb = TDBInternal.getDatasetGraphTDB(dsg);
        NodeTable nodeTable = dsgtdb.getTripleTable().getNodeTupleTable().getNodeTable();
        int x = 0;
        for (var iter = nodeTable.all(); iter.hasNext(); ) {
            var pair = iter.next();
            x++;
            if (x > limit)
                return;
            NodeId nid = pair.getLeft();
            Node n = pair.getRight();
            System.out.printf("%s %s\n", nid, NodeFmtLib.strNT(n));
        }
        // long x = Iter.count(nodeTable.all());
        System.out.println("Node table length: " + x);
    });
}
Also used : Node(org.apache.jena.graph.Node) NodeId(org.apache.jena.tdb2.store.NodeId) NodeTable(org.apache.jena.tdb2.store.nodetable.NodeTable) DatasetGraphTDB(org.apache.jena.tdb2.store.DatasetGraphTDB)

Aggregations

NodeId (org.apache.jena.tdb2.store.NodeId)21 NodeTable (org.apache.jena.tdb2.store.nodetable.NodeTable)16 Node (org.apache.jena.graph.Node)14 Tuple (org.apache.jena.atlas.lib.tuple.Tuple)6 Quad (org.apache.jena.sparql.core.Quad)6 NodeTupleTable (org.apache.jena.tdb2.store.nodetupletable.NodeTupleTable)6 ArrayList (java.util.ArrayList)5 Triple (org.apache.jena.graph.Triple)5 NodeTableTRDF (org.apache.jena.tdb2.store.nodetable.NodeTableTRDF)5 Iterator (java.util.Iterator)3 Predicate (java.util.function.Predicate)3 RecordFactory (org.apache.jena.dboe.base.record.RecordFactory)3 Index (org.apache.jena.dboe.index.Index)3 RangeIndex (org.apache.jena.dboe.index.RangeIndex)3 Binding (org.apache.jena.sparql.engine.binding.Binding)3 TupleIndex (org.apache.jena.tdb2.store.tupletable.TupleIndex)3 Function (java.util.function.Function)2 Iter (org.apache.jena.atlas.iterator.Iter)2 InternalErrorException (org.apache.jena.atlas.lib.InternalErrorException)2 TupleFactory (org.apache.jena.atlas.lib.tuple.TupleFactory)2