forked from MigoXLab/dingo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsdk_register_rule.py
More file actions
47 lines (40 loc) · 1.31 KB
/
sdk_register_rule.py
File metadata and controls
47 lines (40 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import re
from dingo.config.input_args import EvaluatorRuleArgs
from dingo.io import Data
from dingo.model.model import Model
from dingo.model.modelres import ModelRes
from dingo.model.rule.base import BaseRule
@Model.rule_register('QUALITY_BAD_RELEVANCE', ['test'])
class CommonPatternDemo(BaseRule):
"""let user input pattern to search"""
dynamic_config = EvaluatorRuleArgs(pattern = "blue")
@classmethod
def eval(cls, input_data: Data) -> ModelRes:
res = ModelRes()
matches = re.findall(cls.dynamic_config.pattern, input_data.content)
if matches:
res.error_status = True
res.type = cls.metric_type
res.name = cls.__name__
res.reason = matches
return res
if __name__ == '__main__':
from dingo.config import InputArgs
from dingo.exec import Executor
input_data = {
"input_path": "../../test/data/test_local_json.json",
"dataset": {
"source": "local",
"format": "json",
"field": {
"content": "prediction"
}
},
"executor": {
"rule_list": ['CommonPatternDemo']
}
}
input_args = InputArgs(**input_data)
executor = Executor.exec_map["local"](input_args)
result = executor.execute()
print(result)