changeset 333:e01de9b8dfcd no-hierarchy

~ reformating pass
author Alexandre Bertails <bertails@gmail.com>
date Sat, 12 Feb 2011 16:41:13 -0500
parents 0b6248c67203
children f5fd76348339
files directmapping/src/main/scala/DirectMapping.scala
diffstat 1 files changed, 17 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/directmapping/src/main/scala/DirectMapping.scala	Sat Feb 12 16:10:50 2011 -0500
+++ b/directmapping/src/main/scala/DirectMapping.scala	Sat Feb 12 16:41:13 2011 -0500
@@ -17,7 +17,7 @@
      */
     type KeyMap = PartialFunction[CandidateKey, PartialFunction[List[CellValue], Node]]
 
-    def KeyMap(r:Relation):KeyMap = {
+    def keyMapForRelation(r:Relation):KeyMap = {
       def ++(m:Map[CandidateKey,  Map[List[CellValue], Node]],
 	     pairs:List[(CandidateKey, List[CellValue])],
 	     n:Node):Map[CandidateKey,  Map[List[CellValue], Node]] = {
@@ -39,9 +39,9 @@
 
     type NodeMap = PartialFunction[RelName, KeyMap]
 
-    def NodeMap(db:Database):NodeMap = {
+    def dbToNodeMap(db:Database):NodeMap = {
       val idxables = db.keySet filter { rn => db(rn).candidates nonEmpty }
-      idxables map { rn:RelName => rn -> KeyMap(db(rn)) } toMap
+      idxables map { rn => rn -> keyMapForRelation(db(rn)) } toMap
     }
     
     /**
@@ -64,8 +64,8 @@
       val s:Node =
         r.pk match {
           case Some(pk) =>
-            /** Table has a primkary key. */
-            NodeIRI(nodemap(r.name, pk.attrs, t.notNullLexvalues(pk)))
+            /** Table has a primkary key. */	    
+            NodeIRI(iri(r, pk, t.notNullLexvalues(pk)))
           case None =>
             /** Table has no primkary key (but has some candidate keys). */
             NodeBNode(freshbnode())
@@ -75,7 +75,7 @@
   
     /** The triples-generating functions start with databasemap: */
     def directDB (db:Database) : Graph = {
-      val nodeMap = NodeMap(db)
+      val nodeMap = dbToNodeMap(db)
       Graph(db.keySet flatMap  { (rn:RelName) => directR(db(rn), nodeMap, db) })
     }
   
@@ -106,7 +106,7 @@
       ( scalars(t, r) flatMap { directL(r.name, s, _, r.header, t) } ) +
       Triple(SubjectNode(s),
 	     PredicateIRI(IRI("http://www.w3.org/1999/02/22-rdf-syntax-ns#type")),
-	     ObjectNode(NodeIRI(IRI(UE(relName2string(r.name))))))
+	     ObjectNode(NodeIRI(IRI(UE(r)))))
     }
   
     // should be done by BNode
@@ -144,18 +144,20 @@
        Triple(SubjectNode(s), PredicateIRI(p), o)
      }
   
-    // These implicits make nodemap and predicatemap functions prettier.
-    implicit def relName2string (rn:RelName) = rn.n
-    implicit def attrName2string (rn:AttrName) = rn.n
-  
-    def nodemap (rn:RelName, as:List[AttrName], ls:List[LexicalValue]) : IRI = {
-      val pairs:List[String] = as.zip(ls) map { case (attrName, lexicalValue) => UE(attrName) + "." + UE(lexicalValue.s) }
-      IRI(UE(rn) + "/" + pairs.mkString("_") + "#_")
-    }
+    // These invariants make nodemap and predicatemap functions prettier.
+    def UE(s:String):String = s.replaceAll(" ", "+")
+    def UE(rn:RelName):String = UE(rn.n)
+    def UE(r:Relation):String = UE(r.name)
+    def UE(a:AttrName):String = UE(a.n)
   
     def predicatemap (rn:RelName, as:AttrList) : IRI =
       IRI(UE(rn) + "#" + as.attrs.mkString("_"))
 
+    def iri(rn:Relation, as:AttrList, ls:List[LexicalValue]):IRI = {
+      val pairs:List[String] = as.attrs zip ls map { case (attrName, lexicalValue) => UE(attrName) + "." + UE(lexicalValue.s) }
+      IRI(UE(rn) + "/" + pairs.mkString("_") + "#_")
+    }
+
     // TODO: aren't they already part of the RDF model?
     def XSD (d:Datatype) : IRI =
       d match {
@@ -175,7 +177,6 @@
 	case _ => TypedLiteral(l.s, XSD(d))
       }
   
-    def UE (s:String) : String = s.replaceAll(" ", "+")
 
   }
 
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.