Giter Club home page Giter Club logo

actrie's Introduction

Project actrie

GitHub issues GitHub forks GitHub stars GitHub license PyPI - Implementation PyPI - Python Version PyPI - Wheel

English | 简体中文

What is actrie?

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.

Pattern syntax

1. plain pattern

abc

2. anti-ambiguity pattern

center (?&! ambiguity )

3. anti-antonym pattern

(?<! antonym ) center

4. distance pattern

prefix .{min,max} suffix

5. alternation pattern

pattern0 | pattern1

6. wrapper pattern

( pattern )

Build and install

1. Build C library

# 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

2. Build and install Python package

# build wheel package
python setup.py bdist_wheel

# install wheel package
pip install dist/actrie-*.whl

# Or install from PyPI
pip install actrie

3. Build and install Java package

# go to jni directory
pushd jni

# build nar package
mvn clean package

# install to local maven repository
mvn install

popd

Example

vocab.txt

f|(a|b).{0,5}(e(?&!ef)|g)	pattern0
abc	pattern1
efg	pattern2

Python: example.py

#!/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()

Java: Example.java

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();
        }
    }

}

actrie's People

Contributors

ifplusor avatar

Stargazers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.