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/15 20:41:47 UTC

svn commit: r1244673 - in /incubator/jena/Scratch/AFS/Dev/trunk: src-dev/dev/RunAFS.java src-dev/dev/path/PathEngine.java src-dev/dev/path/PathEngine1.java src-dev/dev/path/PathEngineN.java src/main/java/riot/reader/WebReader2.java

Author: andy
Date: Wed Feb 15 19:41:46 2012
New Revision: 1244673

URL: http://svn.apache.org/viewvc?rev=1244673&view=rev
Log:
DISTINCT(path) evaluator.

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/main/java/riot/reader/WebReader2.java

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=1244673&r1=1244672&r2=1244673&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 Wed Feb 15 19:41:46 2012
@@ -88,27 +88,32 @@ public class RunAFS
         
         String[] paths = 
         {
-            "(alt :p :q)"
-            , "(alt :q :r)"
-
-            , "(seq :p :p)"
-            , "(seq :q :q)"
-
-            //, "(path? :p)"
-            //, "(notoneof :p)"
-            
-            , "(path* :p)"
-            , "(path+ :p)"
-
+            "(link :p)"
+//            , "(alt :q :r)"
+//
+//            , "(seq :p :p)"
+//            , "(seq :q :q)"
+
+//            , "(path? :p)"
+//            , "(path? :X)"
+            , "(notoneof :p)"
+            , "(notoneof :Z)"
+            , "(notoneof (rev :p))" // Test on difefrent node.
+            , "(notoneof (rev :Z))"
+            , "(notoneof :q (rev :p))" // Test on difefrent node.
+            , "(notoneof :q (rev :Z))"
             
-//            "(mod 0 2 :q)" 
+//            , "(path* :p)"
+//            , "(path+ :p)"
+//
+//            
+//            , "(mod 0 2 :q)" 
 //            , "(mod 0 1 :q)" 
 //            , "(mod 0 1 :r)" 
 //            , "(mod 0 3 :r)" 
 //            , "(mod 0 99 :r)" 
-
-            
-//              "(path+ :r)" 
+//
+//            ,  "(path+ :r)" 
 //            , "(mod 0 2 :q)" 
 //            , "(pathN 2 :p)"
 //            , "(pathN 2 :q)"
@@ -126,8 +131,8 @@ public class RunAFS
             System.out.println(pathStr) ;
             String ps = "("+prefix+" "+pathStr+")" ;
             Path path = SSE.parsePath(ps) ;
-            pathTest(g, x, path) ;
-            System.out.println() ;
+            if ( ! pathTest(g, x, path) ) 
+                System.out.println() ;
         }
         
         
@@ -137,8 +142,10 @@ public class RunAFS
         
     }
     
-    static void pathTest(Graph graph, Node start, Path path)
+    static boolean pathTest(Graph graph, Node start, Path path)
     {
+        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> nodes3 = Iter.toList(PathEval.eval(graph, start, path)) ;
@@ -156,6 +163,7 @@ public class RunAFS
             print(count1) ;
             System.out.printf("eval  (%d)\n", count3.size()) ;
             print(count4) ;
+            rc = false ;
         }
         
         if ( ! equal(count1, count4) )
@@ -165,7 +173,7 @@ public class RunAFS
             print(count1) ;
             System.out.printf("eval  (%d)\n", count4.size()) ;
             print(count4) ;
-
+            rc = false ;
         }
         
         // tests.
@@ -182,6 +190,8 @@ public class RunAFS
             //System.out.println(equal(count3, count3)) ;
             print(count3) ;
         }
+        
+        return rc ;
     }
     
     private static Map<Node, Integer> count(List<Node> nodes)

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=1244673&r1=1244672&r2=1244673&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 Wed Feb 15 19:41:46 2012
@@ -20,6 +20,7 @@ package dev.path;
 
 import java.util.Collection ;
 import java.util.Iterator ;
+import java.util.List ;
 
 import org.openjena.atlas.iterator.Iter ;
 import org.openjena.atlas.iterator.Transform ;
@@ -30,6 +31,8 @@ import com.hp.hpl.jena.graph.Triple ;
 import com.hp.hpl.jena.sparql.path.P_NegPropSet ;
 import com.hp.hpl.jena.sparql.path.Path ;
 
