flashtext icon indicating copy to clipboard operation
flashtext copied to clipboard

Priority Rank of Keyword Replacements

Open SamShowalter opened this issue 5 years ago • 2 comments

Is there a way to set the priority of string replacements? Could I do something that could preference longer replacements (e.g. "I Love New York" -> "ILNY" v. "New York" -> "NYC") over shorter ones? How can I incorporate this flexibility?

SamShowalter avatar Mar 18 '19 16:03 SamShowalter

EDIT: The system appears to do this already. I just want to verify this is the case.

`from flashtext import KeywordProcessor keyword_processor = KeywordProcessor() keyword_processor.add_keyword('I Love New York', 'ILNY') keyword_processor.add_keyword("New York", "NYC") keyword_processor.add_keyword("I Love", "ILY")

keyword_processor.replace_keywords("This is true, I Love I Love New York New York and everything else")`

Output: 'This is true, ILY ILNY NYC and everything else'

SamShowalter avatar Mar 18 '19 16:03 SamShowalter

Yes so longest match is preferred.

On Mon, Mar 18, 2019, 10:02 PM Sam Showalter [email protected] wrote:

EDIT: The system appears to do this already. I just want to verify this is the case.

`from flashtext import KeywordProcessor keyword_processor = KeywordProcessor() keyword_processor.add_keyword('I Love New York', 'ILNY') keyword_processor.add_keyword("New York", "NYC") keyword_processor.add_keyword("I Love", "ILY")

keyword_processor.replace_keywords("This is true, I Love I Love New York New York and everything else")`

Output: 'This is true, ILY ILNY NYC and everything else'

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/vi3k6i5/flashtext/issues/76#issuecomment-473992484, or mute the thread https://github.com/notifications/unsubscribe-auth/AC-Nwsb47H4utmDgmY2ZOpq9I2e5JMBIks5vX79_gaJpZM4b6Ox- .

vi3k6i5 avatar Mar 18 '19 16:03 vi3k6i5