@Override public NodeId getNodeIdForNode(Node node) { return nodeTable.getNodeIdForNode(node) ; }
@Override public NodeId getNodeIdForNode(Node node) { //info("getNodeIdForNode("+node+") =>") ; NodeId nId = nodeTable.getNodeIdForNode(node) ; info("getNodeIdForNode("+node+") => "+nId) ; return nId ; }
public NodeTupleTableView(NodeTupleTable ntt, Node prefix) { super(ntt) ; this.prefix = prefix ; this.prefixId = ntt.getNodeTable().getNodeIdForNode(prefix) ; }
protected final NodeId idForNode(Node node) { if (node == null || node == Node.ANY) return NodeId.NodeIdAny ; if (node.isVariable()) throw new TDBException("Can't pass variables to NodeTupleTable.find*") ; return nodeTable.getNodeIdForNode(node) ; }
public static Set<NodeId> convertToNodeIds(Collection<Node> nodes, DatasetGraphTDB dataset) { Set<NodeId> graphIds = new HashSet<>() ; NodeTable nt = dataset.getQuadTable().getNodeTupleTable().getNodeTable() ; for ( Node n : nodes ) graphIds.add(nt.getNodeIdForNode(n)) ; return graphIds ; }
public static Tuple<NodeId> tupleNodeIds(NodeTable nodeTable, Tuple<Node> nodes) { int N = nodes.len() ; NodeId[] n = new NodeId[N] ; for ( int i = 0 ; i < N ; i++ ) n[i] = nodeTable.getNodeIdForNode(nodes.get(i)) ; return TupleFactory.asTuple(n) ; }
/** Return null for variables, and for nodes, the node id or NodeDoesNotExist */ private static NodeId idFor(NodeTable nodeTable, BindingNodeId input, Node node) { if ( Var.isVar(node) ) { NodeId n = input.get((Var.alloc(node))) ; // Bound to NodeId or null. return n ; } // May return NodeId.NodeDoesNotExist which must not be null. return nodeTable.getNodeIdForNode(node) ; }
public static NodeId lookup(DatasetGraphTDB dsg, Node n) { NodeTable nt = dsg.getTripleTable().getNodeTupleTable().getNodeTable() ; NodeId nid = nt.getNodeIdForNode(n) ; return nid ; }
/** * Return the NodeId for a node. Returns NodeId.NodeDoesNotExist when the * node is not found. Returns null when not a TDB-backed dataset. */ public static NodeId getNodeId(DatasetGraphTDB dsg, Node node) { if ( dsg == null ) return null ; NodeTable nodeTable = dsg.getQuadTable().getNodeTupleTable().getNodeTable() ; NodeId nodeId = nodeTable.getNodeIdForNode(node) ; return nodeId ; }
/** Binding {@literal ->} BindingNodeId, given a NodeTable */ public static BindingNodeId convert(Binding binding, NodeTable nodeTable) { if ( binding instanceof BindingTDB ) return ((BindingTDB)binding).getBindingId() ; BindingNodeId b = new BindingNodeId(binding) ; // and copy over, getting NodeIds. Iterator<Var> vars = binding.vars() ; for ( ; vars.hasNext() ; ) { Var v = vars.next() ; Node n = binding.get(v) ; if ( n == null ) // Variable mentioned in the binding but not actually defined. // Can occur with BindingProject continue ; // Rely on the node table cache for efficency - we will likely be // repeatedly looking up the same node in different bindings. NodeId id = nodeTable.getNodeIdForNode(n) ; // Optional: whether to put in "known missing" // Currently, we do. The rest of the code should work with either choice. //if ( ! NodeId.isDoesNotExist(id) ) b.put(v, id) ; } return b ; }
/** * Create a graph filter for a TDB1 {@link DatasetGraph}. The filter matches (returns * true) for Tuples where the graph slot in quad is in the collection or for triples in the default * graph according the boolean. */ public static GraphFilterTDB1 graphFilter(DatasetGraph dsg, Collection<Node> namedGraphs, boolean matchDefaultGraph) { if ( ! TDBInternal.isTDB1(dsg) ) throw new IllegalArgumentException("DatasetGraph is not TDB1-backed"); List<NodeId> x = Txn.calculateRead(dsg, ()->{ NodeTable nt = TDBInternal.getDatasetGraphTDB(dsg).getQuadTable().getNodeTupleTable().getNodeTable(); return ListUtils.toList( namedGraphs.stream() .map(n->nt.getNodeIdForNode(n)) .filter(Objects::nonNull) ); }); return new GraphFilterTDB1(x, matchDefaultGraph); } }
private NodeId _idForNode(Node node, boolean allocate) { if ( node == Node.ANY ) return NodeId.NodeIdAny ; // Try once outside the synchronized // (Cache access is thread-safe.) NodeId nodeId = cacheLookup(node) ; if ( nodeId != null ) return nodeId ; synchronized (lock) { // Update two caches inside synchronized. // Check stil valid. nodeId = cacheLookup(node) ; if ( nodeId != null ) return nodeId ; if ( allocate ) nodeId = baseTable.getAllocateNodeId(node) ; else nodeId = baseTable.getNodeIdForNode(node) ; // Ensure caches have it. Includes recording "no such node" cacheUpdate(node, nodeId) ; return nodeId ; } }
@Test public void stats_03() { NodeId gid = nt.getNodeIdForNode(NodeFactory.createURI("g2")) ; StatsResults r = statsForGraph(gid) ; assertEquals(2, r.getCount()) ; assertEquals(1, r.getPredicates().keySet().size()) ; }
@Test public void stats_03() { NodeId gid = nt.getNodeIdForNode(NodeFactory.createURI("g2")) ; StatsResults r = statsForGraph(gid) ; assertEquals(2, r.getCount()) ; assertEquals(1, r.getPredicates().keySet().size()) ; }
@Test public void stats_02() { NodeId gid = nt.getNodeIdForNode(NodeFactory.createURI("g1")) ; StatsResults r = statsForGraph(gid) ; assertEquals(1, r.getCount()) ; assertEquals(1, r.getPredicates().keySet().size()) ; }
@Test public void stats_02() { NodeId gid = nt.getNodeIdForNode(NodeFactory.createURI("g1")) ; StatsResults r = statsForGraph(gid) ; assertEquals(1, r.getCount()) ; assertEquals(1, r.getPredicates().keySet().size()) ; }
protected static void writeNode(NodeTable nt, Node n) { NodeId nodeId = nt.getAllocateNodeId(n) ; assertNotNull(nodeId) ; assertNotEquals(NodeId.NodeDoesNotExist, nodeId) ; assertNotEquals(NodeId.NodeIdAny, nodeId) ; Node n2 = nt.getNodeForNodeId(nodeId) ; assertEquals(n, n2) ; NodeId nodeId2 = nt.getNodeIdForNode(n) ; assertEquals(nodeId, nodeId2) ; }
protected static void writeNode(NodeTable nt, Node n) { NodeId nodeId = nt.getAllocateNodeId(n) ; assertNotNull(nodeId) ; assertNotEquals(NodeId.NodeDoesNotExist, nodeId) ; assertNotEquals(NodeId.NodeIdAny, nodeId) ; Node n2 = nt.getNodeForNodeId(nodeId) ; assertEquals(n, n2) ; NodeId nodeId2 = nt.getNodeIdForNode(n) ; assertEquals(nodeId, nodeId2) ; }
/** Create a filter to exclude the graph http://example/g2 */ private static Predicate<Tuple<NodeId>> createFilter(Dataset ds) { DatasetGraphTDB dsg = (DatasetGraphTDB)(ds.asDatasetGraph()) ; final NodeTable nodeTable = dsg.getQuadTable().getNodeTupleTable().getNodeTable() ; final NodeId target = nodeTable.getNodeIdForNode(NodeFactory.createURI(graphToHide)) ; return item -> !( item.len() == 4 && item.get(0).equals(target) ); }
/** Create a filter to exclude the graph http://example/g2 */ private static Predicate<Tuple<NodeId>> createFilter(Dataset ds) { DatasetGraphTDB dsg = (DatasetGraphTDB)(ds.asDatasetGraph()) ; final NodeTable nodeTable = dsg.getQuadTable().getNodeTupleTable().getNodeTable() ; final NodeId target = nodeTable.getNodeIdForNode(NodeFactory.createURI(graphToHide)) ; return item -> !( item.len() == 4 && item.get(0).equals(target) ); }