~ function depending on tuplemap are higher-order functions no-hierarchy
authorAlexandre Bertails <bertails@gmail.com>
Mon, 14 Feb 2011 20:59:36 -0500
branchno-hierarchy
changeset 349 0407570a9826
parent 348 6d8801b9713c
child 357 0c37406e4268
~ function depending on tuplemap are higher-order functions
directmapping/src/main/scala/DirectMapping.scala
--- 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)