English | 简体中文
In the beginning, actrie is an implementation of Aho-Corasick automation, optimize for large scale multi-pattern.
Now, we support more types of pattern: anti-ambiguity pattern, anti-antonym pattern, distance pattern, alternation pattern, etc. You can combine all of them together.
abc
center (?&! ambiguity )
(?<! antonym ) center
prefix .{min,max} suffix
pattern0 | pattern1
( pattern )
# download source
git clone --depth=1 --recurse-submodules --shallow-submodules https://github.com/ifplusor/actrie.git
# go to project directory
cd actrie
# make build directory
mkdir build && pushd build
# configure cmake project
cmake -DCMAKE_BUILD_TYPE=Release ..
# configure cmake project if no stdatomic.h in gcc
#cmake -DCMAKE_BUILD_TYPE=Release -D__GCC_ATOMICS__=ON ..
# build alib and actrie libraries
make actrie
popd
# build wheel package
python setup.py bdist_wheel
# install wheel package
pip install dist/actrie-*.whl
# Or install from PyPI
pip install actrie
# go to jni directory
pushd jni
# build nar package
mvn clean package
# install to local maven repository
mvn install
popd
f|(a|b).{0,5}(e(?&!ef)|g) pattern0
abc pattern1
efg pattern2
#!/usr/bin/env python
# coding=utf-8
from actrie import *
# with open("vocab.txt") as rf:
# pattern = rf.read()
pattern = """
f|(a|b).{0,5}(e(?&!ef)|g)
abc
efg
"""
content = "abcdefg"
def test():
global pattern, content
# create matcher by file
# matcher = Matcher.create_by_file("vocab.txt")
# create matcher by string
matcher = Matcher.create_by_string(pattern)
# iterator
for matched in matcher.finditer(content):
print(matched)
# find all
all_matched = matcher.findall(content)
print(all_matched)
if __name__ == "__main__":
test()
package psn.ifplusor.actrie;
public class Example {
public static void main(String[] args) {
String pattern = "f|(a|b).{0,5}(e(?&!ef)|g)\nabc\nefg";
String content = "abcdefg";
// create matcher by string
try (Matcher matcher = Matcher.createByString(pattern)) {
try (Context context = matcher.match(content)) {
// iterator
for (Word word : context) {
System.out.println(word);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}