@@ -233,99 +233,106 @@ def test_get_position_map_conjunction_second_sentence_mentions_true(self):
233233 position_map = self .sm_tendencies_analyzer .get_position_map (Mention (doc [9 ], True ), doc )
234234 self .assertEqual ([5 , 2 , 1 , 2 , 0 , 1 , 0 ], position_map )
235235
236+ def compare_compatibility_map (self , expected_compatibility_map , returned_compatibility_map ):
237+ self .assertEqual (expected_compatibility_map [0 ], returned_compatibility_map [0 ])
238+ self .assertEqual (expected_compatibility_map [1 ], returned_compatibility_map [1 ])
239+ self .assertEqual (expected_compatibility_map [2 ], returned_compatibility_map [2 ])
240+ self .assertAlmostEqual (expected_compatibility_map [3 ], returned_compatibility_map [3 ], 4 )
241+ self .assertEqual (expected_compatibility_map [4 ], returned_compatibility_map [4 ])
242+
236243 def test_get_compatibility_map_simple (self ):
237244
238245 doc = self .sm_nlp ('Richard said he was entering the big house' )
239246 self .sm_rules_analyzer .initialize (doc )
240- self .assertEqual ( ' [2, 0, 1, 0.26251248, 3]' ,
241- str ( self .sm_tendencies_analyzer .get_compatibility_map (Mention (doc [0 ], False ), doc [2 ]) ))
247+ self .compare_compatibility_map ( [2 , 0 , 1 , 0.26251248 , 3 ],
248+ self .sm_tendencies_analyzer .get_compatibility_map (Mention (doc [0 ], False ), doc [2 ]))
242249
243250 def test_get_compatibility_map_coordination (self ):
244251
245252 doc = self .sm_nlp ('Richard and Jane said he was entering the big house' )
246253 self .sm_rules_analyzer .initialize (doc )
247- self .assertEqual ( ' [4, 0, 1, 0.20765561, 3]' ,
248- str ( self .sm_tendencies_analyzer .get_compatibility_map (Mention (doc [0 ], True ), doc [4 ]) ))
254+ self .compare_compatibility_map ( [4 , 0 , 1 , 0.20765561 , 3 ],
255+ self .sm_tendencies_analyzer .get_compatibility_map (Mention (doc [0 ], True ), doc [4 ]))
249256
250257 def test_get_compatibility_map_different_sentences (self ):
251258
252259 doc = self .sm_nlp ('Richard called. He said he was entering the big house' )
253260 self .sm_rules_analyzer .initialize (doc )
254- self .assertEqual ( ' [3, 1, 0, 0.52525896, 6]' ,
255- str ( self .sm_tendencies_analyzer .get_compatibility_map (Mention (doc [0 ], False ), doc [3 ]) ))
261+ self .compare_compatibility_map ( [3 , 1 , 0 , 0.52525896 , 6 ],
262+ self .sm_tendencies_analyzer .get_compatibility_map (Mention (doc [0 ], False ), doc [3 ]))
256263
257264 def test_get_compatibility_map_same_sentence_no_governance (self ):
258265
259266 doc = self .sm_nlp ('After Richard arrived, he said he was entering the big house' )
260267 self .sm_rules_analyzer .initialize (doc )
261- self .assertEqual ( ' [4, 0, 0, -0.12525316, 5]' ,
262- str ( self .sm_tendencies_analyzer .get_compatibility_map (Mention (doc [0 ], False ), doc [4 ]) ))
268+ self .compare_compatibility_map ( [4 , 0 , 0 , - 0.12525316 , 5 ],
269+ self .sm_tendencies_analyzer .get_compatibility_map (Mention (doc [0 ], False ), doc [4 ]))
263270
264271 def test_get_compatibility_map_same_sentence_lefthand_sibling_governance (self ):
265272
266273 doc = self .lg_nlp ('Richard said Peter and he were entering the big house' )
267274 self .lg_rules_analyzer .initialize (doc )
268- self .assertEqual ( ' [4, 0, 1, 0.15999001, 4]' ,
269- str ( self .sm_tendencies_analyzer .get_compatibility_map (Mention (doc [0 ], False ), doc [4 ]) ))
275+ self .compare_compatibility_map ( [4 , 0 , 1 , 0.15999001 , 4 ],
276+ self .sm_tendencies_analyzer .get_compatibility_map (Mention (doc [0 ], False ), doc [4 ]))
270277
271278 def test_get_compatibility_map_same_sentence_lefthand_sibling_no_governance (self ):
272279
273280 doc = self .sm_nlp ('After Richard arrived, Peter and he said he was entering the big house' )
274281 self .sm_rules_analyzer .initialize (doc )
275- self .assertEqual ( ' [5, 0, 0, 0.32681236, 6]' ,
276- str ( self .sm_tendencies_analyzer .get_compatibility_map (Mention (doc [1 ], False ), doc [6 ]) ))
282+ self .compare_compatibility_map ( [5 , 0 , 0 , 0.32681236 , 6 ],
283+ self .sm_tendencies_analyzer .get_compatibility_map (Mention (doc [1 ], False ), doc [6 ]))
277284
278285 def test_get_cosine_similarity_lg (self ):
279286
280287 doc = self .lg_nlp ('After Richard arrived, he said he was entering the big house' )
281288 self .lg_rules_analyzer .initialize (doc )
282- self .assertEqual ( ' [4, 0, 0, 0.3336621, 5]' ,
283- str ( self .lg_tendencies_analyzer .get_compatibility_map (Mention (doc [0 ], False ), doc [4 ]) ))
289+ self .compare_compatibility_map ( [4 , 0 , 0 , 0.3336621 , 5 ],
290+ self .lg_tendencies_analyzer .get_compatibility_map (Mention (doc [0 ], False ), doc [4 ]))
284291
285292 def test_get_cosine_similarity_lg_no_vector_1 (self ):
286293
287294 doc = self .lg_nlp ('After Richard arfewfewfrived, he said he was entering the big house' )
288295 self .lg_rules_analyzer .initialize (doc )
289296
290- self .assertEqual ( ' [4, 0, 0, 0.59521705, 5]' ,
291- str ( self .lg_tendencies_analyzer .get_compatibility_map (Mention (doc [0 ], False ), doc [4 ]) ))
297+ self .compare_compatibility_map ( [4 , 0 , 0 , 0.59521705 , 5 ],
298+ self .lg_tendencies_analyzer .get_compatibility_map (Mention (doc [0 ], False ), doc [4 ]))
292299
293300 def test_get_cosine_similarity_lg_no_vector_2 (self ):
294301
295302 doc = self .lg_nlp ('After Richard arrived, he saifefefwefefd he was entering the big house' )
296303 self .lg_rules_analyzer .initialize (doc )
297- self .assertEqual ( ' [4, 0, 0, 0.59521705, 3]' ,
298- str ( self .lg_tendencies_analyzer .get_compatibility_map (Mention (doc [0 ], False ), doc [4 ]) ))
304+ self .compare_compatibility_map ( [4 , 0 , 0 , 0.59521705 , 3 ],
305+ self .lg_tendencies_analyzer .get_compatibility_map (Mention (doc [0 ], False ), doc [4 ]))
299306
300307 def test_get_cosine_similarity_sm_root_1 (self ):
301308
302309 doc = self .sm_nlp ('Richard. He said he was entering the big house' )
303310 self .sm_rules_analyzer .initialize (doc )
304311
305- self .assertEqual ( ' [2, 1, 0, -1, 1]' ,
306- str ( self .sm_tendencies_analyzer .get_compatibility_map (Mention (doc [0 ], False ), doc [2 ]) ))
312+ self .compare_compatibility_map ( [2 , 1 , 0 , - 1 , 1 ],
313+ self .sm_tendencies_analyzer .get_compatibility_map (Mention (doc [0 ], False ), doc [2 ]))
307314
308315 def test_get_cosine_similarity_sm_root_2 (self ):
309316
310317 doc = self .sm_nlp ('Richard arrived. He.' )
311318 self .sm_rules_analyzer .initialize (doc )
312- self .assertEqual ( ' [3, 1, 0, -1, 1]' ,
313- str ( self .sm_tendencies_analyzer .get_compatibility_map (Mention (doc [0 ], False ), doc [3 ]) ))
319+ self .compare_compatibility_map ( [3 , 1 , 0 , - 1 , 1 ],
320+ self .sm_tendencies_analyzer .get_compatibility_map (Mention (doc [0 ], False ), doc [3 ]))
314321
315322 def test_get_cosine_similarity_lg_root_1 (self ):
316323
317324 doc = self .lg_nlp ('Richard. He said he was entering the big house' )
318325 self .lg_rules_analyzer .initialize (doc )
319326
320- self .assertEqual ( ' [2, 1, 0, -1, 1]' ,
321- str ( self .lg_tendencies_analyzer .get_compatibility_map (Mention (doc [0 ], False ), doc [2 ]) ))
327+ self .compare_compatibility_map ( [2 , 1 , 0 , - 1 , 1 ],
328+ self .lg_tendencies_analyzer .get_compatibility_map (Mention (doc [0 ], False ), doc [2 ]))
322329
323330 def test_get_cosine_similarity_lg_root_2 (self ):
324331
325332 doc = self .lg_nlp ('Richard arrived. He.' )
326333 self .lg_rules_analyzer .initialize (doc )
327- self .assertEqual ( ' [3, 1, 0, -1, 1]' ,
328- str ( self .lg_tendencies_analyzer .get_compatibility_map (Mention (doc [0 ], False ), doc [3 ]) ))
334+ self .compare_compatibility_map ( [3 , 1 , 0 , - 1 , 1 ],
335+ self .lg_tendencies_analyzer .get_compatibility_map (Mention (doc [0 ], False ), doc [3 ]))
329336
330337 def test_get_vectors_token_with_head_sm (self ):
331338
0 commit comments