+import dev.path.PathEvaluator.FilterExclude ;
+
 abstract class PathEngine {
 
    protected abstract void doNegatedPropertySet(P_NegPropSet pathNotOneOf, Node node, Collection<Node> output) ;
@@ -84,27 +87,57 @@ abstract class PathEngine {
     protected static long dec(long x) { return (x<=0) ? x : x-1 ; }
     
     protected static Transform<Triple, Node> selectSubject   = new Transform<Triple, Node>() {
-                                                                 @Override
-                                                                 public Node convert(Triple triple)
-                                                                 {
-                                                                     return triple.getSubject() ;
-                                                                 }
-                                                             } ;
+        @Override
+        public Node convert(Triple triple)
+        {
+            return triple.getSubject() ;
+        }
+    } ;
     protected static Transform<Triple, Node> selectPredicate = new Transform<Triple, Node>() {
-                                                                 @Override
-                                                                 public Node convert(Triple triple)
-                                                                 {
-                                                                     return triple.getPredicate() ;
-                                                                 }
-                                                             } ;
+        @Override
+        public Node convert(Triple triple)
+        {
+            return triple.getPredicate() ;
+        }
+    } ;
     protected static Transform<Triple, Node> selectObject    = new Transform<Triple, Node>() {
-                                                                 @Override
-                                                                 public Node convert(Triple triple)
-                                                                 {
-                                                                     return triple.getObject() ;
-                                                                 }
-                                                             } ;
+        @Override
+        public Node convert(Triple triple)
+        {
+            return triple.getObject() ;
+        }
+    } ;
+
 
+    protected static Iterator<Node> stepExcludeForwards(Graph graph , Node node , List<Node> excludedNodes )
+    {
+        Iter<Triple> iter1 = forwardLinks(graph, node, excludedNodes) ;
+        Iter<Node> r1 = iter1.map(selectObject) ;
+        return r1 ;
+    }
+
+    protected static Iterator<Node> stepExcludeBackwards(Graph graph , Node node , List<Node> excludedNodes )
+    {
+        Iter<Triple> iter1 = backwardLinks(graph, node, excludedNodes) ;
+        Iter<Node> r1 = iter1.map(selectSubject) ;
+        return r1 ;
+    }
+
+    protected static  Iter<Triple> forwardLinks(Graph graph, Node x, Collection<Node> excludeProperties)
+    {
+        Iter<Triple> iter1 = Iter.iter(graph.find(x, Node.ANY, Node.ANY)) ;
+        if ( excludeProperties != null )
+            iter1 = iter1.filter(new FilterExclude(excludeProperties)) ;
+        return iter1 ;
+    }
+
+    protected static  Iter<Triple> backwardLinks(Graph graph, Node x, Collection<Node> excludeProperties)
+    {
+        Iter<Triple> iter1 = Iter.iter(graph.find(Node.ANY, Node.ANY, x)) ;
+        if ( excludeProperties != null )
+            iter1 = iter1.filter(new FilterExclude(excludeProperties)) ;
+        return iter1 ;
+    }
 }
     
 

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=1244673&r1=1244672&r2=1244673&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 Wed Feb 15 19:41:46 2012
@@ -21,8 +21,6 @@ package dev.path;
 //import java.util.ArrayList ;
 import java.util.* ;
 
-import org.openjena.atlas.lib.NotImplemented ;
-
 import com.hp.hpl.jena.graph.Graph ;
 import com.hp.hpl.jena.graph.Node ;
 import com.hp.hpl.jena.sparql.path.P_Mod ;
@@ -44,6 +42,17 @@ class PathEngine1 extends PathEngine
     // Choose the underlying impl - different choice for debugging.
     private static 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)
+    {
+        for ( ; nodes.hasNext() ; )
+        {
+            Node n = nodes.next() ;
+            if ( !acc.contains(n) )
+                acc.add(n) ;
+        }
+    }
+    
 
     @Override
     protected void doMultiLengthPath(Path pathStep, Node node, long min1, long max1, Collection<Node> output)
@@ -185,13 +194,25 @@ class PathEngine1 extends PathEngine
     @Override
     protected void doNegatedPropertySet(P_NegPropSet pathNotOneOf, Node node, Collection<Node> output)
     {
-        throw new NotImplemented() ;
+        // X !(:a|:b|^:c|^:d) Y = { X !(:a|:b) Y } UNION { Y !(:c|:d) X }
+        if ( pathNotOneOf.getFwdNodes().size() > 0 )
+        {
+            Iterator<Node> nodes1 = stepExcludeForwards(graph, node, pathNotOneOf.getFwdNodes()) ;
+            fillUnique(nodes1, output) ;
+        }
+        if ( pathNotOneOf.getBwdNodes().size() > 0 )
+        {
+            Iterator<Node> nodes2 = stepExcludeBackwards(graph, node, pathNotOneOf.getBwdNodes()) ;
+            fillUnique(nodes2, output) ;
+        }
     }
 
     @Override
     protected void doZeroOrOne(Path pathStep, Node node, Collection<Node> output)
     {
-        throw new NotImplemented() ;
+        PathEval2.eval1$(graph, node, pathStep, forwardMode, output) ;
+        if ( ! output.contains(node) )
+            output.add(node) ;
     }
 
     @Override

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=1244673&r1=1244672&r2=1244673&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 Wed Feb 15 19:41:46 2012
@@ -21,21 +21,15 @@ package dev.path;
 import java.util.Collection ;
 import java.util.HashSet ;
 import java.util.Iterator ;
