Skip to content

Instantly share code, notes, and snippets.

@vi3k6i5
Created September 15, 2017 18:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vi3k6i5/eabca9de9853e523d142beed46654d4e to your computer and use it in GitHub Desktop.
Save vi3k6i5/eabca9de9853e523d142beed46654d4e to your computer and use it in GitHub Desktop.
FlashText extract keywords from sentence
# pip install flashtext
from flashtext.keyword import KeywordProcessor
keyword_processor = KeywordProcessor()
keyword_processor.add_keyword('Big Apple', 'New York')
keyword_processor.add_keyword('Bay Area')
keywords_found = keyword_processor.extract_keywords('I love Big Apple and Bay Area.')
keywords_found
# ['New York', 'Bay Area']
@vivekyandapalli
Copy link

Please correct me If I'm wrong, Here is my doubt:
The program outputs ['New York', 'Bay Area'] where New York is not in the given string.
keyword_processor.add_keywords_from_list(['Big Apple', 'New York']) results in correct output.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment