treg使用trie结构的regex模式来搜索文本中可能大量的单词和短语。
treg的Python项目详细描述
树0.0.3
treg使用trie结构的regex模式来搜索文本中可能大量的单词和短语。在
实验状态
该项目处于早期和试验阶段,未来可能会有重大变化。在
文件
文档可从https://treg.readthedocs.io获得
入门
fromtregimportTreg,Phrase,Match# Initialize a new patterntreg=Treg()# Add some phrasestreg.add_phrases([Phrase(phrase='afternoon tea',meta={'fun':1}),Phrase(phrase='tea party',meta={'fun':3}),# ...])# Compile the patterntreg.compile()# Happy searching!formatchintreg.find_iter("A long collection of afternoon tea party recipes ...",overlapped=True):print(match)# OutputMatch(phrases=[Phrase(phrase='afternoon tea',meta={'fun':1})],start=16,end=29)Match(phrases=[Phrase(phrase='tea party',meta={'fun':3})],start=26,end=35)
- 项目
标签: