changeset 328:6343be6fac49 no-hierarchy

- hierarchy stuff
author Eric Prud'hommeaux <eric@w3.org>
date Sat, 12 Feb 2011 11:41:00 -0500
parents 0a9c000c9dd5
children d23caa599848
files directmapping-test/src/main/scala/DirectMappingTestSuite.scala directmapping/src/main/scala/DirectMapping.scala sharedtestdata/directmappingspec/hier_tabl.ttl sharedtestdata/directmappingspec/hier_tabl_proto.ttl
diffstat 4 files changed, 20 insertions(+), 60 deletions(-) [+]
line wrap: on
line diff
--- a/directmapping-test/src/main/scala/DirectMappingTestSuite.scala	Sat Feb 12 11:11:50 2011 -0500
+++ b/directmapping-test/src/main/scala/DirectMappingTestSuite.scala	Sat Feb 12 11:41:00 2011 -0500
@@ -52,38 +52,28 @@
 
   val turtleParser = new TurtleParser { }
 
-  def testDirectMapping(testName:String, db:Database, expectedGraph:Graph, respectHierarchy:Boolean):Unit =
+  def testDirectMapping(testName:String, db:Database, expectedGraph:Graph):Unit =
     test(testName) {
-      DirectMapping.HierarchyDetection = respectHierarchy
       val computedGraph = directDB(db)
-      DirectMapping.HierarchyDetection = true
       DirectMapping.NextBNode = 97 // @@ call the "i'd like to reset my fresh variables to 0 so i can have predictable node names" function
       assert (expectedGraph === computedGraph)
     }
 
-  def testDirectMapping(testName:String, dbFile:File, expectedGraphFile:File, respectHierarchy:Boolean):Unit = {
+  def testDirectMapping(testName:String, dbFile:File, expectedGraphFile:File):Unit = {
     val db = SqlParser.toDB(dbFile)
     val expectedGraph:Graph = turtleParser.toGraph(expectedGraphFile)
-    testDirectMapping(testName, db, expectedGraph, respectHierarchy)
+    testDirectMapping(testName, db, expectedGraph)
   }
 
   def testDirectMappingSpec(testName:String):Unit =
     testDirectMapping(testName,
 		      new File("./sharedtestdata/directmappingspec/" + testName + ".sql"),
-		      new File("./sharedtestdata/directmappingspec/" + testName + ".ttl"),
-		      true)
-
-  def testDirectMappingSpecNoHierarchy(testName:String):Unit =
-    testDirectMapping(testName,
-		      new File("./sharedtestdata/directmappingspec/" + testName + ".sql"),
-		      new File("./sharedtestdata/directmappingspec/" + testName + ".ttl"),
-		      false)
+		      new File("./sharedtestdata/directmappingspec/" + testName + ".ttl"))
 
   def testDirectMapping(testName:String):Unit =
     testDirectMapping(testName,
 		      new File("./sharedtestdata/tests/" + testName + ".sql"),
-		      new File("./sharedtestdata/tests/" + testName + ".ttl"),
-		      false)
+		      new File("./sharedtestdata/tests/" + testName + ".ttl"))
 
   // 2 People 1 Addresses
   testDirectMappingSpec("emp_addr")
@@ -99,8 +89,6 @@
 
   // 1 People 1 Addresses 1 Offices 1 ExectutiveOffices
   testDirectMappingSpec("hier_tabl")
-  // Try that again without respecting hierarchies
-  testDirectMappingSpecNoHierarchy("non-hier_tabl")
 
   // !!! goes in different module
 
--- a/directmapping/src/main/scala/DirectMapping.scala	Sat Feb 12 11:11:50 2011 -0500
+++ b/directmapping/src/main/scala/DirectMapping.scala	Sat Feb 12 11:41:00 2011 -0500
@@ -35,15 +35,7 @@
       def apply(rn:RelName) = m(rn)
       def ultimateReferent (rn:RelName, k:CandidateKey, vs:List[LexicalValue], db:Database) : Node = {
         // Issue: What if fk is a rearrangement of the pk, per issue fk-pk-order?
-        (HierarchyDetection, db(rn).pk) match {
-          case (true, Some(pk)) if db(rn).fks contains(pk.attrs) => {
-            /** Table's primary key is a foreign key. */
-            val target = db(rn).fks(ForeignKeyKey(pk.attrs))
-            ultimateReferent(target.rel, target.key, vs, db)
-          }
-          case (_, _) =>
-            m(rn)(k)(vs)  
-        }
+        m(rn)(k)(vs)  
       }
       def contains(rn:RelName) = m.contains(rn)
     }
