示例#1
0
    def pickCase(self, des):
        #用于搜索相似的新闻案例,基于Elastic

        result = searchInEs(des, self._indexCase, self.doc_type_case,
                            self.caseKey, 1)

        return result
示例#2
0
    def es_presearch(self,des):
        '''
        根据描述进行预搜索
        '''

        result=searchInEs(des,self.index,self.type,self.key,self.num)

        #取出title
        return [a['_source']['title'] for a in result]
示例#3
0
    def es_preSearch(self):
        '''ES预搜索'''

        result = searchInEs(self.des, self.index, self.docType, self.key,
                            self.res_limit)

        title_list = []
        for res in result:
            title_list.append(res['_source']['title'])

        return title_list
示例#4
0
    def getLawData(self):
        '''
            由ES引擎给出相关的具体法条
        '''

        #下列参数与具体的数据库相关,
        #根据标题返回五个法条
        resOfLaw1 = searchInEs(self.bestTitle, 'law_data', 'line', 'line', 5)

        #下列参数与具体数据库相关
        set = 0
        if self.cause:
            resOfLaw2 = searchInEs(self.cause, 'law_data', 'line', 'line', 5)
            set = 1

        #包装相关法条
        lawLine = list()
        for line in resOfLaw1:
            lawLine.append(line['_source'])
        if set == 1:
            for line in resOfLaw2:
                lawLine.append(line['_source'])

        return lawLine
示例#5
0
    def es_presearch(self, des):
        '''
        根据描述进行预搜索
        '''

        result = searchInEs(des, self.index, "_doc", self.key, self.num)
        print("{+} es搜索中...")
        print(result)
        #取出title

        #special adjustment:
        resultTitle = [a['_source']['title'] for a in result]
        resultTitle.remove("骗子")

        return resultTitle
示例#6
0
    def findAnswer(self, des):
        '''答案查找主函数'''

        result = searchInEs(des, self._index, self.doc_type, self.targetKey,
                            self.num_res)

        answer = []
        #process the result
        for each in result:

            #use dict to store every answer
            answer_dict = {}

            #build answer dict
            answer_dict["score"] = each["_score"]
            answer_dict["sim_question"] = each["_source"]["question"]
            answer_dict['answer'] = each["_source"]["answer"]

            answer.append(answer_dict)

        #return 这一句里的作用是字典去重
        return [dict(t) for t in set([tuple(d.items()) for d in answer])]