vi3k6i5 / flashtext

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

Create Insert Around Use Case #60

Open jamespeacock opened 6 years ago

jamespeacock commented 6 years ago

For any use case where the goal is to preserve the original text keyword and prepend/append to it, these changes allow for that without replacing the original text with the perhaps differently cased keyword text that matches.

For HTML highlighting in particular, this will be incredibly useful.

These code changes do not affect any other use case, and the custom replacement is optional. I have also included an example in the README for how this could be used.

coveralls commented 6 years ago

Coverage Status

Coverage decreased (-0.3%) to 98.973% when pulling 142889ebd4e334ec20038b123168c09f0cc94cb8 on jamespeacock:master into 5591859aabe3da37499a20d0d0d6dd77e480ed8d on vi3k6i5:master.

jamespeacock commented 6 years ago

Will create tests to cover this new usage if you let me know whether this is an acceptable addition to the Keyword Processor.

jamespeacock commented 6 years ago

Additionally, perhaps this could be a separate method that takes in a 'prepend' and an 'append' rather than a 'replacement' and this could eliminate the need for str.replace() in keyword.py:644