-
-
16 Jul 2010 19:06:10 UTC
- Distribution: Algorithm-AhoCorasick
- Source (raw)
- Browse (raw)
- Changes
- How to Contribute
- Issues (0)
- Testers (865 / 0 / 0)
- Kwalitee
Bus factor: 1- 94.63% Coverage
- License: unknown
- Activity
24 month- Tools
- Download (6.02KB)
- MetaCPAN Explorer
- Permissions
- Subscribe to distribution
- Permalinks
- This version
- Latest version
and 1 contributors-
Vaclav Barta
- Dependencies
- Test::More
- and possibly others
- Reverse dependencies
- CPAN Testers List
- Dependency graph
NAME
Algorithm::AhoCorasick::SearchMachine - implementation and low-level interface of Algorithm::AhoCorasick
VERSION
Version 0.03
SYNOPSIS
use Algorithm::AhoCorasick::SearchMachine; sub callback { my ($pos, $keyword) = @_; ... return undef; } $machine = Algorithm::AhoCorasick::SearchMachine->new(@keywords); while (<STDIN>) { $machine->feed($_, \&callback); }
METHODS
new
The constructor. Takes the list of keywords as parameters (there must be at least one, and the constructor dies if they contain an empty string).
feed
Feeds input to the state machine. First (after the instance) argument of this method is the input text (which can be empty, in which case the method doesn't do anything), second argument is the callback invoked on each match.
feed
calls the callback with 2 arguments: the position and the matched keyword. The callback can stop further search by returning a true value, whichfeed
returns. If the search wasn't stopped,feed
returns undef, and can then be called with another chunk of input text to continue the search (matching all keywords, even those spanning multiple chunks). Note that when the callback stops the search, this scenario doesn't work (because the state machine gets out of sync);feed
should not be called again on the same instance after the callback returned true. Also note that the position passed to the callback is relative to the current input text chunk; it is negative for keywords spanning multiple chunks.AUTHOR
Vaclav Barta,
<vbar@comp.cz>
COPYRIGHT & LICENSE
Copyright 2010 Vaclav Barta, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Module Install Instructions
To install Algorithm::AhoCorasick, copy and paste the appropriate command in to your terminal.
cpanm Algorithm::AhoCorasick
perl -MCPAN -e shell install Algorithm::AhoCorasick
For more information on module installation, please visit the detailed CPAN module installation guide.