Пример #1
0
 def make_hmd_model(self, temp_list, model_name):
     model = hmd_pb2.HmdModel()
     model.lang = lang_pb2.kor
     model.model = model_name
     rules = list()
     for item in temp_list:
         category_list = item[0]
         dtc_rule = item[1]
         rule = hmd_pb2.HmdRule()
         rule.rule = dtc_rule
         rule.categories.extend(category_list)
         rules.append(rule)
     model.rules.extend(rules)
     self.stub.SetModel(model)
     model_key = hmd_pb2.ModelKey()
     model_key.lang = lang_pb2.kor
     model_key.model = model_name
     self.stub.GetModel(model_key)
Пример #2
0
 def set_model(self, model_name, target_list):
     model = hmd_pb2.HmdModel()
     model.lang = lang_pb2.kor
     model.model = model_name
     rules_list = list()
     for item_dict in target_list:
         category = item_dict['category']
         rule = item_dict['rule']
         category_list = category.split('!@#$')
         hmd_client = hmd_pb2.HmdRule()
         hmd_client.rule = rule
         hmd_client.categories.extend(category_list)
         rules_list.append(hmd_client)
     model.rules.extend(rules_list)
     self.stub.SetModel(model)
     model_key = hmd_pb2.ModelKey()
     model_key.lang = lang_pb2.kor
     model_key.model = model_name
Пример #3
0
 def set_model(self, model_name, target_file_path):
     model = hmd_pb2.HmdModel()
     model.lang = lang_pb2.kor
     model.model = model_name
     rules_list = list()
     with open(target_file_path) as target_file:
         for line in target_file:
             line = line.strip()
             line_list = line.split(self.args.file_delimiter)
             if len(line_list) < 2:
                 print '[ERROR] Line field count at least two [{0}]'.format(
                     line)
                 continue
             hmd_client = hmd_pb2.HmdRule()
             hmd_client.rule = line_list[-1]
             hmd_client.categories.extend(line_list[:-1])
             rules_list.append(hmd_client)
     model.rules.extend(rules_list)
     self.stub.SetModel(model)
     model_key = hmd_pb2.ModelKey()
     model_key.lang = lang_pb2.kor
     model_key.model = model_name
Пример #4
0
 def set_model(self):
     model = hmd_pb2.HmdModel()
     model.lang = lang_pb2.kor
     model.model = 'news'
     rules = list()
     rule1 = hmd_pb2.HmdRule()
     # 형태소 분석 결과를 바탕으로 원형 단어를 이용
     # ex) 안녕하세요. -> 안녕하/pa 시/ep 어/ec 요/jx ./s (ETRI 기준)
     # 안녕하, 시어, 요 를 이용 rule을 제작
     rule1.rule = '(안녕하)'
     rule1.categories.extend(['level1', 'level2'])
     rules.append(rule1)
     rule2 = hmd_pb2.HmdRule()
     rule2.rule = '(자연)'
     rule2.categories.extend(['level1', 'level3'])
     rules.append(rule2)
     model.rules.extend(rules)
     self.stub.SetModel(model)
     model_key = hmd_pb2.ModelKey()
     model_key.lang = lang_pb2.kor
     model_key.model = 'news'
     ret_model = self.stub.GetModel(model_key)
     print unicode(ret_model)
Пример #5
0
 def set_model2(self, file_name, model_name):
     model = hmd_pb2.HmdModel()
     model.lang = lang_pb2.kor
     model.model = model_name
     rules = list()
     f = open(file_name)
     for line in f.readlines():
         tokens = line.strip().split('\t')
         # level1, level2, level3...
         levels = tokens[:-1]
         # Last element of tokens
         keyword = tokens[-1]
         print levels, keyword
         rule = hmd_pb2.HmdRule()
         rule.rule = keyword
         rule.categories.extend(levels)
         rules.append(rule)
     model.rules.extend(rules)
     self.stub.SetModel(model)
     model_key = hmd_pb2.ModelKey()
     model_key.lang = lang_pb2.kor
     model_key.model = model_name
     ret_model = self.stub.GetModel(model_key)
     print unicode(ret_model)