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

is_variant 是否为异体字

Browse files
Files changed (2) hide show
  1. exinfo.py +17 -3
  2. is_variant.txt +5 -0
exinfo.py CHANGED
@@ -23,7 +23,12 @@ if __name__ == '__main__':
23
 
24
  with open(f"{out2}/pageIds_pageNames.json", "r", encoding='UTF-8') as fp:
25
  pageIds_pageNames = json.load(fp)
 
 
 
 
26
 
 
27
  boxs = glob.glob(f"{out2}/*.boxs", recursive=False)
28
 
29
  last_x = -1
@@ -31,12 +36,21 @@ if __name__ == '__main__':
31
  lines = []
32
  line = []
33
  for j, pt in enumerate(boxs):
 
 
 
 
34
  pt_lines = pt.replace('.boxs', '.lines')
35
  with open(pt, "r", encoding='UTF-8') as fp:
36
  box = json.load(fp)
37
 
38
- for bx in box:
39
  charPoly = bx["charPoly"]
 
 
 
 
 
40
  lu = [charPoly["x0"], charPoly["y0"]]
41
  ru = [charPoly["x1"], charPoly["y1"]]
42
  rd = [charPoly["x2"], charPoly["y2"]]
@@ -63,8 +77,8 @@ if __name__ == '__main__':
63
  last_x = lu[0]
64
 
65
 
66
- with open(pt_lines, 'w', encoding='utf-8') as fp:
67
- json.dump(lines, fp, indent=4, ensure_ascii=False)
68
 
69
  print(f"box {j+1} / {len(boxs)}")
70
 
 
23
 
24
  with open(f"{out2}/pageIds_pageNames.json", "r", encoding='UTF-8') as fp:
25
  pageIds_pageNames = json.load(fp)
26
+
27
+ pageNames_pageIds = {}
28
+ for k, v in pageIds_pageNames.items():
29
+ pageNames_pageIds[v] = k
30
 
31
+
32
  boxs = glob.glob(f"{out2}/*.boxs", recursive=False)
33
 
34
  last_x = -1
 
36
  lines = []
37
  line = []
38
  for j, pt in enumerate(boxs):
39
+ stem = Path(pt).stem
40
+ pageId = pageNames_pageIds[stem]
41
+ page_text = page_texts[pageId]
42
+ page_text = page_text.replace(' ', '')
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
54
  lu = [charPoly["x0"], charPoly["y0"]]
55
  ru = [charPoly["x1"], charPoly["y1"]]
56
  rd = [charPoly["x2"], charPoly["y2"]]
 
77
  last_x = lu[0]
78
 
79
 
80
+ # with open(pt_lines, 'w', encoding='utf-8') as fp:
81
+ # json.dump(lines, fp, indent=4, ensure_ascii=False)
82
 
83
  print(f"box {j+1} / {len(boxs)}")
84
 
is_variant.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ >>> '懐' == '懷'
2
+ False
3
+
4
+ is_variant IS '是否为异体字';
5
+