- Notifications
You must be signed in to change notification settings - Fork5
Extract Keywords from sentence or Replace keywords in sentences. @https://github.com/vi3k6i5/flashtext
License
shdev/phpflashtext
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
It's a port from the wonderful python projecthttps://github.com/vi3k6i5/flashtext,for internals of the algorithm look there.
This algorithm allows you to extract or replace several keywords at ones.If you deal with 300 keywords, which have 5 variants each a regex approach is slower than the flashtext approach.For 1000 keyword with 5 variants each the regex can't be build.
In PHP 5.6 using regex is really slow. In newer verions it performs better.
composer require shdev/phpflashtext
<?phpuseShdev\FlashText\KeywordProcessor;$keywordProcessor=newKeywordProcessor();$keywords = ['java' => ['java_2e','java programing'],'product management' => ['product management techniques','product management'],];$keywordProcessor->addKeywordsFromAssocArray($keywords);$sentence ='I know java_2e and product management techniques';$keywordsExtracted =$keywordProcessor->extractKeywords($sentence);// $keywordsExtracted = ['java', 'product management']$keywordsExtractedWithSpanInfo =$keywordProcessor->extractKeywords($sentence,true);// $keywordsExtractedWithSpanInfo = [//['java', 7, 14],// ['product management', 19, 48],//]$sentenceNew =$keywordProcessor->replaceKeywords($sentence);// $sentenceNew = 'I know java and product management';
The original paper published onFlashText algorithm.
@ARTICLE{2017arXiv171100046S, author = {{Singh}, V.}, title ="{Replace or Retrieve Keywords In Documents at Scale}", journal = {ArXiv e-prints}, archivePrefix ="arXiv", eprint = {1711.00046}, primaryClass ="cs.DS", keywords = {Computer Science - Data Structures and Algorithms}, year = 2017, month = oct, adsurl = {http://adsabs.harvard.edu/abs/2017arXiv171100046S}, adsnote = {Provided by the SAO/NASA Astrophysics Data System} }
The article published onMedium freeCodeCamp.
About
Extract Keywords from sentence or Replace keywords in sentences. @https://github.com/vi3k6i5/flashtext
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors3
Uh oh!
There was an error while loading.Please reload this page.