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/12 21:01:15 UTC

svn commit: r1243311 [3/3] - in /incubator/jena/Jena2/ARQ/trunk: Grammar/ src/main/java/com/hp/hpl/jena/sparql/algebra/optimize/ src/main/java/com/hp/hpl/jena/sparql/lang/arq/ src/main/java/com/hp/hpl/jena/sparql/path/ src/main/java/com/hp/hpl/jena/spa...

Added: incubator/jena/Jena2/ARQ/trunk/src/main/java/com/hp/hpl/jena/sparql/path/P_Multi.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/ARQ/trunk/src/main/java/com/hp/hpl/jena/sparql/path/P_Multi.java?rev=1243311&view=auto
==============================================================================
--- incubator/jena/Jena2/ARQ/trunk/src/main/java/com/hp/hpl/jena/sparql/path/P_Multi.java (added)
+++ incubator/jena/Jena2/ARQ/trunk/src/main/java/com/hp/hpl/jena/sparql/path/P_Multi.java Sun Feb 12 20:01:14 2012
@@ -0,0 +1,51 @@
+/*
+ * 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 com.hp.hpl.jena.sparql.path;
+
+import com.hp.hpl.jena.sparql.util.NodeIsomorphismMap ;
+
+/** A path element that, on evalution, switches to multi-cardinality semantics. */  
+public class P_Multi extends P_Path1
+{
+    public P_Multi(Path p)
+    {
+         super(p) ;
+    }
+    
+    @Override
+    public void visit(PathVisitor visitor)
+    { visitor.visit(this) ; }
+    
+    @Override
+    public boolean equalTo(Path path2, NodeIsomorphismMap isoMap)
+    {
+        if ( ! ( path2 instanceof P_Multi ) ) return false ;
+        P_Multi other = (P_Multi)path2 ;
+        return getSubPath().equalTo(other.getSubPath(), isoMap)  ;
+    }
+
+    @Override
+    public int hashCode()
+    {
+        return getSubPath().hashCode() ^ hashMulti ;
+    }
+
+   
+
+}

Modified: incubator/jena/Jena2/ARQ/trunk/src/main/java/com/hp/hpl/jena/sparql/path/PathBase.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/ARQ/trunk/src/main/java/com/hp/hpl/jena/sparql/path/PathBase.java?rev=1243311&r1=1243310&r2=1243311&view=diff
==============================================================================
--- incubator/jena/Jena2/ARQ/trunk/src/main/java/com/hp/hpl/jena/sparql/path/PathBase.java (original)
+++ incubator/jena/Jena2/ARQ/trunk/src/main/java/com/hp/hpl/jena/sparql/path/PathBase.java Sun Feb 12 20:01:14 2012
@@ -35,6 +35,7 @@ public abstract class PathBase implement
     protected static final int hashZeroOrOne    = 0x199 ;
     protected static final int hashFixedLength  = 0x200 ;
     protected static final int hashDistinct     = 0x201 ;
+    protected static final int hashMulti        = 0x202 ;
 
     
     @Override

Modified: incubator/jena/Jena2/ARQ/trunk/src/main/java/com/hp/hpl/jena/sparql/path/PathEval.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/ARQ/trunk/src/main/java/com/hp/hpl/jena/sparql/path/PathEval.java?rev=1243311&r1=1243310&r2=1243311&view=diff
==============================================================================
--- incubator/jena/Jena2/ARQ/trunk/src/main/java/com/hp/hpl/jena/sparql/path/PathEval.java (original)
+++ incubator/jena/Jena2/ARQ/trunk/src/main/java/com/hp/hpl/jena/sparql/path/PathEval.java Sun Feb 12 20:01:14 2012
@@ -29,6 +29,7 @@ import org.openjena.atlas.io.IndentedWri
 import org.openjena.atlas.iterator.Filter ;
 import org.openjena.atlas.iterator.Iter ;
 import org.openjena.atlas.iterator.Transform ;
+import org.openjena.atlas.lib.NotImplemented ;
 import org.openjena.atlas.logging.Log ;
 import org.slf4j.Logger ;
 import org.slf4j.LoggerFactory ;
@@ -333,6 +334,12 @@ public class PathEval
         }
 
         @Override
+        public void visit(P_Multi pathMulti)
+        {
+            throw new NotImplemented() ; 
+        }
+
+        @Override
         public void visit(P_ZeroOrOne path)
         { 
             doZero(path.getSubPath()) ;
@@ -567,77 +574,4 @@ public class PathEval
             visited.remove(node) ;
         }
     }
