zoukankan      html  css  js  c++  java
  • 自动摘要

    每天都要发两三次的企业信息咨询,所以来一个自动摘要试试看吧!

    用conda,在服务器端启动jupyter notebook服务。
    为了对比效果,选择多个自动摘要模块。

    1. 安装依赖
    !pip install snownlp
    !pip install summa
    !pip install textrank4zh
    
    1. 读取文件
      这里没有使用爬虫,直接加载文本文件
    file_name = 'text.txt'
    text = open(file_name).read()
    
    1. 定义函数,抽取摘要并打印出来
    from snownlp import SnowNLP
    from summa.summarizer import summarize
    from textrank4zh import TextRank4Keyword, TextRank4Sentence
    
    def get_summary(text):
    
        s = SnowNLP(text)
        summary = s.summary(5)
        print(summary)
        print("***"*20)
    
        r = summarize(text, ratio=0.2)
        print(r)
        print("***"*20)
    
        tr4s = TextRank4Sentence()
        tr4s.analyze(text=text, lower=True, source='all_filters')
        for item in tr4s.get_key_sentences(num=5):
           print(item.sentence+'。')
        print("***"*20)
    
    1. 运行查看效果
    get_summary(text)
    
  • 相关阅读:
    我是来讲笑话的
    dom4j读取xml
    Mysql常用命令
    如何快速开发小型系统
    Spring aop的实现原理
    Spring IOC容器解析及实现原理
    如何编写更棒的代码
    Git使用教程
    关于程序员吃青春饭问题之探讨
    如何自学编程
  • 原文地址:https://www.cnblogs.com/xuehuiping/p/12107031.html
Copyright © 2011-2022 走看看