Skip to content

Commit

Permalink
fuzzy extract_keywords : [ADD] examples for levensthein and fix mista…
Browse files Browse the repository at this point in the history
…kes in testing doc
  • Loading branch information
remiadon committed Jun 6, 2019
1 parent bb56cb6 commit fec427c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
16 changes: 14 additions & 2 deletions flashtext/keyword.py
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,10 @@ def get_next_word(self, sentence):
Returns:
next_word (str): The next word in the sentence
Examples:
TODO
>>> from flashtext import KeywordProcessor
>>> keyword_processor = KeywordProcessor()
>>> keyword_processor.add_keyword('Big Apple')
>>> 'Big'
"""
next_word = str()
for char in sentence:
Expand All @@ -739,7 +742,16 @@ def levensthein(self, word, max_cost=2, start_node=None):
the cost (i.e the distance), and the depth in the trie
Examples:
TODO
>>> from flashtext import KeywordProcessor
>>> keyword_processor = KeywordProcessor(case_sensitive=True)
>>> keyword_processor.add_keyword('Marie', 'Mary')
>>> next(keyword_processor.levensthein('Maria', max_cost=1))
>>> ({'_keyword_': 'Mary'}, 1, 5)
...
>>> keyword_processor = KeywordProcessor(case_sensitive=True
>>> keyword_processor.add_keyword('Marie Blanc', 'Mary')
>>> next(keyword_processor.levensthein('Mari', max_cost=1))
>>> ({' ': {'B': {'l': {'a': {'n': {'c': {'_keyword_': 'Mary'}}}}}}}, 1, 5)
"""
start_node = start_node or self.keyword_trie_dict
rows = range(len(word) + 1)
Expand Down
6 changes: 3 additions & 3 deletions test/test_extract_fuzzy.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def test_extract_addition(self):
def test_correct_keyword_on_addition(self):
"""
Test for simple additions using the levensthein function
We ensure we end up on the right node in the when starting from the current node
We ensure we end up on the right node in the trie when starting from the current node
"""
keyword_proc = KeywordProcessor()
for keyword in (('colour here', 'couleur ici'), ('and heere', 'et ici')):
Expand Down Expand Up @@ -69,7 +69,7 @@ def test_correct_keyword_on_addition(self):
def test_correct_keyword_on_deletion(self):
"""
Test for simple deletions using the levensthein function
We ensure we end up on the right node in the when starting from the current node
We ensure we end up on the right node in the trie when starting from the current node
"""
keyword_proc = KeywordProcessor()
keyword_proc.add_keyword('skype')
Expand All @@ -87,7 +87,7 @@ def test_correct_keyword_on_deletion(self):
def test_correct_keyword_on_substitution(self):
"""
Test for simple substitions using the levensthein function
We ensure we end up on the right node in the when starting from the current node
We ensure we end up on the right node in the trie when starting from the current node
"""
keyword_proc = KeywordProcessor()
for keyword in (('skype', 'messenger'),):
Expand Down

0 comments on commit fec427c

Please sign in to comment.