Project

flashtext

0.0
No commit activity in last 3 years
No release in over 3 years
Ruby implementation of FlashText Algorithm
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

~> 1.16
~> 2.0
~> 10.0
~> 3.0
 Project Readme

Flashtext Ruby Gem

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

More about Flashtext algorithm.

The original paper published on FlashText algorithm

The article published on Medium freeCodeCamp

Installation

$ gem install flashtext

API doc

Documentation can be found at FlashText Read the Docs

Usage

If you are using irb console

require 'flashtext'

Extract keywords

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"]

Replace keywords

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."

Case Sensitive example

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']

Test

rspec spec

Contribute

Implementation in other languages

License

This code is under MIT license.