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