+ test quuery with only a triple with a constant in O position
authorEric Prud'hommeaux <eric@w3.org>
Sun, 28 Feb 2010 15:08:32 -0500
changeset 188 636ceb7f6d4d
parent 187 02d1b3ee9362
child 189 5289beae5a4e
+ test quuery with only a triple with a constant in O position
src/test/scala/SparqlToSparqlTest.scala
src/test/scala/SparqlToSparqlToSqlTest.scala
--- a/src/test/scala/SparqlToSparqlTest.scala	Sun Feb 28 15:07:28 2010 -0500
+++ b/src/test/scala/SparqlToSparqlTest.scala	Sun Feb 28 15:08:32 2010 -0500
@@ -80,6 +80,36 @@
     assert(transformed === expected)
   }
 
+  test("match only const in rule") {
+    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  a    foaf:Person
+}
+""").get
+    val flname = sparqlParser.parseAll(sparqlParser.construct, """
+PREFIX foaf : <http://xmlns.com/foaf/0.1/>
+PREFIX empP : <http://hr.example/DB/Employee#>
+CONSTRUCT { ?who a               foaf:Person .
+            ?who foaf:first_name ?fname .
+            ?who foaf:last_name  ?lname }
+    WHERE { ?who empP:firstName  ?fname .
+            ?who empP:lastName   ?lname }
+""").get
+    val transformed = SparqlToSparql(query, List(flname))
+    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:firstName    ?_0_fname .
+?emp  empP:lastName     ?_0_lname .
+}
+""").get
+    assert(transformed == expected)
+  }
+
   test("foaf:last_name FILTER") {
     val sparqlParser = Sparql()
     val query = sparqlParser.parseAll(sparqlParser.select, """
--- a/src/test/scala/SparqlToSparqlToSqlTest.scala	Sun Feb 28 15:07:28 2010 -0500
+++ b/src/test/scala/SparqlToSparqlToSqlTest.scala	Sun Feb 28 15:08:32 2010 -0500
@@ -71,7 +71,8 @@
     val hr2foaf = sparqlParser.parseAll(sparqlParser.construct, """
 PREFIX foaf : <http://xmlns.com/foaf/0.1/>
 PREFIX empP : <http://hr.example/DB/Employee#>
-CONSTRUCT { ?who foaf:first_name ?fname .
+CONSTRUCT { ?who a               foaf:Person .
+            ?who foaf:first_name ?fname .
             ?who foaf:last_name  ?lname }
     WHERE { ?who empP:firstName  ?fname .
             ?who empP:lastName   ?lname }
@@ -80,6 +81,11 @@
     val sqlParser = Sql()
     val expected = sqlParser.parseAll(sqlParser.createview, """
 CREATE VIEW triples AS
+  SELECT "<http://xmlns.com/foaf/0.1/Person>" AS O, "<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>" AS P, CONCAT("http://hr.example/DB/", "Employee", "/", "empid", ".", R_S.empid, "#record") AS S
+    FROM Employee AS R_S
+   WHERE (R_S.firstName IS NOT NULL)
+     AND (R_S.lastName IS NOT NULL)
+UNION
   SELECT CONCAT("'", R_S.firstName, "'^^<http://www.w3.org/2001/XMLSchema#string>") AS O, "<http://xmlns.com/foaf/0.1/first_name>" AS P, CONCAT("http://hr.example/DB/", "Employee", "/", "empid", ".", R_S.empid, "#record") AS S
     FROM Employee AS R_S
    WHERE (R_S.empid IS NOT NULL)
@@ -100,7 +106,7 @@
 CREATE TABLE Person (ID INT PRIMARY KEY, MiddleName STRING, DateOfBirth DATE, SexDE INT, PRIMARY KEY (ID), FOREIGN KEY (SexDE) REFERENCES Sex_DE(ID));
 CREATE TABLE Sex_DE (ID INT PRIMARY KEY, EntryName STRING);
 CREATE TABLE Item_Medication (ID INT PRIMARY KEY, PRIMARY KEY (ID), PatientID INT, FOREIGN KEY (PatientID) REFERENCES Person(ID), PerformedDTTM DATE, EntryName STRING);
-CREATE TABLE Medication (ID INT PRIMARY KEY, PRIMARY KEY (ID), ItemID INT, FOREIGN KEY (ItemID) REFERENCES Item_Medication(ID), MedDictDE INT, FOREIGN KEY (MedDictDE) REFERENCES Medication_DE(ID));
+CREATE TABLE Medication (ID INT PRIMARY KEY, PRIMARY KEY (ID), ItemID INT, FOREIGN KEY (ItemID) REFERENCES Item_Medication(ID), MedDictDE INT, FOREIGN KEY (MedDictDE) REFERENCES Medication_DE(ID), DaysToTake INT);
 CREATE TABLE Medication_DE (ID INT PRIMARY KEY, NDC INT);
 CREATE TABLE NDCcodes (ID INT PRIMARY KEY, NDC INT, ingredient INT);
 """
@@ -328,11 +334,13 @@
 
 //   test("hospital as view") {
 //     val sparqlParser = Sparql()
-//     val view = toView(List(db2hl7), HR, StemURI("http://hospital.example/DB/"))
-//     val sqlParser = Sql()
-//     val expected = sqlParser.parseAll(sqlParser.createview, """
-// """).get
-//     assert(expected === view)
+//     println("hospital view...")
+//     val view = toView(List(db2hl7), hosp1, StemURI("http://hospital.example/DB/"))
+//     println("hospital view: " + view)
+// //     val sqlParser = Sql()
+// //     val expected = sqlParser.parseAll(sqlParser.createview, """
+// // """).get
+// //     assert(expected === view)
 //   }
 
 }