-    
-    /** Path evaluation visitor that provide distinct nodes visited, */ 
-    static class PathEvaluator1 implements PathVisitor
-    {
-        private final Graph graph ;
-        private final Node node ;
-        private final Collection<Node> output ;
-        private boolean forwardMode ; 
-
-        public PathEvaluator1(Graph g, Node n, Collection<Node> output, boolean forward)
-        {
-            this.graph = g ; 
-            this.node = n ;
-            this.output = output ;
-            this.forwardMode = forward ;
-        }
-        
-        @Override
-        public void visit(P_Link pathNode)
-        {
-            Iterator<Node> nodes = doOne(pathNode.getNode()) ;
-        }
-
-        private Iterator<Node> doOne(Node node)
-        {
-            return null ;
-        }
-
-        @Override
-        public void visit(P_ReverseLink pathNode)
-        {}
-
-        @Override
-        public void visit(P_NegPropSet pathNotOneOf)
-        {}
-
-        @Override
-        public void visit(P_Inverse inversePath)
-        {}
-
-        @Override
-        public void visit(P_Mod pathMod)
-        {}
-
-        @Override
-        public void visit(P_FixedLength pFixedLength)
-        {}
-
-        @Override
-        public void visit(P_Distinct pathDistinct)
-        {}
-
-        @Override
-        public void visit(P_ZeroOrOne path)
-        {}
-
-        @Override
-        public void visit(P_ZeroOrMore path)
-        {}
-
-        @Override
-        public void visit(P_OneOrMore path)
-        {}
-
-        @Override
-        public void visit(P_Alt pathAlt)
-        {}
-
-        @Override
-        public void visit(P_Seq pathSeq)
-        {}
-        
-    }
 }

Modified: incubator/jena/Jena2/ARQ/trunk/src/main/java/com/hp/hpl/jena/sparql/path/PathEval_ARQ.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/ARQ/trunk/src/main/java/com/hp/hpl/jena/sparql/path/PathEval_ARQ.java?rev=1243311&r1=1243310&r2=1243311&view=diff
==============================================================================
--- incubator/jena/Jena2/ARQ/trunk/src/main/java/com/hp/hpl/jena/sparql/path/PathEval_ARQ.java (original)
+++ incubator/jena/Jena2/ARQ/trunk/src/main/java/com/hp/hpl/jena/sparql/path/PathEval_ARQ.java Sun Feb 12 20:01:14 2012
@@ -27,6 +27,7 @@ import java.util.Set ;
 import org.openjena.atlas.iterator.Filter ;
 import org.openjena.atlas.iterator.Iter ;
 import org.openjena.atlas.iterator.Transform ;
+import org.openjena.atlas.lib.NotImplemented ;
 import org.openjena.atlas.logging.Log ;
 import org.slf4j.Logger ;
 import org.slf4j.LoggerFactory ;
@@ -278,6 +279,12 @@ public class PathEval_ARQ
         }
 
         @Override
+        public void visit(P_Multi pathMulti)
+        {
+            throw new NotImplemented() ; 
+        }
+
+        @Override
         public void visit(P_ZeroOrOne path)
         { 
             doZero(path.getSubPath()) ;

Modified: incubator/jena/Jena2/ARQ/trunk/src/main/java/com/hp/hpl/jena/sparql/path/PathFactory.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/ARQ/trunk/src/main/java/com/hp/hpl/jena/sparql/path/PathFactory.java?rev=1243311&r1=1243310&r2=1243311&view=diff
==============================================================================
--- incubator/jena/Jena2/ARQ/trunk/src/main/java/com/hp/hpl/jena/sparql/path/PathFactory.java (original)
+++ incubator/jena/Jena2/ARQ/trunk/src/main/java/com/hp/hpl/jena/sparql/path/PathFactory.java Sun Feb 12 20:01:14 2012
@@ -30,7 +30,7 @@ public class PathFactory
     public static Path pathMod(Path path, long min, long max)   { return new P_Mod(path, min, max) ; }
     public static Path pathFixedLength(Path path, long count)   { return new P_FixedLength(path, count) ; }
     public static Path pathDistinct(Path path)          { return new P_Distinct(path) ; }
-    
+    public static Path pathMulti(Path path)             { return new P_Multi(path) ; }
 
     public static Path pathAlt(Path path1, Path path2)  { return new P_Alt(path1, path2) ; }
     public static Path pathSeq(Path path1, Path path2)  { return new P_Seq(path1, path2) ; }

Modified: incubator/jena/Jena2/ARQ/trunk/src/main/java/com/hp/hpl/jena/sparql/path/PathVisitor.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/ARQ/trunk/src/main/java/com/hp/hpl/jena/sparql/path/PathVisitor.java?rev=1243311&r1=1243310&r2=1243311&view=diff
==============================================================================
--- incubator/jena/Jena2/ARQ/trunk/src/main/java/com/hp/hpl/jena/sparql/path/PathVisitor.java (original)
+++ incubator/jena/Jena2/ARQ/trunk/src/main/java/com/hp/hpl/jena/sparql/path/PathVisitor.java Sun Feb 12 20:01:14 2012
@@ -29,6 +29,7 @@ public interface PathVisitor
     public void visit(P_Mod pathMod) ;
     public void visit(P_FixedLength pFixedLength) ;
     public void visit(P_Distinct pathDistinct) ;
+    public void visit(P_Multi pathMulti) ;
     public void visit(P_ZeroOrOne path) ;
     public void visit(P_ZeroOrMore path) ;
     public void visit(P_OneOrMore path) ;

Modified: incubator/jena/Jena2/ARQ/trunk/src/main/java/com/hp/hpl/jena/sparql/path/PathWriter.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/ARQ/trunk/src/main/java/com/hp/hpl/jena/sparql/path/PathWriter.java?rev=1243311&r1=1243310&r2=1243311&view=diff
==============================================================================
--- incubator/jena/Jena2/ARQ/trunk/src/main/java/com/hp/hpl/jena/sparql/path/PathWriter.java (original)
+++ incubator/jena/Jena2/ARQ/trunk/src/main/java/com/hp/hpl/jena/sparql/path/PathWriter.java Sun Feb 12 20:01:14 2012
@@ -248,7 +248,14 @@ public class PathWriter
             pathDistinct.getSubPath().visit(this) ;
             out.print(")") ;
         }
