class SearchEngineBase(object):
def __init__(self):
pass
def add_corpus(self, file_path):
with open(file_path, 'r') as fin:
text = fin.read()
self.process_corpus(file_path, text)
def process_corpus(self, id, text):
raise Exception('process_corpus not implemented.')
def search(self, query):
raise Exception('search not implemented.')
def main(search_engine):
for file_path in ['1.txt', '2.txt', '3.txt', '4.txt', '5.txt']:
###将文件逐个传递给add_corpus, 再传递给process_corpus函数
search_engine.add_corpus(file_path)
while True:
query = input()
results = search_engine.search(query)
print('found {} resul
实现简单的搜索引擎<1>
最新推荐文章于 2023-07-13 16:48:22 发布
本文将引导读者了解如何从零开始创建一个简单的搜索引擎。我们将探讨文本预处理、倒排索引的构建以及搜索查询的匹配原理。
摘要由CSDN通过智能技术生成