--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/directmapping-webapp/src/main/resources/queries/emp_addr2FOAF.construct Thu May 05 19:43:02 2011 -0400
@@ -0,0 +1,8 @@
+PREFIX foaf: <http://xmlns.com/foaf/0.1/>
+PREFIX vcard: <http://www.w3.org/2006/vcard/ns#>
+
+CONSTRUCT { ?who foaf:given ?fname } WHERE { ?who <People#fname> ?fname }
+
+CONSTRUCT { ?addr vcard:streetNumber ?no ; vcard:streetName ?name } WHERE { ?addr <Addresses#streetNo> ?no ; <Addresses#streetName> ?name }
+
+CONSTRUCT { ?who vcard:homeAddr ?addr } WHERE { ?who <People#addr> ?addr }
\ No newline at end of file
--- a/directmapping-webapp/src/main/scala/code/snippet/HelloWorld.scala Thu May 05 19:08:53 2011 -0400
+++ b/directmapping-webapp/src/main/scala/code/snippet/HelloWorld.scala Thu May 05 19:43:02 2011 -0400
@@ -54,7 +54,7 @@
}
case "parse-construct" :: Nil Post _ => {
try {
- val construct = Construct(S.param("construct").openOr(""))
+ val constructs = Construct.extractAll(S.param("construct").openOr(""))
PlainTextResponse("SPARQL CONSTRUCT successfully parsed")
} catch {
case e => PlainTextResponse(e.getMessage, 500)
@@ -63,22 +63,22 @@
case "dm-then-construct" :: Nil Post _ => {
try {
val ddl = S.param("ddl").openOr("")
- val construct = S.param("construct").openOr("")
- PlainTextResponse(dmThenConstruct(ddl, construct))
+ val constructs = S.param("construct").openOr("")
+ PlainTextResponse(dmThenConstruct(ddl, constructs))
} catch {
case e => PlainTextResponse(e.getMessage, 500)
}
}
}
- def dmThenConstruct(ddl:String, construct:String):String = {
+ def dmThenConstruct(ddl:String, constructs:String):String = {
import DirectMapping._
val SQLParser = sql.SqlParser()
val db = SQLParser.toDB(ddl)
DirectMapping.MinEncode = false
val computedGraph:Graph = databaseSemantics(db)
- val construc = Construct(construct)
- val resultGraph = RDF2RDF(computedGraph) | construc
+ val allConstructs:List[Construct] = Construct.extractAll(constructs)
+ val resultGraph = RDF2RDF(computedGraph) | allConstructs
this.toString(resultGraph)
}
@@ -91,8 +91,8 @@
val SQLParser = sql.SqlParser()
- val defaultDDL = "ref_no_pk"
- val defaultCONSTRUCT = "identity"
+ val defaultDDL = "emp_addr"
+ val defaultCONSTRUCTs = "emp_addr2FOAF"
def render = {
val (ddlName, ddl, ddlMessage) = S.param("ddl") match {
@@ -107,15 +107,15 @@
}
}
- val (constructName, construct, constructMessage) = S.param("construct") match {
+ val (constructName, constructs, constructMessage) = S.param("construct") match {
case Full(name) if QueryManager.embeddedCONSTRUCTs contains name => {
(name, QueryManager.embeddedCONSTRUCTs(name), "SPARQL CONSTRUCT successfully loaded")
}
case Full(name) => {
- (defaultCONSTRUCT, QueryManager.embeddedCONSTRUCTs(defaultCONSTRUCT), name + "not found: default SPARQL CONSTRUCT used instead")
+ (defaultCONSTRUCTs, QueryManager.embeddedCONSTRUCTs(defaultCONSTRUCTs), name + "not found: default SPARQL CONSTRUCT used instead")
}
case _ => {
- (defaultCONSTRUCT, QueryManager.embeddedCONSTRUCTs(defaultCONSTRUCT), "Default SPARQL CONSTRUCT used")
+ (defaultCONSTRUCTs, QueryManager.embeddedCONSTRUCTs(defaultCONSTRUCTs), "Default SPARQL CONSTRUCT used")
}
}
@@ -123,9 +123,9 @@
"#ddl *" #> ddl &
"#ddl-message *" #> ddlMessage &
"#construct-name [value]" #> "" &
- "#construct *" #> construct &
+ "#construct *" #> constructs &
"#construct-message *" #> constructMessage &
- "#result *" #> Services.dmThenConstruct(ddl, construct)
+ "#result *" #> Services.dmThenConstruct(ddl, constructs)
}
--- a/directmapping-webapp/src/main/webapp/index.html Thu May 05 19:08:53 2011 -0400
+++ b/directmapping-webapp/src/main/webapp/index.html Thu May 05 19:43:02 2011 -0400
@@ -110,7 +110,7 @@
</div>
</div>
- <h2>SPARQL</h2>
+ <h2>SPARQL CONSTRUCTs</h2>
If empty or non-valid SPARQL CONSTRUCT, this will be ignored.
@@ -140,7 +140,7 @@
<hr ></hr>
<address>
- <a href="http://www.w3.org/People/Eric/">Eric Prud'hommeaux</a>, <a href="http://www.w3.org/People/Bertails/">Alexandre Bertails</a>, Apr 2011<br />
+ <a href="http://www.w3.org/People/Eric/">Eric Prud'hommeaux</a>, <a href="http://www.w3.org/People/Bertails/">Alexandre Bertails</a>, May 2011<br />
Contributors: <a href="mailto:bvillazon@fi.upm.es">Boris Villazon-Terrazas</a>, <a href="mailto:tgambet@w3.org">Thomas Gambet</a>
</address>
</div>
--- a/rdf2rdf/src/main/scala/RDF2RDF.scala Thu May 05 19:08:53 2011 -0400
+++ b/rdf2rdf/src/main/scala/RDF2RDF.scala Thu May 05 19:43:02 2011 -0400
@@ -20,8 +20,10 @@
val pattern = """(?s)(?i)CONSTRUCT +?\{.*?\} +?WHERE +?\{.*?\}""".r
- def extractAll(query:String, base:String = RDF2RDFModule.base):List[Construct] =
- pattern.findAllIn(query) map { Construct(_, base) } toList
+ def extractAll(query:String, base:String = RDF2RDFModule.base):List[Construct] = {
+ val prefixes = query.split("\n").filter{ _.matches("""(?i)^\s*prefix.*$""")}.mkString("\n")
+ pattern.findAllIn(query) map { construct => Construct(prefixes+construct, base) } toList
+ }
}