+ 2 generation hierarchical example
authorEric Prud'hommeaux <eric@w3.org>
Tue, 28 Sep 2010 23:40:05 -0400
changeset 28 4e6c7a41fac0
parent 27 594065eeeedc
child 29 0e1bfa74e36c
+ 2 generation hierarchical example
src/main/scala/Main.scala
src/test/scala/Test.scala
--- a/src/main/scala/Main.scala	Tue Sep 28 22:54:18 2010 -0400
+++ b/src/main/scala/Main.scala	Tue Sep 28 23:40:05 2010 -0400
@@ -125,7 +125,7 @@
   case class NodeMap(m:Map[RelName, KeyMap]) {
     def apply(rn:RelName) = m(rn)
     def ultimateReferent (rn:RelName, k:CandidateKey, vs:List[LexicalValue], db:Database) : Node = {
-      // Issue: what if fk is to a rearrangement of the pk?
+      // Issue: What if fk is to a rearrangement of the pk?
       if (db.m(rn).pk.isDefined && db.m(rn).fks.contains(db.m(rn).pk.get)) {
 	/** Table's primary key is a foreign key. */
 	val target = db.m(rn).fks(db.m(rn).pk.get)
--- a/src/test/scala/Test.scala	Tue Sep 28 22:54:18 2010 -0400
+++ b/src/test/scala/Test.scala	Tue Sep 28 23:40:05 2010 -0400
@@ -309,6 +309,74 @@
     assert (expected === g)
   }
 
+
+  test("1 People 1 Addresses 1 Offices 1 ExectutiveOffices") {
+
+    val addresses = Relation(Header(Map("ID" -> SQLInt(),
+					"city" -> SQLString(),
+					"state" -> SQLString())),
+			     Set(Map("ID" -> LexicalValue("18"),
+				     "city" -> LexicalValue("Cambridge"),
+				     "state" -> LexicalValue("MA"))),
+			     List(List("ID")),
+			     Some(List("ID")),
+			     Map())
+
+    val people = Relation(Header(Map("ID" -> SQLInt(),
+				     "fname" -> SQLString(),
+				     "addr" -> SQLInt())),
+			  Set(Map("ID" -> LexicalValue("7"),
+				  "fname" -> LexicalValue("Bob"),
+				  "addr" -> LexicalValue("18"))),
+			  List(List("ID")),
+			  Some(List("ID")),
+			  Map(List("addr") -> Target("Addresses", List("ID"))))
+
+    val offices = Relation(Header(Map("ID" -> SQLInt(),
+				      "building" -> SQLInt(),
+				      "ofcNumber" -> SQLString())),
+			     Set(Map("ID" -> LexicalValue("18"),
+				     "building" -> LexicalValue("32"),
+				     "ofcNumber" -> LexicalValue("G528"))),
+			     List(List("ID")),
+			     Some(List("ID")),
+			     Map(List("ID") -> Target("Addresses", List("ID"))))
+
+    val execoffices = Relation(Header(Map("ID" -> SQLInt(),
+					  "desk" -> SQLString())),
+			       Set(Map("ID" -> LexicalValue("18"),
+				       "desk" -> LexicalValue("oak"))),
+			       List(List("ID")),
+			       Some(List("ID")),
+			       Map(List("ID") -> Target("Offices", List("ID"))))
+
+    val db = Database(Map("Addresses" -> addresses, 
+			  "People" -> people, 
+			  "Offices" -> offices, 
+			  "ExecutiveOffices" -> execoffices))
+    val g = databasemap(StemIRI("http://foo.example/DB"), db)
+
+    val expected:RDFGraph =
+      Set(
+	Triple(IRI("http://foo.example/DB/Addresses/ID.18#_"),IRI("http://foo.example/DB/ExecutiveOffices#ID"),TypedLiteral("18",IRI("http://www.w3.org/2001/XMLSchema#int"))),
+	Triple(IRI("http://foo.example/DB/Addresses/ID.18#_"),IRI("http://foo.example/DB/ExecutiveOffices#desk"),TypedLiteral("oak",IRI("http://www.w3.org/2001/XMLSchema#string"))), 
+
+	Triple(IRI("http://foo.example/DB/Addresses/ID.18#_"),IRI("http://foo.example/DB/Offices#ID"),TypedLiteral("18",IRI("http://www.w3.org/2001/XMLSchema#int"))),
+	Triple(IRI("http://foo.example/DB/Addresses/ID.18#_"),IRI("http://foo.example/DB/Offices#building"),TypedLiteral("32",IRI("http://www.w3.org/2001/XMLSchema#int"))),
+	Triple(IRI("http://foo.example/DB/Addresses/ID.18#_"),IRI("http://foo.example/DB/Offices#ofcNumber"),TypedLiteral("G528",IRI("http://www.w3.org/2001/XMLSchema#string"))), 
+
+	Triple(IRI("http://foo.example/DB/People/ID.7#_"),IRI("http://foo.example/DB/People#ID"),TypedLiteral("7",IRI("http://www.w3.org/2001/XMLSchema#int"))),
+	Triple(IRI("http://foo.example/DB/People/ID.7#_"),IRI("http://foo.example/DB/People#fname"),TypedLiteral("Bob",IRI("http://www.w3.org/2001/XMLSchema#string"))),
+	Triple(IRI("http://foo.example/DB/People/ID.7#_"),IRI("http://foo.example/DB/People#addr"),IRI("http://foo.example/DB/Addresses/ID.18#_")),
+
+	Triple(IRI("http://foo.example/DB/Addresses/ID.18#_"),IRI("http://foo.example/DB/Addresses#ID"),TypedLiteral("18",IRI("http://www.w3.org/2001/XMLSchema#int"))),
+	Triple(IRI("http://foo.example/DB/Addresses/ID.18#_"),IRI("http://foo.example/DB/Addresses#city"),TypedLiteral("Cambridge",IRI("http://www.w3.org/2001/XMLSchema#string"))),
+	Triple(IRI("http://foo.example/DB/Addresses/ID.18#_"),IRI("http://foo.example/DB/Addresses#state"),TypedLiteral("MA",IRI("http://www.w3.org/2001/XMLSchema#string")))
+      )
+    assert (expected === g)
+  }
+
+
   test("NodeMap") {
 
     val ck1:CandidateKey = List("name", "ssn")
@@ -333,6 +401,7 @@
     assert(goal === test)
   }
 
+
   test("2 Employees") {
     val employees = Relation(Header(Map("ID" -> SQLInt(),
 					"fname" -> SQLString(),