File size: 1,048 Bytes
6371026
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from service_dops_api.dops_config import ServiceDopsConfig

class DopsClassifier:

    def __init__(self,config: ServiceDopsConfig):
        self.config = config

    def run_regular_search(self,text,dop_name):
        result = {}
        options_patterns = self.config.option_patterns_dict[dop_name]
        result = {key: 1 if value.search(text) else 0 for key, value in options_patterns.items()}
        if 1 not in result.values():
            result[self.config.dops_default_values[dop_name]] = 1
        else:
            result[self.config.dops_default_values[dop_name]] = 0
        return result
    
    def convert_search_to_human(self,dict_from_search):
        return [key for key, value in dict_from_search.items() if value == 1]
    
    def run_all_dops(self,text):
        all_dops = self.config.option_patterns_dict.keys()
        result_dict = {}
        for dop in all_dops:
            temp_dop = self.run_regular_search(text,dop)
            result_dict[dop] = self.convert_search_to_human(temp_dop)
        return result_dict