--- a/directmapping-test/src/main/scala/DirectMappingTestSuite.scala Mon Jan 31 15:16:20 2011 -0500
+++ b/directmapping-test/src/main/scala/DirectMappingTestSuite.scala Tue Feb 01 19:44:35 2011 -0500
@@ -55,6 +55,7 @@
def testDirectMapping(testName:String, db:Database, expectedGraph:Graph):Unit =
test(testName) {
val computedGraph = directDB(db)
+ DirectMapping.NextBNode = 97 // @@ call the "i'd like to reset my fresh variables to 0 so i can have predictable node names" function
assert (expectedGraph === computedGraph)
}
@@ -64,25 +65,38 @@
testDirectMapping(testName, db, expectedGraph)
}
- def testDirectMapping(testName:String):Unit =
+ def testDirectMappingSpec(testName:String):Unit =
testDirectMapping(testName,
new File("./sharedtestdata/directmappingspec/" + testName + ".sql"),
new File("./sharedtestdata/directmappingspec/" + testName + ".ttl"))
+ def testDirectMapping(testName:String):Unit =
+ testDirectMapping(testName,
+ new File("./sharedtestdata/rdb2rdf-wg-tests/" + testName + ".sql"),
+ new File("./sharedtestdata/rdb2rdf-wg-tests/" + testName + ".ttl"))
+
// 2 People 1 Addresses
- testDirectMapping("emp_addr")
+ testDirectMappingSpec("emp_addr")
// 2 People 1 Addresses 1 Department
- testDirectMapping("multi_key")
+ testDirectMappingSpec("multi_key")
// 2 People 1 Addresses 1 Department 2 Projects 1 Task
- testDirectMapping("ref_no_pk")
+ testDirectMappingSpec("ref_no_pk")
// 1 People 1 Addresses 1 Offices
- testDirectMapping("hier_tabl_proto")
+ testDirectMappingSpec("hier_tabl_proto")
// 1 People 1 Addresses 1 Offices 1 ExectutiveOffices
- testDirectMapping("hier_tabl")
+ testDirectMappingSpec("hier_tabl")
+ // !!! goes in different module
+
+ testDirectMapping("1table0rows")
+ testDirectMapping("1table1row")
+ testDirectMapping("1table2columns1row")
+ testDirectMapping("1table3columns1row")
+ testDirectMapping("varchar_varchar_1row")
+ testDirectMapping("2duplicates0nulls")
}
--- a/directmapping/src/main/scala/DirectMapping.scala Mon Jan 31 15:16:20 2011 -0500
+++ b/directmapping/src/main/scala/DirectMapping.scala Tue Feb 01 19:44:35 2011 -0500
@@ -143,7 +143,10 @@
def directS (s:Node, t:Tuple, r:Relation, nodes:NodeMap, db:Database) : Set[Triple] = {
( references(t, r) map { directN(s, _, r, t, nodes) } ) ++
- ( scalars(t, r) flatMap { directL(r.name, s, _, r.header, t) } )
+ ( scalars(t, r) flatMap { directL(r.name, s, _, r.header, t) } ) +
+ Triple(SubjectNode(s),
+ PredicateIRI(IRI("http://www.w3.org/1999/02/22-rdf-syntax-ns#type")),
+ ObjectNode(NodeIRI(IRI(UE(relName2string(r.name))))))
}
// should be done by BNode
@@ -206,8 +209,11 @@
case Datatype.STRING => IRI("http://www.w3.org/2001/XMLSchema#string")
}
- def literalmap (l:LexicalValue, d:Datatype) : TypedLiteral =
- TypedLiteral(l.s, XSD(d))
+ def literalmap (l:LexicalValue, d:Datatype) : Literal =
+ d match {
+ case Datatype.STRING => PlainLiteral(l.s, None)
+ case _ => TypedLiteral(l.s, XSD(d))
+ }
def UE (s:String) : String = s.replaceAll(" ", "+")
--- a/rdf/src/main/scala/RDF.scala Mon Jan 31 15:16:20 2011 -0500
+++ b/rdf/src/main/scala/RDF.scala Tue Feb 01 19:44:35 2011 -0500
@@ -53,6 +53,7 @@
val StringDatatype = IRI("http://www.w3.org/2001/XMLSchema#string")
val IntegerDatatype = IRI("http://www.w3.org/2001/XMLSchema#integer")
+ val FloatDatatype = IRI("http://www.w3.org/2001/XMLSchema#float")
val DateDatatype = IRI("http://www.w3.org/2001/XMLSchema#date")
val DateTimeDatatype = IRI("http://www.w3.org/2001/XMLSchema#dateTime")
--- a/sharedtestdata/directmappingspec/emp_addr.ttl Mon Jan 31 15:16:20 2011 -0500
+++ b/sharedtestdata/directmappingspec/emp_addr.ttl Tue Feb 01 19:44:35 2011 -0500
@@ -1,9 +1,11 @@
-@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
+<People/ID.7#_> a <People> .
<People/ID.7#_> <People#ID> 7 .
-<People/ID.7#_> <People#fname> "Bob"^^<http://www.w3.org/2001/XMLSchema#string> .
+<People/ID.7#_> <People#fname> "Bob" .
<People/ID.7#_> <People#addr> <Addresses/ID.18#_> .
+<People/ID.8#_> a <People> .
<People/ID.8#_> <People#ID> 8 .
-<People/ID.8#_> <People#fname> "Sue"^^xsd:string .
+<People/ID.8#_> <People#fname> "Sue" .
+<Addresses/ID.18#_> a <Addresses> .
<Addresses/ID.18#_> <Addresses#ID> 18 .
-<Addresses/ID.18#_> <Addresses#city> "Cambridge"^^xsd:string .
-<Addresses/ID.18#_> <Addresses#state> "MA"^^xsd:string .
+<Addresses/ID.18#_> <Addresses#city> "Cambridge" .
+<Addresses/ID.18#_> <Addresses#state> "MA" .
--- a/sharedtestdata/directmappingspec/hier_tabl.ttl Mon Jan 31 15:16:20 2011 -0500
+++ b/sharedtestdata/directmappingspec/hier_tabl.ttl Tue Feb 01 19:44:35 2011 -0500
@@ -1,15 +1,19 @@
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
+<Addresses/ID.18#_> a <ExecutiveOffices> .
<Addresses/ID.18#_> <ExecutiveOffices#ID> 18 .
-<Addresses/ID.18#_> <ExecutiveOffices#desk> "oak"^^xsd:string .
+<Addresses/ID.18#_> <ExecutiveOffices#desk> "oak" .
+<Addresses/ID.18#_> a <Offices> .
<Addresses/ID.18#_> <Offices#ID> 18 .
<Addresses/ID.18#_> <Offices#building> 32 .
-<Addresses/ID.18#_> <Offices#ofcNumber> "G528"^^xsd:string .
+<Addresses/ID.18#_> <Offices#ofcNumber> "G528" .
+<People/ID.7#_> a <People> .
<People/ID.7#_> <People#ID> 7 .
-<People/ID.7#_> <People#fname> "Bob"^^xsd:string .
+<People/ID.7#_> <People#fname> "Bob" .
<People/ID.7#_> <People#addr> <Addresses/ID.18#_> .
+<Addresses/ID.18#_> a <Addresses> .
<Addresses/ID.18#_> <Addresses#ID> 18 .
-<Addresses/ID.18#_> <Addresses#city> "Cambridge"^^xsd:string .
-<Addresses/ID.18#_> <Addresses#state> "MA"^^xsd:string .
+<Addresses/ID.18#_> <Addresses#city> "Cambridge" .
+<Addresses/ID.18#_> <Addresses#state> "MA" .
--- a/sharedtestdata/directmappingspec/hier_tabl_proto.ttl Mon Jan 31 15:16:20 2011 -0500
+++ b/sharedtestdata/directmappingspec/hier_tabl_proto.ttl Tue Feb 01 19:44:35 2011 -0500
@@ -1,12 +1,15 @@
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
+<Addresses/ID.18#_> a <Offices> .
<Addresses/ID.18#_> <Offices#ID> 18 .
<Addresses/ID.18#_> <Offices#building> 32 .
-<Addresses/ID.18#_> <Offices#ofcNumber> "G528"^^xsd:string .
+<Addresses/ID.18#_> <Offices#ofcNumber> "G528" .
+<People/ID.7#_> a <People> .
<People/ID.7#_> <People#ID> 7 .
-<People/ID.7#_> <People#fname> "Bob"^^xsd:string .
+<People/ID.7#_> <People#fname> "Bob" .
<People/ID.7#_> <People#addr> <Addresses/ID.18#_> .
+<Addresses/ID.18#_> a <Addresses> .
<Addresses/ID.18#_> <Addresses#ID> 18 .
-<Addresses/ID.18#_> <Addresses#city> "Cambridge"^^xsd:string .
-<Addresses/ID.18#_> <Addresses#state> "MA"^^xsd:string .
+<Addresses/ID.18#_> <Addresses#city> "Cambridge" .
+<Addresses/ID.18#_> <Addresses#state> "MA" .
--- a/sharedtestdata/directmappingspec/multi_key.ttl Mon Jan 31 15:16:20 2011 -0500
+++ b/sharedtestdata/directmappingspec/multi_key.ttl Tue Feb 01 19:44:35 2011 -0500
@@ -1,19 +1,23 @@
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
-<People/ID.7#_> <People#deptName> "accounting"^^xsd:string .
-<People/ID.7#_> <People#deptCity> "Cambridge"^^xsd:string .
+<People/ID.7#_> <People#deptName> "accounting" .
+<People/ID.7#_> <People#deptCity> "Cambridge" .
<People/ID.7#_> <People#deptName_deptCity> <Department/ID.23#_> .
+<Department/ID.23#_> a <Department> .
<Department/ID.23#_> <Department#ID> 23 .
-<Department/ID.23#_> <Department#name> "accounting"^^xsd:string .
-<Department/ID.23#_> <Department#city> "Cambridge"^^xsd:string .
+<Department/ID.23#_> <Department#name> "accounting" .
+<Department/ID.23#_> <Department#city> "Cambridge" .
<Department/ID.23#_> <Department#manager> <People/ID.8#_> .
+<People/ID.7#_> a <People> .
<People/ID.7#_> <People#ID> 7 .
-<People/ID.7#_> <People#fname> "Bob"^^xsd:string .
+<People/ID.7#_> <People#fname> "Bob" .
<People/ID.7#_> <People#addr> <Addresses/ID.18#_> .
+<People/ID.8#_> a <People> .
<People/ID.8#_> <People#ID> 8 .
-<People/ID.8#_> <People#fname> "Sue"^^xsd:string .
+<People/ID.8#_> <People#fname> "Sue" .
+<Addresses/ID.18#_> a <Addresses> .
<Addresses/ID.18#_> <Addresses#ID> 18 .
-<Addresses/ID.18#_> <Addresses#city> "Cambridge"^^xsd:string .
-<Addresses/ID.18#_> <Addresses#state> "MA"^^xsd:string .
+<Addresses/ID.18#_> <Addresses#city> "Cambridge" .
+<Addresses/ID.18#_> <Addresses#state> "MA" .
--- a/sharedtestdata/directmappingspec/ref_no_pk.ttl Mon Jan 31 15:16:20 2011 -0500
+++ b/sharedtestdata/directmappingspec/ref_no_pk.ttl Tue Feb 01 19:44:35 2011 -0500
@@ -1,38 +1,45 @@
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
+_:a a <Projects> .
_:a <Projects#lead> <People/ID.8#_> .
-_:a <Projects#name> "pencil survey"^^xsd:string .
-_:a <Projects#deptName> "accounting"^^xsd:string .
-_:a <Projects#deptCity> "Cambridge"^^xsd:string .
+_:a <Projects#name> "pencil survey" .
+_:a <Projects#deptName> "accounting" .
+_:a <Projects#deptCity> "Cambridge" .
_:a <Projects#deptName_deptCity> <Department/ID.23#_> .
+_:b a <Projects> .
_:b <Projects#lead> <People/ID.8#_> .
-_:b <Projects#name> "eraser survey"^^xsd:string .
-_:b <Projects#deptName> "accounting"^^xsd:string .
-_:b <Projects#deptCity> "Cambridge"^^xsd:string .
+_:b <Projects#name> "eraser survey" .
+_:b <Projects#deptName> "accounting" .
+_:b <Projects#deptCity> "Cambridge" .
_:b <Projects#deptName_deptCity> <Department/ID.23#_> .
+<TaskAssignments/worker.7_project.pencil+survey#_> a <TaskAssignments> .
<TaskAssignments/worker.7_project.pencil+survey#_> <TaskAssignments#worker> <People/ID.7#_> .
-<TaskAssignments/worker.7_project.pencil+survey#_> <TaskAssignments#project> "pencil survey"^^xsd:string .
-<TaskAssignments/worker.7_project.pencil+survey#_> <TaskAssignments#deptName> "accounting"^^xsd:string .
-<TaskAssignments/worker.7_project.pencil+survey#_> <TaskAssignments#deptCity> "Cambridge"^^xsd:string .
+<TaskAssignments/worker.7_project.pencil+survey#_> <TaskAssignments#project> "pencil survey" .
+<TaskAssignments/worker.7_project.pencil+survey#_> <TaskAssignments#deptName> "accounting" .
+<TaskAssignments/worker.7_project.pencil+survey#_> <TaskAssignments#deptCity> "Cambridge" .
<TaskAssignments/worker.7_project.pencil+survey#_> <TaskAssignments#deptName_deptCity> <Department/ID.23#_> .
<TaskAssignments/worker.7_project.pencil+survey#_> <TaskAssignments#project_deptName_deptCity> _:a .
-<People/ID.7#_> <People#deptName> "accounting"^^xsd:string .
-<People/ID.7#_> <People#deptCity> "Cambridge"^^xsd:string .
+<People/ID.7#_> a <People> .
+<People/ID.7#_> <People#deptName> "accounting" .
+<People/ID.7#_> <People#deptCity> "Cambridge" .
<People/ID.7#_> <People#deptName_deptCity> <Department/ID.23#_> .
+<Department/ID.23#_> a <Department> .
<Department/ID.23#_> <Department#ID> 23 .
-<Department/ID.23#_> <Department#name> "accounting"^^xsd:string .
-<Department/ID.23#_> <Department#city> "Cambridge"^^xsd:string .
+<Department/ID.23#_> <Department#name> "accounting" .
+<Department/ID.23#_> <Department#city> "Cambridge" .
<Department/ID.23#_> <Department#manager> <People/ID.8#_> .
<People/ID.7#_> <People#ID> 7 .
-<People/ID.7#_> <People#fname> "Bob"^^xsd:string .
+<People/ID.7#_> <People#fname> "Bob" .
<People/ID.7#_> <People#addr> <Addresses/ID.18#_> .
+<People/ID.8#_> a <People> .
<People/ID.8#_> <People#ID> 8 .
-<People/ID.8#_> <People#fname> "Sue"^^xsd:string .
+<People/ID.8#_> <People#fname> "Sue" .
+<Addresses/ID.18#_> a <Addresses> .
<Addresses/ID.18#_> <Addresses#ID> 18 .
-<Addresses/ID.18#_> <Addresses#city> "Cambridge"^^xsd:string .
-<Addresses/ID.18#_> <Addresses#state> "MA"^^xsd:string .
+<Addresses/ID.18#_> <Addresses#city> "Cambridge" .
+<Addresses/ID.18#_> <Addresses#state> "MA" .
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sharedtestdata/tests/1table0rows.sql Tue Feb 01 19:44:35 2011 -0500
@@ -0,0 +1,3 @@
+CREATE TABLE Student (
+ Name VARCHAR(50)
+);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sharedtestdata/tests/1table0rows.ttl Tue Feb 01 19:44:35 2011 -0500
@@ -0,0 +1,1 @@
+@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sharedtestdata/tests/1table1row.sql Tue Feb 01 19:44:35 2011 -0500
@@ -0,0 +1,4 @@
+CREATE TABLE Student (
+ Name VARCHAR(50)
+);
+INSERT INTO Student (Name) VALUES ("Venus");
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sharedtestdata/tests/1table1row.ttl Tue Feb 01 19:44:35 2011 -0500
@@ -0,0 +1,2 @@
+_:a <Student#Name> "Venus" .
+_:a a <Student> .
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sharedtestdata/tests/1table2columns1row.sql Tue Feb 01 19:44:35 2011 -0500
@@ -0,0 +1,5 @@
+CREATE TABLE Student (
+ ID INT,
+ Name VARCHAR(50)
+);
+INSERT INTO Student (ID, Name) VALUES(10,"Venus");
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sharedtestdata/tests/1table2columns1row.ttl Tue Feb 01 19:44:35 2011 -0500
@@ -0,0 +1,3 @@
+_:a a <Student> .
+_:a <Student#ID> 10 .
+_:a <Student#Name> "Venus" .
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sharedtestdata/tests/1table3columns1row.sql Tue Feb 01 19:44:35 2011 -0500
@@ -0,0 +1,6 @@
+CREATE TABLE Student (
+ ID INT,
+ FirstName VARCHAR(50),
+ LastName VARCHAR(50)
+);
+INSERT INTO Student (ID, FirstName, LastName) VALUES (10,"Venus", "Williams");
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sharedtestdata/tests/1table3columns1row.ttl Tue Feb 01 19:44:35 2011 -0500
@@ -0,0 +1,4 @@
+_:a a <Student> .
+_:a <Student#ID> 10 .
+_:a <Student#FirstName> "Venus" .
+_:a <Student#LastName> "Williams" .
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sharedtestdata/tests/2duplicates0nulls.sql Tue Feb 01 19:44:35 2011 -0500
@@ -0,0 +1,7 @@
+CREATE TABLE IOUs (
+ fname CHAR(20),
+ lname CHAR(20),
+ amount FLOAT);
+INSERT INTO IOUs (fname, lname, amount) VALUES ("Bob", "Smith", 30);
+INSERT INTO IOUs (fname, lname, amount) VALUES ("Sue", "Jones", 20);
+INSERT INTO IOUs (fname, lname, amount) VALUES ("Bob", "Smith", 30);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sharedtestdata/tests/2duplicates0nulls.ttl Tue Feb 01 19:44:35 2011 -0500
@@ -0,0 +1,17 @@
+@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
+
+_:a a <IOUs> .
+_:a <IOUs#fname> "Bob" .
+_:a <IOUs#lname> "Smith" .
+_:a <IOUs#amount> "30"^^xsd:float .
+
+_:b a <IOUs> .
+_:b <IOUs#fname> "Sue" .
+_:b <IOUs#lname> "Jones" .
+_:b <IOUs#amount> "20"^^xsd:float .
+
+_:c a <IOUs> .
+_:c <IOUs#fname> "Bob" .
+_:c <IOUs#lname> "Smith" .
+_:c <IOUs#amount> "30"^^xsd:float .
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sharedtestdata/tests/varchar_varchar_1row.sql Tue Feb 01 19:44:35 2011 -0500
@@ -0,0 +1,5 @@
+CREATE TABLE Student_Sport(
+ Student VARCHAR(50),
+ Sport VARCHAR(50)
+);
+INSERT INTO Student_Sport (Student,Sport) VALUES ("Venus", "Tennis");
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sharedtestdata/tests/varchar_varchar_1row.ttl Tue Feb 01 19:44:35 2011 -0500
@@ -0,0 +1,3 @@
+_:a a <Student_Sport> .
+_:a <Student_Sport#Student> "Venus" .
+_:a <Student_Sport#Sport> "Tennis" .
--- a/sql/src/main/scala/SQL.scala Mon Jan 31 15:16:20 2011 -0500
+++ b/sql/src/main/scala/SQL.scala Tue Feb 01 19:44:35 2011 -0500
@@ -267,10 +267,13 @@
def typpe:Parser[RDB.Datatype] = (
"INT" ~ opt(size) ^^ { case _ => RDB.Datatype.INTEGER } // alias for INTEGER
| "INTEGER" ~ opt(size)^^ { case _ => RDB.Datatype.INTEGER }
+ | "integer" ~ opt(size)^^ { case _ => RDB.Datatype.INTEGER } // @@ handle case-insensitivity
| "DOUBLE" ^^ { case _ => RDB.Datatype.DOUBLE }
+ | "FLOAT" ^^ { case _ => RDB.Datatype.FLOAT }
| "STRING" ^^ { case _ => RDB.Datatype.STRING }
| "CHAR" ~ opt(size) ^^ { case _ => RDB.Datatype.STRING }
| "VARCHAR" ~ opt(size) ^^ { case _ => RDB.Datatype.STRING }
+ | "varchar" ~ opt(size) ^^ { case _ => RDB.Datatype.STRING }
| "DATETIME" ^^ { case _ => RDB.Datatype.DATETIME }
| "DATE" ^^ { case _ => RDB.Datatype.DATE }
)
--- a/turtle/src/main/scala/turtle.scala Mon Jan 31 15:16:20 2011 -0500
+++ b/turtle/src/main/scala/turtle.scala Tue Feb 01 19:44:35 2011 -0500
@@ -7,6 +7,7 @@
object MyParsers extends RegexParsers {
val uri = """[a-zA-Z0-9:/#_\.\-\+]+""".r
val integer = """[0-9]+""".r
+ val float = """([0-9]+)?\.([0-9]+)?""".r
val name = """[a-zA-Z][a-zA-Z0-9_-]*|[a-zA-Z_][a-zA-Z0-9_]+""".r
var prefixes:Map[String, String] = Map()
var nextBNode = 1
@@ -77,15 +78,20 @@
"_:"~name ^^ { case "_:"~name => BNode(name) }
def literal:Parser[Literal] = (
- stringLiteral~"^^"~qnameORuri ^^ {
+ stringLiteral~"^^"~qnameORuri ^^ {
case lit~"^^"~dt => TypedLiteral(lit.substring(1,lit.size - 1), dt match {
case IRI("http://www.w3.org/2001/XMLSchema#string") => StringDatatype
case IRI("http://www.w3.org/2001/XMLSchema#integer") => IntegerDatatype
+ case IRI("http://www.w3.org/2001/XMLSchema#float") => FloatDatatype
case IRI("http://www.w3.org/2001/XMLSchema#date") => DateDatatype
case IRI("http://www.w3.org/2001/XMLSchema#dateTime") => DateTimeDatatype
case x => error("only programed to deal with string and integer, not " + x)
})
}
+ | stringLiteral ^^ {
+ case lit => PlainLiteral(lit.substring(1,lit.size - 1), None)
+ }
+ | float ^^ { l => TypedLiteral(l, FloatDatatype) }
| integer ^^ { l => TypedLiteral(l, IntegerDatatype) }
)
}