用python编写的通用索引器。
indexr的Python项目详细描述
用python编写的通用索引器。根据麻省理工学院的许可证。
功能
indexr.buildr
包能够构造反向索引。
indexr.utils
包包含实用程序,例如用于将文本转换为标记的标记化方法。
设置
此软件包可以使用pip安装:
pip install indexr
示例
在本例中,索引器是为3个文件构造的。示例使用以下3个文件:
0.txt
:
The0thdocument.
1.txt
:
The1stdocument.
2.txt
:
The2nddocument.Somewords:repeat,repeat,repeat.
下面的代码示例可以在demo目录(demo/buildr.py
)中找到。
# Build the indexindex=build_index(files,'index',force_rebuild=True,indexer=SPIMI(show_progress=True))# Try to find the word "1st"print('All found occurrences of "1st":')print(index.find('1st',frequencies=True),"\n")# Try to find the word "The"print('All found occurrences of "The":')print(index.find('The',frequencies=True),"\n")# Try to find the word "repeat"print('All found occurrences of "repeat":')print(index.find('repeat',frequencies=True),"\n")
它提供以下输出:
>>>Allfoundoccurrencesof"1st":>>>{'1.txt':1}>>>>>>Allfoundoccurrencesof"The":>>>{'0.txt':1,'1.txt':1,'2.txt':1}>>>>>>Allfoundoccurrencesof"repeat":>>>{'2.txt':3}
因此,它确实找到了1个“1st”,3个“the”(每个文件中出现1次)和3个“repeat”(一个文件中出现3次)。
历史记录
1.0.1(2015-12-07)
- 第一个版本,包括bsb算法和spimi算法。
0.1.0(2015-12-04)
- pypi上的第一个版本。