Просмотр исходного кода

Merge remote-tracking branch 'origin/master'

luojiehua 3 лет назад
Родитель
Сommit
12e2b29f8a
4 измененных файлов с 63 добавлено и 130 удалено
  1. 2 2
      format_convert/convert.py
  2. 24 3
      format_convert/convert_pdf.py
  3. 6 6
      otr/table_line.py
  4. 31 119
      result.html

+ 2 - 2
format_convert/convert.py

@@ -2605,9 +2605,9 @@ else:
         _path = os.path.dirname(os.path.abspath(__file__))
 if __name__ == '__main__':
     if get_platform() == "Windows":
-        file_path = "C:/Users/Administrator/Desktop/error8.pdf"
+        # file_path = "C:/Users/Administrator/Desktop/error13.pdf"
         # file_path = "D:/BIDI_DOC/比地_文档/2022/Test_Interface/1622529434414.rar"
-        # file_path = "D:/BIDI_DOC/比地_文档/2022/Test_ODPS/1625369915229.zip"
+        file_path = "D:/BIDI_DOC/比地_文档/2022/Test_ODPS/1624267820641.pdf"
     else:
         file_path = "1.doc"
 

+ 24 - 3
format_convert/convert_pdf.py

@@ -688,6 +688,7 @@ class PDFConvert:
                     if isinstance(y, LTImage):
                         lt_image_list.append(y)
                         image_count += 1
+        lt_text_list = self.delete_water_mark(lt_text_list)
 
         # 若只有文本且图片数为0,直接提取文字及表格
         if only_image == 0 and image_count == 0:
@@ -708,6 +709,7 @@ class PDFConvert:
                                                   (float(_edge["x1"]), float(_edge["y1"]))))
                 list_tables, filter_objs, _ = self.lt.recognize_table(lt_text_list, lt_line_list)
                 self._page.in_table_objs = filter_objs
+
                 for table in list_tables:
                     _table = _Table(table["table"], table["bbox"])
                     # self._page.children.append(_table)
@@ -715,11 +717,10 @@ class PDFConvert:
 
                 list_sentences = ParseUtils.recognize_sentences(lt_text_list, filter_objs,
                                                                 layout.bbox, page_no)
+
+
                 for sentence in list_sentences:
                     _sen = _Sentence(sentence.text, sentence.bbox)
-                    # _sen.x = sentence.x0
-                    # _sen.y = sentence.y0
-                    # self._page.children.append(_sen)
                     self._page.add_child(_sen)
                 # pdf对象需反向排序
                 self._page.is_reverse = True
@@ -889,6 +890,26 @@ class PDFConvert:
             return self._doc.error_code
         return self._doc.get_html()
 
+    def delete_water_mark(self, lt_text_list, times=8):
+        # 删除过多重复字句,为水印
+        duplicate_dict = {}
+        for _obj in lt_text_list:
+            t = _obj.get_text()
+            if t in duplicate_dict.keys():
+                duplicate_dict[t] += 1
+            else:
+                duplicate_dict[t] = 1
+        delete_text = []
+        for t in duplicate_dict.keys():
+            if duplicate_dict[t] >= times:
+                delete_text.append(t)
+        temp_text_list = []
+        for _obj in lt_text_list:
+            t = _obj.get_text()
+            if t not in delete_text:
+                temp_text_list.append(_obj)
+        return temp_text_list
+
 
 # 以下为现成pdf单页解析接口
 class ParseSentence:

+ 6 - 6
otr/table_line.py

@@ -217,7 +217,6 @@ def draw_pixel(pred):
 
 def points2lines(pred, sourceP_LB=True, prob=0.2, line_width=7, padding=3, min_len=10,
                  cell_width=13):
-
     def inBbox(bbox,point,line_width):
         x,y = point
         if x>=bbox[0]-line_width and x<=bbox[2]+line_width and y>=bbox[1]-line_width and y<=bbox[3]+line_width:
