--- a/directmapping/src/main/scala/DirectMapping.scala Sun Feb 13 00:29:29 2011 -0500
+++ b/directmapping/src/main/scala/DirectMapping.scala Sun Feb 13 00:55:48 2011 -0500
@@ -27,13 +27,13 @@
/**
* given:
- * - rn a RelName
- * - ck a CandidateKey <- ck must be part of the relation rn with name rn
+ * - r a Relation
+ * - ck a CandidateKey <- ck must be part of the relation r
* - vs a list of values <- vs should correspond to the values for ck
* a function of type NodeMap maps these elements to a unique RDF node
* it's type is equivalent to the following curried function:
- * RelName -> CandidateKey -> List[CellValue] -> Node
- * it verifies the following axiom:
+ * Relation -> CandidateKey -> List[CellValue] -> Node
+ * the following property holds:
* ∀ r:Relation, ∀ ck:CandidateKey, ck ∊ Relation, ∀ t1:Tuple, ∀ t2:Tuple,
* t1 ≠ t2 -> l1 = t1(ck) -> l2 = t2(ck) -> l1 = l2 -> nodemap(r)(ck)(l1) ≠ nodemap(r)(ck)(l1)
*/
@@ -61,10 +61,14 @@
n:Node):Map[CandidateKey, Map[List[CellValue], Node]] = {
pairs.foldLeft(m) { case (m, (ck, cellValues)) => {
m.get(ck) match {
+ // if a tuple is already mapped to a node, it's an error
case Some(byKey) if byKey.get(cellValues).isDefined =>
error("tried to set " + ck + cellValues + " = " + n + "(was " + byKey(cellValues) + ")")
+ // if this candidate key is already known,
+ // we just have to add the information for these values and this particular node
case Some(byKey) =>
m + (ck -> (byKey + (cellValues -> n)))
+ // if this is the first time we meet the candidate key, we initialize the map
case None =>
m + (ck -> Map(cellValues -> n))
}
@@ -100,7 +104,7 @@
def databaseSemantics(db:Database):Graph = {
NextBNode = 97
val nodemap = dbToNodeMap(db)
- Graph(db.relNames flatMap { rn:RelName => relationSemantics(db, nodemap, db(rn)) })
+ Graph(db.relations flatMap { r => relationSemantics(db, nodemap, r) })
}
def relationSemantics(db:Database, nodemap:NodeMap, r:Relation):Graph =
@@ -128,7 +132,6 @@
}
}
val fromFKs = t.references(r) map { fk => referenceSemantics(r, nodemap, t, fk) }
- //
val fromLexicalValues = t.scalars(r) flatMap { a => lexicalValueSemantics(r, t, a) }
// the relation provenance is mapped to an RDF type information, computed from the relation itself
val fromRelation = (PredicateIRI(IRI("http://www.w3.org/1999/02/22-rdf-syntax-ns#type")),
--- a/rdb/src/main/scala/RDB.scala Sun Feb 13 00:29:29 2011 -0500
+++ b/rdb/src/main/scala/RDB.scala Sun Feb 13 00:55:48 2011 -0500
@@ -21,8 +21,8 @@
def apply(rn:RelName) = m(rn)
def isDefinedAt(rn:RelName) = m isDefinedAt rn
- /** returns all the relation names */
- def relNames:Set[RelName] = m.keySet.toSet
+ /** returns all the relations */
+ def relations:Set[Relation] = m.values.toSet
/** return all the relations with at least on Candidate Key */
def indexables = m collect { case (rn, r) if r.isIndexable => r }
}