import unittest
import dedupe

class CanonicalizationTest(unittest.TestCase) :

	def setUp(self) :
		self.data_d = { 1 : {"name": "mary crane", "address": "123 main st", "zip":"12345"}, 
					 	2 : {"name": "mary crane east", "address": "123 main street", "zip":""}, 
						3 : {"name": "mary crane west", "address": "123 man st", "zip":""}}
		deduper = dedupe.Dedupe({'name': {'type': 'String'},
                      			 'address':   {'type': 'String'},
                      			 'zip': {'type': 'String'}})
		self.data_model = deduper.data_model

	def test_get_centroid(self) :
		from dedupe.distance.affinegap import normalizedAffineGapDistance as comparator
		attributeList = ['mary crane center', 'mary crane center north', 'mary crane league - mary crane - west', 'mary crane league mary crane center (east)', 'mary crane league mary crane center (north)', 'mary crane league mary crane center (west)', 'mary crane league - mary crane - east', 'mary crane family and day care center', 'mary crane west', 'mary crane center east', 'mary crane league mary crane center (east)', 'mary crane league mary crane center (north)', 'mary crane league mary crane center (west)', 'mary crane league', 'mary crane', 'mary crane east 0-3', 'mary crane north', 'mary crane north 0-3', 'mary crane league - mary crane - west', 'mary crane league - mary crane - north', 'mary crane league - mary crane - east', 'mary crane league - mary crane - west', 'mary crane league - mary crane - north', 'mary crane league - mary crane - east']
		centroid = dedupe.centroid.getCentroid (attributeList, comparator)
		assert centroid == 'mary crane'

	def test_get_canonical_rep(self) :
		rep = dedupe.centroid.getCanonicalRep((1,2,3), self.data_d, self.data_model)
		assert rep == {'name': 'mary crane', 'address': '123 main street', 'zip':"12345"}

		rep = dedupe.centroid.getCanonicalRep((1,2), self.data_d, self.data_model)
		assert rep == {"name": "mary crane", "address": "123 main st", "zip":"12345"}

		rep = dedupe.centroid.getCanonicalRep((1,), self.data_d, self.data_model)
		assert rep == {"name": "mary crane", "address": "123 main st", "zip":"12345"}

if __name__ == "__main__":
	unittest.main()

@@ -103,22 +103,23 @@
 elf.
-data_d = %7B 1 :
+record_list = %5B
  %7B%22n
@@ -192,11 +192,9 @@
 %09%09 %09
-2 :
+%09
  %7B%22n
@@ -270,11 +270,9 @@
 %09%09%09%09
-3 :
+%09
  %7B%22n
@@ -334,216 +334,10 @@
 :%22%22%7D
-%7D%0A%09%09deduper = dedupe.Dedupe(%7B'name': %7B'type': 'String'%7D,%0A                      %09%09%09 'address':   %7B'type': 'String'%7D,%0A                      %09%09%09 'zip': %7B'type': 'String'%7D%7D)%0A%09%09self.data_model = deduper.data_model
+ %5D
 %0A%0A%09d
@@ -1495,21 +1495,21 @@
 ep((
+0,
 1,2
-,3
 ), self.
 data
@@ -1504,39 +1504,27 @@
 ), self.
-data_d, self.data_model
+record_list
 )%0A%09%09asse
@@ -1643,27 +1643,27 @@
 calRep((
-1,2
+0,1
 ), self.
 data_d, 
@@ -1654,39 +1654,27 @@
 ), self.
-data_d, self.data_model
+record_list
 )%0A%09%09asse
@@ -1789,17 +1789,17 @@
 calRep((
-1
+0
 ,), self
@@ -1803,31 +1803,19 @@
 elf.
-data_d, self.data_model
+record_list
 )%0A%09%09

tweak getCanonicalRep - take in list of dictionaries (representing records) instead of data dictionary, take out data model set comparator to string distance for all fields