【信息检索】大作业:jieba/gensim制作一个搜索引擎

设计思路

  • 利用jieba分词
  • 去停用词
  • 利用nltk进行词干提取、词形还原等预处理 (效果太差了)
  • 利用genism的bm25模型建立索引
  • 对于query设置置信区,并逐条搜索
  • 讲搜索内容写入字典
  • 按照指定格式输出字典内容
    (当然用es写也可以)
# -*- coding:utf-8 -*-
import nltk.tokenize
import time
import jieba
"""
———————————————————————————————————————————————————
2020信息检索期末考试
凌珑
————————————————————————————————————————————————————
"""

'''建索引'''
def readfile(filename):
    file= open(filename,'r',encoding='UTF-8')
    print("获取文件成功")
    return file

def makestops():
    stopwords=set()
    with open('stopwords.txt','r')as f:
        while True:
            line = f.readline()
            if not line:
                break
            line = line.strip('\n')
            stopwords.add(line)
    return stopwords


def cutsentence(sen,stops):
    # words = sen.split()
    # words = nltk.tokenize.word_tokenize(sen)
    words = jieba.lcut_for_search(sen.strip(), HMM=True)
    words = [i for i in words if i not in stops]

    return words

def pretreatment(datafile,corpus,dataid):
    begin=time.time()
    stops = makestops()
    for sentence in datafile:
        sen = sentence.split("\t", 1)
        words=cutsentence(sen
  • 0
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值