~ trim to ?s <p> const yields all patterns with ?s
authorEric Prud'hommeaux <eric@w3.org>
Sun, 28 Feb 2010 15:04:42 -0500
changeset 185 c95ae0c8d28b
parent 184 b64f1d9ee47e
child 186 b1dfc6142d44
~ trim to ?s <p> const yields all patterns with ?s
src/main/scala/SPARQL.scala
--- a/src/main/scala/SPARQL.scala	Sun Feb 28 11:40:20 2010 -0500
+++ b/src/main/scala/SPARQL.scala	Sun Feb 28 15:04:42 2010 -0500
@@ -58,7 +58,15 @@
 	      r.neededFor(terms, t.o, Set(t.s))) s + t
 	  else s
 	})
-	TriplesBlock(useful.toList)
+	val useful2 =
+	  if (useful.size == 0)
+	    triplepatterns.foldLeft(Set[TriplePattern]())((s, t) => {
+	      if (r.neededFor(terms, t.s, Set(t.o)) ||
+		  r.neededFor(terms, t.o, Set(t.s))) s + t
+	      else s
+	    })
+          else useful
+	TriplesBlock(useful2.toList)
       }
 
       case TableConjunction(list) =>