@@ -353,17 +352,18 @@ def points2lines(pred, sourceP_LB=True, prob=0.2, line_width=7, padding=3, min_l
 
     logging.info("points2lines cost %.2fs"%(time.time()-_time))
 
-    import matplotlib.pyplot as plt
-    plt.figure()
-    for _line in list_line:
-        x0,y0,x1,y1 = _line
-        plt.plot([x0,x1],[y0,y1])
+    # import matplotlib.pyplot as plt
+    # plt.figure()
+    # for _line in list_line:
+    #     x0,y0,x1,y1 = _line
+    #     plt.plot([x0,x1],[y0,y1])
     # for _line in list_line:
     #     x0,y0,x1,y1 = _line.bbox
     #     plt.plot([x0,x1],[y0,y1])
     # for point in list_crosspoints:
     #     plt.scatter(point.get("point")[0],point.get("point")[1])
     # plt.show()
+
     return list_line
 
 

+ 31 - 119
result.html

@@ -1,131 +1,43 @@
-<!DOCTYPE HTML><head><meta charset="UTF-8"></head><body><div>南网数研院数字化转型和数字电网建设价</div>
-<div>值与路径研究项目中标结果</div>
-<div>(招标编号:0002200000087033)</div>
-<div>南网数研院数字化转型和数字电网建设价值与路径研究项目(招标编号:</div>
-<div>0002200000087033),确定中标人如下:</div>
-<div>一、中标人信息</div>
+<!DOCTYPE HTML><head><meta charset="UTF-8"></head><body><div>政府采购意向公告</div>
+<div>内乡县农业农村局2021年06月(至)07月政府采购意向</div>
+<div>为便于供应商及时了解政府采购信息,根据《河南省财</div>
+<div>政厅关于全面开展政府采购意向公开工作的通知》(豫财购</div>
+<div>(2020)8号)等有关规定,现将农业农村局2021年06</div>
+<div>月(至)07月采购意向公开如下:</div>
 <table border="1">
 <tr>
-<td colspan=1 rowspan=1>标的
-</td>
-<td colspan=1 rowspan=1>标包
-</td>
-<td colspan=1 rowspan=1>中标人
-</td>
+<td colspan=1 rowspan=1>号</td>
+<td colspan=1 rowspan=1>序采购项目名称</td>
+<td colspan=0 rowspan=1></td>
+<td colspan=1 rowspan=1>采购需求概况</td>
+<td colspan=1 rowspan=1>预算金额(万)</td>
+<td colspan=1 rowspan=1>预计采购时间</td>
+<td colspan=1 rowspan=1>备注</td>
 </tr>
 <tr>
-<td colspan=1 rowspan=1>南
-网
-数
-研
-院
-数
-字
-化
-转
-型
-和
-数
-字
-电
-网
-建
-设
-价
-值
-与
-路
-径
-研
-究
-项目
-</td>
-<td colspan=1 rowspan=1>标包
-1:新时期数字化发展推
-动价值创造研究项目
-</td>
-<td colspan=1 rowspan=1>中
-国
-电
-子
-系
-统
-技
-术
-有
-限
-公
-司
-</td>
+<td colspan=1 rowspan=1></td>
+<td colspan=1 rowspan=1>内乡县乡</td>
+<td colspan=0 rowspan=1></td>
+<td colspan=4 rowspan=1></td>
 </tr>
 <tr>
-<td colspan=1 rowspan=1>南
-网
-数
-研
-院
-数
-字
-化
-转
-型
-和
-数
-字
-电
-网
-建
-设
-价
-值
-与
-路
-径
-研
-究
-项目
-</td>
-<td colspan=1 rowspan=1></td>
-<td colspan=1 rowspan=1>标包
-3:数字化转型支撑服务
-项目
-</td>
-<td colspan=1 rowspan=1>广
-州
-德
-永
-计
-算
-机
-科
-技
-有
-限
-公司
-</td>
+<td colspan=2 rowspan=1>村振兴现代高效特色农业生产(小番茄)示范</td>
+<td colspan=0 rowspan=1></td>
+<td colspan=4 rowspan=1></td>
 </tr>
 <tr>
 <td colspan=1 rowspan=1></td>
-<td colspan=1 rowspan=1>标包
-4:数字电网建设标准化
-服务支撑项目
-</td>
-<td colspan=1 rowspan=1>广州信安数据有限公司
-</td>
+<td colspan=1 rowspan=3>基地建设项目</td>
+<td colspan=1 rowspan=1>内乡县乡村振兴现代高效特色农业生产(小番茄)示范基地建设项目,项目实施地点:灌涨镇瑞东镇、赵店乡,计划工期:二年,质量要求:合格,达到国家验收规范合格标准,工程内容:计划建设标准暖棚100座及配套设施。</td>
+<td colspan=1 rowspan=1>4000</td>
+<td colspan=1 rowspan=1>2021年7月</td>
+<td colspan=1 rowspan=1></td>
 </tr>
 </table>
-<div>二、其他</div>
-<div>请中标人按要求登陆中国南方电网有限责任公司供应链统一服务平台</div>
-<div>(http://www.bidding.csg.cn),查看并下载中标通知书。</div>
-<div>三、联系方式</div>
-<div>招标人:南方电网数字电网研究院有限公司</div>
-<div>联系人:李工</div>
-<div>电,话:4008100100-2</div>
-<div>招标代理机构:南方电网物资有限公司</div>
-<div>地,址:广州市天河区天河路,178号南网物资公司</div>
-<div>联系人:韦工</div>
-<div>电,话:4008100100-2</div>
-<div>招标人(或招标代理机构)主要负责人或授权的项目负责人(签名):任寅寅</div>
-<div>招标人或其招标代理机构名称:南方电网物资有限公司</div>
-<div>2022年02月08日</div>
+<div>本次公开的采购意向是本单位政府采购工作的初步安</div>
+<div>农业</div>
+<div>排,具体采购项目情况以相美采购公告和采购文件为准。</div>
+<div>内乡县衣业农村局</div>
+<div>2021年6月21</div>
+<div>132800</div>
 </body>