This is an automated email from the ASF dual-hosted git repository.

andy pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/jena.git


The following commit(s) were added to refs/heads/main by this push:
     new e5760fcfd9 Tidy up comments and code in TDB
     new 76189bec3e Merge pull request #1962 from afs/comments-tidy
e5760fcfd9 is described below

commit e5760fcfd9ebdad15389a5bd0877885c15b01b56
Author: Andy Seaborne <[email protected]>
AuthorDate: Wed Jul 19 13:41:44 2023 +0100

    Tidy up comments and code in TDB
---
 .../java/org/apache/jena/tdb/solver/PatternMatchTDB1.java  |  7 ++++---
 .../src/main/java/org/apache/jena/tdb/solver/SolverRX.java | 11 +++++------
 .../java/org/apache/jena/tdb/solver/StageMatchTuple.java   |  9 +++++++--
 .../java/org/apache/jena/tdb2/solver/PatternMatchTDB2.java |  7 ++++---
 .../main/java/org/apache/jena/tdb2/solver/SolverRX.java    | 14 +++++++-------
 .../java/org/apache/jena/tdb2/solver/StageMatchTuple.java  |  9 +++++++--
 6 files changed, 34 insertions(+), 23 deletions(-)

diff --git 
a/jena-tdb1/src/main/java/org/apache/jena/tdb/solver/PatternMatchTDB1.java 
b/jena-tdb1/src/main/java/org/apache/jena/tdb/solver/PatternMatchTDB1.java
index bc3c2f1f59..07701b8953 100644
--- a/jena-tdb1/src/main/java/org/apache/jena/tdb/solver/PatternMatchTDB1.java
+++ b/jena-tdb1/src/main/java/org/apache/jena/tdb/solver/PatternMatchTDB1.java
@@ -60,9 +60,10 @@ public class PatternMatchTDB1 {
         return execute(ntt, graph.getGraphName(), pattern, input, filter, 
execCxt);
     }
 
