forked from yihong0618/bilingual_book_maker
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
8 changed files
with
136 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import re | ||
from copy import copy | ||
|
||
|
||
class EPUBBookLoaderHelper: | ||
def __init__(self, translate_model, accumulated_num): | ||
self.translate_model = translate_model | ||
self.accumulated_num = accumulated_num | ||
|
||
def deal_new(self, p, wait_p_list): | ||
self.deal_old(wait_p_list) | ||
new_p = copy(p) | ||
new_p.string = self.translate_model.translate(p.text) | ||
p.insert_after(new_p) | ||
|
||
def deal_old(self, wait_p_list): | ||
if not wait_p_list: | ||
return | ||
|
||
result_txt_list = self.translate_model.translate_list(wait_p_list) | ||
|
||
for i in range(len(wait_p_list)): | ||
if i < len(result_txt_list): | ||
p = wait_p_list[i] | ||
new_p = copy(p) | ||
new_p.string = result_txt_list[i] | ||
p.insert_after(new_p) | ||
|
||
wait_p_list.clear() | ||
|
||
|
||
def is_text_link(text): | ||
url_pattern = re.compile( | ||
r"http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+" | ||
) | ||
return bool(url_pattern.match(text.strip())) | ||
|
||
|
||
def is_text_tail_link(text, num=100): | ||
text = text.strip() | ||
url_pattern = re.compile( | ||
r".*http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+$" | ||
) | ||
return bool(url_pattern.match(text)) and len(text) < num | ||
|
||
|
||
def is_text_source(text): | ||
return text.strip().startswith("Source: ") | ||
|
||
|
||
def is_text_list(text, num=80): | ||
text = text.strip() | ||
return re.match(r"^Listing\s*\d+", text) and len(text) < num | ||
|
||
|
||
def is_text_figure(text, num=80): | ||
text = text.strip() | ||
return re.match(r"^Figure\s*\d+", text) and len(text) < num |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import time | ||
import re | ||
import time | ||
from copy import copy | ||
from os import environ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters