3 Commits ff787263a2 ... beff35e712

Author SHA1 Message Date
  Zhang Li beff35e712 feat: combined_decorator 10 months ago
  Zhang Li a388b95ef5 Merge branch 'new' of http://gogsb.soaringnova.com/chenguilong/ocr-table into new 10 months ago
  Zhang Li cb2b0440e3 feat: combined_decorator 10 months ago
2 changed files with 25 additions and 8 deletions
  1. 23 1
      cores/post_decorators.py
  2. 2 7
      cores/post_hander.py

+ 23 - 1
cores/post_decorators.py

@@ -116,4 +116,26 @@ def rule6_decorator(f, *args, **kwargs):
                     predict_line[2] = '营养素参考值'+r[1]
     except IndexError as e:
         print('rule6_decorator', e)
-    return predict_line
+    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)
+

+ 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