Exemplo n.º 1
0
 def __init__(self):
     multiwheelUnit._init()
     multiwheelUnit.set_value('userid', 1)
     self._aiml_kernal = aiml_cn.Kernel()
     self._aiml_kernal.learn('../../resource/template.aiml')
     self._aiml_kernal.learn('../../resource/contain_template.aiml')
     self._aiml_kernal.learn('../../resource/multiwheelQA.aiml')
     self._aiml_kernal.learn('../../resource/time_template.aiml')
Exemplo n.º 2
0
 def answer_business_readerCard_00(cls, entity_dict, graph):
     respons_str=""
     if (len(rdfPrepare.rdf_query_propertiy("办理读书卡", "pro_step1", graph)) != 0):
         respons_str += rdfPrepare.rdf_query_propertiy("办理读书卡", "pro_step1", graph)[0]
         if multiwheelUnit.get_value('business') == None:
             multiwheelUnit.set_value('business', "办理读书卡")
         if multiwheelUnit.get_value('step') == None:
             multiwheelUnit.set_value('step', "_step1")
         return respons_str
     else:
         return None
Exemplo n.º 3
0
 def answer_business_readerCard_no(cls, entity_dict, graph):
     if multiwheelUnit.get_value('business')=="办理读书卡":
         if multiwheelUnit.get_value('step')!=None:
             arr = multiwheelUnit.get_value('step').split('_')
             step=arr[len(arr) - 1]
             if (len(rdfPrepare.rdf_query_propertiy("办理读书卡", "pro_"+step+"_no", graph)) != 0):
                 step_ans =rdfPrepare.rdf_query_propertiy("办理读书卡", "pro_"+step+"_no", graph)[0]
                 respons_str=rdfPrepare.rdf_query_propertiy("办理读书卡", "pro_"+step_ans, graph)[0]
                 multiwheelUnit.set_value('step',multiwheelUnit.get_value('step')+"_"+step_ans)
                 return respons_str
     else:
         return None
Exemplo n.º 4
0
    def question_answer_hub(self, question_str):
        """
        问答总控,基于aiml构建问题匹配器
        :param question_str:问句输入
        :return:
        """
        g = rdfPrepare.load_graph()
        question_replaced, entity_dict = entityMatch2.match_and_replace_all(
            question_str, g)
        #print(question_replaced,entity_dict)

        navi_g = rdfPrepare.load_navi_graph()
        navi_question_replaced, navi_entity_dict = entityMatch2.match_and_replace_all(
            question_str, navi_g)
        #print(navi_question_replaced, navi_entity_dict)
        # question_replaced, entity_dict = entityMatch.match_and_replace_all(question_str)
        '''
        arr = []
        if len(entity_dict['room']) > 0:
            for i in entity_dict['room']:
                if len(i) == 0:
                    continue
                index = question_str.find(i[0])
                arr.append(index)
            # print(arr)
            arr_index = np.argsort(np.array(arr))
            # print(arr_index)
            entity_dict2 = []
            for i in entity_dict['room']:
                if len(i) == 0:
                    continue
                entity_dict2.append(i)

            for i in range(len(entity_dict['room'])):
                if len(entity_dict['room'][i]) == 0:
                    continue
                # print(arr_index[i],entity_dict2[arr_index[i]])
                entity_dict['room'][i] = entity_dict2[arr_index[i]]
        '''
        if multiwheelUnit.get_value('business') == "办理读书卡":
            if "answer" not in multiwheelUnit.get_value('step'):
                question_replaced += "读卡"
            else:
                multiwheelUnit.set_value('business', None)
                multiwheelUnit.set_value('step', None)

        aiml_respons = self._aiml_kernal.respond(question_replaced)

        if 'multiwheeltask_' in aiml_respons:
            print("aiml_respons: ", str(aiml_respons))
            # print("entity_dict: ", str(entity_dict))
            graph_respons = rdfBotMul.task_response(aiml_respons, entity_dict,
                                                    question_str, g)
            return graph_respons
        elif 'task_' in aiml_respons:
            print("aiml_respons: ", str(aiml_respons))
            #print("entity_dict: ", str(entity_dict))
            if aiml_respons == 'task_room_pos':
                graph_respons = rdfBot.task_response(aiml_respons,
                                                     navi_entity_dict,
                                                     question_str, navi_g)
            else:
                graph_respons = rdfBot.task_response(aiml_respons, entity_dict,
                                                     question_str, g)

            return graph_respons
        else:
            return aiml_respons