vi3k6i5 / flashtext

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

Feature request #99

Closed KrishnaSindhur closed 4 years ago

KrishnaSindhur commented 4 years ago

hi i am from belong we have one use case that is we need to store additional meta data along with sibling. {"java": [{ "name": "xyz", "meta": { "count":10, "score":0.24 } }, { "name : "abc", "meta": { "count :12, "score": 0.5 } }]

so now if sentence is like this "i know xyz" it should return - ["java": { "meta": { "count: 10, "score":0.24 } }]

so if this look like generic one can we implement to the flash text library.

Thanks

Regards Krishna

thakur-nandan commented 4 years ago

Hey Krishna, If I understood correctly your problem, flashtext already solves it.

Just mention, the keyword, and metadata expected before to the keyword Processor. In your case keyword "xyz" you can mention the metadata which you want to retrieve: {"java": { "meta": { "count": 10, "score": 0.24 } } }`.

Code Snippet: from flashtext import KeywordProcessor kp = KeywordProcessor() kp.add_keyword('xyz', {"java": { "meta": { "count": 10, "score": 0.24 } } }) kp.extract_keywords('i know xyz.')

Returns: [{'java': {'meta': {'count': 10, 'score': 0.24}}}]