changeset 349:0407570a9826 no-hierarchy

~ function depending on tuplemap are higher-order functions
author Alexandre Bertails <bertails@gmail.com>
date Mon, 14 Feb 2011 20:59:36 -0500
parents 6d8801b9713c
children 0c37406e4268
files directmapping/src/main/scala/DirectMapping.scala
diffstat 1 files changed, 8 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/directmapping/src/main/scala/DirectMapping.scala	Mon Feb 14 18:36:35 2011 -0500
+++ b/directmapping/src/main/scala/DirectMapping.scala	Mon Feb 14 20:59:36 2011 -0500
@@ -28,7 +28,7 @@
     /**
      * TODO
      */
-    def dbToNodeMap(db:Database):PartialFunction[Tuple, Node] =
+    def dbToTupleMap(db:Database):PartialFunction[Tuple, Node] =
       db.relations map { relation => tupleMapForRelation(relation) } reduceLeft { _ orElse _ }
 
     /**
@@ -51,16 +51,16 @@
     def databaseSemantics(db:Database):Graph = {
       // that makes this implementation not thread-safe
       NextBNode = 97
-      val nodemap = dbToNodeMap(db)
-      Graph(db.relations flatMap { r => relationSemantics(nodemap, r) })
+      val tuplemap = dbToTupleMap(db)
+      Graph(db.relations flatMap { r => relationSemantics(tuplemap)(r) })
     }
   
-    def relationSemantics(tuplemap:PartialFunction[Tuple, Node], r:Relation):Graph =
-      Graph(r.body flatMap { t => tupleSemantics(tuplemap, t) })
+    def relationSemantics(tuplemap:PartialFunction[Tuple, Node])(r:Relation):Graph =
+      Graph(r.body flatMap { t => tupleSemantics(tuplemap)(t) })
   
-    def tupleSemantics (tuplemap:PartialFunction[Tuple, Node], t:Tuple):Set[Triple] = {
+    def tupleSemantics (tuplemap:PartialFunction[Tuple, Node])(t:Tuple):Set[Triple] = {
       val s:SubjectNode = SubjectNode(tuplemap(t))
-      val poFromFKs = t.references map { fk => referenceSemantics(tuplemap, t, fk) }
+      val poFromFKs = t.references map { fk => referenceSemantics(tuplemap)(t, fk) }
       val poFromLexicalValues = t.scalars flatMap { a => lexicalValueSemantics(t, a) }
       val poFromRelation = (PredicateIRI(IRI("http://www.w3.org/1999/02/22-rdf-syntax-ns#type")),
 			    ObjectNode(NodeIRI(IRI(UE(t.relation)))))
@@ -70,7 +70,7 @@
     /**
      * a foreign key contribute to generating triples
      */
-    def referenceSemantics (tuplemap:PartialFunction[Tuple, Node], t:Tuple, fk:ForeignKey):(Predicate, Object) = {
+    def referenceSemantics (tuplemap:PartialFunction[Tuple, Node])(t:Tuple, fk:ForeignKey):(Predicate, Object) = {
       val p = referencePredicateSemantics(t.relation, fk)
       val o = ObjectNode(tuplemap(t.dereference(fk)))
       (PredicateIRI(p), o)
@@ -139,7 +139,6 @@
         case Datatype.STRING => IRI("http://www.w3.org/2001/XMLSchema#string")
       }
 
-    // These invariants make nodemap and predicateSemantics functions prettier.
     def UE(s:String):String = s.replaceAll(" ", "+")
     def UE(r:Relation):String = UE(r.name.n)
     def UE(a:AttrName):String = UE(a.n)
Set up and maintained by W3C Systems Team, please report bugs to sysreq@w3.org.

W3C would like to thank Microsoft who donated the server that allows us to run this service.