Ruby (zero dependencies) gem for amazing Python package flashtext
This module can be used to replace keywords in sentences or extract keywords from sentences. It is based on the FlashText algorithm
The original paper published on FlashText algorithm
The article published on Medium freeCodeCamp
$ gem install flashtext
Documentation can be found at FlashText Read the Docs
If you are using irb console
require 'flashtext'
keyword_processor = Flashtext::KeywordProcessor.new
# keyword_processor.add_keyword(<unclean name>, <standardised name>)
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"]
keyword_processor.add_keyword('New Delhi', 'NCR region')
new_sentence = keyword_processor.replace_keywords('I love Big Apple and new delhi.')
new_sentence
#=> "I love New York and NCR region."
keyword_processor = Flashtext::KeywordProcessor.new(case_sensitive = true)
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
#=> ['Bay Area']
rspec spec
- Issue Tracker: https://github.com/imran3180/flashtext/issues
- Source Code: https://github.com/imran3180/flashtext/issues
- Python: https://github.com/vi3k6i5/flashtext (Core Project)
- JavaScript: https://github.com/drenther/flashtext.js
- Golang: https://github.com/sundy-li/flashtext
This code is under MIT license.