2017 © Pedro Peláez
 

library phpflashtext

A port of the flashtext python implementation

image

shdev/phpflashtext

A port of the flashtext python implementation

  • Tuesday, December 26, 2017
  • by shdev
  • Repository
  • 1 Watchers
  • 1 Stars
  • 6 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 8 Versions
  • 20 % Grown

The README.md

Flashtext for PHP

Build Status Coverage Status, (*1)

It's a port from the wonderful python project https://github.com/vi3k6i5/flashtext, for internals of the algorithm look there., (*2)

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., (*3)

In PHP 5.6 using regex is really slow. In newer verions it performs better., (*4)

Install

composer require shdev/phpflashtext

Usage

<?php

use Shdev\FlashText\KeywordProcessor;

$keywordProcessor= new KeywordProcessor();

$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';

Citation

The original paper published on FlashText algorithm., (*5)

    @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 on Medium freeCodeCamp., (*6)

The Versions

26/12 2017

dev-develop

dev-develop

A port of the flashtext python implementation

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

The Development Requires

by Sebastian Holtz

25/12 2017

dev-master

9999999-dev

A port of the flashtext python implementation

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

The Development Requires

by Sebastian Holtz

25/12 2017

1.1.4

1.1.4.0

A port of the flashtext python implementation

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

The Development Requires

by Sebastian Holtz

25/12 2017

1.1.3

1.1.3.0

A port of the flashtext python implementation

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

The Development Requires

by Sebastian Holtz

25/12 2017

1.1.2

1.1.2.0

A port of the flashtext python implementation

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

The Development Requires

by Sebastian Holtz

25/12 2017

1.1.1

1.1.1.0

A port of the flashtext python implementation

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

The Development Requires

by Sebastian Holtz

25/12 2017

1.1.0

1.1.0.0

A port of the flashtext python implementation

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sebastian Holtz

25/12 2017

1.0.0

1.0.0.0

A port of the flashtext python implementation

  Sources   Download

The Requires

 

The Development Requires

by Sebastian Holtz