You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by an...@apache.org on 2012/02/16 17:54:27 UTC

svn commit: r1245079 - in /incubator/jena/Scratch/AFS/Dev/trunk/src-dev/dev: PathMain.java RunAFS.java path/PathEngine.java path/PathEngine1.java path/PathEngineN.java path/PathEval2.java path/PathEvaluator.java

Author: andy
Date: Thu Feb 16 16:54:27 2012
New Revision: 1245079

URL: http://svn.apache.org/viewvc?rev=1245079&view=rev
Log: (empty)

Added:
    incubator/jena/Scratch/AFS/Dev/trunk/src-dev/dev/PathMain.java
Modified:
    incubator/jena/Scratch/AFS/Dev/trunk/src-dev/dev/RunAFS.java
    incubator/jena/Scratch/AFS/Dev/trunk/src-dev/dev/path/PathEngine.java
    incubator/jena/Scratch/AFS/Dev/trunk/src-dev/dev/path/PathEngine1.java
    incubator/jena/Scratch/AFS/Dev/trunk/src-dev/dev/path/PathEngineN.java
    incubator/jena/Scratch/AFS/Dev/trunk/src-dev/dev/path/PathEval2.java
    incubator/jena/Scratch/AFS/Dev/trunk/src-dev/dev/path/PathEvaluator.java

Added: incubator/jena/Scratch/AFS/Dev/trunk/src-dev/dev/PathMain.java
URL: http://svn.apache.org/viewvc/incubator/jena/Scratch/AFS/Dev/trunk/src-dev/dev/PathMain.java?rev=1245079&view=auto
==============================================================================
--- incubator/jena/Scratch/AFS/Dev/trunk/src-dev/dev/PathMain.java (added)
+++ incubator/jena/Scratch/AFS/Dev/trunk/src-dev/dev/PathMain.java Thu Feb 16 16:54:27 2012
@@ -0,0 +1,87 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package dev;
+
+import org.openjena.atlas.iterator.Iter ;
+import org.openjena.atlas.logging.Log ;
+
+import com.hp.hpl.jena.graph.Graph ;
+import com.hp.hpl.jena.graph.Node ;
+import com.hp.hpl.jena.rdf.model.Model ;
+import com.hp.hpl.jena.sparql.path.Path ;
+import com.hp.hpl.jena.sparql.path.PathEval ;
+import com.hp.hpl.jena.sparql.sse.SSE ;
+import com.hp.hpl.jena.sparql.sse.writers.WriterPath ;
+import com.hp.hpl.jena.sparql.util.Timer ;
+import com.hp.hpl.jena.util.FileManager ;
+
+import dev.path.PathEval2 ;
+
+public class PathMain
+{
+
+    public static void main(String[] args)
+    {
+        Log.setLoggingCmd();
+        
+        if ( args.length == 0 )
+        {
+            System.err.println("Usage: data [path]") ;
+            System.exit(0) ;
+        }
+        String data = args[0] ;
+        
+        Model m = FileManager.get().loadModel(data) ;
+        Graph graph = m.getGraph() ;
+
+        String pathStr = "(path* :P)" ;
+        
+        if ( args.length >= 2 )
+            pathStr  = args[1] ;
+        
+        System.out.printf("Path: %s  Data: %s\n", pathStr, data) ; 
+        String pathStrFull = "(prefix ((: <http://example.org/>)) "+pathStr+")" ;
+        
+        Path path = SSE.parsePath(pathStrFull) ;
+        System.out.println(WriterPath.asString(path)) ;
+        Node start = SSE.parseNode("<http://example.org/A0>") ;
+        
+        Timer timer = new Timer() ;
+        System.out.println("START") ;
+        
+        timer.startTimer() ;
+        long c0 = Iter.count(PathEval.eval(graph, start, path)) ;
+        long t0 = timer.endTimer() ;
+        System.out.printf("Time eval0 : %6.3fs (%d)\n", (t0/1000.0), c0) ;
+        
+        timer.startTimer() ;
+        long c1 = Iter.count(PathEval2.eval1(graph, start, path)) ;
+        long t1 = timer.endTimer() ;
+        System.out.printf("Time eval1 : %6.3fs (%d)\n",  (t1/1000.0), c1) ;
+        
+        timer.startTimer() ;
+        long c2 = Iter.count(PathEval2.eval(graph, start, path)) ;
+        long t2 = timer.endTimer() ;
+        
+        System.out.printf("Time evalN : %6.3fs (%d)\n",  (t2/1000.0), c2) ;
+        System.out.println("FINISH") ;
+    }
+
+}
+

