--- a/src/main/scala/SparqlToSql.scala Sun Jan 31 20:30:34 2010 -0500
+++ b/src/main/scala/SparqlToSql.scala Tue Feb 02 15:52:27 2010 -0500
@@ -116,16 +116,16 @@
*/
def relVarFromS(s:sparql.S):sql.RelVar = {
s match {
- case sparql.SUri(ob) => relVarFromNode(ob)
- case sparql.SVar(v) => relVarFromVar(v)
+ case u:sparql.Uri => relVarFromNode(u)
+ case v:sparql.Var => relVarFromVar(v)
}
}
def relVarFromO(o:sparql.O):sql.RelVar = {
o match {
- case sparql.OUri(ob) => relVarFromNode(ob)
- case sparql.OVar(v) => relVarFromVar(v)
- case sparql.OLit(l) => relVarFromLiteral(l)
+ case u:sparql.Uri => relVarFromNode(u)
+ case v:sparql.Var => relVarFromVar(v)
+ case l:sparql.Literal => relVarFromLiteral(l)
}
}
@@ -236,8 +236,8 @@
def bindOnPredicate(db:sql.DatabaseDesc, stateP:R2RState, triple:sparql.TriplePattern, enforceForeignKeys:Boolean):R2RState = {
val sparql.TriplePattern(s, p, o) = triple
p match {
- case sparql.PVar(v) => error("variable predicates require tedious enumeration; too tedious for me.")
- case sparql.PUri(uri) => {
+// case v:sparql.Var => error("variable predicate " + +" require tedious enumeration; too tedious for me.")
+ case uri:sparql.Uri => {
val PUri(stem, spRel, spAttr) = parsePredicateURI(uri)
/* Attributes that come from the predicate: */
val rel = sql.Relation(sql.Name(spRel.s))
@@ -247,8 +247,8 @@
/* Attributes that come from the subject: */
val objattr = sql.RelVarAttr(relvar, attr)
val state_postSubj = s match {
- case sparql.SUri(u) => uriConstraint(stateP, sql.RelVarAttr(relvar, db.relationdescs(rel).primarykey.get), parseObjectURI(u), true)
- case sparql.SVar(v) => varConstraint(stateP, relvar, db.relationdescs(rel).primarykey, v, db, rel)
+ case u:sparql.Uri => uriConstraint(stateP, sql.RelVarAttr(relvar, db.relationdescs(rel).primarykey.get), parseObjectURI(u), true)
+ case v:sparql.Var => varConstraint(stateP, relvar, db.relationdescs(rel).primarykey, v, db, rel)
}
val state_subjJoin = R2RState(state_postSubj.joins + sql.InnerJoin(sql.AliasedResource(rel,relvar), None), state_postSubj.varmap, state_postSubj.exprs)
@@ -284,9 +284,9 @@
case sql.Value(dt) => (objattr, rel, dt, state_subjJoin)
}
o match {
- case sparql.OLit(l) => literalConstraint(state_fkeys, targetattr, l, dt)
- case sparql.OUri(u) => uriConstraint (state_fkeys, targetattr, parseObjectURI(u), enforceForeignKeys)
- case sparql.OVar(v) => varConstraint (state_fkeys, targetattr.relvar, Some(targetattr.attribute), v, db, targetrel)
+ case l:sparql.Literal => literalConstraint(state_fkeys, targetattr, l, dt)
+ case u:sparql.Uri => uriConstraint (state_fkeys, targetattr, parseObjectURI(u), enforceForeignKeys)
+ case v:sparql.Var => varConstraint (state_fkeys, targetattr.relvar, Some(targetattr.attribute), v, db, targetrel)
}
}
}
@@ -295,11 +295,11 @@
def findVars(triple:sparql.TriplePattern):Set[sparql.Var] = {
val sparql.TriplePattern(s, p, o) = triple
val varS:Set[sparql.Var] = s match {
- case sparql.SVar(v) => Set(v)
+ case v:sparql.Var => Set(v)
case _ => Set()
}
val varO:Set[sparql.Var] = o match {
- case sparql.OVar(v) => Set(v)
+ case v:sparql.Var => Set(v)
case _ => Set()
}
varS ++ varO
@@ -401,21 +401,21 @@
// sql.RelationalExpressionEq(_,_) === (x,y) => PrymaryExpressionEq(x,y)
lTerm match {
// does not handle FILTER (<x> = ?v)
- case sparql.TermUri(obj) => error("only SPARQL PrimaryExpressions with a variable on the left have been implemented: punting on " + f)
+ case f:sparql.Uri => error("only SPARQL PrimaryExpressions with a variable on the left have been implemented: punting on " + f)
// FILTER (?v = <x> && ?v = ?x && ?v = 7)
- case sparql.TermVar(v) => { // :sparql.Var
+ case v:sparql.Var => { // :sparql.Var
val l = varToAttribute(varmap, v)
val r = rTerm match {
- case sparql.TermUri(obj) => null // :sparql.Uri
- case sparql.TermVar(v) => { // :sparql.Var
+ case u:sparql.Uri => error ("!") // !!! :sparql.Uri
+ case v:sparql.Var => { // :sparql.Var
sql.PrimaryExpressionAttr(varToAttribute(varmap, v))
}
- case sparql.TermLit(lit) => null // :sparql.Literal => sql.PrimaryExpressionTyped(sql.Datatype, lit.n)
+ case sparql.Literal(lit) => error ("!") // !!! :sparql.Literal => sql.PrimaryExpressionTyped(sql.Datatype, lit.n)
}
sqlexpr(sql.PrimaryExpressionAttr(l), r)
}
// does not handle FILTER (7 = ?v)
- case sparql.TermLit(lit) => error("only SPARQL PrimaryExpressions with a variable on the left have been implemented: punting on " + f)
+ case sparql.Literal(lit) => error("only SPARQL PrimaryExpressions with a variable on the left have been implemented: punting on " + f)
}
}
--- a/src/test/scala/SparqlTest.scala Sun Jan 31 20:30:34 2010 -0500
+++ b/src/test/scala/SparqlTest.scala Tue Feb 02 15:52:27 2010 -0500
@@ -11,7 +11,7 @@
val e = """
?emp <http://hr.example/DB/Employee#lastName> "bob"^^<http://www.w3.org/2001/XMLSchema#string>
"""
- val expected = TriplesBlock(List(TriplePattern(SVar(Var("emp")),PUri(Uri("http://hr.example/DB/Employee#lastName")),OLit(Literal(RDFLiteral("bob",Datatype(new URI("http://www.w3.org/2001/XMLSchema#string"))))))))
+ val expected = TriplesBlock(List(TriplePattern(Var("emp"),Uri("http://hr.example/DB/Employee#lastName"),Literal(RDFLiteral("bob",Datatype(new URI("http://www.w3.org/2001/XMLSchema#string")))))))
assert(expected === (a.parseAll(a.triplesblock, e).get))
}
@@ -20,7 +20,7 @@
val e = """
?emp <http://hr.example/DB/Employee#age> "21"^^<http://www.w3.org/2001/XMLSchema#integer>
"""
- val expected = TriplesBlock(List(TriplePattern(SVar(Var("emp")),PUri(Uri("http://hr.example/DB/Employee#age")),OLit(Literal(RDFLiteral("21",Datatype(new URI("http://www.w3.org/2001/XMLSchema#integer"))))))))
+ val expected = TriplesBlock(List(TriplePattern(Var("emp"),Uri("http://hr.example/DB/Employee#age"),Literal(RDFLiteral("21",Datatype(new URI("http://www.w3.org/2001/XMLSchema#integer")))))))
assert(expected === (a.parseAll(a.triplesblock, e).get))
}
@@ -35,17 +35,17 @@
TriplesBlock(
List(
TriplePattern(
- SVar(Var("emp")),
- PUri(Uri("http://hr.example/DB/Employee#lastName")),
- OVar(Var("empName"))),
+ Var("emp"),
+ Uri("http://hr.example/DB/Employee#lastName"),
+ Var("empName")),
TriplePattern(
- SVar(Var("emp")),
- PUri(Uri("http://hr.example/DB/Employee#manager")),
- OVar(Var("manager"))),
+ Var("emp"),
+ Uri("http://hr.example/DB/Employee#manager"),
+ Var("manager")),
TriplePattern(
- SVar(Var("manager")),
- PUri(Uri("http://hr.example/DB/Employee#lastName")),
- OVar(Var("managName")))))
+ Var("manager"),
+ Uri("http://hr.example/DB/Employee#lastName"),
+ Var("managName"))))
assert(tps === a.parseAll(a.triplesblock, e).get)
}
@@ -55,7 +55,7 @@
val e = """
?emp
"""
- val expected = SparqlTermExpression(TermVar(Var("emp")))
+ val expected = SparqlTermExpression(Var("emp"))
assert(expected === (a.parseAll(a.value, e).get))
}
@@ -64,7 +64,7 @@
val e = """
?emp<?emp
"""
- val expected = PrimaryExpressionLt(SparqlTermExpression(TermVar(Var("emp"))), SparqlTermExpression(TermVar(Var("emp"))))
+ val expected = PrimaryExpressionLt(SparqlTermExpression(Var("emp")), SparqlTermExpression(Var("emp")))
assert(expected === (a.parseAll(a.primaryexpression, e).get))
}
@@ -74,8 +74,8 @@
?manBday < ?empBday && ?grandManBday < ?manBday
"""
val expected = Expression(List(
- PrimaryExpressionLt(SparqlTermExpression(TermVar(Var("manBday"))), SparqlTermExpression(TermVar(Var("empBday")))),
- PrimaryExpressionLt(SparqlTermExpression(TermVar(Var("grandManBday"))), SparqlTermExpression(TermVar(Var("manBday"))))))
+ PrimaryExpressionLt(SparqlTermExpression(Var("manBday")), SparqlTermExpression(Var("empBday"))),
+ PrimaryExpressionLt(SparqlTermExpression(Var("grandManBday")), SparqlTermExpression(Var("manBday")))))
assert(expected === (a.parseAll(a.expression, e).get))
}
@@ -85,8 +85,8 @@
FILTER(?manBday < ?empBday && ?grandManBday < ?manBday)
"""
val expected = Expression(List(
- PrimaryExpressionLt(SparqlTermExpression(TermVar(Var("manBday"))), SparqlTermExpression(TermVar(Var("empBday")))),
- PrimaryExpressionLt(SparqlTermExpression(TermVar(Var("grandManBday"))), SparqlTermExpression(TermVar(Var("manBday"))))))
+ PrimaryExpressionLt(SparqlTermExpression(Var("manBday")), SparqlTermExpression(Var("empBday"))),
+ PrimaryExpressionLt(SparqlTermExpression(Var("grandManBday")), SparqlTermExpression(Var("manBday")))))
assert(expected === (a.parseAll(a.filter, e).get))
}
@@ -104,9 +104,9 @@
TriplesBlock(
List(
TriplePattern(
- SVar(Var("emp")),
- PUri(Uri("http://hr.example/DB/Employee#lastName")),
- OVar(Var("empName"))))))
+ Var("emp"),
+ Uri("http://hr.example/DB/Employee#lastName"),
+ Var("empName")))))
assert(tps === a.parseAll(a.select, e).get)
}
@@ -125,9 +125,9 @@
TriplesBlock(
List(
TriplePattern(
- SVar(Var("emp")),
- PUri(Uri("http://hr.example/DB/Employee#lastName")),
- OVar(Var("empName"))))))
+ Var("emp"),
+ Uri("http://hr.example/DB/Employee#lastName"),
+ Var("empName")))))
assert(tps === a.parseAll(a.select, e).get)
}
@@ -146,14 +146,14 @@
TriplesBlock(
List(
TriplePattern(
- SVar(Var("emp")),
- PUri(Uri("http://hr.example/DB/Employee#lastName")),
- OVar(Var("empName"))))),
+ Var("emp"),
+ Uri("http://hr.example/DB/Employee#lastName"),
+ Var("empName")))),
Expression(List(
- PrimaryExpressionLt(SparqlTermExpression(TermVar(Var("manBday"))),
- SparqlTermExpression(TermVar(Var("empBday")))),
- PrimaryExpressionLt(SparqlTermExpression(TermVar(Var("grandManBday"))),
- SparqlTermExpression(TermVar(Var("manBday"))))))))
+ PrimaryExpressionLt(SparqlTermExpression(Var("manBday")),
+ SparqlTermExpression(Var("empBday"))),
+ PrimaryExpressionLt(SparqlTermExpression(Var("grandManBday")),
+ SparqlTermExpression(Var("manBday")))))))
assert(tps === a.parseAll(a.select, e).get)
}
@@ -172,17 +172,17 @@
TriplesBlock(
List(
TriplePattern(
- SVar(Var("emp")),
- PUri(Uri("http://hr.example/DB/Employee#lastName")),
- OVar(Var("empName"))),
+ Var("emp"),
+ Uri("http://hr.example/DB/Employee#lastName"),
+ Var("empName")),
TriplePattern(
- SVar(Var("emp")),
- PUri(Uri("http://hr.example/DB/Employee#manager")),
- OVar(Var("manager"))),
+ Var("emp"),
+ Uri("http://hr.example/DB/Employee#manager"),
+ Var("manager")),
TriplePattern(
- SVar(Var("manager")),
- PUri(Uri("http://hr.example/DB/Employee#lastName")),
- OVar(Var("managName"))))))
+ Var("manager"),
+ Uri("http://hr.example/DB/Employee#lastName"),
+ Var("managName")))))
assert(tps === a.parseAll(a.select, e).get)
}
@@ -218,9 +218,9 @@
TriplesBlock(
List(
TriplePattern(
- SVar(Var("x")),
- PUri(Uri("http://hr.example/DB/Employee#manager")),
- OVar(Var("y"))))))
+ Var("x"),
+ Uri("http://hr.example/DB/Employee#manager"),
+ Var("y")))))
assert(tps === a.parseAll(a.select, e).get)
}
@@ -236,15 +236,15 @@
TriplesBlock(
List(
TriplePattern(
- SVar(Var("x")),
- PUri(Uri("http://hr.example/DB/Employee#manager")),
- OVar(Var("y"))))),
+ Var("x"),
+ Uri("http://hr.example/DB/Employee#manager"),
+ Var("y")))),
TriplesBlock(
List(
TriplePattern(
- SVar(Var("x")),
- PUri(Uri("http://hr.example/DB/Employee#manager")),
- OVar(Var("y"))))))))
+ Var("x"),
+ Uri("http://hr.example/DB/Employee#manager"),
+ Var("y")))))))
assert(tps === a.parseAll(a.select, e).get)
}
@@ -260,15 +260,15 @@
TriplesBlock(
List(
TriplePattern(
- SVar(Var("x")),
- PUri(Uri("http://hr.example/DB/Employee#manager")),
- OVar(Var("y"))))),
+ Var("x"),
+ Uri("http://hr.example/DB/Employee#manager"),
+ Var("y")))),
TriplesBlock(
List(
TriplePattern(
- SVar(Var("x")),
- PUri(Uri("http://hr.example/DB/Employee#manager")),
- OVar(Var("y"))))))))
+ Var("x"),
+ Uri("http://hr.example/DB/Employee#manager"),
+ Var("y")))))))
assert(tps === a.parseAll(a.select, e).get)
}
@@ -284,16 +284,16 @@
TriplesBlock(
List(
TriplePattern(
- SVar(Var("x")),
- PUri(Uri("http://hr.example/DB/Employee#manager")),
- OVar(Var("y"))))),
+ Var("x"),
+ Uri("http://hr.example/DB/Employee#manager"),
+ Var("y")))),
OptionalGraphPattern(
TriplesBlock(
List(
TriplePattern(
- SVar(Var("x")),
- PUri(Uri("http://hr.example/DB/Employee#manager")),
- OVar(Var("y")))))))))
+ Var("x"),
+ Uri("http://hr.example/DB/Employee#manager"),
+ Var("y"))))))))
assert(tps === a.parseAll(a.select, e).get)
}
@@ -309,9 +309,9 @@
TriplesBlock(
List(
TriplePattern(
- SVar(Var("x")),
- PUri(Uri("http://hr.example/DB/Employee#manager")),
- OVar(Var("y")))))))
+ Var("x"),
+ Uri("http://hr.example/DB/Employee#manager"),
+ Var("y"))))))
assert(tps === a.parseAll(a.select, e).get)
}
@@ -327,16 +327,16 @@
TriplesBlock(
List(
TriplePattern(
- SVar(Var("x")),
- PUri(Uri("http://hr.example/DB/Employee#manager")),
- OVar(Var("y"))))),
+ Var("x"),
+ Uri("http://hr.example/DB/Employee#manager"),
+ Var("y")))),
MinusGraphPattern(
TriplesBlock(
List(
TriplePattern(
- SVar(Var("x")),
- PUri(Uri("http://hr.example/DB/Employee#manager")),
- OVar(Var("y")))))))))
+ Var("x"),
+ Uri("http://hr.example/DB/Employee#manager"),
+ Var("y"))))))))
assert(tps === a.parseAll(a.select, e).get)
}
@@ -360,39 +360,39 @@
TriplesBlock(
List(
TriplePattern(
- SVar(Var("who")),
- PUri(Uri("http://hr.example/DB/Employee#lastName")),
- OLit(Literal(RDFLiteral("Smith",Datatype(new URI("http://www.w3.org/2001/XMLSchema#string")))))))),
+ Var("who"),
+ Uri("http://hr.example/DB/Employee#lastName"),
+ Literal(RDFLiteral("Smith",Datatype(new URI("http://www.w3.org/2001/XMLSchema#string"))))))),
TableDisjunction(List(
TriplesBlock(
List(
TriplePattern(
- SVar(Var("above")),
- PUri(Uri("http://hr.example/DB/Manage#manages")),
- OVar(Var("who"))),
+ Var("above"),
+ Uri("http://hr.example/DB/Manage#manages"),
+ Var("who")),
TriplePattern(
- SVar(Var("above")),
- PUri(Uri("http://hr.example/DB/Manage#manager")),
- OVar(Var("manager"))),
+ Var("above"),
+ Uri("http://hr.example/DB/Manage#manager"),
+ Var("manager")),
TriplePattern(
- SVar(Var("manager")),
- PUri(Uri("http://hr.example/DB/Employee#lastName")),
- OVar(Var("name")))
+ Var("manager"),
+ Uri("http://hr.example/DB/Employee#lastName"),
+ Var("name"))
)),
TriplesBlock(
List(
TriplePattern(
- SVar(Var("below")),
- PUri(Uri("http://hr.example/DB/Manage#manager")),
- OVar(Var("who"))),
+ Var("below"),
+ Uri("http://hr.example/DB/Manage#manager"),
+ Var("who")),
TriplePattern(
- SVar(Var("below")),
- PUri(Uri("http://hr.example/DB/Manage#manages")),
- OVar(Var("managed"))),
+ Var("below"),
+ Uri("http://hr.example/DB/Manage#manages"),
+ Var("managed")),
TriplePattern(
- SVar(Var("managed")),
- PUri(Uri("http://hr.example/DB/Employee#lastName")),
- OVar(Var("name")))
+ Var("managed"),
+ Uri("http://hr.example/DB/Employee#lastName"),
+ Var("name"))
)))))))
assert(tps === a.parseAll(a.select, e).get)
}
@@ -412,12 +412,12 @@
"""
val tps =
Select(SparqlAttributeList(List(Var("emp1Name"), Var("emp2Name"), Var("emp3Name"))),
- TableFilter(TableConjunction(List(TriplesBlock(List(TriplePattern(SVar(Var("emp1")), PUri(Uri("http://hr.example/DB/Employee#lastName")), OVar(Var("emp1Name"))))),
- OptionalGraphPattern(TriplesBlock(List(TriplePattern(SVar(Var("emp1")), PUri(Uri("http://hr.example/DB/Employee#birthday")), OVar(Var("birthday")))))),
- TriplesBlock(List(TriplePattern(SVar(Var("emp2")), PUri(Uri("http://hr.example/DB/Employee#lastName")), OVar(Var("emp2Name"))))),
- OptionalGraphPattern(TriplesBlock(List(TriplePattern(SVar(Var("emp2")), PUri(Uri("http://hr.example/DB/Employee#birthday")), OVar(Var("birthday")))))),
- TriplesBlock(List(TriplePattern(SVar(Var("emp4")),PUri(Uri("http://hr.example/DB/Employee#birthday")),OVar(Var("birthday"))))))),
- Expression(List(PrimaryExpressionLt(SparqlTermExpression(TermVar(Var("emp1Name"))),SparqlTermExpression(TermVar(Var("emp2Name")))), PrimaryExpressionLt(SparqlTermExpression(TermVar(Var("emp2Name"))),SparqlTermExpression(TermVar(Var("emp3Name")))), PrimaryExpressionLt(SparqlTermExpression(TermVar(Var("emp3Name"))),SparqlTermExpression(TermVar(Var("emp4Name"))))))))
+ TableFilter(TableConjunction(List(TriplesBlock(List(TriplePattern(Var("emp1"), Uri("http://hr.example/DB/Employee#lastName"), Var("emp1Name")))),
+ OptionalGraphPattern(TriplesBlock(List(TriplePattern(Var("emp1"), Uri("http://hr.example/DB/Employee#birthday"), Var("birthday"))))),
+ TriplesBlock(List(TriplePattern(Var("emp2"), Uri("http://hr.example/DB/Employee#lastName"), Var("emp2Name")))),
+ OptionalGraphPattern(TriplesBlock(List(TriplePattern(Var("emp2"), Uri("http://hr.example/DB/Employee#birthday"), Var("birthday"))))),
+ TriplesBlock(List(TriplePattern(Var("emp4"),Uri("http://hr.example/DB/Employee#birthday"),Var("birthday")))))),
+ Expression(List(PrimaryExpressionLt(SparqlTermExpression(Var("emp1Name")),SparqlTermExpression(Var("emp2Name"))), PrimaryExpressionLt(SparqlTermExpression(Var("emp2Name")),SparqlTermExpression(Var("emp3Name"))), PrimaryExpressionLt(SparqlTermExpression(Var("emp3Name")),SparqlTermExpression(Var("emp4Name")))))))
assert(tps === a.parseAll(a.select, e).get)
}
@@ -434,15 +434,15 @@
TriplesBlock(
List(
TriplePattern(
- SVar(Var("emp")),
- PUri(Uri("http://xmlns.com/foaf/0.1/last_name")),
- OVar(Var("empName"))))),
+ Var("emp"),
+ Uri("http://xmlns.com/foaf/0.1/last_name"),
+ Var("empName")))),
TriplesBlock(
List(
TriplePattern(
- SVar(Var("emp")),
- PUri(Uri("http://hr.example/DB/Employee#lastName")),
- OVar(Var("empName"))))))
+ Var("emp"),
+ Uri("http://hr.example/DB/Employee#lastName"),
+ Var("empName")))))
assert(tps === a.parseAll(a.construct, e).get)
}