my python version is 2.7,5
aahocorasick.so is copyed from git.
#encoding=utf-8`
import ahocorasick
class AC(object):
def __init__(self, keys):
self.keys=keys
A = ahocorasick.Automaton()
for key in keys:
A.add_word(key, key)
A.make_automaton()
self.A=A
def get_locss(self, text):
if not self.keys: return []
locss=[[key,end_idx-len(key)+1,end_idx+1] for end_idx, key in self.A.iter(text)]
return locss
if __name__=="__main__":
a=AC(["你","wo "])
s="你妹啊。。。。"
for i in range(100000000000):
a.get_locss(s)
my python version is 2.7,5 aahocorasick.so is copyed from git.
Test this script, i get