@@ -56,11 +48,6 @@
     }
   
     /**
-     * Switch for special case for hierarchies:
-     */
-    var HierarchyDetection = true
-
-    /**
      * The mapping functions implementing
      * <http://www.w3.org/2001/sw/rdb2rdf/directGraph/>
      */
@@ -69,30 +56,15 @@
       val allFKs:Set[ForeignKeyKey] = r.fks.keySet
       val nulllist:Set[AttrName] = t.nullAttributes(r.header)
       val nullFKs:Set[ForeignKeyKey] = allFKs filter { fk => (nulllist & fk.toSet) nonEmpty  }
-  
-      /** Check to see if r's primary key is a hierarchical key.
-       * http://www.w3.org/2001/sw/rdb2rdf/directGraph/#rule3 */
-      (HierarchyDetection, r.pk) match {
-        case (true, Some(pk)) if r.fks contains (pk.attrs) =>
-          r.fks.keySet -- nullFKs - ForeignKeyKey(r.fks.refdAttrs(ForeignKeyKey(pk.attrs)))
-        case (_, _) =>
-          r.fks.keySet -- nullFKs
-      }
+      r.fks.keySet -- nullFKs
     }
   
     def scalars (t:Tuple, r:Relation):Set[AttrName] = {
       val allAttrs:Set[AttrName] = r.header.keySet
       val allFKs:Set[ForeignKeyKey] = r.fks.keySet
       val unaryFKs:Set[AttrName] = allFKs map { _.attrs } filter { _.length == 1 } flatten
-  
-      /** Check to see if r's primary key is a hierarchical key.
-       * http://www.w3.org/2001/sw/rdb2rdf/directGraph/#rule3 */
-      (HierarchyDetection, r.pk) match {
-        case (true, Some(pk)) if r.fks contains (pk.attrs) =>
-          allAttrs -- unaryFKs ++ r.fks.refdAttrs(ForeignKeyKey(pk.attrs))
-        case (_, _) =>
-          allAttrs -- unaryFKs
-      }
+
+      allAttrs -- unaryFKs
     }
   
     /** The NodeMap-generating functions: */
--- a/sharedtestdata/directmappingspec/hier_tabl.ttl	Sat Feb 12 11:11:50 2011 -0500
+++ b/sharedtestdata/directmappingspec/hier_tabl.ttl	Sat Feb 12 11:41:00 2011 -0500
@@ -1,12 +1,12 @@
 @prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
-<Addresses/ID.18#_> a <ExecutiveOffices> .
-<Addresses/ID.18#_> <ExecutiveOffices#ID> 18 .
-<Addresses/ID.18#_> <ExecutiveOffices#desk> "oak" . 
+<ExecutiveOffices/ID.18#_> a <ExecutiveOffices> .
+<ExecutiveOffices/ID.18#_> <ExecutiveOffices#ID> <Offices/ID.18#_> .
+<ExecutiveOffices/ID.18#_> <ExecutiveOffices#desk> "oak" . 
 
-<Addresses/ID.18#_> a <Offices> .
-<Addresses/ID.18#_> <Offices#ID> 18 .
-<Addresses/ID.18#_> <Offices#building> 32 .
-<Addresses/ID.18#_> <Offices#ofcNumber> "G528" . 
+<Offices/ID.18#_> a <Offices> .
+<Offices/ID.18#_> <Offices#ID> <Addresses/ID.18#_> .
+<Offices/ID.18#_> <Offices#building> 32 .
+<Offices/ID.18#_> <Offices#ofcNumber> "G528" . 
 
 <People/ID.7#_> a <People> .
 <People/ID.7#_> <People#ID> 7 .
--- a/sharedtestdata/directmappingspec/hier_tabl_proto.ttl	Sat Feb 12 11:11:50 2011 -0500
+++ b/sharedtestdata/directmappingspec/hier_tabl_proto.ttl	Sat Feb 12 11:41:00 2011 -0500
@@ -1,8 +1,8 @@
 @prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
-<Addresses/ID.18#_> a <Offices> .
-<Addresses/ID.18#_> <Offices#ID> 18 .
-<Addresses/ID.18#_> <Offices#building> 32 .
-<Addresses/ID.18#_> <Offices#ofcNumber> "G528" . 
+<Offices/ID.18#_> a <Offices> .
+<Offices/ID.18#_> <Offices#ID> <Addresses/ID.18#_> .
+<Offices/ID.18#_> <Offices#building> 32 .
+<Offices/ID.18#_> <Offices#ofcNumber> "G528" . 
 
 <People/ID.7#_> a <People> .
 <People/ID.7#_> <People#ID> 7 .
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.