use of org.apache.jena.atlas.lib.tuple.Tuple in project jena by apache.
the class TestIsoMatcher method testTripleTerms.
private static void testTripleTerms(String term1, String term2, boolean expected) {
Node n1 = SSE.parseNode(term1);
Node n2 = SSE.parseNode(term2);
Collection<Tuple<Node>> x1 = Collections.singletonList(TupleFactory.create1(n1));
Collection<Tuple<Node>> x2 = Collections.singletonList(TupleFactory.create1(n2));
boolean b = IsoMatcher.isomorphic(x1, x2);
if (b != expected) {
System.out.println("====");
System.out.println(n1);
System.out.println("----");
System.out.println(n2);
System.out.println("Expected: " + expected + "; got: " + b);
}
assertEquals(expected, b);
}
use of org.apache.jena.atlas.lib.tuple.Tuple in project jena by apache.
the class tdbstats method stats.
public static StatsResults stats(DatasetGraphTDB dsg, Node gn) {
NodeTable nt = dsg.getTripleTable().getNodeTupleTable().getNodeTable();
StatsCollectorNodeId stats = new StatsCollectorNodeId(nt);
if (gn == null) {
Iterator<Tuple<NodeId>> iter = dsg.getTripleTable().getNodeTupleTable().findAll();
for (; iter.hasNext(); ) {
Tuple<NodeId> t = iter.next();
stats.record(null, t.get(0), t.get(1), t.get(2));
}
} else {
// If the union graph, then we need to scan all quads but with uniqueness.
boolean unionGraph = Quad.isUnionGraph(gn);
NodeId gnid = null;
if (!unionGraph) {
gnid = nt.getNodeIdForNode(gn);
if (NodeId.isDoesNotExist(gnid))
Log.warn(tdbstats.class, "No such graph: " + gn);
}
NodeTupleTable ntt = dsg.getQuadTable().getNodeTupleTable();
Iterator<Tuple<NodeId>> iter = unionGraph ? SolverLibTDB.unionGraph(ntt) : ntt.find(gnid, null, null, null);
for (; iter.hasNext(); ) {
Tuple<NodeId> t = iter.next();
stats.record(t.get(0), t.get(1), t.get(2), t.get(3));
}
}
return stats.results();
}
use of org.apache.jena.atlas.lib.tuple.Tuple in project jena by apache.
the class SolverLibTDB method graphNames.
/**
* Find all the graph names in the quads table.
*/
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));
// Project is cheap - don't brother wrapping iter1
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));
return new QueryIterAbortable(iterBinding, killList, input, execCxt);
}
use of org.apache.jena.atlas.lib.tuple.Tuple in project jena by apache.
the class SolverLibTDB method testForGraphName.
/**
* Find whether a specific graph name is in the quads table.
*/
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);
}
}
use of org.apache.jena.atlas.lib.tuple.Tuple in project jena by apache.
the class StageGeneratorDirectTDB method execute.
@Override
public QueryIterator execute(BasicPattern pattern, QueryIterator input, ExecutionContext execCxt) {
// --- In case this isn't for TDB2
Graph g = execCxt.getActiveGraph();
if (g instanceof GraphViewSwitchable) {
GraphViewSwitchable gvs = (GraphViewSwitchable) g;
g = gvs.getBaseGraph();
}
if (!(g instanceof GraphTDB))
// Not us - bounce up the StageGenerator chain
return above.execute(pattern, input, execCxt);
GraphTDB graph = (GraphTDB) g;
Predicate<Tuple<NodeId>> filter = QC2.getFilter(execCxt.getContext());
return PatternMatchTDB2.execute(graph, pattern, input, filter, execCxt);
}
Aggregations