영문 PDF의 번역을 시도 1
htps : // m / r rt / ms / 00d4 c8216d04f9274
시도해 보았습니다.
환경
기사에는 몇 가지 버전이 표시되어 있지만, 이번에는 8/11 추기분의 「문장 분해 강화판 코드」를 사용했습니다.
Word 통하지 않고도 어느 정도 단락을 분해할 수 있도록 했습니다.
(대개) 단락 마다 번역하기 위해, 1문씩에 비해 번역 속도도 상당히 맛이 되었습니다.
이 코드를 pdftrans.py로 저장했습니다.
라이브러리 설정 등
$ python3 pdftrans.py
로 실행하면
Traceback (most recent call last):
File "pdftrans.py", line 1, in <module>
from selenium import webdriver
ModuleNotFoundError: No module named 'selenium'
그리고 나왔기 때문에
$ sudo pip3 install selenium
로 설치. pyperclip도 마찬가지로 필요했기 때문에,
$ sudo pip3 install pyperclip
로 설치.
Traceback (most recent call last):
File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/common/service.py", line 76, in start
stdin=PIPE)
File "/usr/lib/python3.6/subprocess.py", line 729, in __init__
restore_signals, start_new_session)
File "/usr/lib/python3.6/subprocess.py", line 1364, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'chromedriver.exe': 'chromedriver.exe'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "pdftrans.py", line 165, in <module>
TranslateFromClipboard(*args)
File "pdftrans.py", line 75, in TranslateFromClipboard
chrome_options=options)
File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/chrome/webdriver.py", line 73, in __init__
self.service.start()
File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/common/service.py", line 83, in start
os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'chromedriver.exe' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
되었기 때문에,
https://sites.google.com/a/chromium.org/chromedriver/home에서
chromedriver_linux64.zip
다운로드 및 배포.
$ ls -alh
合計 16M
drwxrwxr-x 2 nanbuwks nanbuwks 4.0K 8月 17 21:07 .
drwxrwxr-x 91 nanbuwks nanbuwks 56K 8月 17 21:06 ..
-rwxr-xr-x 1 nanbuwks nanbuwks 11M 5月 29 06:05 chromedriver
-rw-rw-r-- 1 nanbuwks nanbuwks 5.1M 8月 17 21:06 chromedriver_linux64.zip
-rw-r--r-- 1 nanbuwks nanbuwks 8.0K 8月 17 16:53 pdftrans.py
으로 pdftrans.py 같은 디렉토리에 넣었습니다.
그 위에 pdftrans.py의 9 행
DRIVER_PATH = 'chromedriver.exe'
되어 있는 곳을 다음과 같이 변경.
DRIVER_PATH = './chromedriver'
PATH 설정을 간소화하고 일단 pdftrans.py는 스크립트가있는 디렉토리에서 실행하기로 결정했습니다.
Traceback (most recent call last):
File "pdftrans.py", line 165, in <module>
TranslateFromClipboard(*args)
File "pdftrans.py", line 75, in TranslateFromClipboard
chrome_options=options)
File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/chrome/webdriver.py", line 81, in __init__
desired_capabilities=desired_capabilities)
File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.SessionNotCreatedException: Message: session not created: This version of ChromeDriver only supports Chrome version 84
라고 나왔기 때문에 Chrome은 Version 83 을 사용하고 있었습니다만, 최신판에 업데이트해 버전: 84.0.4147.125(Official Build) (64 비트)로 했습니다.
실행
$ python3 pdftrans.py
1. 英語 → 日本語 2. 日本語 → 英語 1
1. DeepL 2.GoogleTranslate 1
翻訳結果を書き出しますか? y/n y
1. txt 2. HTML 3. both 2
出力ファイルにつける名前を入力してください(デフォルトは'translated_text.html')
(論文の)タイトルを入力してください zigbeebdb
翻訳経過をここに表示しますか? y/n n
準備ができたらEnterを押してください
1/900 0% done
2/900 0% done
3/900 0% done
4/900 0% done
・
・
・
결과
사용해보십시오.
$ python3 pdftrans.py
Traceback (most recent call last):
File "pdftrans.py", line 1, in <module>
from selenium import webdriver
ModuleNotFoundError: No module named 'selenium'
$ sudo pip3 install selenium
$ sudo pip3 install pyperclip
Traceback (most recent call last):
File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/common/service.py", line 76, in start
stdin=PIPE)
File "/usr/lib/python3.6/subprocess.py", line 729, in __init__
restore_signals, start_new_session)
File "/usr/lib/python3.6/subprocess.py", line 1364, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'chromedriver.exe': 'chromedriver.exe'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "pdftrans.py", line 165, in <module>
TranslateFromClipboard(*args)
File "pdftrans.py", line 75, in TranslateFromClipboard
chrome_options=options)
File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/chrome/webdriver.py", line 73, in __init__
self.service.start()
File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/common/service.py", line 83, in start
os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'chromedriver.exe' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
$ ls -alh
合計 16M
drwxrwxr-x 2 nanbuwks nanbuwks 4.0K 8月 17 21:07 .
drwxrwxr-x 91 nanbuwks nanbuwks 56K 8月 17 21:06 ..
-rwxr-xr-x 1 nanbuwks nanbuwks 11M 5月 29 06:05 chromedriver
-rw-rw-r-- 1 nanbuwks nanbuwks 5.1M 8月 17 21:06 chromedriver_linux64.zip
-rw-r--r-- 1 nanbuwks nanbuwks 8.0K 8月 17 16:53 pdftrans.py
DRIVER_PATH = 'chromedriver.exe'
DRIVER_PATH = './chromedriver'
Traceback (most recent call last):
File "pdftrans.py", line 165, in <module>
TranslateFromClipboard(*args)
File "pdftrans.py", line 75, in TranslateFromClipboard
chrome_options=options)
File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/chrome/webdriver.py", line 81, in __init__
desired_capabilities=desired_capabilities)
File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.SessionNotCreatedException: Message: session not created: This version of ChromeDriver only supports Chrome version 84
$ python3 pdftrans.py
1. 英語 → 日本語 2. 日本語 → 英語 1
1. DeepL 2.GoogleTranslate 1
翻訳結果を書き出しますか? y/n y
1. txt 2. HTML 3. both 2
出力ファイルにつける名前を入力してください(デフォルトは'translated_text.html')
(論文の)タイトルを入力してください zigbeebdb
翻訳経過をここに表示しますか? y/n n
準備ができたらEnterを押してください
1/900 0% done
2/900 0% done
3/900 0% done
4/900 0% done
・
・
・
결과
사용해보십시오.
8/16 추가
멀티 스레드로 대량으로 Chrome을 여는 역기 고속화를 실시했습니다.
이쪽은 내보내기는 HTML만으로 되어 있습니다.
또한 DeepL의 경우, 너무 열리면 제한이 걸려 번역 중지되므로주의하시기 바랍니다.
제대로 읽고 사전에 PDF 문자 정보를 클립보드에 복사해 두면 제대로 움직였습니다!
「【Python】영문 PDF(에 한정되지 않지만)를 DeepL이나 Google 번역으로 자동으로 번역시켜 텍스트 파일로 해 버리자.」
htps : // m / r rt / ms / c56477033c 17 A2 A 28 A
덧붙여 8/16판의 고속판으로 시험해 보았다
동시 병행 30이 되면 위와 같은 87페이지 1249문장의 문서를 10분 정도로 번역할 수 있었습니다만, 로드 애버레이지가 어려워졌습니다.
오버헤드의 손실이 걸리지 않도록 환경에 따라 궁리하는 것이 좋을 것 같습니다.
실제로, 동시 병행 10으로 해 보면 6분 정도로 처리할 수 있었습니다.
Reference
이 문제에 관하여(영문 PDF의 번역을 시도 1), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/nanbuwks/items/7ec191ad4e585a7ca10b
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
Reference
이 문제에 관하여(영문 PDF의 번역을 시도 1), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/nanbuwks/items/7ec191ad4e585a7ca10b텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)