- Notifications
You must be signed in to change notification settings - Fork10
A PHP implementation of the Aho-Corasick string search algorithm. Mirror fromhttps://gerrit.wikimedia.org/g/AhoCorasick - our actual code is hosted with Gerrit (please seehttps://www.mediawiki.org/wiki/Developer_access for contributing)
License
wikimedia/AhoCorasick
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
AhoCorasick is a PHP implementation of theAho-Corasick string searchalgorithm, which is an efficient way of searching a body of text for multiplesearch keywords.
Here is how you use it:
useAhoCorasick\MultiStringMatcher;$keywords =newMultiStringMatcher(array('ore','hell' ) );$keywords->searchIn('She sells sea shells by the sea shore.' );// Result: array( array( 15, 'hell' ), array( 34, 'ore' ) )$keywords->searchIn('Say hello to more text. MultiStringMatcher objects are reusable!' );// Result: array( array( 4, 'hell' ), array( 14, 'ore' ) )
The algorithm works by constructing a finite-state machine out of the set ofsearch keywords. The time it takes to construct the finite state machine isproportional to the sum of the lengths of the search keywords. Onceconstructed, the machine can locate all occurences of all search keywords inany body of text in a single pass, making exactly one state transition perinput character.
The algorithm originates from"Efficient string matching: an aid to bibliographic search" (CACM, Volume 18, Issue 6, June 1975) by Alfred V. Aho and Margaret J. Corasick.
See also the definition and reference implementation onnist.gov.
- Issue tracker:https://phabricator.wikimedia.org/tag/ahocorasick/
- Source code:https://gerrit.wikimedia.org/g/AhoCorasick
If you are having issues,please let us know.
The project is licensed under the Apache license.
About
A PHP implementation of the Aho-Corasick string search algorithm. Mirror fromhttps://gerrit.wikimedia.org/g/AhoCorasick - our actual code is hosted with Gerrit (please seehttps://www.mediawiki.org/wiki/Developer_access for contributing)