TriplePatterns always has a SparqlExpression
authorEric Prud'hommeaux <bertails@w3.org>
Wed, 16 Dec 2009 15:15:32 -0500
changeset 52 8955fa73705e
parent 51 5b40601af012
child 53 8ea6f8c6fcaf
TriplePatterns always has a SparqlExpression
src/main/scala/RDB2RDFMain.scala
src/main/scala/SPARQL.scala
src/test/scala/SparqlTest.scala
--- a/src/main/scala/RDB2RDFMain.scala	Wed Dec 16 15:13:27 2009 -0500
+++ b/src/main/scala/RDB2RDFMain.scala	Wed Dec 16 15:15:32 2009 -0500
@@ -304,14 +304,11 @@
     var inConstraint:Set[Var] = r2rState.inConstraint
 
     /* Add constraints for all the FILTERS */
-    triples.filter match {
-      case Some(x) => x.conjuncts.foreach(f => {
+    triples.filter.conjuncts.foreach(f => {
 	val pair = filter(exprs, inConstraint, r2rState.varmap, f)
 	exprs = pair._1
 	inConstraint = pair._2
       })
-      case None => 
-    }
 
     /* Add null guards for attributes associated with variables which
      * are not optional and have not been used in constraints. */
--- a/src/main/scala/SPARQL.scala	Wed Dec 16 15:13:27 2009 -0500
+++ b/src/main/scala/SPARQL.scala	Wed Dec 16 15:15:32 2009 -0500
@@ -14,7 +14,7 @@
 case class SparqlSelect(attrs:SparqlAttributeList, triples:TriplePatterns)
 case class SparqlAttributeList(attributelist:List[Var])
 
-case class TriplePatterns(triplepatterns:List[TriplePattern], filter:Option[SparqlExpression])
+case class TriplePatterns(triplepatterns:List[TriplePattern], filter:SparqlExpression)
 case class TriplePattern(s:S, p:P, o:O)
 
 case class ObjUri(stem:Stem, rel:Rel, attr:Attr, v:CellValue)
@@ -83,7 +83,14 @@
     rep(varr) ^^ { SparqlAttributeList(_) }
 
   def triplepatterns:Parser[TriplePatterns] =
-    repsep(triplepattern, ".") ~ opt(filter) ^^ { case pats~filter => TriplePatterns(pats, filter) }
+    repsep(triplepattern, ".") ~ opt(filter) ^^ {
+      case pats~filter =>
+	val sparqlExpression:SparqlExpression = filter match {
+	  case None => SparqlExpression(List())
+	  case Some(f) => f
+	}
+      TriplePatterns(pats, sparqlExpression)
+    }
 
   def triplepattern:Parser[TriplePattern] =
     subject ~ predicate ~ objectt ^^ { case s~p~o => TriplePattern(s, p, o) }
--- a/src/test/scala/SparqlTest.scala	Wed Dec 16 15:13:27 2009 -0500
+++ b/src/test/scala/SparqlTest.scala	Wed Dec 16 15:15:32 2009 -0500
@@ -10,7 +10,7 @@
     val e = """
 ?emp      <http://hr.example/DB/Employee#lastName>   "bob"^^<http://www.w3.org/2001/XMLSchema#string>
 """
-    val expected = TriplePatterns(List(TriplePattern(SVar(Var("emp")),PUri(Stem("http://hr.example/DB"),Rel("Employee"),Attr("lastName")),OLit(SparqlLiteral(RDFLiteral("bob",Datatype(new URI("http://www.w3.org/2001/XMLSchema#string"))))))), None)
+    val expected = TriplePatterns(List(TriplePattern(SVar(Var("emp")),PUri(Stem("http://hr.example/DB"),Rel("Employee"),Attr("lastName")),OLit(SparqlLiteral(RDFLiteral("bob",Datatype(new URI("http://www.w3.org/2001/XMLSchema#string"))))))), SparqlExpression(List()))
     assert(expected === (a.parseAll(a.triplepatterns, e).get))
   }
 
@@ -19,7 +19,7 @@
     val e = """
 ?emp      <http://hr.example/DB/Employee#age>   "21"^^<http://www.w3.org/2001/XMLSchema#integer>
 """
-    val expected = TriplePatterns(List(TriplePattern(SVar(Var("emp")),PUri(Stem("http://hr.example/DB"),Rel("Employee"),Attr("age")),OLit(SparqlLiteral(RDFLiteral("21",Datatype(new URI("http://www.w3.org/2001/XMLSchema#integer"))))))), None)
+    val expected = TriplePatterns(List(TriplePattern(SVar(Var("emp")),PUri(Stem("http://hr.example/DB"),Rel("Employee"),Attr("age")),OLit(SparqlLiteral(RDFLiteral("21",Datatype(new URI("http://www.w3.org/2001/XMLSchema#integer"))))))), SparqlExpression(List()))
     assert(expected === (a.parseAll(a.triplepatterns, e).get))
   }
 
@@ -44,7 +44,7 @@
 	  TriplePattern(
 	    SVar(Var("manager")),
 	    PUri(Stem("http://hr.example/DB"),Rel("Employee"),Attr("lastName")),
-	    OVar(Var("managName")))), None)
+	    OVar(Var("managName")))), SparqlExpression(List()))
     assert(tps === a.parseAll(a.triplepatterns, e).get)
   }
 
@@ -106,11 +106,11 @@
 	      SVar(Var("emp")),
 		PUri(Stem("http://hr.example/DB"),Rel("Employee"),Attr("lastName")),
 	      OVar(Var("empName")))), 
-	  Some(SparqlExpression(List(
+	  SparqlExpression(List(
 	    SparqlPrimaryExpressionLt(SparqlTermExpression(TermVar(Var("manBday"))),
 				      SparqlTermExpression(TermVar(Var("empBday")))), 
 	    SparqlPrimaryExpressionLt(SparqlTermExpression(TermVar(Var("grandManBday"))),
-				      SparqlTermExpression(TermVar(Var("manBday")))))))))
+				      SparqlTermExpression(TermVar(Var("manBday"))))))))
     assert(tps === a.parseAll(a.select, e).get)
   }
 
@@ -139,7 +139,7 @@
 	    TriplePattern(
 	      SVar(Var("manager")),
 	      PUri(Stem("http://hr.example/DB"),Rel("Employee"),Attr("lastName")),
-	      OVar(Var("managName")))), None))
+	      OVar(Var("managName")))), SparqlExpression(List())))
     assert(tps === a.parseAll(a.select, e).get)
   }