--- a/src/main/scala/SPARQL.scala Mon Dec 28 16:40:45 2009 -0500
+++ b/src/main/scala/SPARQL.scala Mon Dec 28 21:53:32 2009 -0500
@@ -96,6 +96,7 @@
case Some(x) => x
case _ => EmptyGraphPattern()
}
+ // println("groupgraphpattern: " + tbOPT + " " + gpntORf_tbOPT)
gpntORf_tbOPT.foldLeft(init)((gp, lentry) => lentry match {
case ~(TableFilter(null, expr), None) => TableFilter(gp, expr)
case ~(TriplesBlock(triples), None) => gp match {
@@ -104,7 +105,7 @@
}
case ~(TableDisjunction(list), None) => gp match {
case EmptyGraphPattern() => TableDisjunction(list)
- case x => TableConjunction(List(gp, x))
+ case x => TableConjunction(List(gp, TableDisjunction(list)))
}
case ~(OptionalGraphPattern(gp2), None) => TableConjunction(List(gp, OptionalGraphPattern(gp2)))
case x => error("found " + x)
--- a/src/test/scala/SparqlTest.scala Mon Dec 28 16:40:45 2009 -0500
+++ b/src/test/scala/SparqlTest.scala Mon Dec 28 21:53:32 2009 -0500
@@ -292,6 +292,63 @@
assert(tps === a.parseAll(a.select, e).get)
}
+ test("parse disj1") {
+ val a = Sparql()
+ val e = """
+SELECT ?name
+ { ?who <http://hr.example/DB/Employee#lastName> "Smith"^^<http://www.w3.org/2001/XMLSchema#string>
+ { ?above <http://hr.example/DB/Manage#manages> ?who .
+ ?above <http://hr.example/DB/Manage#manager> ?manager .
+ ?manager <http://hr.example/DB/Employee#lastName> ?name }
+ UNION
+ { ?below <http://hr.example/DB/Manage#manager> ?who .
+ ?below <http://hr.example/DB/Manage#manages> ?managed .
+ ?managed <http://hr.example/DB/Employee#lastName> ?name } }
+"""
+ val tps =
+ SparqlSelect(
+ SparqlAttributeList(List(Var("name"))),
+ TableConjunction(List(
+ TriplesBlock(
+ List(
+ TriplePattern(
+ SVar(Var("who")),
+ PUri(Stem("http://hr.example/DB"),Rel("Employee"),Attr("lastName")),
+ OLit(SparqlLiteral(RDFLiteral("Smith",Datatype(new URI("http://www.w3.org/2001/XMLSchema#string")))))))),
+ TableDisjunction(List(
+ TriplesBlock(
+ List(
+ TriplePattern(
+ SVar(Var("above")),
+ PUri(Stem("http://hr.example/DB"),Rel("Manage"),Attr("manages")),
+ OVar(Var("who"))),
+ TriplePattern(
+ SVar(Var("above")),
+ PUri(Stem("http://hr.example/DB"),Rel("Manage"),Attr("manager")),
+ OVar(Var("manager"))),
+ TriplePattern(
+ SVar(Var("manager")),
+ PUri(Stem("http://hr.example/DB"),Rel("Employee"),Attr("lastName")),
+ OVar(Var("name")))
+ )),
+ TriplesBlock(
+ List(
+ TriplePattern(
+ SVar(Var("below")),
+ PUri(Stem("http://hr.example/DB"),Rel("Manage"),Attr("manager")),
+ OVar(Var("who"))),
+ TriplePattern(
+ SVar(Var("below")),
+ PUri(Stem("http://hr.example/DB"),Rel("Manage"),Attr("manages")),
+ OVar(Var("managed"))),
+ TriplePattern(
+ SVar(Var("managed")),
+ PUri(Stem("http://hr.example/DB"),Rel("Employee"),Attr("lastName")),
+ OVar(Var("name")))
+ )))))))
+ assert(tps === a.parseAll(a.select, e).get)
+ }
+
test("decompose a predicate uri in stem, rel and attr") {
val uri = "http://hr.example/our/favorite/DB/Employee#lastName"
val puri:PUri = Sparql.parsePredicateURI(uri)