-    /** Non-reordering execution of a quad pattern, given an iterator of 
bindings as input.
-     *  GraphNode is Node.ANY for execution over the union of named graphs.
-     *  GraphNode is null for execution over the real default graph.
+    /**
+     * Non-reordering execution of a quad pattern, given an iterator of 
bindings as input.
+     * GraphNode is Node.ANY for execution over the union of named graphs.
+     * GraphNode is null for execution over the real default graph.
      */
     public static QueryIterator execute(DatasetGraphTDB ds, Node graphNode, 
BasicPattern pattern,
                                         QueryIterator input, 
Predicate<Tuple<NodeId>> filter,
diff --git a/jena-tdb1/src/main/java/org/apache/jena/tdb/solver/SolverRX.java 
b/jena-tdb1/src/main/java/org/apache/jena/tdb/solver/SolverRX.java
index e84783ad23..a65de09bc2 100644
--- a/jena-tdb1/src/main/java/org/apache/jena/tdb/solver/SolverRX.java
+++ b/jena-tdb1/src/main/java/org/apache/jena/tdb/solver/SolverRX.java
@@ -53,18 +53,18 @@ public class SolverRX {
      */
     public static final boolean DATAPATH = true;
 
-    // Entry point from SolverLib.
+    /** Entry point from {@link PatternMatchTDB1} */
     /*package*/
     static Iterator<BindingNodeId> matchQuadPattern(Iterator<BindingNodeId> 
chain, Node graphNode, Triple tPattern,
                                                     NodeTupleTable 
nodeTupleTable, Tuple<Node> patternTuple,
                                                     boolean anyGraph, 
Predicate<Tuple<NodeId>> filter, ExecutionContext execCxt) {
         if ( DATAPATH ) {
             if ( ! tripleHasEmbTripleWithVars(tPattern) )
-                // No RDF-star <<>> with variables.
+                // No RDF-star <<>> with variables which are wildcards at this 
point.
                 return StageMatchTuple.access(nodeTupleTable, chain, 
patternTuple, filter, anyGraph, execCxt);
         }
 
-        // RDF-star <<>> with variables.
+        // RDF-star <<>> with wildcards.
         // This path should work regardless.
 
         boolean isTriple = (patternTuple.len() == 3);
@@ -102,11 +102,10 @@ public class SolverRX {
         return convFromBinding(matched, nodeTable);
     }
 
-    static Iterator<Quad> accessData(Tuple<Node> patternTuple, NodeTupleTable 
nodeTupleTable,
+    private static Iterator<Quad> accessData(Tuple<Node> patternTuple, 
NodeTupleTable nodeTupleTable,
                                      boolean anyGraph, 
Predicate<Tuple<NodeId>> filter,
                                      ExecutionContext execCxt) {
         NodeTable nodeTable = nodeTupleTable.getNodeTable();
-        Function<Tuple<NodeId>, Quad> asQuad = asQuad(nodeTable, 
nodeTupleTable.getTupleLen(), anyGraph);
         Tuple<NodeId> patternTupleId = TupleLib.tupleNodeIds(nodeTable, 
patternTuple);
         if ( patternTupleId.contains(NodeId.NodeDoesNotExist) )
             // Can not match.
@@ -124,7 +123,7 @@ public class SolverRX {
             iterMatches = Iter.distinctAdjacent(iterMatches);
         }
         // -- DRY/StageMatchTuple
-        //Iterator<Quad> qIter = TupleLib.convertToQuads(nodeTable, 
iterMatches) ;
+        Function<Tuple<NodeId>, Quad> asQuad = asQuad(nodeTable, 
nodeTupleTable.getTupleLen(), anyGraph);
         Iterator<Quad> qIter = Iter.map(iterMatches, asQuad);
         return qIter;
     }
diff --git 
a/jena-tdb1/src/main/java/org/apache/jena/tdb/solver/StageMatchTuple.java 
b/jena-tdb1/src/main/java/org/apache/jena/tdb/solver/StageMatchTuple.java
index 740451d0b8..91af9db0d1 100644
--- a/jena-tdb1/src/main/java/org/apache/jena/tdb/solver/StageMatchTuple.java
+++ b/jena-tdb1/src/main/java/org/apache/jena/tdb/solver/StageMatchTuple.java
@@ -36,9 +36,14 @@ import 
org.apache.jena.tdb.store.nodetupletable.NodeTupleTable;
 
 class StageMatchTuple {
 
-    /* Entry point */
+    /**
+     * Function to access the data storage.
+     * This code only matches patterns with
+     * concrete terms or wildcards, not wildcards within <<>> terms.
+     * Called from {@link SolverRx#matchQuadPattern}
+     */
     static Iterator<BindingNodeId> access(NodeTupleTable nodeTupleTable, 
Iterator<BindingNodeId> input, Tuple<Node> patternTuple,
-                                                 Predicate<Tuple<NodeId>> 
filter, boolean anyGraph, ExecutionContext execCxt) {
+                                          Predicate<Tuple<NodeId>> filter, 
boolean anyGraph, ExecutionContext execCxt) {
         return Iter.flatMap(input, bnid -> {
             return StageMatchTuple.access(nodeTupleTable, bnid, patternTuple, 
filter, anyGraph, execCxt);
         });
diff --git 
a/jena-tdb2/src/main/java/org/apache/jena/tdb2/solver/PatternMatchTDB2.java 
b/jena-tdb2/src/main/java/org/apache/jena/tdb2/solver/PatternMatchTDB2.java
index b5e0078316..a58524b068 100644
--- a/jena-tdb2/src/main/java/org/apache/jena/tdb2/solver/PatternMatchTDB2.java
+++ b/jena-tdb2/src/main/java/org/apache/jena/tdb2/solver/PatternMatchTDB2.java
@@ -60,9 +60,10 @@ public class PatternMatchTDB2 {
         return execute(ntt, graph.getGraphName(), pattern, input, filter, 
execCxt);
     }
 
-    /** Non-reordering execution of a quad pattern, given an iterator of 
bindings as input.
-     *  GraphNode is Node.ANY for execution over the union of named graphs.
-     *  GraphNode is null for execution over the real default graph.
+    /**
+     * Non-reordering execution of a quad pattern, given an iterator of 
bindings as input.
+     * GraphNode is Node.ANY for execution over the union of named graphs.
+     * GraphNode is null for execution over the real default graph.
      */
     public static QueryIterator execute(DatasetGraphTDB ds, Node graphNode, 
BasicPattern pattern,
                                         QueryIterator input, 
Predicate<Tuple<NodeId>> filter,
diff --git a/jena-tdb2/src/main/java/org/apache/jena/tdb2/solver/SolverRX.java 
b/jena-tdb2/src/main/java/org/apache/jena/tdb2/solver/SolverRX.java
index 7bb24cd27d..8f7b4636b8 100644
--- a/jena-tdb2/src/main/java/org/apache/jena/tdb2/solver/SolverRX.java
+++ b/jena-tdb2/src/main/java/org/apache/jena/tdb2/solver/SolverRX.java
@@ -53,18 +53,18 @@ public class SolverRX {
      */
     public static final boolean DATAPATH = true;
 
-    // Entry point from SolverLib.
+    /** Entry point from {@link PatternMatchTDB2} */
     /*package*/
     static Iterator<BindingNodeId> matchQuadPattern(Iterator<BindingNodeId> 
chain, Node graphNode, Triple tPattern,
                                                     NodeTupleTable 
nodeTupleTable, Tuple<Node> patternTuple,
                                                     boolean anyGraph, 
Predicate<Tuple<NodeId>> filter, ExecutionContext execCxt) {
         if ( DATAPATH ) {
             if ( ! tripleHasEmbTripleWithVars(tPattern) )
-                // No RDF-star <<>> with variables.
+                // No RDF-star <<>> with variables which are wildcards at this 
point.
                 return StageMatchTuple.access(nodeTupleTable, chain, 
patternTuple, filter, anyGraph, execCxt);
         }
 
-        // RDF-star <<>> with variables.
+        // RDF-star <<>> with wildcards.
         // This path should work regardless.
 
         boolean isTriple = (patternTuple.len() == 3);
@@ -102,17 +102,15 @@ public class SolverRX {
         return convFromBinding(matched, nodeTable);
     }
 
-    static Iterator<Quad> accessData(Tuple<Node> patternTuple, NodeTupleTable 
nodeTupleTable,
+    private static Iterator<Quad> accessData(Tuple<Node> patternTuple, 
NodeTupleTable nodeTupleTable,
                                      boolean anyGraph, 
Predicate<Tuple<NodeId>> filter,
                                      ExecutionContext execCxt) {
         NodeTable nodeTable = nodeTupleTable.getNodeTable();
-        Function<Tuple<NodeId>, Quad> asQuad = asQuad(nodeTable, 
nodeTupleTable.getTupleLen(), anyGraph);
         Tuple<NodeId> patternTupleId = TupleLib.tupleNodeIds(nodeTable, 
patternTuple);
         if ( patternTupleId.contains(NodeId.NodeDoesNotExist) )
             // Can not match.
             return Iter.nullIterator();
-
-        // -- DRY/StageMatchTuple ??
+        // -- DRY/StageMatchTuple
         Iterator<Tuple<NodeId>> iterMatches = 
nodeTupleTable.find(patternTupleId);
         // Add filter
         if ( filter != null )
@@ -124,6 +122,8 @@ public class SolverRX {
             iterMatches = Iter.distinctAdjacent(iterMatches);
         }
         // -- DRY/StageMatchTuple
+        // Reverse mapping function : NodeIds to Nodes.
+        Function<Tuple<NodeId>, Quad> asQuad = asQuad(nodeTable, 
nodeTupleTable.getTupleLen(), anyGraph);
         Iterator<Quad> qIter = Iter.map(iterMatches, asQuad);
         return qIter;
     }
diff --git 
a/jena-tdb2/src/main/java/org/apache/jena/tdb2/solver/StageMatchTuple.java 
b/jena-tdb2/src/main/java/org/apache/jena/tdb2/solver/StageMatchTuple.java
index c04c1f54e5..0be831369c 100644
--- a/jena-tdb2/src/main/java/org/apache/jena/tdb2/solver/StageMatchTuple.java
+++ b/jena-tdb2/src/main/java/org/apache/jena/tdb2/solver/StageMatchTuple.java
@@ -36,9 +36,14 @@ import 
org.apache.jena.tdb2.store.nodetupletable.NodeTupleTable;
 
 class StageMatchTuple {
 
-    /* Entry point */
+    /**
+     * Function to access the data storage.
+     * This code only matches patterns with
+     * concrete terms or wildcards, not wildcards within <<>> terms.
+     * Called from {@link SolverRx#matchQuadPattern}
+     */
     static Iterator<BindingNodeId> access(NodeTupleTable nodeTupleTable, 
Iterator<BindingNodeId> input, Tuple<Node> patternTuple,
-                                                 Predicate<Tuple<NodeId>> 
filter, boolean anyGraph, ExecutionContext execCxt) {
+                                          Predicate<Tuple<NodeId>> filter, 
boolean anyGraph, ExecutionContext execCxt) {
         return Iter.flatMap(input, bnid -> {
             return StageMatchTuple.access(nodeTupleTable, bnid, patternTuple, 
filter, anyGraph, execCxt);
         });

Reply via email to