当前位置:网站首页 > 技术博客 > 正文

pythonjieba库函数



import jieba # 创建停用词列表 def stopwordslist(): stopwords = [line.strip() for line in open('stop_words.txt', encoding='UTF-8').readlines()] return stopwords # 对句子进行中文分词 def seg_depart(sentence): # 对文档中的每一行进行中文分词 print("正在分词") sentence_depart = jieba.cut(sentence.strip()) # 创建一个停用词列表 stopwords = stopwordslist() # 输出结果为outstr outstr = '' # 去停用词 for word in sentence_depart: if word not in stopwords: if word != ' ': outstr += word outstr += " " return outstr # 给出文档路径 filename = "Init.txt" outfilename = "out.txt" inputs = open(filename, 'rb') outputs = open(outfilename, 'w') # 将输出结果写入ou.txt中 for line in inputs: line_seg = seg_depart(line) outputs.write(line_seg + ' ') print("-------------------正在分词和去停用词-----------") outputs.close() inputs.close() print("删除停用词和分词成功!!!")

  • 上一篇: mysql8.0触发器
  • 下一篇: 免费的dns
  • 版权声明


    相关文章:

  • mysql8.0触发器2025-06-10 21:01:03
  • monaco字体win102025-06-10 21:01:03
  • 树莓派3b+价格2025-06-10 21:01:03
  • redis缓存怎么用2025-06-10 21:01:03
  • 数据库设置字符集utf82025-06-10 21:01:03
  • 免费的dns2025-06-10 21:01:03
  • u盘的写保护开关在哪2025-06-10 21:01:03
  • 路由交换技术有哪些2025-06-10 21:01:03
  • c引用类型主要有四种2025-06-10 21:01:03
  • flex布局视频教程2025-06-10 21:01:03