~ moved Option from lexvalues to return of scalarT
authorEric Prud'hommeaux <eric@w3.org>
Thu, 27 Jan 2011 15:48:57 -0500
changeset 307 6adb6a0a5243
parent 306 1c9d2ae8d049
child 308 b7c8a3157e6c
~ moved Option from lexvalues to return of scalarT
directmapping/src/main/scala/DirectMapping.scala
rdb/src/main/scala/RDB.scala
--- a/directmapping/src/main/scala/DirectMapping.scala	Mon Jan 17 15:38:26 2011 -0500
+++ b/directmapping/src/main/scala/DirectMapping.scala	Thu Jan 27 15:48:57 2011 -0500
@@ -79,15 +79,14 @@
       val allAttrs:Set[AttrName] = r.header.keySet
       val allFKs:Set[List[AttrName]] = r.fks.keySet
       val unaryFKs:Set[AttrName] = allFKs filter { _.length == 1 } flatten
-      val nulllist:Set[AttrName] = t.nullAttributes(r.header)
   
       /** Check to see if r's primary key is a hierarchical key.
        * http://www.w3.org/2001/sw/rdb2rdf/directGraph/#rule3 */
       r.pk match {
         case Some(pk) if r.fks contains (pk.attrs) =>
-          allAttrs -- unaryFKs -- nulllist ++ r.fks(pk.attrs).key.attrs
+          allAttrs -- unaryFKs ++ r.fks(pk.attrs).key.attrs
         case _ =>
-          allAttrs -- unaryFKs -- nulllist
+          allAttrs -- unaryFKs
       }
     }
   
@@ -143,8 +142,8 @@
     }
   
     def directS (s:Node, t:Tuple, r:Relation, nodes:NodeMap, db:Database) : Set[Triple] = {
-      ( references(t, r) map { directN(s, _, r, t, nodes) } ) ++
-      ( scalars(t, r)    map { directL(r.name, s, _, r.header, t) } )
+      ( references(t, r)  map { directN(s, _, r, t, nodes) } ) ++
+      ( scalars(t, r) flatMap { directL(r.name, s, _, r.header, t) } )
     }
   
     // should be done by BNode
@@ -155,14 +154,17 @@
       BNode(ret.toChar.toString)
     }
   
-    def directL (rn:RelName, s:Node, a:AttrName, h:Header, t:Tuple) : Triple = {
+    def directL (rn:RelName, s:Node, a:AttrName, h:Header, t:Tuple) : Option[Triple] = {
       val p = predicatemap (rn, List(a))
-      // hrmmmmm
-      val l = t.lexvalue(a).get
-      val o = literalmap(l, h.sqlDatatype(a))
-      Triple(SubjectNode(s),
-             PredicateIRI(p),
-             ObjectLiteral(o))
+      t.lexvalue(a) match {
+	case l:LexicalValue => {
+	  val o = literalmap(l, h.sqlDatatype(a))
+	  Some(Triple(SubjectNode(s),
+		      PredicateIRI(p),
+		      ObjectLiteral(o)))
+	}
+	case ␀ => None
+      }
     }
 
     def directN (s:Node, as:List[AttrName], r:Relation, t:Tuple, nodes:NodeMap) : Triple = {
--- a/rdb/src/main/scala/RDB.scala	Mon Jan 17 15:38:26 2011 -0500
+++ b/rdb/src/main/scala/RDB.scala	Thu Jan 27 15:48:57 2011 -0500
@@ -66,13 +66,9 @@
 
   case class Tuple (m:Map[AttrName, CellValue]) {
     def apply (a:AttrName) = m(a)
-    def lexvalue (a:AttrName) : Option[LexicalValue] = 
-      m(a) match {
-	case ␀ => None
-	case v:LexicalValue => Some(v)
-      }
+    def lexvalue (a:AttrName) : CellValue = m(a)
     def lexvaluesNoNulls (as:List[AttrName]) = as map { m(_).asInstanceOf[LexicalValue] }
-    def nullAttributes (h:Header) : Set[AttrName] = h.keySet filter { lexvalue(_) isEmpty }
+    def nullAttributes (h:Header) : Set[AttrName] = h.keySet filter { m(_) == ␀ }
   }
   object Tuple {
     def apply (s:(String, CellValue)*):Tuple =