1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

長文英語を翻訳し、要約の粒度を自由に変更出来るツール

Last updated at Posted at 2023-06-19

目的

英語の長文を読むとき、とても苦労してしまう。自分が読むときは一番最初に全体の要約を知りたい。その次はもう少し細かくした要約。その次はもっともっと細かい要約という様にどんどん細かくして要約が欲しい。

そこで今回は全体をn分割したツールの作成を行う

ツールの挙動

  • M行の文章があった時
  1. M行をN分割する
  2. N分割した文章を翻訳する
  3. 翻訳した結果を要約する。
  4. 要約した内容を合併する

完成

全体を2分割した要約が欲しい場合
image.png

要約結果
image.png

コード

from deep_translator import GoogleTranslator
from pysummarization.nlpbase.auto_abstractor import AutoAbstractor
from pysummarization.tokenizabledoc.mecab_tokenizer import MeCabTokenizer
from pysummarization.abstractabledoc.top_n_rank_abstractor import TopNRankAbstractor
import pymsteams, re, time, math, sys

args = sys.argv
b=args[1]
b=int(b)

translist=[]
translists=[]


f = open('text2.txt', 'r')
intext = f.read()
f.close()


split_text = intext.split('. ') 
print(len(split_text))


n = math.ceil(len(split_text) / b)
result = [ split_text[idx: idx + n] for idx in range(0,len(split_text), n)] 

for splitsaki in result:
    documentlist=[]
    for sourcetext in splitsaki:
        sourcetext = sourcetext.replace('\n+', ' ')
        sourcetext = re.sub('\s+', ' ', sourcetext)

        try:
            document = GoogleTranslator(source='auto',target='ja').translate(sourcetext)
            documentlist.append(document)
        except:
            pass

    documents=''.join(documentlist)
    auto_abstractor = AutoAbstractor()
    auto_abstractor.tokenizable_doc = MeCabTokenizer()
    auto_abstractor.delimiter_list = ["", "\n"]
    abstractable_doc = TopNRankAbstractor()
    result_dict = auto_abstractor.summarize(documents, abstractable_doc)
    for x in result_dict["summarize_result"]:
        translist.append(x)
        print(x)


transresult = ''.join(translist)
print(transresult)


f = open('youyaku.txt', 'x')
f.write(transresult)
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?