+ filter test
authorEric Prud'hommeaux <eric@w3.org>
Sat, 27 Feb 2010 11:08:51 -0500
changeset 179 3ddae4e60614
parent 178 d925d4cd7e32
child 180 f87818a1cb27
+ filter test
src/test/scala/SparqlToSparqlTest.scala
--- a/src/test/scala/SparqlToSparqlTest.scala	Sat Feb 27 11:07:28 2010 -0500
+++ b/src/test/scala/SparqlToSparqlTest.scala	Sat Feb 27 11:08:51 2010 -0500
@@ -14,26 +14,9 @@
  */
 class SparqlToSparqlTest extends FunSuite {
 
-//   test("cat") {
-//     val sparqlParser = Sparql()
-//     val query = sparqlParser.parseAll(sparqlParser.select, """
-// PREFIX empP : <http://hr.example/DB/Employee#>
-// SELECT ?emp {
-// ?emp  empP:manager    <http://hr.example/DB/Employee/empid.18#record>
-// }
-// """).get
-//     val transformed = SparqlToSparql(query, List[sparql.Construct]())
-//     val expected = sparqlParser.parseAll(sparqlParser.select, """
-// PREFIX empP : <http://hr.example/DB/Employee#>
-// SELECT ?emp {
-// ?emp  empP:manager    <http://hr.example/DB/Employee/empid.18#record>
-// }
-// """).get
-//     assert(transformed === expected)
-//   }
-
-  test("foaf:last_name single") {
+  test("foaf:last_name simple head") {
     val sparqlParser = Sparql()
+    /* Query to be fired over view created by some transformation rules. */
     val query = sparqlParser.parseAll(sparqlParser.select, """
 PREFIX foaf : <http://xmlns.com/foaf/0.1/>
 PREFIX xsd : <http://www.w3.org/2001/XMLSchema#>
@@ -41,12 +24,17 @@
 ?emp  foaf:last_name    "Smith"^^xsd:string
 }
 """).get
+
+    /* This transformation rule maps last_name to empP:lastName. */
     val lname = sparqlParser.parseAll(sparqlParser.construct, """
 PREFIX foaf : <http://xmlns.com/foaf/0.1/>
 PREFIX empP : <http://hr.example/DB/Employee#>
 CONSTRUCT { ?who foaf:last_name  ?lname }
     WHERE { ?who empP:lastName   ?lname }
 """).get
+
+    /* The query doesn't reference the graph produced by this transformation
+     * so the rule antecedent (empP:firstName) should not appear in result.  */
     val fname = sparqlParser.parseAll(sparqlParser.construct, """
 PREFIX foaf : <http://xmlns.com/foaf/0.1/>
 PREFIX empP : <http://hr.example/DB/Employee#>
@@ -64,7 +52,7 @@
     assert(transformed === expected)
   }
 
-  test("foaf:last_name multi") {
+  test("foaf:last_name conjunctive head") {
     val sparqlParser = Sparql()
     val query = sparqlParser.parseAll(sparqlParser.select, """
 PREFIX foaf : <http://xmlns.com/foaf/0.1/>
@@ -92,6 +80,35 @@
     assert(transformed === expected)
   }
 
+  test("foaf:last_name FILTER") {
+    val sparqlParser = Sparql()
+    val query = sparqlParser.parseAll(sparqlParser.select, """
+PREFIX foaf : <http://xmlns.com/foaf/0.1/>
+PREFIX xsd : <http://www.w3.org/2001/XMLSchema#>
+SELECT ?emp {
+?emp  foaf:last_name    ?name
+FILTER (?name = "Smith"^^xsd:string)
+}
+""").get
+    val lname = sparqlParser.parseAll(sparqlParser.construct, """
+PREFIX foaf : <http://xmlns.com/foaf/0.1/>
+PREFIX empP : <http://hr.example/DB/Employee#>
+CONSTRUCT { ?who foaf:last_name  ?lname }
+    WHERE { ?who empP:lastName   ?lname }
+""").get
+    val transformed = SparqlToSparql(query, List(lname))
+    val expected = sparqlParser.parseAll(sparqlParser.select, """
+PREFIX empP : <http://hr.example/DB/Employee#>
+PREFIX xsd : <http://www.w3.org/2001/XMLSchema#>
+SELECT ?emp {
+?emp  empP:lastName    ?name
+FILTER (?name = "Smith"^^xsd:string)
+}
+""").get
+    assert(transformed === expected)
+  }
+
+  /* Rule used for several examples. */
   val GlobalSparqlParser = Sparql()
   val Emp_TaskToFoaf = GlobalSparqlParser.parseAll(GlobalSparqlParser.construct, """
   PREFIX foaf : <http://xmlns.com/foaf/0.1/>
@@ -105,6 +122,7 @@
          ?pair task:manager    ?man .
          ?man  empP:lastName   ?mname }
   """).get // "
+  /* Make error output a bit more terse. */
   val Emp_TaskToFoaf_abbr = Map[String,String]("<http://xmlns.com/foaf/0.1/last_name>" -> "foaf:last_name", 
                                                "<http://xmlns.com/foaf/0.1/knows>" -> "foaf:knows",
                                                "<http://hr.example/DB/Employee#lastName>" -> "Employee:lastName",