基础类
"""
SearchEngineBase可以被继承,继承的类分别代表不同的算法引擎;
每一个引擎都应该实现process_corpus 和 search 函数
"""
class SearchEngineBase(object):
def __init__(self):
pass
# 添加语料:读取文件内容,将文件路径作为ID,连同内容一起送到process_corpus中
def add_corpus(self, file_path):
with open(file_path, 'r') as fin:
text = fin.read()
# print(text)
self.process_corpus(file_path, text)
# 需要对内容进行处理,然后文件路径为ID,将处理后的内容存下来。处理后的内容,就叫做索引?
def process_corpus(self, id, text):
raise Exception('process_corpus not implemented.')
# 给定一个询问,处理询问,再通过索引检索,然后返回
def search(self, query):
raise Exception('search not implemented.')
def