-        
+
+        @Override
+        public void visit(P_Multi pathMulti)
+        {
+            out.print("MULTI(") ;
+            pathMulti.getSubPath().visit(this) ;
+            out.print(")") ;
+        }
 
         @Override
         public void visit(P_ZeroOrOne path)

Modified: incubator/jena/Jena2/ARQ/trunk/src/main/java/com/hp/hpl/jena/sparql/sse/Tags.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/ARQ/trunk/src/main/java/com/hp/hpl/jena/sparql/sse/Tags.java?rev=1243311&r1=1243310&r2=1243311&view=diff
==============================================================================
--- incubator/jena/Jena2/ARQ/trunk/src/main/java/com/hp/hpl/jena/sparql/sse/Tags.java (original)
+++ incubator/jena/Jena2/ARQ/trunk/src/main/java/com/hp/hpl/jena/sparql/sse/Tags.java Sun Feb 12 20:01:14 2012
@@ -95,10 +95,12 @@ public class Tags
     public static final String tagPathOneOrMore     = "path+" ;
     public static final String tagPathZeroOrOne     = "path?" ;
     public static final String tagPathFixedLength   = "pathN" ;
+    public static final String tagPathDistinct      = "distinct" ;
+    public static final String tagPathMulti         = "multi" ;
     
-    public static final String tagPathReverse   = "reverse" ;
-    public static final String tagPathRev       = "rev" ;
-    public static final String pathNotOneOf     = "notoneof" ;
+    public static final String tagPathReverse       = "reverse" ;
+    public static final String tagPathRev           = "rev" ;
+    public static final String tagPathNotOneOf      = "notoneof" ;
 
     // Not used - nowadays extensions are not explicitly flagged in the algebra.
     // But needed to override existing operations.

Modified: incubator/jena/Jena2/ARQ/trunk/src/main/java/com/hp/hpl/jena/sparql/sse/builders/BuilderPath.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/ARQ/trunk/src/main/java/com/hp/hpl/jena/sparql/sse/builders/BuilderPath.java?rev=1243311&r1=1243310&r2=1243311&view=diff
==============================================================================
--- incubator/jena/Jena2/ARQ/trunk/src/main/java/com/hp/hpl/jena/sparql/sse/builders/BuilderPath.java (original)
+++ incubator/jena/Jena2/ARQ/trunk/src/main/java/com/hp/hpl/jena/sparql/sse/builders/BuilderPath.java Sun Feb 12 20:01:14 2012
@@ -63,15 +63,16 @@ public class BuilderPath
         dispatch.put(Tags.tagPathAlt, buildAlt) ;
         dispatch.put(Tags.tagPathMod, buildMod) ;
         
-        dispatch.put(Tags.tagPathFixedLength, buildFixedLength) ;
-        dispatch.put(Tags.tagDistinct, buildDistinct) ;
-        dispatch.put(Tags.tagPathZeroOrMore, buildZeroOrMore) ;
-        dispatch.put(Tags.tagPathZeroOrOne, buildZeroOrOne) ;
-        dispatch.put(Tags.tagPathOneOrMore, buildOneOrMore) ;
+        dispatch.put(Tags.tagPathFixedLength,   buildFixedLength) ;
+        dispatch.put(Tags.tagPathDistinct,      buildDistinct) ;
+        dispatch.put(Tags.tagPathMulti,         buildMulti) ;
+        dispatch.put(Tags.tagPathZeroOrMore,    buildZeroOrMore) ;
+        dispatch.put(Tags.tagPathZeroOrOne,     buildZeroOrOne) ;
+        dispatch.put(Tags.tagPathOneOrMore,     buildOneOrMore) ;
         
         dispatch.put(Tags.tagPathReverse, buildReverse) ;
         dispatch.put(Tags.tagPathRev, buildRev) ;
-        dispatch.put(Tags.pathNotOneOf, buildNotOneOf) ;
+        dispatch.put(Tags.tagPathNotOneOf, buildNotOneOf) ;
     }
     
     private Path build(Item item)
@@ -203,12 +204,23 @@ public class BuilderPath
         @Override
         public Path make(ItemList list)
         {
-            BuilderLib.checkLength(2, 2, list, "path distinct repeat: wanted 1 argument") ;
+            BuilderLib.checkLength(2, 2, list, "path distinct: wanted 1 argument") ;
             Path path  = build(list, 1) ;
             return new P_Distinct(path) ;
         }
     } ;
 
+    final protected Build buildMulti = new Build()
+    {
+        @Override
+        public Path make(ItemList list)
+        {
+            BuilderLib.checkLength(2, 2, list, "path multi : wanted 1 argument") ;
+            Path path  = build(list, 1) ;
+            return new P_Multi(path) ;
+        }
+    } ;
+
     final protected Build buildZeroOrMore = new Build()
     {
         @Override

Modified: incubator/jena/Jena2/ARQ/trunk/src/main/java/com/hp/hpl/jena/sparql/sse/writers/WriterPath.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/ARQ/trunk/src/main/java/com/hp/hpl/jena/sparql/sse/writers/WriterPath.java?rev=1243311&r1=1243310&r2=1243311&view=diff
==============================================================================
--- incubator/jena/Jena2/ARQ/trunk/src/main/java/com/hp/hpl/jena/sparql/sse/writers/WriterPath.java (original)
+++ incubator/jena/Jena2/ARQ/trunk/src/main/java/com/hp/hpl/jena/sparql/sse/writers/WriterPath.java Sun Feb 12 20:01:14 2012
@@ -151,7 +151,7 @@ public class WriterPath
         public void visit(P_NegPropSet pathNotOneOf)
         {
             out.print("(") ;
-            out.print(Tags.pathNotOneOf) ;
+            out.print(Tags.tagPathNotOneOf) ;
 
             for ( P_Path0 p : pathNotOneOf.getNodes() )
             {
@@ -218,31 +218,34 @@ public class WriterPath
             out.print(")") ;
         }
         
-
         @Override
         public void visit(P_Distinct pathDistinct)
         {
-            out.print("(distinct ") ;
-            output(pathDistinct.getSubPath()) ;
-            out.print(")") ;
+            writePath(Tags.tagPathDistinct, pathDistinct.getSubPath()) ;
+        }
+
+        @Override
+        public void visit(P_Multi pathMulti)
+        {
+            writePath(Tags.tagPathMulti, pathMulti.getSubPath()) ;
         }
 
         @Override
         public void visit(P_ZeroOrOne path)
         { 
-            writeStarPlusQuery(Tags.tagPathZeroOrOne, path.getSubPath()) ;
+            writePath(Tags.tagPathZeroOrOne, path.getSubPath()) ;
         }
 
         @Override
         public void visit(P_ZeroOrMore path)
         { 
-            writeStarPlusQuery(Tags.tagPathZeroOrMore, path.getSubPath()) ;
+            writePath(Tags.tagPathZeroOrMore, path.getSubPath()) ;
         }
 
         @Override
         public void visit(P_OneOrMore path)
         { 
-            writeStarPlusQuery(Tags.tagPathOneOrMore, path.getSubPath()) ;
+            writePath(Tags.tagPathOneOrMore, path.getSubPath()) ;
         }
         
         private void writeOneLiner(Path path)
@@ -256,7 +259,7 @@ public class WriterPath
             out.decIndent() ;
         }
         
-        private void writeStarPlusQuery(String tag, Path subPath)
+        private void writePath(String tag, Path subPath)
         {
             out.print("(") ;
             out.print(tag) ;