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)
    
  • 相关阅读:
    5.Longest Palindrome substring
    3. Longest Substring Without Repeating Characters
    1.Two Sum
    2.Add two Numbers
    oplog
    airflow笔记
    airflow
    grpc protobuf
    modbus
    Linux 工具,一本好书 大牛的博客
  • 原文地址:https://www.cnblogs.com/xuehuiping/p/12107031.html
Copyright © 2011-2022 走看看