Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Indexing 从InvertedIndex创建.p文件_Indexing - Fatal编程技术网

Indexing 从InvertedIndex创建.p文件

Indexing 从InvertedIndex创建.p文件,indexing,Indexing,我正在尝试构建一个Python搜索引擎,它将从TwitterAPI中提取查询到的tweets我不能使用tweepy。我已经构建了TwitterWrapper类和类引擎,并且还根据我的查询词“raptor”创建了(pickle)语料库,没有问题。我创建了Invertdindex类,但似乎无法构建柠檬化单词的索引,并将其作为pickle文件(.p)添加到我的Jupyter笔记本中(我必须这样做),以便使用我的TwittIR.py接口: t = TwittIR.Engine(“raptor.p”, “

我正在尝试构建一个Python搜索引擎,它将从TwitterAPI中提取查询到的tweets我不能使用tweepy。我已经构建了TwitterWrapper类和类引擎,并且还根据我的查询词“raptor”创建了(pickle)语料库,没有问题。我创建了Invertdindex类,但似乎无法构建柠檬化单词的索引,并将其作为pickle文件(.p)添加到我的Jupyter笔记本中(我必须这样做),以便使用我的TwittIR.py接口:

t = TwittIR.Engine(“raptor.p”, “index (to be named).p”)
results = t.query (“raptor”)
for result in results:
   print(result)
所以,我的问题是,如何制作索引(使用反向索引),并将其作为.p文件保存到我的Jupyter笔记本中?当然,我是一个Python初学者

def build_index(self, corpus):
    index = {}
    if self.lemmatizer == None:
        self.lemmatizer = nltk.WordNetLemmatizer()
    if self.stop_words is None:
        self.stop_words = [self.wordtotoken(word) for word in 
        nltk.corpus.stopwords.words('english')]
    for doc in corpus:
        self.add_document(doc['text'], self.ndocs)
        self.ndocs = self.ndocs + 1


def __getitem__(self,index):
    return self.index[self.normalize_document(index)[0]]