【发布时间】:2018-05-16 20:57:23
【问题描述】:
我是使用Python NLTK创建倒排索引来获取信息检索的初学者。
我成功创建的函数makeInvertedIndex是将一个dict变量rdes_list作为输入,输出是一个倒排索引字典。 例如:
input rdes_list = {1:'hello world',2:'hello',3:'hello cat',4:'hellolot of cats'}
输出 index_dict = {'hello': [0, 1, 2], 'cat': [2], 'of': [3], 'world': [0], 'cats': [3] , 'hellolot': [3]}
基于上面的函数,我遇到了创建另外两个函数的问题: 第一个是创建一个orSearch (invertedIndex, query)函数,它接受一个倒排索引(即index_dict)和查询(即一个单词列表),然后返回一组文档编号指定所有包含查询中任何字词的文档。
第二个是创建一个andSearch(invertedIndex, query)函数,它接受一个倒排索引(即index_dict)和query(即一个单词列表),然后返回集合文档编号指定包含查询中的所有个单词的所有文档。
【问题讨论】:
标签: python-3.x nltk information-retrieval