vi3k6i5 / flashtext

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

Incorrect Output in a specific scenario #73

Open ankurphutela opened 5 years ago

ankurphutela commented 5 years ago

Scenario -

Use Dictionary for multiple keywords and one keyword is present in more than one class/category, then, output is incorrect and shows only one class/category.

Below mentioned is example code for detailed explanation.

#Import library
from flashtext import KeywordProcessor

#Define Dictionary
dict_keywords={}

#'Russia' is present in both classes/categories - Europe and Asia 
dict_keywords["Europe"]=['France','Germany','Russia']
dict_keywords["Asia"]=['India','Russia','China']

keyword_processor = KeywordProcessor()
keyword_processor.add_keywords_from_dict(dict_keywords)

#Content has 'Russia' keyword
content="Russia is a federal semi-presidential republic"
flashtext_out=keyword_processor.extract_keywords(content)

print(flashtext_out)
#Output - ['Asia'] 
#Output should consist of both classes/categories - Asia and Europe
Santhosh0505 commented 3 years ago

@biswajitpatra - If the commit which you have done in your forked instance working fine, could you please create a pull request to this main repo so that this could be the part of release package which we can use

@vi3k6i5 - Could you please confirm if this can be merged into this primary repo?