aho-corasick

Aho-Corasick algorithm for python


Keywords
AhoCorasick, Aho-Corasick, Entities matching
License
MIT
Install
pip install aho-corasick==0.1

Documentation

Aho-corasick Algorithm

用法

一般用法

    ac = AhoCorasick()
    
    # 添加词语
    ac.add_words(["he", "hers", "she", "his", "is"])

    # 搜索
    result = json.dumps(ac.search("ushersis"), indent=2, ensure_ascii=False)

    # 结果
    {
        "result": [
          {
            "start": 1,
            "word": "she",
            "stop": 4
          },
          {
            "start": 6,
            "word": "is",
            "stop": 8
          },
          {
            "start": 2,
            "word": "hers",
            "stop": 6
          },
          {
            "start": 2,
            "word": "he",
            "stop": 4
          }
        ]
    }