alessandro trinca tornidor
commited on
Commit
·
0802362
1
Parent(s):
c451b7f
test: add more test cases for process_synonym_groups() and get_wordnet_synonyms()
Browse files- tests/test_text_parsers2.py +40 -0
tests/test_text_parsers2.py
CHANGED
|
@@ -89,6 +89,22 @@ class TestTextParsers2(unittest.TestCase):
|
|
| 89 |
self.assertIn('synonyms', first_result)
|
| 90 |
self.assertIsInstance(first_result['synonyms'], list)
|
| 91 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
def test_get_wordnet_synonyms_pos_filter(self):
|
| 93 |
# Test with POS filtering
|
| 94 |
word = "hunt"
|
|
@@ -257,6 +273,30 @@ class TestTextParsers2(unittest.TestCase):
|
|
| 257 |
# For a past-tense verb, the inflected form should be different from the base
|
| 258 |
self.assertNotEqual(first_synonym_info['base_form'], first_synonym_info['inflected_form'])
|
| 259 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 260 |
@patch("my_ghost_writer.text_parsers2.wn.synsets")
|
| 261 |
def test_process_synonym_groups_not_synonyms_by_sense(self, mock_synsets):
|
| 262 |
mock_synsets.return_value = []
|
|
|
|
| 89 |
self.assertIn('synonyms', first_result)
|
| 90 |
self.assertIsInstance(first_result['synonyms'], list)
|
| 91 |
|
| 92 |
+
def test_get_wordnet_synonyms_custom_entry(self):
|
| 93 |
+
word = "happy"
|
| 94 |
+
pos = "ADJ"
|
| 95 |
+
synonyms_list = get_wordnet_synonyms(word, pos)
|
| 96 |
+
for synonym_by_sense in synonyms_list:
|
| 97 |
+
self.assertIsInstance(synonym_by_sense, dict)
|
| 98 |
+
self.assertIsInstance(synonym_by_sense["definition"], str)
|
| 99 |
+
self.assertEqual(synonym_by_sense["pos"], pos)
|
| 100 |
+
self.assertIsInstance(synonym_by_sense["examples"], list)
|
| 101 |
+
synonyms = synonym_by_sense["synonyms"]
|
| 102 |
+
for synonym_dict in synonyms:
|
| 103 |
+
self.assertIsInstance(synonym_dict, dict)
|
| 104 |
+
self.assertIsInstance(synonym_dict["definition"], str)
|
| 105 |
+
self.assertIsInstance(synonym_dict["synonym"], str)
|
| 106 |
+
self.assertIsInstance(synonym_dict["is_custom"], bool)
|
| 107 |
+
|
| 108 |
def test_get_wordnet_synonyms_pos_filter(self):
|
| 109 |
# Test with POS filtering
|
| 110 |
word = "hunt"
|
|
|
|
| 273 |
# For a past-tense verb, the inflected form should be different from the base
|
| 274 |
self.assertNotEqual(first_synonym_info['base_form'], first_synonym_info['inflected_form'])
|
| 275 |
|
| 276 |
+
def test_process_synonym_groups_custom_entry(self):
|
| 277 |
+
word = "happy"
|
| 278 |
+
context_info = {
|
| 279 |
+
'char_end': 60, 'char_start': 55,
|
| 280 |
+
'context_sentence': 'Even Muggles like yourself should be celebrating, this happy, happy day!"',
|
| 281 |
+
'context_words': ['should', 'be', 'celebrating', ',', 'this', 'happy', ',', 'happy', 'day', '!', '"'],
|
| 282 |
+
'dependency': 'amod', 'is_lower': True, 'is_title': False, 'is_upper': False, 'lemma': 'happy',
|
| 283 |
+
'original_indices': {'end': 60, 'start': 55}, 'pos': 'ADJ', 'sentence_position': 9,
|
| 284 |
+
'tag': 'JJ', 'word': 'happy'
|
| 285 |
+
}
|
| 286 |
+
result_synonym_groups_list = process_synonym_groups(word, context_info)
|
| 287 |
+
self.assertIsInstance(result_synonym_groups_list, list)
|
| 288 |
+
for expected_synonym_group in result_synonym_groups_list:
|
| 289 |
+
self.assertIsInstance(expected_synonym_group, dict)
|
| 290 |
+
self.assertIsInstance(expected_synonym_group["definition"], str)
|
| 291 |
+
self.assertEqual(expected_synonym_group["wordnet_pos"], context_info["pos"])
|
| 292 |
+
self.assertIsInstance(expected_synonym_group["examples"], list)
|
| 293 |
+
synonyms = expected_synonym_group["synonyms"]
|
| 294 |
+
for synonym_dict in synonyms:
|
| 295 |
+
self.assertIsInstance(synonym_dict, dict)
|
| 296 |
+
self.assertIsInstance(synonym_dict["base_form"], str)
|
| 297 |
+
self.assertIsInstance(synonym_dict["inflected_form"], str)
|
| 298 |
+
self.assertIsInstance(synonym_dict["matches_context"], bool)
|
| 299 |
+
|
| 300 |
@patch("my_ghost_writer.text_parsers2.wn.synsets")
|
| 301 |
def test_process_synonym_groups_not_synonyms_by_sense(self, mock_synsets):
|
| 302 |
mock_synsets.return_value = []
|