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/13 23:06:49 UTC

svn commit: r1243714 - in /incubator/jena/Scratch/AFS/Dev/trunk/src-dev/dev: PathEval2.java RunAFS.java

Author: andy
Date: Mon Feb 13 22:06:48 2012
New Revision: 1243714

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

Modified:
    incubator/jena/Scratch/AFS/Dev/trunk/src-dev/dev/PathEval2.java
    incubator/jena/Scratch/AFS/Dev/trunk/src-dev/dev/RunAFS.java

Modified: incubator/jena/Scratch/AFS/Dev/trunk/src-dev/dev/PathEval2.java
URL: http://svn.apache.org/viewvc/incubator/jena/Scratch/AFS/Dev/trunk/src-dev/dev/PathEval2.java?rev=1243714&r1=1243713&r2=1243714&view=diff
==============================================================================
--- incubator/jena/Scratch/AFS/Dev/trunk/src-dev/dev/PathEval2.java (original)
+++ incubator/jena/Scratch/AFS/Dev/trunk/src-dev/dev/PathEval2.java Mon Feb 13 22:06:48 2012
@@ -20,7 +20,6 @@ package dev;
 
 import java.util.* ;
 
-import org.openjena.atlas.io.IndentedWriter ;
 import org.openjena.atlas.iterator.Filter ;
 import org.openjena.atlas.iterator.Iter ;
 import org.openjena.atlas.iterator.Transform ;
@@ -141,6 +140,10 @@ public class PathEval2
         p.visit(evaluator) ;
     }
 
+    // TODO
+    // More common code:
+    //  abstract: doFixedlength, doZeroOrMore, doOneOrMore, doAlt
+    //  Generalized ALP (with count and end bound). 
     
     protected static abstract class PathEvaluatorBase implements PathVisitor
     {
@@ -333,13 +336,9 @@ public class PathEval2
             fill(iter) ;
         }
 
-        static boolean DEBUG = false ;
-        
         @Override
         public void visit(P_Mod pathMod)
         {
-            if ( DEBUG ) IndentedWriter.stdout.println("Eval: "+pathMod+" "+node+"("+(forwardMode?"fwd":"bkd")+")") ;
-            
             // :p{0,} Y is :p*
             // :p{n,} Y where n > 0  is :p{N}/:p*
             
@@ -349,11 +348,8 @@ public class PathEval2
             
             if ( pathMod.isZeroOrMore() )
             {
-                if ( DEBUG ) IndentedWriter.stdout.println("ZeroOrMore") ;
-                if ( DEBUG ) IndentedWriter.stdout.println("ZeroOrMore: "+output) ;
                 // :p{0,}
                 doZeroOrMore(pathMod.getSubPath()) ;
-                if ( DEBUG ) IndentedWriter.stdout.println("ZeroOrMore: "+output) ;
                 return ;
             }
 
@@ -401,31 +397,14 @@ public class PathEval2
             // One step.
             Iterator<Node> iter = evalN(graph, node, p1, forwardMode) ;
 
-            if ( DEBUG )
-            {
-                // Debug.
-                List<Node> x = Iter.toList(iter) ;
-                IndentedWriter.stdout.println("** One step: "+pathMod+" "+node+"("+(forwardMode?"fwd":"bkd")+") ==> "+x) ;
-                iter = x.iterator() ;
-            }
-            
             // Moved on one step
             for ( ; iter.hasNext() ; )
             {
                 Node n2 = iter.next() ;
-                if ( DEBUG ) IndentedWriter.stdout.incIndent(4) ;
                 Iterator<Node> iter2 = evalN(graph, n2, p2, forwardMode) ;
-                if ( DEBUG ) IndentedWriter.stdout.decIndent(4) ;
-                if ( DEBUG )
-                {
-                    List<Node> x = Iter.toList(iter2) ;
-                    IndentedWriter.stdout.println("** Recursive step: "+n2+" "+pathMod+" => "+x) ;
-                    iter2 = x.iterator() ;
-                }
                 fill(iter2) ;
             }
             
-            if ( DEBUG ) IndentedWriter.stdout.println("** Output: "+pathMod+" => "+output) ;
             // If no matches, will not call eval and we drop out.
         }
         
@@ -440,7 +419,7 @@ public class PathEval2
             // P_Mod(path, count, count)
             // One step.
             Iterator<Node> iter = evalN(graph, node, pFixedLength.getSubPath(), forwardMode) ;
-            // Build a path for all remainign steps.
+            // Build a path for all remaining steps.
             long count2 = dec(pFixedLength.getCount()) ;
             P_FixedLength nextPath = new P_FixedLength(pFixedLength.getSubPath(), count2) ;
             // For each element in the first step, do remaining step
@@ -523,15 +502,9 @@ public class PathEval2
                 iter1 = iter1.filter(new FilterExclude(excludeProperties)) ;
             return iter1 ;
         }
-
-
-        // NEW
-        
-        static final boolean trace = false ;
         
         private void doZeroOrMore(Path path)
         {
-            if ( trace ) System.out.printf("\nZeroOrMore: %s\n", node) ;
             //Deque<Node> visited = new ArrayDeque<Node>() ;
             Set<Node> visited = new HashSet<Node>() ;
             ALP(node, path, visited) ;
@@ -539,16 +512,12 @@ public class PathEval2
         
         private void doOneOrMore(Path path)
         {
-            if ( trace ) System.out.printf("\nOneOrMore: %s\n", node) ;
-            //Deque<Node> visited = new ArrayDeque<Node>() ;
-            
             Set<Node> visited = new HashSet<Node>() ;
             // Do one step without including.
             Iterator<Node> iter1 = evalN(graph, node, path, forwardMode) ;
             for ( ; iter1.hasNext() ; )
             {
                 Node n1 = iter1.next();
-                if ( trace ) System.out.printf("One from %s\n   visited=%s\n   output=%s\n", n1, visited, output) ;
                 ALP(n1, path, visited) ;
             }
         }
@@ -556,7 +525,6 @@ public class PathEval2
         // This is the worker function for path*
         private void ALP(Node node, Path path, Collection<Node> visited)
         {
-            if ( trace ) System.out.printf("ALP node=%s\n   visited=%s\n   output=%s\n", node, visited, output) ;
             if ( visited.contains(node) ) return ;
             
             // If output is a set, then no point going on if node has been added to the results.
@@ -666,7 +634,22 @@ public class PathEval2
 
         private void doFixedLength(Path subPath, Node node, long count, Collection<Node> output)
         {
-            throw new NotImplemented() ;
+            // One step.
+            Collection<Node> visitedOne = new ArrayList<Node>() ;
+            eval1$(graph, node, subPath, forwardMode, visitedOne) ;
+            if ( count == 1 )
+            {
+                // BAD
+                for ( Node n : visitedOne )
+                {
+                    if ( ! output.contains(n) )
+                        output.add(n) ;
+                }
+                return ;
+            }
+            
+            for ( Node n : visitedOne)
+                doFixedLength(subPath, n, count-1, output) ;
         }
 
         @Override

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=1243714&r1=1243713&r2=1243714&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 Mon Feb 13 22:06:48 2012
@@ -62,7 +62,8 @@ public class RunAFS
     {
         String prefix = "prefix ((: <http://example/>))" ;
         
-        String pathStr = "(mod 0 2 :q)" ;
+        //String pathStr = "(mod 0 2 :q)" ;
+        String pathStr = "(pathN 2 :q)" ;
         
         String qs = StrUtils.strjoinNL(
            "("+prefix,