API Documentation#
- class patternpiece.matcher.PatternPiece(patterns, mode='memory')[source]#
Pattern piece matching class, used to call the AC automaton’s Cython implementation.
Multi-pattern, multi-element sequence matching.
Examples
>>> patterns = {(1, 2, 3): 0, (4, 5, 6) : 1} # In this dict, key -> pattern, value -> index >>> automation = PatternPiece(patterns)
- match(encoded, num_workers=-1)[source]#
Search for the added patterns in the given sequences.
- Parameters:
- Returns:
A list of found patterns with their positions and indexes (Index, start, end).
- Return type:
Examples
>>> patterns = {(1, 40, 500): 6} >>> automation = PatternPiece(patterns) >>> sequences = [[(1, 10, 100), (4, 40, 400), (5, 50, 500)]] >>> results = automation.match(sequences) >>> # results = [[(6, 0, 3)]]
- Raises:
Exception – If num_workers is not an integer, or exceeds the maximum number of available CPUs.
ValueError – If the automaton has not been built.