--- a/src/main/scala/SparqlToSparql.scala Sun Feb 14 09:28:58 2010 -0500
+++ b/src/main/scala/SparqlToSparql.scala Sun Feb 14 09:59:39 2010 -0500
@@ -67,12 +67,12 @@
count = count + 1))
count
}
- def toGraphPattern ():sparql.GraphPattern = {
+ def toGraphPattern (ident:String):sparql.GraphPattern = {
var conjNo = 0
val conjuncts = b.foldLeft(List[sparql.GraphPattern]())((conj, constructlist) => {
val (construct, l) = constructlist
l.map((vartermmap) => {
- val unique = "_" + conjNo + "_"
+ val unique = ident + conjNo + "_"
conjNo = conjNo + 1
substituteGraphPattern(construct.gp, vartermmap, unique)
})
@@ -218,24 +218,30 @@
}
- def mapGraphPattern (gp:sparql.GraphPattern, ruleMap:RuleMap):sparql.GraphPattern = {
+ def mapGraphPattern (gp:sparql.GraphPattern, ruleMap:RuleMap, ident:String):sparql.GraphPattern = {
gp match {
case sparql.TriplesBlock(tps) => {
val emptyBindings = createEmptyBindings
- ruleMap.transform(tps, Set[sparql.TriplePattern](), emptyBindings).toGraphPattern
+ ruleMap.transform(tps, Set[sparql.TriplePattern](), emptyBindings).toGraphPattern(ident)
}
case sparql.TableFilter(gp2:sparql.GraphPattern, expr:sparql.Expression) =>
- sparql.TableFilter(mapGraphPattern(gp2, ruleMap), expr)
+ sparql.TableFilter(mapGraphPattern(gp2, ruleMap, ident), expr)
case sparql.MinusGraphPattern(gp2) =>
- sparql.MinusGraphPattern(mapGraphPattern(gp2, ruleMap))
+ sparql.MinusGraphPattern(mapGraphPattern(gp2, ruleMap, ident))
case sparql.OptionalGraphPattern(gp2) =>
- sparql.OptionalGraphPattern(mapGraphPattern(gp2, ruleMap))
+ sparql.OptionalGraphPattern(mapGraphPattern(gp2, ruleMap, ident))
case sparql.GraphGraphPattern(gp2) =>
- sparql.GraphGraphPattern(mapGraphPattern(gp2, ruleMap))
+ sparql.GraphGraphPattern(mapGraphPattern(gp2, ruleMap, ident))
case sparql.TableDisjunction(l) =>
- sparql.TableDisjunction({l.map(gp2 => mapGraphPattern(gp2, ruleMap))})
+ sparql.TableDisjunction({l.foldLeft((List[sparql.GraphPattern](), 0))((p, gp2) => {
+ val (l, disjNo) = p
+ (l ++ List(mapGraphPattern(gp2, ruleMap, ident + disjNo + "_")), disjNo + 1)
+ })}._1)
case sparql.TableConjunction(l) =>
- sparql.TableConjunction({l.map(gp2 => mapGraphPattern(gp2, ruleMap))})
+ sparql.TableConjunction({l.foldLeft((List[sparql.GraphPattern](), 0))((p, gp2) => {
+ val (l, conjNo) = p
+ (l ++ List(mapGraphPattern(gp2, ruleMap, ident + conjNo + "_")), conjNo + 1)
+ })}._1)
}
}
@@ -259,7 +265,7 @@
//println("ruleMap: " + ruleMap)
sparql.Select(
query.attrs,
- mapGraphPattern(query.gp, ruleMap)
+ mapGraphPattern(query.gp, ruleMap, "_")
)
}