From 21ff138756987c63ca97b0335f1b2c23dd50fc26 Mon Sep 17 00:00:00 2001 From: aloknayak29 Date: Thu, 15 Apr 2021 03:01:11 +0530 Subject: [PATCH] added test of persistence of connector_words during save & load in test_phrases.py --- gensim/test/test_phrases.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/gensim/test/test_phrases.py b/gensim/test/test_phrases.py index bbfbfaad40..86ef83e40f 100644 --- a/gensim/test/test_phrases.py +++ b/gensim/test/test_phrases.py @@ -95,7 +95,7 @@ class PhrasesData: sentences = common_texts + [ ['graph', 'minors', 'survey', 'human', 'interface'], ] - connector_words = frozenset() + connector_words = frozenset({'of'}) bigram1 = u'response_time' bigram2 = u'graph_minors' @@ -321,9 +321,10 @@ def test_save_load_custom_scorer(self): def test_save_load(self): """Test saving and loading a Phrases object.""" with temporary_file("test.pkl") as fpath: - bigram = Phrases(self.sentences, min_count=1, threshold=1) + bigram = Phrases(self.sentences, min_count=1, threshold=1, connector_words=self.connector_words) bigram.save(fpath) bigram_loaded = Phrases.load(fpath) + self.assertEqual(bigram_loaded.connector_words, frozenset(self.connector_words)) test_sentences = [['graph', 'minors', 'survey', 'human', 'interface', 'system']] seen_scores = set(round(score, 3) for score in bigram_loaded.find_phrases(test_sentences).values()) @@ -378,9 +379,10 @@ def test_save_load_custom_scorer(self): def test_save_load(self): """Test saving and loading a FrozenPhrases object.""" with temporary_file("test.pkl") as fpath: - bigram = FrozenPhrases(Phrases(self.sentences, min_count=1, threshold=1)) + bigram = FrozenPhrases(Phrases(self.sentences, min_count=1, threshold=1, connector_words=self.connector_words)) bigram.save(fpath) bigram_loaded = FrozenPhrases.load(fpath) + self.assertEqual(bigram_loaded.connector_words, frozenset(self.connector_words)) self.assertEqual( bigram_loaded[['graph', 'minors', 'survey', 'human', 'interface', 'system']], ['graph_minors', 'survey', 'human_interface', 'system'])