fasdfsa commited on
Commit
c138808
·
1 Parent(s): c745baf

给 box 加上标点符号,增加 sign 字段

Browse files
Files changed (2) hide show
  1. data/variants.json +0 -0
  2. exinfo.py +25 -2
data/variants.json ADDED
Binary file (127 Bytes). View file
 
exinfo.py CHANGED
@@ -10,6 +10,8 @@ if __name__ == '__main__':
10
  from pathlib import Path
11
  chs = glob.glob('data/ch*', recursive=False)
12
  m5s = {}
 
 
13
  for i, pth in enumerate(chs):
14
  pth = pth.replace('\\', '/')
15
  parts = pth.split('/')
@@ -35,6 +37,8 @@ if __name__ == '__main__':
35
  new_line = False
36
  lines = []
37
  line = []
 
 
38
  for j, pt in enumerate(boxs):
39
  stem = Path(pt).stem
40
  pageId = pageNames_pageIds[stem]
@@ -43,11 +47,30 @@ if __name__ == '__main__':
43
  pt_lines = pt.replace('.boxs', '.lines')
44
  with open(pt, "r", encoding='UTF-8') as fp:
45
  box = json.load(fp)
46
-
47
  for k, bx in enumerate(box):
48
  charPoly = bx["charPoly"]
49
  charText = bx["charText"]
50
- if page_text[k] == charText:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51
  pass
52
  else:
53
  pass
 
10
  from pathlib import Path
11
  chs = glob.glob('data/ch*', recursive=False)
12
  m5s = {}
13
+ with open('data/variants.json', "r", encoding='UTF-8') as fp:
14
+ variants = json.load(fp)
15
  for i, pth in enumerate(chs):
16
  pth = pth.replace('\\', '/')
17
  parts = pth.split('/')
 
37
  new_line = False
38
  lines = []
39
  line = []
40
+ signs = ['。', ':', ',', ]
41
+ sign_count = 0
42
  for j, pt in enumerate(boxs):
43
  stem = Path(pt).stem
44
  pageId = pageNames_pageIds[stem]
 
47
  pt_lines = pt.replace('.boxs', '.lines')
48
  with open(pt, "r", encoding='UTF-8') as fp:
49
  box = json.load(fp)
50
+ g = 0
51
  for k, bx in enumerate(box):
52
  charPoly = bx["charPoly"]
53
  charText = bx["charText"]
54
+ sign = ''
55
+ if charText in variants:
56
+ charText = variants[charText]
57
+ g = k + sign_count
58
+ if page_text[g] in signs:
59
+ sign = page_text[g]
60
+ # 把符号加到前一个字
61
+ box[k-1]["sign"] = sign
62
+
63
+ sign_count += 1
64
+ g = k + sign_count
65
+
66
+ if page_text[g] in variants:
67
+ before = page_text[:g]
68
+ after = page_text[g+1:]
69
+ oldchar = page_text[g]
70
+ newchar = variants[page_text[g]]
71
+ page_text = before + newchar + after
72
+
73
+ if page_text[g] == charText:
74
  pass
75
  else:
76
  pass