Skip to content

Commit

Permalink
added test of persistence of connector_words during save & load in te…
Browse files Browse the repository at this point in the history
…st_phrases.py
  • Loading branch information
aloknayak29 committed Apr 15, 2021
1 parent 62b0e9c commit 49dfe1b
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions gensim/test/test_phrases.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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())

Expand Down Expand Up @@ -378,9 +379,11 @@ 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'])
Expand Down

0 comments on commit 49dfe1b

Please sign in to comment.