hpprc commited on
Commit
5ad5573
·
1 Parent(s): 697087c
Files changed (1) hide show
  1. en-ja-align.py +15 -12
en-ja-align.py CHANGED
@@ -58,22 +58,27 @@ def parse_html_table(path: Path):
58
  cur_left_quote, cur_right_quote = 0, 0
59
  cur_left_parens_ja, cur_right_parens_ja = 0, 0
60
  cur_left_parens_ja2, cur_right_parens_ja2 = 0, 0
61
- continue_count = 0
62
 
63
  for table in tables:
64
  for tr in table.find_all("tr"):
65
  text_en, _, text_ja = (preprocess(td.text) for td in tr.find_all("td"))
66
  text_ja = unicodedata.normalize("NFKC", text_ja)
67
 
68
- cur_left_parens += text_en.count("(")
69
- cur_right_parens += text_en.count(")")
70
- cur_left_quote += len(list(re.findall(r"``", text_en)))
71
- cur_right_quote += len(list(re.findall(r"''", text_en)))
72
 
73
- cur_left_parens_ja += text_ja.count("「")
74
- cur_right_parens_ja += text_ja.count("")
75
- cur_left_parens_ja2 += text_ja.count("『")
76
- cur_right_parens_ja2 += text_ja.count("』")
 
 
 
 
 
 
 
 
77
 
78
  if (
79
  text_ja.strip().endswith("。")
@@ -82,7 +87,7 @@ def parse_html_table(path: Path):
82
  and cur_left_quote == cur_right_quote
83
  and cur_left_parens_ja == cur_right_parens_ja
84
  and cur_left_parens_ja2 == cur_right_parens_ja2
85
- ) or continue_count >= 10:
86
  texts_en.append((cur_text_en + " " + text_en).strip())
87
  texts_ja.append((cur_text_ja + text_ja).strip())
88
  cur_text_en, cur_text_ja = "", ""
@@ -90,11 +95,9 @@ def parse_html_table(path: Path):
90
  cur_left_quote, cur_right_quote = 0, 0
91
  cur_left_parens_ja, cur_right_parens_ja = 0, 0
92
  cur_left_parens_ja2, cur_right_parens_ja2 = 0, 0
93
- continue_count = 0
94
  else:
95
  cur_text_en += " " + text_en
96
  cur_text_ja += text_ja
97
- continue_count += 1
98
 
99
  texts_en.append(cur_text_en.strip())
100
  texts_ja.append(cur_text_ja.strip())
 
58
  cur_left_quote, cur_right_quote = 0, 0
59
  cur_left_parens_ja, cur_right_parens_ja = 0, 0
60
  cur_left_parens_ja2, cur_right_parens_ja2 = 0, 0
 
61
 
62
  for table in tables:
63
  for tr in table.find_all("tr"):
64
  text_en, _, text_ja = (preprocess(td.text) for td in tr.find_all("td"))
65
  text_ja = unicodedata.normalize("NFKC", text_ja)
66
 
67
+ cur_left_parens = min(cur_left_parens + text_en.count("("), 1)
68
+ cur_right_parens = min(cur_right_parens + text_en.count(")"), 1)
 
 
69
 
70
+ cur_left_quote = min(
71
+ cur_left_quote + len(list(re.findall(r"``", text_en))), 1
72
+ )
73
+ cur_right_quote = min(
74
+ cur_right_quote + len(list(re.findall(r"''", text_en))), 1
75
+ )
76
+
77
+ cur_left_parens_ja = min(cur_left_parens_ja + text_ja.count("「"), 1)
78
+ cur_right_parens_ja = min(cur_right_parens_ja + text_ja.count("」"), 1)
79
+
80
+ cur_left_parens_ja2 = min(cur_left_parens_ja2 + text_ja.count("『"), 1)
81
+ cur_right_parens_ja2 = min(cur_right_parens_ja2 + text_ja.count("』"), 1)
82
 
83
  if (
84
  text_ja.strip().endswith("。")
 
87
  and cur_left_quote == cur_right_quote
88
  and cur_left_parens_ja == cur_right_parens_ja
89
  and cur_left_parens_ja2 == cur_right_parens_ja2
90
+ ):
91
  texts_en.append((cur_text_en + " " + text_en).strip())
92
  texts_ja.append((cur_text_ja + text_ja).strip())
93
  cur_text_en, cur_text_ja = "", ""
 
95
  cur_left_quote, cur_right_quote = 0, 0
96
  cur_left_parens_ja, cur_right_parens_ja = 0, 0
97
  cur_left_parens_ja2, cur_right_parens_ja2 = 0, 0
 
98
  else:
99
  cur_text_en += " " + text_en
100
  cur_text_ja += text_ja
 
101
 
102
  texts_en.append(cur_text_en.strip())
103
  texts_ja.append(cur_text_ja.strip())