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 17:51:14 UTC
svn commit: r1243604 - in /incubator/jena:
Jena2/ARQ/trunk/src/main/java/org/openjena/riot/web/HttpOp.java
Scratch/AFS/Dev/trunk/src-dev/dev/PathEval2.java
Scratch/AFS/Dev/trunk/src-dev/dev/RunAFS.java
Author: andy
Date: Mon Feb 13 16:51:14 2012
New Revision: 1243604
URL: http://svn.apache.org/viewvc?rev=1243604&view=rev
Log: (empty)
Modified:
incubator/jena/Jena2/ARQ/trunk/src/main/java/org/openjena/riot/web/HttpOp.java
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/Jena2/ARQ/trunk/src/main/java/org/openjena/riot/web/HttpOp.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/ARQ/trunk/src/main/java/org/openjena/riot/web/HttpOp.java?rev=1243604&r1=1243603&r2=1243604&view=diff
==============================================================================
--- incubator/jena/Jena2/ARQ/trunk/src/main/java/org/openjena/riot/web/HttpOp.java (original)
+++ incubator/jena/Jena2/ARQ/trunk/src/main/java/org/openjena/riot/web/HttpOp.java Mon Feb 13 16:51:14 2012
@@ -59,6 +59,11 @@ import com.hp.hpl.jena.sparql.ARQInterna
*/
public class HttpOp
{
+
+ // See also:
+ // Fluent API in HttpClient from v4.2
+
+
static private Logger log = LoggerFactory.getLogger(HttpOp.class) ;
static private AtomicLong counter = new AtomicLong(0) ;
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=1243604&r1=1243603&r2=1243604&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 16:51:14 2012
@@ -24,6 +24,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 ;
@@ -588,7 +589,7 @@ public class PathEval2
@Override
public void visit(P_NegPropSet pathNotOneOf)
{
-
+ throw new NotImplemented() ;
}
@Override
@@ -601,33 +602,116 @@ public class PathEval2
@Override
public void visit(P_Mod pathMod)
{
- // WORK : projection
+ // do..Or.. need to take a visited set.
+
+ if ( pathMod.isZeroOrMore() )
+ {
+ // :p{0,}
+ doZeroOrMore(pathMod.getSubPath()) ;
+ return ;
+ }
+ if ( pathMod.isOneOrMore() )
+ {
+ doOneOrMore(pathMod.getSubPath()) ;
+ return ;
+ }
+// if ( pathMod.isZeroOrOne() )
+
+ // This algrothim can be used for counting {n,m}
+ // abstract ALP(=>rename?) , doFixedLength
+
+ long min1 = pathMod.getMin() ;
+ long max1 = pathMod.getMax() ;
+ if ( min1 == P_Mod.UNSET )
+ // {,N}
+ min1 = 0 ;
+
+ // do 0-min1 steps, not collecting.
+ Collection<Node> collectStartPoints = new ArrayList<Node>() ;
+
+ if ( min1 > 0 )
+ //WRONG - this is {0,min1} not {min1}
+ doFixedLength(pathMod.getSubPath(), node, min1, collectStartPoints) ;
+ else
+ collectStartPoints.add(node) ;
+
+ System.out.println("Start points: "+collectStartPoints) ;
+
+ // {N,M} = {N} then {0,M-N}
+ int length = (int)(max1-min1) ;
+
+ Collection<Node> visited = new ArrayList<Node>() ;
+ for ( Node n : collectStartPoints )
+ doModPath(pathMod.getSubPath(), n, length, visited) ;
+
+ // Uck.
+ output.addAll(visited) ;
}
+
+
+ // Do {0,length}
+ private void doModPath(Path path, Node node, int length, Collection<Node>visited)
+ {
+ System.out.printf("doModPath (%d) %s\n", length, node) ;
+ ALP1(graph, forwardMode, 0, length, node, path, visited) ;
+ }
+
@Override
public void visit(P_FixedLength pFixedLength)
{
+ doFixedLength(pFixedLength.getSubPath(), node, pFixedLength.getCount(), output) ;
// WORK : projection
}
+ private void doFixedLength(Path subPath, Node node, long count, Collection<Node> output)
+ {
+ throw new NotImplemented() ;
+ }
+
@Override
public void visit(P_ZeroOrOne path)
{
- // WORK
+ //WORK
+ throw new NotImplemented() ;
}
-
+
@Override
public void visit(P_ZeroOrMore path)
{
- // WORK
+ doZeroOrMore(path.getSubPath()) ;
+ }
+
+ private void doZeroOrMore(Path path)
+ {
+ // Reuse "output"
+ Collection<Node> visited = new LinkedList<Node>() ; //new HashSet<Node>() ;
+ ALP1(graph, forwardMode, 0, -1, node, path, visited) ;
+ output.addAll(visited) ;
}
@Override
public void visit(P_OneOrMore path)
{
- // WORK
+ doOneOrMore(path.getSubPath()) ;
}
+
+ private void doOneOrMore(Path path)
+ {
+ // Reuse "output"
+ Collection<Node> visited = new LinkedList<Node>() ; // new HashSet<Node>() ;
+ // Do one step without including.
+ Iterator<Node> iter1 = evalN(graph, node, path, forwardMode) ;
+ for ( ; iter1.hasNext() ; )
+ {
+ Node n1 = iter1.next();
+ ALP1(graph, forwardMode, 0, -1, n1, path, visited) ;
+ }
+ output.addAll(visited) ;
+ }
+
+
@Override
public void visit(P_Alt pathAlt)
{
@@ -640,20 +724,21 @@ public class PathEval2
// WORK : projection.
}
- private static void ALP1(Graph graph, boolean forwardMode, Node node, Path path, Collection<Node> visited)
+ private static 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 ;
if ( visited.contains(node) ) return ;
if ( ! visited.add(node) )
return ;
- Iterator<Node> iter1 = evalN(graph, node, path, forwardMode) ;
+ Iterator<Node> iter1 = eval1(graph, node, path, forwardMode) ;
// For each step, add to results and recurse.
for ( ; iter1.hasNext() ; )
{
Node n1 = iter1.next();
- ALP1(graph, forwardMode, n1, path, visited) ;
+ ALP1(graph, forwardMode, stepCount+1, maxStepCount, n1, path, visited) ;
}
// Different from ALP-counting.
// visited.remove(node) ;
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=1243604&r1=1243603&r2=1243604&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 16:51:14 2012
@@ -19,6 +19,7 @@
package dev;
import java.util.Iterator ;
+import java.util.List ;
import org.openjena.atlas.iterator.Iter ;
import org.openjena.atlas.lib.StrUtils ;
@@ -61,7 +62,7 @@ public class RunAFS
{
String prefix = "prefix ((: <http://example/>))" ;
- String pathStr = "(path* :q)" ;
+ String pathStr = "(mod 0 2 :q)" ;
String qs = StrUtils.strjoinNL(
"("+prefix,
@@ -85,7 +86,17 @@ public class RunAFS
" (:x :q :y2)" ,
" (:y1 :q :z)" ,
" (:y2 :q :z)" ,
+
+ " (:x :r :y1)" ,
+ " (:x :r :y2)" ,
+ " (:y1 :r :z)" ,
+ " (:y2 :r :z)" ,
+ " (:z :r :a1)" ,
+ " (:z :r :a2)" ,
+ " (:a1 :r :b)" ,
+ " (:a2 :r :b)" ,
+
"))"
) ;
@@ -95,9 +106,19 @@ public class RunAFS
Graph g = SSE.parseGraph(gs) ;
DatasetGraph dsg = DatasetGraphFactory.create(g) ;
- Iterator<Node> iter = PathEval2.evalN(g, x, path) ;
+ List<Node> nodes1 = Iter.toList(PathEval2.eval1(g, x, path)) ;
+ List<Node> nodes2 = Iter.toList(PathEval2.evalN(g, x, path)) ;
+
System.out.println(WriterPath.asString(path)) ;
- System.out.println(Iter.asString(iter, "\n")) ;
+
+ String SEP = "\n " ;
+
+ System.out.printf("Eval1: (%d)%s", nodes1.size(), SEP) ;
+ System.out.print(Iter.asString(nodes1, SEP)) ;
+ System.out.println() ;
+
+ System.out.printf("EvalN: (%d)%s", nodes2.size(), SEP) ;
+ System.out.print(Iter.asString(nodes2, SEP)) ;
System.out.println() ;
if ( false )
@@ -109,10 +130,13 @@ public class RunAFS
System.out.println(b) ;
}
}
- System.out.print(op) ;
- QueryExecUtils.execute(op, dsg) ;
- System.out.println() ;
+ if ( false )
+ {
+ System.out.print(op) ;
+ QueryExecUtils.execute(op, dsg) ;
+ System.out.println() ;
+ }
System.out.println("DONE") ;
System.exit(0) ;
}