Add 07th VN parsing
Browse files- utils/07_parse.py +60 -0
- utils/clean.py +2 -0
utils/07_parse.py
ADDED
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from re import T
|
2 |
+
import parse
|
3 |
+
import argparse
|
4 |
+
|
5 |
+
from clean import clean
|
6 |
+
|
7 |
+
parser = argparse.ArgumentParser(description='Process some 07th stuff idk')
|
8 |
+
parser.add_argument('-f', '--file', type=str, help='file to process', required=True)
|
9 |
+
args = parser.parse_args()
|
10 |
+
|
11 |
+
with open(args.file, 'r') as f:
|
12 |
+
lines = f.readlines()
|
13 |
+
|
14 |
+
jap_characters = ['。', '「', '」', '?', '!', '、', '…', 'ー']
|
15 |
+
|
16 |
+
author = parse.parse('\ufeff== {0} ==\n', lines[0])[0]
|
17 |
+
|
18 |
+
with open('output.txt', 'w') as f:
|
19 |
+
for line in lines:
|
20 |
+
if line.startswith('\ufeff'):
|
21 |
+
continue
|
22 |
+
# check if line has jap_characters
|
23 |
+
if any(substr in line for substr in jap_characters):
|
24 |
+
continue
|
25 |
+
if line.startswith('\n==') or line.startswith('=='):
|
26 |
+
try:
|
27 |
+
author = parse.parse('== {0} ==\n', line)[0]
|
28 |
+
except:
|
29 |
+
author = 'Narrator'
|
30 |
+
continue
|
31 |
+
if line == '\n':
|
32 |
+
continue
|
33 |
+
line = line.rstrip()
|
34 |
+
if author == 'Narrator':
|
35 |
+
f.write(clean('[' + line.replace('\"', '').lstrip().rstrip() + ']').replace('\"', '')+'\n')
|
36 |
+
else:
|
37 |
+
txt = line.replace('\"', '')
|
38 |
+
if '<Meta End>' in clean(txt) or '<Meta Start>' in clean(txt):
|
39 |
+
continue
|
40 |
+
f.write(clean(author + ': ' + line.replace('\"', '')).replace('\"', '')+'\n')
|
41 |
+
|
42 |
+
with open('output.txt', 'r') as f:
|
43 |
+
lines = f.read()
|
44 |
+
|
45 |
+
def clean_07(txt):
|
46 |
+
txt = txt.replace(']\n[', ' ')
|
47 |
+
txt = txt.replace('[ ', '[')
|
48 |
+
txt = txt.replace(' ]', ']')
|
49 |
+
txt = txt.replace('\n\n', '\n')
|
50 |
+
txt = txt.replace('~ib~', '**')
|
51 |
+
txt = txt.replace('#fefefe', '')
|
52 |
+
txt = txt.replace('<white>', '')
|
53 |
+
txt = txt.replace('<red>', '')
|
54 |
+
txt = txt.replace('<blue>', '')
|
55 |
+
txt = txt.replace('<Meta End>', '')
|
56 |
+
txt = txt.replace('<Meta Start>', '')
|
57 |
+
return txt
|
58 |
+
|
59 |
+
with open('output.txt', 'w') as f:
|
60 |
+
f.write(clean_07(lines))
|
utils/clean.py
CHANGED
@@ -25,6 +25,7 @@ r_space_normalizer = re.compile(r'[\U00003000\U0000205F\U0000202F\U0000200A\U000
|
|
25 |
r_newline_cleaner = re.compile(r'\n+')
|
26 |
r_single_apostrophe_normalizer = re.compile(r'[’`]')
|
27 |
r_double_apostrophe_normalizer = re.compile(r'[“”]')
|
|
|
28 |
|
29 |
def clean(text):
|
30 |
text = text.translate(normal_map)
|
@@ -33,4 +34,5 @@ def clean(text):
|
|
33 |
text = r_newline_cleaner.sub(' ', text)
|
34 |
text = r_single_apostrophe_normalizer.sub('\'', text)
|
35 |
text = r_double_apostrophe_normalizer.sub('\"', text)
|
|
|
36 |
return text
|
|
|
25 |
r_newline_cleaner = re.compile(r'\n+')
|
26 |
r_single_apostrophe_normalizer = re.compile(r'[’`]')
|
27 |
r_double_apostrophe_normalizer = re.compile(r'[“”]')
|
28 |
+
r_strange_apostrophe_normalizer = re.compile(r'[『』]')
|
29 |
|
30 |
def clean(text):
|
31 |
text = text.translate(normal_map)
|
|
|
34 |
text = r_newline_cleaner.sub(' ', text)
|
35 |
text = r_single_apostrophe_normalizer.sub('\'', text)
|
36 |
text = r_double_apostrophe_normalizer.sub('\"', text)
|
37 |
+
text = r_strange_apostrophe_normalizer.sub('\"', text)
|
38 |
return text
|