--- a/.hgignore Thu Dec 10 13:48:01 2009 -0500
+++ b/.hgignore Thu Dec 10 14:15:16 2009 -0500
@@ -9,3 +9,5 @@
*~
*.class
*.log
+\#*
+.\#*
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/scala/RDF.scala Thu Dec 10 14:15:16 2009 -0500
@@ -0,0 +1,25 @@
+package w3c.sw
+
+import java.net.URI
+
+case class RDFTriple()
+
+sealed abstract class RDFSubject()
+case class RDFSubjectUri(uri:URI) extends RDFSubject
+case class RDFSubjectBlankNode(b:BlankNode) extends RDFSubject
+
+case class RDFPredicate(uri:URI)
+
+sealed abstract class RDFObject()
+case class RDFObjectUri(uri:URI) extends RDFObject
+case class RDFObjectBlankNode(b:BlankNode) extends RDFObject
+
+case class BlankNode(debugName:String)
+
+case class RDFLiteral(lexicalForm:String, datatype:Datatype)
+case class Datatype(uri:URI)
+
+object RDFLiteral {
+ val StringDatatype = Datatype(new URI("http://www.w3.org/2001/XMLSchema#string"))
+ val IntegerDatatype = Datatype(new URI("http://www.w3.org/2001/XMLSchema#integer"))
+}
--- a/src/main/scala/SPARQL.scala Thu Dec 10 13:48:01 2009 -0500
+++ b/src/main/scala/SPARQL.scala Thu Dec 10 14:15:16 2009 -0500
@@ -21,22 +21,13 @@
sealed abstract class O
case class OUri(uri:URI) extends O
case class OVar(v:Var) extends O
-case class OLit(lit:Lit) extends O
+case class OLit(lit:SparqlLiteral) extends O
sealed abstract class P
case class PUri(stem:Stem, rel:Rel, attr:Attr) extends P
case class PVar(v:Var) extends P
-// sealed abstract class Lit
-// case class LitInt(i:Int) extends Lit
-// case class LitString(s:String) extends Lit
-case class Lit(lexicalForm:String, datatype:Datatype)
-case class Datatype(uri:URI)
-
-object Lit {
- val StringDatatype = Datatype(new URI("http://www.w3.org/2001/XMLSchema#string"))
- val IntegerDatatype = Datatype(new URI("http://www.w3.org/2001/XMLSchema#integer"))
-}
+case class SparqlLiteral(lit:RDFLiteral)
case class Stem(s:String)
case class Attr(s:String)
@@ -66,14 +57,11 @@
| literal ^^ { x => OLit(x) }
)
-// case class Lit(lexicalForm:String, datatype:Datatype)
-// case class Datatype(uri:URI)
-
- def literal:Parser[Lit] = (
+ def literal:Parser[SparqlLiteral] = (
stringLiteral~"^^<http://www.w3.org/2001/XMLSchema#string>" ^^
- { case lit ~ _ => Lit(lit.substring(1,lit.size - 1), Lit.StringDatatype) }
+ { case lit ~ _ => SparqlLiteral(RDFLiteral(lit.substring(1,lit.size - 1), RDFLiteral.StringDatatype)) }
| stringLiteral~"^^<http://www.w3.org/2001/XMLSchema#integer>" ^^
- { case lit ~ _ => Lit(lit.substring(1,lit.size - 1), Lit.IntegerDatatype) }
+ { case lit ~ _ => SparqlLiteral(RDFLiteral(lit.substring(1,lit.size - 1), RDFLiteral.IntegerDatatype)) }
)
def varr:Parser[Var] = "?"~ident ^^ { case "?"~x => Var(x) }
--- a/src/test/scala/RDB2RDFTest.scala Thu Dec 10 13:48:01 2009 -0500
+++ b/src/test/scala/RDB2RDFTest.scala Thu Dec 10 14:15:16 2009 -0500
@@ -3,56 +3,8 @@
import org.scalatest.FunSuite
import java.net.URI
-class TestBank extends FunSuite {
-
- test("SQLbgp") {
- val a = Sql()
- val e = """
-SELECT emp.lastName AS empName, manager.lastName AS managName
- FROM Employee AS emp
- INNER JOIN Employee AS manager ON manager.id=emp.manager
- WHERE emp.lastName IS NOT NULL AND manager.lastName IS NOT NULL
-"""
- println(a.parseAll(a.select, e))
- }
-
- test("tup1") {
- val a = Sql()
- val e = """
-SELECT emp.lastName AS empName
- FROM Employee AS emp
- WHERE emp.manager=18 AND emp.lastName IS NOT NULL
-"""
- println(a.parseAll(a.select, e))
- }
+class RDB2RDFTest extends FunSuite {
- test("litConst1") {
- val a = Sql()
- val e = """
-SELECT emp.lastName AS empName
- FROM Employee AS emp
- INNER JOIN Employee AS manager ON emp.manager=manager.id
- AND manager.lastName="Johnson"
-WHERE emp.lastName IS NOT NULL
-"""
- println(a.parseAll(a.select, e))
- }
-
- test("filter1") {
- val a = Sql()
- val e = """
-SELECT emp.lastName AS empName, grandManager.lastName AS grandManagName
- FROM Employee AS emp
- INNER JOIN Manage AS lower ON lower.manages=emp.id
- INNER JOIN Employee AS manager ON manager.id=lower.manager
- AND manager.birthday < emp.birthday
- INNER JOIN Manage AS upper ON upper.manages=manager.id
- INNER JOIN Employee AS grandManager ON grandManager.id=upper.manager
- AND grandManager.birthday < manager.birthday
- WHERE emp.lastName IS NOT NULL AND grandManager.lastName IS NOT NULL
-"""
- println(a.parseAll(a.select, e))
- }
}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/test/scala/SQLTest.scala Thu Dec 10 14:15:16 2009 -0500
@@ -0,0 +1,58 @@
+package w3c.sw
+
+import org.scalatest.FunSuite
+import java.net.URI
+
+class SQLTest extends FunSuite {
+
+ test("SQLbgp") {
+ val a = Sql()
+ val e = """
+SELECT emp.lastName AS empName, manager.lastName AS managName
+ FROM Employee AS emp
+ INNER JOIN Employee AS manager ON manager.id=emp.manager
+ WHERE emp.lastName IS NOT NULL AND manager.lastName IS NOT NULL
+"""
+ println(a.parseAll(a.select, e))
+ }
+
+ test("tup1") {
+ val a = Sql()
+ val e = """
+SELECT emp.lastName AS empName
+ FROM Employee AS emp
+ WHERE emp.manager=18 AND emp.lastName IS NOT NULL
+"""
+ println(a.parseAll(a.select, e))
+ }
+
+ test("litConst1") {
+ val a = Sql()
+ val e = """
+SELECT emp.lastName AS empName
+ FROM Employee AS emp
+ INNER JOIN Employee AS manager ON emp.manager=manager.id
+ AND manager.lastName="Johnson"
+WHERE emp.lastName IS NOT NULL
+"""
+ println(a.parseAll(a.select, e))
+ }
+
+ test("filter1") {
+ val a = Sql()
+ val e = """
+SELECT emp.lastName AS empName, grandManager.lastName AS grandManagName
+ FROM Employee AS emp
+ INNER JOIN Manage AS lower ON lower.manages=emp.id
+ INNER JOIN Employee AS manager ON manager.id=lower.manager
+ AND manager.birthday < emp.birthday
+ INNER JOIN Manage AS upper ON upper.manages=manager.id
+ INNER JOIN Employee AS grandManager ON grandManager.id=upper.manager
+ AND grandManager.birthday < manager.birthday
+ WHERE emp.lastName IS NOT NULL AND grandManager.lastName IS NOT NULL
+"""
+ println(a.parseAll(a.select, e))
+ }
+
+
+}
--- a/src/test/scala/SparqlTest.scala Thu Dec 10 13:48:01 2009 -0500
+++ b/src/test/scala/SparqlTest.scala Thu Dec 10 14:15:16 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(Lit("bob",Datatype(new URI("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"))))))))
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(Lit("21",Datatype(new URI("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"))))))))
assert(expected === (a.parseAll(a.triplepatterns, e).get))
}