学习信息检索课程,老师让写一个倒排索引与查询处理的程序,于是抱着试试的心态自学python写了出来。
整个没有什么太大的算法技巧,唯一的就是查询处理那里递归函数正反两次反复查找需要多调试下。
数据结构:
#-*-coding:utf-8-*-
#!/usr/bin/python
'''
数据结构
建立索引
mydir 文档列表
onedoc 每一个文档
mydoc 当前查询的文档
mywords 建立索引的字典
myindex 0 文档下标 1 单词下标 2 次数 3...
wordcntdict中的个数 doccnt文档个数
三个字典
mywordsdictindex 单词编号 起始位置
antimywordsdict 单词编号 结束位置
mywordsdict 单词->单词编号
查询
mypos是每个的单词起始的index下标
myfindindex是每个单词的标号,
mydocs 查询到的文档号
'''
mydir=[]
mywords=[]
myindex=[]
mywordsdictindex={}
antimywordsdict={}
mywordsdict={}
wordcnt=0#dict中的个数
doccnt=0#文档个数
listcnt=0#index个数
mypos=[]
mydocs=[]
myfindindex=[]
mydoc=0
direct=0
print id(mydir)
创建索引:
#-*-coding:utf-8-*-
#!/usr/bin/python
from mydate import *
import sys
i