Modified: incubator/jena/Scratch/AFS/Dev/trunk/src-dev/dev/RunAFS.java
URL: http://svn.apache.org/viewvc/incubator/jena/Scratch/AFS/Dev/trunk/src-dev/dev/RunAFS.java?rev=1245079&r1=1245078&r2=1245079&view=diff
==============================================================================
--- incubator/jena/Scratch/AFS/Dev/trunk/src-dev/dev/RunAFS.java (original)
+++ incubator/jena/Scratch/AFS/Dev/trunk/src-dev/dev/RunAFS.java Thu Feb 16 16:54:27 2012
@@ -35,6 +35,7 @@ import com.hp.hpl.jena.iri.Violation ;
 import com.hp.hpl.jena.iri.ViolationCodes ;
 import com.hp.hpl.jena.sparql.path.Path ;
 import com.hp.hpl.jena.sparql.path.PathEval ;
+import com.hp.hpl.jena.sparql.path.PathFactory ;
 import com.hp.hpl.jena.sparql.sse.SSE ;
 
 import dev.path.PathEval2 ;
@@ -146,8 +147,8 @@ public class RunAFS
     {
         boolean rc = true ;
         
-        List<Node> nodes1 = Iter.toList(PathEval2.eval1(graph, start, path)) ;
-        List<Node> nodes2 = Iter.toList(PathEval2.evalN(graph, start, path)) ;
+        List<Node> nodes1 = Iter.toList(PathEval2.eval(graph, start, PathFactory.pathDistinct(path))) ;
+        List<Node> nodes2 = Iter.toList(PathEval2.eval(graph, start, path)) ;
         List<Node> nodes3 = Iter.toList(PathEval.eval(graph, start, path)) ;
         List<Node> nodes4 = Iter.iter(nodes3).distinct().toList() ;
         

Modified: incubator/jena/Scratch/AFS/Dev/trunk/src-dev/dev/path/PathEngine.java
URL: http://svn.apache.org/viewvc/incubator/jena/Scratch/AFS/Dev/trunk/src-dev/dev/path/PathEngine.java?rev=1245079&r1=1245078&r2=1245079&view=diff
==============================================================================
--- incubator/jena/Scratch/AFS/Dev/trunk/src-dev/dev/path/PathEngine.java (original)
+++ incubator/jena/Scratch/AFS/Dev/trunk/src-dev/dev/path/PathEngine.java Thu Feb 16 16:54:27 2012
@@ -43,7 +43,7 @@ abstract class PathEngine {
     //    protected abstract void doOne(Path pathStep, Node node, Collection<Node> output) ;
     
     // --- Where we touch the graph
-    // Because it SP? or ?PO, no duplicates occur.
+    // Because it SP? or ?PO, no duplicates occur, so works for both strategies.
     protected final Iterator<Node> doOne(Graph graph, Node node, Node property, boolean forwardMode)
     {
         Iterator<Node> iter2 = null ;
@@ -61,7 +61,18 @@ abstract class PathEngine {
         return iter2 ;
     }
 
-        
+    protected final Iter<Node> eval(Graph graph, Path path, Node node, boolean forwardMode)
+    {
+        return PathEval2.eval(graph, node, path, forwardMode, this) ;
+    }
+    
+    protected final void eval(Graph graph, Path path, Node node, boolean forwardMode, Collection<Node> output)
+    {
+        PathEval2.eval(graph, node, path, forwardMode, this, output) ;
+    }
+    
+    protected abstract Collection<Node> collector() ;
+    
     protected abstract void doOneOrMore(Path pathStep, Node node, Collection<Node> output) ;
 
     protected abstract void doZeroOrMore(Path pathStep, Node node, Collection<Node> output) ;

Modified: incubator/jena/Scratch/AFS/Dev/trunk/src-dev/dev/path/PathEngine1.java
URL: http://svn.apache.org/viewvc/incubator/jena/Scratch/AFS/Dev/trunk/src-dev/dev/path/PathEngine1.java?rev=1245079&r1=1245078&r2=1245079&view=diff
==============================================================================
--- incubator/jena/Scratch/AFS/Dev/trunk/src-dev/dev/path/PathEngine1.java (original)
+++ incubator/jena/Scratch/AFS/Dev/trunk/src-dev/dev/path/PathEngine1.java Thu Feb 16 16:54:27 2012
@@ -21,6 +21,8 @@ package dev.path;
 //import java.util.ArrayList ;
 import java.util.* ;
 
+import org.openjena.atlas.iterator.Iter ;
+
 import com.hp.hpl.jena.graph.Graph ;
 import com.hp.hpl.jena.graph.Node ;
 import com.hp.hpl.jena.sparql.path.P_Mod ;
@@ -28,7 +30,7 @@ import com.hp.hpl.jena.sparql.path.P_Neg
 import com.hp.hpl.jena.sparql.path.Path ;
 
 /** Path evaluation visitor that provide distinct nodes visited, */ 
-class PathEngine1 extends PathEngine
+final class PathEngine1 extends PathEngine
 {
     private final Graph graph ;
     private final boolean forwardMode ;
@@ -40,7 +42,8 @@ class PathEngine1 extends PathEngine
     }
     
     // Choose the underlying impl - different choice for debugging.
-    private static Collection<Node> collector() { return new ArrayList<Node>()  ; }
+    @Override
+    protected Collection<Node> collector() { return new ArrayList<Node>()  ; }
     
     // Can use .addAll if collector is set-like.
     private static void fillUnique(Iterator<Node> nodes, Collection<Node> acc)
@@ -97,7 +100,7 @@ class PathEngine1 extends PathEngine
             return ;
             
         // One step.
-        Iterator<Node> iter = PathEval2.eval1(graph, node, pathStep, forwardMode) ;
+        Iterator<Node> iter = eval(graph, pathStep, node, forwardMode) ;
         for ( ; iter.hasNext() ; )
         {
             Node m = iter.next() ;
@@ -127,8 +130,8 @@ class PathEngine1 extends PathEngine
         {}
         if ( fixedLength == 1 )
         {
-            PathEval2.eval1$(graph, node, pathStep, forwardMode, visited) ;
-            for ( Node n : visited )
+            Iter<Node> iter = eval(graph, pathStep, node, forwardMode) ;
+            for ( Node n : iter )
             {
                 if ( !output.contains(n) )
                     output.add(n) ;
@@ -137,12 +140,9 @@ class PathEngine1 extends PathEngine
         }
         // TODO Incomplete
         // Loop, not recurse.
-        Iterator<Node> iter = PathEval2.eval1(graph, node, pathStep, forwardMode) ;
-        for ( ; iter.hasNext() ; )
-        {
-            Node n = iter.next() ;
+        Iter<Node> iter = eval(graph, pathStep, node, forwardMode) ;
+        for ( Node n : iter )
             doFixedLengthPath(pathStep, n, fixedLength-1, output) ;
-        }
         return ;
     }
     
@@ -162,7 +162,7 @@ class PathEngine1 extends PathEngine
         // Reuse "output"
         Collection<Node> visited = new LinkedList<Node>() ; // new HashSet<Node>() ;
         // Do one step without including.
-        Iterator<Node> iter1 = PathEval2.evalN(graph, node, path, forwardMode) ;
+        Iter<Node> iter1 = eval(graph, path, node, forwardMode) ;
         for ( ; iter1.hasNext() ; )
         {
             Node n1 = iter1.next();
@@ -171,7 +171,7 @@ class PathEngine1 extends PathEngine
         output.addAll(visited) ;
     }
 
-    private static void ALP1(Graph graph, boolean forwardMode, int stepCount, int maxStepCount, Node node, Path path, Collection<Node> visited)
+    private void ALP1(Graph graph, boolean forwardMode, int stepCount, int maxStepCount, Node node, Path path, Collection<Node> visited)
     {
         if ( false ) System.out.printf("ALP1 node=%s\n   visited=%s\n   output=%s\n", node, visited) ;
         if ( maxStepCount >=0 && stepCount > maxStepCount ) return ; 
@@ -180,7 +180,7 @@ class PathEngine1 extends PathEngine
         if ( ! visited.add(node) )
             return ;
 
-        Iterator<Node> iter1 = PathEval2.eval1(graph, node, path, forwardMode) ;
+        Iter<Node> iter1 = eval(graph, path, node, forwardMode) ;
         // For each step, add to results and recurse.
         for ( ; iter1.hasNext() ; )
         {
@@ -210,7 +210,7 @@ class PathEngine1 extends PathEngine
     @Override
     protected void doZeroOrOne(Path pathStep, Node node, Collection<Node> output)
     {
-        PathEval2.eval1$(graph, node, pathStep, forwardMode, output) ;
+        eval(graph, pathStep, node, forwardMode, output) ;
         if ( ! output.contains(node) )
             output.add(node) ;
     }
@@ -228,9 +228,9 @@ class PathEngine1 extends PathEngine
         // Must be duplicate supressing.
         Collection<Node> nodes = new HashSet<Node>() ;
         // Insert directly.
-        PathEval2.eval1$(graph, node, pathStepLeft, forwardMode, nodes) ;
+        eval(graph, pathStepLeft, node, forwardMode, nodes) ;
         // Need to reduce/check other side.
-        PathEval2.eval1$(graph, node, pathStepRight, forwardMode, nodes) ;
+        eval(graph, pathStepRight, node, forwardMode, nodes) ;
         output.addAll(nodes) ;
     }
 
@@ -238,11 +238,10 @@ class PathEngine1 extends PathEngine
     protected void doSeq(Path pathStepLeft, Path pathStepRight, Node node, Collection<Node> output)
     {
         Collection<Node> nodes = collector() ;
-        PathEval2.eval1$(graph, node, pathStepLeft, forwardMode, nodes) ;
+        eval(graph, pathStepLeft, node, forwardMode, nodes) ;
         Collection<Node> nodes2 = new HashSet<Node>() ;
         for ( Node n : nodes )
-            PathEval2.eval1$(graph, n, pathStepLeft, forwardMode, nodes2) ;
+            eval(graph, pathStepLeft, n, forwardMode, nodes2) ;
         output.addAll(nodes2) ;
     }
-
 }

Modified: incubator/jena/Scratch/AFS/Dev/trunk/src-dev/dev/path/PathEngineN.java
URL: http://svn.apache.org/viewvc/incubator/jena/Scratch/AFS/Dev/trunk/src-dev/dev/path/PathEngineN.java?rev=1245079&r1=1245078&r2=1245079&view=diff
==============================================================================
--- incubator/jena/Scratch/AFS/Dev/trunk/src-dev/dev/path/PathEngineN.java (original)
+++ incubator/jena/Scratch/AFS/Dev/trunk/src-dev/dev/path/PathEngineN.java Thu Feb 16 16:54:27 2012
@@ -18,11 +18,14 @@
 
 package dev.path;
 
+import java.util.ArrayList ;
 import java.util.Collection ;
 import java.util.HashSet ;
 import java.util.Iterator ;
 import java.util.Set ;
 
+import org.openjena.atlas.iterator.Iter ;
+
 import com.hp.hpl.jena.graph.Graph ;
 import com.hp.hpl.jena.graph.Node ;
 import com.hp.hpl.jena.sparql.path.P_FixedLength ;
@@ -35,9 +38,8 @@ import com.hp.hpl.jena.sparql.path.Path 
  *  This is the algorithm in the SPARQL 1.1 spec.  
  * 
  */
-class PathEngineN extends PathEngine
+final class PathEngineN extends PathEngine
 {
-
     private final Graph graph ;
     private final boolean forwardMode ;
 
@@ -48,6 +50,9 @@ class PathEngineN extends PathEngine
     }
     
     @Override
+    protected Collection<Node> collector()  { return new ArrayList<Node>() ; }
+
+    @Override
     protected void doNegatedPropertySet(P_NegPropSet pathNotOneOf, Node node, Collection<Node> output)
     {
         // X !(:a|:b|^:c|^:d) Y = { X !(:a|:b) Y } UNION { Y !(:c|:d) X }
@@ -67,9 +72,9 @@ class PathEngineN extends PathEngine
     protected void doAlt(Path pathStepLeft, Path pathStepRight, Node node, Collection<Node> output)
     {
         // Try both sizes, accumulate into output.
-        Iterator<Node> iter = PathEval2.evalN(graph, node, pathStepLeft, forwardMode) ;
+        Iterator<Node> iter = eval(graph, pathStepLeft, node, forwardMode) ;
         fill(iter, output) ;
-        iter = PathEval2.evalN(graph, node, pathStepRight, forwardMode) ;
+        iter = eval(graph, pathStepRight, node, forwardMode) ;
         fill(iter, output) ;
     }
 
@@ -80,9 +85,9 @@ class PathEngineN extends PathEngine
         Path part2 = forwardMode ? pathStepRight : pathStepLeft ;
 
         // Feed one side into the other
-        Iterator<Node> iter = PathEval2.evalN(graph, node, part1, forwardMode) ;
-        iter = PathEval2.evalN(graph, iter, part2, forwardMode) ;
-        fill(iter, output) ;
+        Iter<Node> iter = eval(graph, part1, node, forwardMode) ;
+        for ( Node n : iter )
+            eval(graph, part2, n, forwardMode, output) ;
     }
 
     @Override
@@ -128,13 +133,13 @@ class PathEngineN extends PathEngine
         // ****
 
         // One step.
-        Iterator<Node> iter = PathEval2.evalN(graph, node, p1, forwardMode) ;
+        Iterator<Node> iter = eval(graph, p1, node, forwardMode) ;
 
         // Moved on one step
         for ( ; iter.hasNext() ; )
         {
             Node n2 = iter.next() ;
-            Iterator<Node> iter2 = PathEval2.evalN(graph, n2, p2, forwardMode) ;
+            Iterator<Node> iter2 = eval(graph, p2, n2, forwardMode) ;
             fill(iter2, output) ;
         }
 
@@ -151,7 +156,7 @@ class PathEngineN extends PathEngine
         }
         // P_Mod(path, count, count)
         // One step.
-        Iterator<Node> iter = PathEval2.evalN(graph, node, pathStep, forwardMode) ;
+        Iterator<Node> iter = eval(graph, pathStep, node, forwardMode) ;
         // Build a path for all remaining steps.
         long count2 = dec(fixedLength) ;
         P_FixedLength nextPath = new P_FixedLength(pathStep, count2) ;
@@ -160,7 +165,7 @@ class PathEngineN extends PathEngine
         for ( ; iter.hasNext() ; )
         {
             Node n2 = iter.next() ;
-            Iterator<Node> iter2 = PathEval2.evalN(graph, n2, nextPath, forwardMode) ;
+            Iterator<Node> iter2 = eval(graph, nextPath, n2, forwardMode) ;
             fill(iter2, output) ;
         }
     }
@@ -174,7 +179,7 @@ class PathEngineN extends PathEngine
 
     private void doOne(Path path, Node node, Collection<Node> output)
     {
-        Iterator<Node> iter = PathEval2.evalN(graph, node, path, forwardMode) ;
+        Iterator<Node> iter = eval(graph, path, node, forwardMode) ;
         fill(iter, output) ;
     }
 
@@ -197,7 +202,7 @@ class PathEngineN extends PathEngine
     {
         Set<Node> visited = new HashSet<Node>() ;
         // Do one step without including.
-        Iterator<Node> iter1 = PathEval2.evalN(graph, node, path, forwardMode) ;
+        Iterator<Node> iter1 = eval(graph, path, node, forwardMode) ;
         for ( ; iter1.hasNext() ; )
         {
             Node n1 = iter1.next();
@@ -218,7 +223,7 @@ class PathEngineN extends PathEngine
 
         visited.add(node) ;
 
-        Iterator<Node> iter1 = PathEval2.evalN(graph, node, path, forwardMode) ;
+        Iterator<Node> iter1 = eval(graph, path, node, forwardMode) ;
         // For each step, add to results and recurse.
         for ( ; iter1.hasNext() ; )
         {

Modified: incubator/jena/Scratch/AFS/Dev/trunk/src-dev/dev/path/PathEval2.java
URL: http://svn.apache.org/viewvc/incubator/jena/Scratch/AFS/Dev/trunk/src-dev/dev/path/PathEval2.java?rev=1245079&r1=1245078&r2=1245079&view=diff
==============================================================================
--- incubator/jena/Scratch/AFS/Dev/trunk/src-dev/dev/path/PathEval2.java (original)
+++ incubator/jena/Scratch/AFS/Dev/trunk/src-dev/dev/path/PathEval2.java Thu Feb 16 16:54:27 2012
@@ -18,15 +18,19 @@
 
 package dev.path;
 
-import java.util.* ;
+import java.util.ArrayList ;
+import java.util.Collection ;
+import java.util.Iterator ;
 
-import org.openjena.atlas.logging.Log ;
+import org.openjena.atlas.iterator.Iter ;
 import org.slf4j.Logger ;
 import org.slf4j.LoggerFactory ;
 
 import com.hp.hpl.jena.graph.Graph ;
 import com.hp.hpl.jena.graph.Node ;
-import com.hp.hpl.jena.sparql.path.* ;
+import com.hp.hpl.jena.sparql.path.Path ;
+import com.hp.hpl.jena.sparql.path.PathEval ;
+import com.hp.hpl.jena.sparql.path.PathFactory ;
 
 public class PathEval2
 {
@@ -59,85 +63,114 @@ public class PathEval2
 //        return convertGraphNodeToRDFNode(model, iter) ;
 //    }
 
-    // **** N-ary
-    
-    /** Evaluate a path in the forward direction */ 
-    static public Iterator<Node> evalN(Graph graph, Node node, Path path)
-    { 
-        if ( node == null  )
-            Log.fatal(PathEval.class, "PathEval.eval applied to a null node") ;
-        if ( node.isVariable() )
-            Log.warn(PathEval.class, "PathEval.eval applied to a variable: "+node) ;
-        return evalN(graph, node, path, true) ;
-    }
-    
-    static Iterator<Node> evalN(Graph graph, Node node, Path path, boolean forward)
-    {
-        Collection<Node> acc = new ArrayList<Node>() ;
-        evalN$(graph, node, path, forward, acc);
-        return acc.iterator() ;
-    }
-    
-    static Iterator<Node> evalN(Graph graph, Iterator<Node> input, Path path, boolean forward) 
-    {
-        Collection<Node> acc = new ArrayList<Node>() ;
-        
-        for ( ; input.hasNext() ; )
-        {
-            Node node = input.next() ;
-            evalN$(graph, node, path, forward, acc) ;
-        }
-        return acc.iterator() ;
-    }
-    
-    // ---- Worker ??
-    static private void evalN$(Graph graph, Node node, Path p, boolean forward, Collection<Node> acc)
+    /** Evaluate a path */ 
+    static public Iterator<Node> eval(Graph graph, Node node, Path path)
     {
-        PathEvaluator evaluator = new PathEvaluator(graph, node, acc, forward, new PathEngineN(graph, forward)) ;
-        p.visit(evaluator) ;
+        return eval(graph, node, path, true, new PathEngineN(graph, true)) ;
     }
 
-    // **** 1-ary
-    
-    /** Evaluate a path in the forward direction */ 
+    /** Evaluate a path : unique results */ 
     static public Iterator<Node> eval1(Graph graph, Node node, Path path)
-    { 
-        if ( node == null  )
-            Log.fatal(PathEval.class, "PathEval.eval applied to a null node") ;
-        if ( node.isVariable() )
-            Log.warn(PathEval.class, "PathEval.eval applied to a variable: "+node) ;
-        return eval1(graph, node, path, true) ;
-    }
-    
-    static Iterator<Node> eval1(Graph graph, Node node, Path path, boolean forward)
     {
-        Collection<Node> acc = new ArrayList<Node>() ;
-        eval1$(graph, node, path, forward, acc);
-        return acc.iterator() ;
+        path = PathFactory.pathDistinct(path) ;
+        return eval(graph, node, path, true, new PathEngineN(graph, true)) ;
     }
-    
-    static private Iterator<Node> eval1(Graph graph, Iterator<Node> input, Path path, boolean forward) 
+
+    /** Evaluate a path */ 
+    static Iter<Node> eval(Graph graph, Node node, Path path, boolean forwardMode, PathEngine engine)
     {
         Collection<Node> acc = new ArrayList<Node>() ;
-        
-        for ( ; input.hasNext() ; )
-        {
-            Node node = input.next() ;
-            eval1$(graph, node, path, forward, acc) ;
-        }
-        return acc.iterator() ;
+        PathEvaluator evaluator = new PathEvaluator(graph, node, acc, forwardMode, engine) ;
+        path.visit(evaluator) ;
+        return Iter.iter(acc) ;
     }
     
-    // ---- Worker ??
-    static void eval1$(Graph graph, Node node, Path p, boolean forward, Collection<Node> acc)
+    /** Evaluate a path */ 
+    static void eval(Graph graph, Node node, Path path, boolean forwardMode, PathEngine engine, Collection<Node> acc)
     {
-        PathEvaluator evaluator = new PathEvaluator(graph, node, acc, forward, new PathEngine1(graph, forward)) ;
-        p.visit(evaluator) ;
+        PathEvaluator evaluator = new PathEvaluator(graph, node, acc, forwardMode, engine) ;
+        path.visit(evaluator) ;
     }
 
-    // TODO
-    // More common code:
-    //  abstract: doFixedlength, doZeroOrMore, doOneOrMore, doAlt
-    //  Generalized ALP (with count and end bound). 
+//    // **** N-ary
+//    
+//    /** Evaluate a path in the forward direction */ 
+//    static public Iterator<Node> evalN(Graph graph, Node node, Path path)
+//    { 
+//        if ( node == null  )
+//            Log.fatal(PathEval.class, "PathEval.eval applied to a null node") ;
+//        if ( node.isVariable() )
+//            Log.warn(PathEval.class, "PathEval.eval applied to a variable: "+node) ;
+//        return evalN(graph, node, path, true) ;
+//    }
+//    
+//    static Iterator<Node> evalN(Graph graph, Node node, Path path, boolean forward)
+//    {
+//        Collection<Node> acc = new ArrayList<Node>() ;
+//        evalN$(graph, node, path, forward, acc);
+//        return acc.iterator() ;
+//    }
+//    
+//    static Iterator<Node> evalN(Graph graph, Iterator<Node> input, Path path, boolean forward) 
+//    {
+//        Collection<Node> acc = new ArrayList<Node>() ;
+//        
+//        for ( ; input.hasNext() ; )
+//        {
+//            Node node = input.next() ;
+//            evalN$(graph, node, path, forward, acc) ;
+//        }
+//        return acc.iterator() ;
+//    }
+//    
+//    // ---- Worker ??
+//    static private void evalN$(Graph graph, Node node, Path p, boolean forward, Collection<Node> acc)
+//    {
+//        PathEvaluator evaluator = new PathEvaluator(graph, node, acc, forward, new PathEngineN(graph, forward)) ;
+//        p.visit(evaluator) ;
+//    }
+//
+//    // **** 1-ary
+//    
+//    /** Evaluate a path in the forward direction */ 
+//    static public Iterator<Node> eval1(Graph graph, Node node, Path path)
+//    { 
+//        if ( node == null  )
+//            Log.fatal(PathEval.class, "PathEval.eval applied to a null node") ;
+//        if ( node.isVariable() )
+//            Log.warn(PathEval.class, "PathEval.eval applied to a variable: "+node) ;
+//        return eval1(graph, node, path, true) ;
+//    }
+//    
+//    static Iterator<Node> eval1(Graph graph, Node node, Path path, boolean forward)
+//    {
+//        Collection<Node> acc = new ArrayList<Node>() ;
+//        eval1$(graph, node, path, forward, acc);
+//        return acc.iterator() ;
+//    }
+//    
+//    static private Iterator<Node> eval1(Graph graph, Iterator<Node> input, Path path, boolean forward) 
+//    {
+//        Collection<Node> acc = new ArrayList<Node>() ;
+//        
+//        for ( ; input.hasNext() ; )
+//        {
+//            Node node = input.next() ;
+//            eval1$(graph, node, path, forward, acc) ;
+//        }
+//        return acc.iterator() ;
+//    }
+//    
+//    // ---- Worker ??
+//    static void eval1$(Graph graph, Node node, Path p, boolean forward, Collection<Node> acc)
+//    {
+//        PathEvaluator evaluator = new PathEvaluator(graph, node, acc, forward, new PathEngine1(graph, forward)) ;
+//        p.visit(evaluator) ;
+//    }
+//
+//    // TODO
+//    // More common code:
+//    //  abstract: doFixedlength, doZeroOrMore, doOneOrMore, doAlt
+//    //  Generalized ALP (with count and end bound). 
 
 }

Modified: incubator/jena/Scratch/AFS/Dev/trunk/src-dev/dev/path/PathEvaluator.java
URL: http://svn.apache.org/viewvc/incubator/jena/Scratch/AFS/Dev/trunk/src-dev/dev/path/PathEvaluator.java?rev=1245079&r1=1245078&r2=1245079&view=diff
==============================================================================
--- incubator/jena/Scratch/AFS/Dev/trunk/src-dev/dev/path/PathEvaluator.java (original)
+++ incubator/jena/Scratch/AFS/Dev/trunk/src-dev/dev/path/PathEvaluator.java Thu Feb 16 16:54:27 2012
@@ -176,16 +176,19 @@ final class PathEvaluator implements Pat
     @Override
     public void visit(P_Distinct pathDistinct)
     {
-// TODO
-//        // CRUDE - No optimization.
-//        Iterator<Node> iter = PathEval2.evalN(graph, node, pathDistinct.getSubPath(), forwardMode) ;
-//        fill(Iter.distinct(iter), output) ; 
+        PathEngine engine2 = engine ;
+        engine = new PathEngine1(graph, forwardMode) ;
+        engine.eval(graph, pathDistinct.getSubPath(), node, forwardMode, output) ;
+        engine = engine2 ;
     }
 
     @Override
     public void visit(P_Multi pathMulti)
     {
-        // Flip.
+        PathEngine engine2 = engine ;
+        engine = new PathEngineN(graph, forwardMode) ;
+        engine.eval(graph, pathMulti.getSubPath(), node, forwardMode, output) ;
+        engine = engine2 ;
     }
 
     @Override
@@ -193,15 +196,10 @@ final class PathEvaluator implements Pat
     {
         engine.doSeq(pathSeq.getLeft(), pathSeq.getRight(), node, output) ;
     }
-
     
     // Other operations can produce duplicates and so may be executed in 
     // different ways depending on cardibnality requirements.  
     
-    
- 
-
-    
     protected static class FilterExclude implements Filter<Triple>
     {
         private Collection<Node> excludes ;