vi3k6i5 / flashtext

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

Unable to use flashtext to remove keywords #62

Open illuminatio opened 5 years ago

illuminatio commented 5 years ago
kwp = KeywordProcessor()
kwp.add_keyword('<br>', '')
kwp.replace('one<br>two')

As a result I get an unchanged string. Is there a way to use flashtext to remove keywords from the text?

JusticeN commented 5 years ago

in the doc you can find something like this:

Characters that will determine if the word is continuing. Defaults to set([A-Za-z0-9_])

special character is not supported at the moment

JusticeN commented 5 years ago

you can also use the add_non_boundary method to add you special chars like this. also make sur to give a not empty clean name. instead of kwp.add_keyword('<br>', '') give somthing else as clean name like kwp.add_keyword('<br>', 'test') this work for me see the example below

kwp = KeywordProcessor()
kwp.add_non_word_boundary('<')
kwp.add_non_word_boundary('>')
kwp.add_keyword('<br>', 'test')
kwp.replace('one<br>two')

results: 'one test two'

illuminatio commented 5 years ago

also make sur to give a not empty clean name

But that's not what I want. I want to have result 'onetwo', not 'one something two'. Or at least 'one two'.