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.

(Python)無料で長文英語を翻訳するツール

Last updated at Posted at 2023-06-26

目的

論文を読むとき、一括で翻訳をするのにとても困ってしまった。今回は英文を一文づつ分割して、翻訳するツールを作成する

入力文章

text.txtで翻訳したい文字列を保存する
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

translist=[]
translists=[]

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



#split_text = [intext[x:x+100] for x in range(0, len(intext), 100)]
#print(split_text)


split_text = intext.split('. ')

for sourcetext in split_text:
    sourcetext = sourcetext.replace('\n+', ' ')
    sourcetext = re.sub('\s+', ' ', sourcetext)

    try:
        document = GoogleTranslator(source='auto',target='ja').translate(sourcetext)
    except:
        pass
    translist = document
    translist = str(sourcetext)+"\n"+ str(translist) + "\n\n"
    translists.append(translist)
    print(translist)


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


f = open('masaseihon3.txt', 'x')
f.write(transresult)
f.close()
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?