Datasets:

Languages:
Chinese
Tags:
Not-For-All-Audiences
License:
Limour commited on
Commit
74f7224
·
verified ·
1 Parent(s): 9585c59

Upload 2 files

Browse files
v-corpus-zh/Navel/近月少女的礼仪/近月少女的礼仪/luna.txt.gz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:11d6388b39eff759323408005d4013f39a40bef9971c3bcadc1f5391e6657f18
3
+ size 602295
v-corpus-zh/Navel/近月少女的礼仪/近月少女的礼仪/tmp_luna.py ADDED
@@ -0,0 +1,111 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import fitz
2
+
3
+ print(fitz.__doc__)
4
+
5
+ a = r'E:\tmp\jysn\luna_v1.0s3.pdf'
6
+
7
+ _end = {'」', '。', '…', '?', '!'}
8
+
9
+ _lines = []
10
+
11
+ doc = fitz.open(a) # open a document
12
+ TIT = False
13
+ for page in doc: # iterate the document pages
14
+ text = page.get_text("blocks") # get plain text encoded as UTF-8
15
+ if len(text) <= 0:
16
+ continue
17
+ tmp = text[0][4]
18
+ tmp = tmp.split(' ')
19
+ if len(tmp) != 2 or not tmp[0].isdigit() or tmp[1] != '\n':
20
+ continue
21
+ # print(tmp)
22
+ if tmp[0] == '732':
23
+ break
24
+ i = 0
25
+ _l = len(text) - 2
26
+ while i <= _l:
27
+ i += 1 # 跳过第一行的页码
28
+ if TIT:
29
+ TIT = False
30
+ line = '章名:' + text[i][4].strip()
31
+ if line[-1] not in _end:
32
+ line += '。'
33
+ print('跨页TIT', line)
34
+ if text[i][4].startswith('TIT \n'): # 小标题
35
+ line = text[i][4][5:].strip()
36
+ if line:
37
+ line = '章名:' + line
38
+ else:
39
+ TIT = True
40
+ continue # 服了,这居中标记还能跨页。。。
41
+ if line[-1] not in _end:
42
+ line += '。'
43
+ print(line)
44
+ else:
45
+ line = text[i][4].strip()
46
+ if not line:
47
+ continue
48
+ if line.startswith('BGT') and line.endswith(_lines[-1]): # 章节之间的空白
49
+ _lines[-1] = '卷名:' + _lines[-1] + '。'
50
+ continue
51
+ _lines.append(line)
52
+
53
+ data = []
54
+
55
+ 左括号 = False
56
+ cache = ''
57
+
58
+ i = -1
59
+ _l = len(_lines) - 2
60
+ while i <= _l:
61
+ i += 1
62
+ line = _lines[i]
63
+ # print(line)
64
+ # tmp = line[-1]
65
+ # _end[tmp] = _end.get(tmp, 0) + 1
66
+ line = line.replace(':\n「', ':「')
67
+ line = line.replace('\n', '\\n')
68
+ if ':「' in line:
69
+ if cache != '':
70
+ print('误判', (cache, line)) # 之前误判的
71
+ if 左括号:
72
+ data.append(cache)
73
+ else:
74
+ data.append('旁白:' + cache)
75
+ cache = ''
76
+
77
+ 左括号 = True
78
+
79
+ if not 左括号 and '「' in line:
80
+ print('待处理', repr(line))
81
+ if line.count('「') != line.count('」'):
82
+ if ':' not in line and ':' not in line:
83
+ pass
84
+ else:
85
+ print('异常中断')
86
+ break # 手动处理错误
87
+
88
+ 左括号 = False
89
+
90
+ if not 左括号:
91
+ if line[-1] in _end:
92
+ data.append('旁白:' + cache + line)
93
+ cache = ''
94
+ else:
95
+ cache += line
96
+ else:
97
+ if line[-1] == '」':
98
+ data.append(cache + line)
99
+ cache = ''
100
+ 左括号 = False
101
+ else:
102
+ cache += line
103
+
104
+
105
+ # sorted_word_freq = sorted(_end.items(), key=lambda x: x[1], reverse=True)
106
+
107
+ b = r'D:\datasets\tmp'
108
+ k = 'luna'
109
+ v = data
110
+ with open(b + f'\\{k}.txt', 'w', encoding='utf-8') as f:
111
+ f.write('\n'.join(v))