vi3k6i5 / flashtext

Extract Keywords from sentence or Replace keywords in sentences.
MIT License
5.6k stars 601 forks source link

Extracting partial term even though complete term is present. #8

Closed vi3k6i5 closed 7 years ago

vi3k6i5 commented 7 years ago

It extracts multiple terms even though it should extract only 1 longest match:

keyword_processor.add_keyword('spring', 'spring framework')
keyword_processor.add_keyword('spring framework', 'spring framework')
keyword_processor.add_keyword('framework', 'framework')
print(keyword_processor.extract_keywords('spring framework'))
output: ['spring framework', 'framework']

But this case it works:


keyword_processor = KeywordProcessor()
keyword_processor.add_keyword('spring', 'springf1')
keyword_processor.add_keyword('spring framework', 'springf2')
keyword_processor.add_keyword('framework', 'framework')
print(keyword_processor.extract_keywords('spring framework'))
output: ['spring framework']```
vi3k6i5 commented 7 years ago

Bug fixed:

from flashtext.keyword import KeywordProcessor
keyword_processor = KeywordProcessor()
keyword_processor.add_keyword('spring', 'spring framework')
keyword_processor.add_keyword('framework', 'framework')
keyword_processor.add_keyword('spring framework', 'spring framework')

print(keyword_processor.extract_keywords('spring framework'))
# ['spring framework']