-import java.util.List ;
 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.graph.Triple ;
 import com.hp.hpl.jena.sparql.path.P_FixedLength ;
 import com.hp.hpl.jena.sparql.path.P_Mod ;
 import com.hp.hpl.jena.sparql.path.P_NegPropSet ;
 import com.hp.hpl.jena.sparql.path.Path ;
 
-import dev.path.PathEvaluator.FilterExclude ;
-
 // ----
 /** Path evaluator that produces duplicates.
  *  This is the algorithm in the SPARQL 1.1 spec.  
@@ -59,12 +53,12 @@ class PathEngineN extends PathEngine
         // X !(:a|:b|^:c|^:d) Y = { X !(:a|:b) Y } UNION { Y !(:c|:d) X }
         if ( pathNotOneOf.getFwdNodes().size() > 0 )
         {
-            Iterator<Node> nodes1 = doOneExcludeForwards(pathNotOneOf.getFwdNodes(), node) ;
+            Iterator<Node> nodes1 = stepExcludeForwards(graph, node, pathNotOneOf.getFwdNodes()) ;
             fill(nodes1, output) ;
         }
         if ( pathNotOneOf.getBwdNodes().size() > 0 )
         {
-            Iterator<Node> nodes2 = doOneExcludeBackwards(pathNotOneOf.getBwdNodes(), node) ;
+            Iterator<Node> nodes2 = stepExcludeBackwards(graph, node, pathNotOneOf.getBwdNodes()) ;
             fill(nodes2, output) ;
         }
     }
@@ -184,36 +178,6 @@ class PathEngineN extends PathEngine
         fill(iter, output) ;
     }
 
-    private final Iterator<Node> doOneExcludeForwards(List<Node> excludedNodes, Node node)
-    {
-        Iter<Triple> iter1 = forwardLinks(node, excludedNodes) ;
-        Iter<Node> r1 = iter1.map(selectObject) ;
-        return r1 ;
-    }
-
-    private final Iterator<Node> doOneExcludeBackwards(List<Node> excludedNodes, Node node)
-    {
-        Iter<Triple> iter1 = backwardLinks(node, excludedNodes) ;
-        Iter<Node> r1 = iter1.map(selectSubject) ;
-        return r1 ;
-    }
-
-    private Iter<Triple> forwardLinks(Node x, Collection<Node> excludeProperties)
-    {
-        Iter<Triple> iter1 = Iter.iter(graph.find(x, Node.ANY, Node.ANY)) ;
-        if ( excludeProperties != null )
-            iter1 = iter1.filter(new FilterExclude(excludeProperties)) ;
-        return iter1 ;
-    }
-
-    private Iter<Triple> backwardLinks(Node x, Collection<Node> excludeProperties)
-    {
-        Iter<Triple> iter1 = Iter.iter(graph.find(Node.ANY, Node.ANY, x)) ;
-        if ( excludeProperties != null )
-            iter1 = iter1.filter(new FilterExclude(excludeProperties)) ;
-        return iter1 ;
-    }
-
     @Override
     protected void doZero(Path path, Node node, Collection<Node> output)
     {

Modified: incubator/jena/Scratch/AFS/Dev/trunk/src/main/java/riot/reader/WebReader2.java
URL: http://svn.apache.org/viewvc/incubator/jena/Scratch/AFS/Dev/trunk/src/main/java/riot/reader/WebReader2.java?rev=1244673&r1=1244672&r2=1244673&view=diff
==============================================================================
--- incubator/jena/Scratch/AFS/Dev/trunk/src/main/java/riot/reader/WebReader2.java (original)
+++ incubator/jena/Scratch/AFS/Dev/trunk/src/main/java/riot/reader/WebReader2.java Wed Feb 15 19:41:46 2012
@@ -73,6 +73,13 @@ import com.hp.hpl.jena.sparql.util.Conte
  */
 public class WebReader2
 {
+    /* TODO
+     * 1/ ContentType vs MediaType
+     * 2/ TypedInputStream vs  TypedInputStream2 (issue is that TIS is an input stream, indirection via FilteredInputStream)
+     *    Drop this, have getInputStream/getOutputStream
+     *    TypedInputStream uses MediaType
+     */
+    
     // **** Additional to, and upgrade of, riot.WebReader
     static Logger log = LoggerFactory.getLogger(WebReader2.class) ;