فهرست منبع

增加后处理

liweiquan 10 ماه پیش
والد
کامیت
98b17dd721
3فایلهای تغییر یافته به همراه61 افزوده شده و 7 حذف شده
  1. 58 0
      cores/post_decorators.py
  2. 2 7
      cores/post_hander.py
  3. 1 0
      server.py

+ 58 - 0
cores/post_decorators.py

@@ -118,3 +118,61 @@ def rule6_decorator(f, *args, **kwargs):
     except IndexError as e:
         print('rule6_decorator', e)
     return predict_line
+
+@decorator
+def rule7_decorator(f, *args, **kwargs):
+    '''
+    predict_line = ['项目 ', '', '每份(70g)营养素参考值%', '']
+    '''
+    predict_line = f(*args, **kwargs)
+    print('-=-=', predict_line)
+    try:
+        if '项目' in predict_line[0] or '项' in predict_line[0] or '目' in predict_line[0]:
+            predict_line[0] = '项目'
+    except IndexError as e:
+        print('rule6_decorator', e)
+    return predict_line
+
+@decorator
+def rule8_decorator(f, *args, **kwargs):
+    '''
+    predict_line = ['项目 ', '', '每份(70g)营养素参考值%', '']
+    '''
+    predict_line = f(*args, **kwargs)
+    print('-=-=', predict_line)
+    try:
+        if len(predict_line) >= 3 \
+                and '' == predict_line[0] \
+                and '' in predict_line[1] \
+                and ('项' in predict_line[2] or '目' in predict_line[2]) \
+                and ('100' in predict_line[2] or '克' in predict_line[2]) \
+                and '营养' in predict_line[2]:
+            predict_line[0] = '项目'
+            predict_line[1] = '每100克'
+            predict_line[2] = '营养素参考值%'
+    except IndexError as e:
+        print('rule6_decorator', e)
+    return predict_line
+
+
+decorators = []
+
+
+def register_decorator(dtor):
+    decorators.append(dtor)
+
+
+def combined_decorator(func):
+    for dtor in reversed(decorators):
+        func = dtor(func)
+    return func
+
+
+register_decorator(rule1_decorator)
+register_decorator(rule2_decorator)
+register_decorator(rule3_decorator)
+register_decorator(rule4_decorator)
+register_decorator(rule5_decorator)
+register_decorator(rule6_decorator)
+register_decorator(rule7_decorator)
+register_decorator(rule8_decorator)

+ 2 - 7
cores/post_hander.py

@@ -1,6 +1,6 @@
 import re
 from typing import List
-from .post_decorators import *
+from .post_decorators import combined_decorator
 
 class PostHandler:
     def __init__(self, predict_html):
@@ -39,12 +39,7 @@ class PostHandler:
         else:
             return self.predict_html
 
-    @rule6_decorator
-    @rule5_decorator
-    @rule4_decorator
-    @rule3_decorator
-    @rule2_decorator
-    @rule1_decorator
+    @combined_decorator
     def _format_predict_line(self, predict_line):
         return predict_line
 

+ 1 - 0
server.py

@@ -178,6 +178,7 @@ def table(image: TableInfo):
     # print(html)
     table = Table(html, img)
     if table.check_html():
+        print('-=-=-=')
         res, html = table_res(table.img)
 
     if html: