Esempio n. 1
0
    def get_judge(cls, subj, hed, obj):
        hed_arr = []
        if len(hed) > 2 and '不' in hed:
            hed_arr = hed.split("不")
            hed = hed_arr[len(hed_arr) - 1]
        print(subj, hed, obj)
        uri = "https://api.ownthink.com/kg/knowledge?entity=" + subj
        r = requests.post(uri)
        print(r.json())

        if r.json()['message'] == 'success':
            try:

                ans_list = list(r.json()['data']['avp'])
                #print(ans_list)
                values = [x[1] for x in ans_list]
                ans = NLPUtil.get_similarity(obj, values)
                if ans != None:
                    return "是的," + subj + hed + obj + "\n"
                elif hed == '有':
                    return "很抱歉," + subj + "没" + hed + obj + "\n"
                else:
                    return "很抱歉," + subj + "不" + hed + obj + "\n"
            except Exception as e:
                print(r.json())
                print(e)
Esempio n. 2
0
    def get_attr(cls, target, attr):
        uri = "https://api.ownthink.com/kg/knowledge?entity=" + target
        r = requests.post(uri)

        if r.json()['message'] == 'success':
            try:
                ans_dict = dict(r.json()['data']['avp'])
                keys = ans_dict.keys()
                print(keys)
                ans = NLPUtil.get_similarity(attr, keys)
                if ans != None:
                    return target + "的" + ans + "为" + ans_dict[ans] + "\n"
            except Exception as e:
                print(r.json())
                print(e)
        else:
            return "对不起,我不太明白你在说什么\n"
Esempio n. 3
0
    def get_judge_att(cls, subj, hed, att, obj, attr):
        uri = "https://api.ownthink.com/kg/knowledge?entity=" + subj
        r = requests.post(uri)

        if r.json()['message'] == 'success':
            try:
                ans_list = list(r.json()['data']['avp'])
                values = [x[1] for x in ans_list]
                ans = NLPUtil.get_similarity(attr, values)
                if ans != None:
                    return "是的," + subj + hed + att + obj + "\n"
                elif hed == '有':
                    return "很抱歉," + subj + "没" + hed + att + obj + "\n"
                else:
                    return "很抱歉," + subj + "不" + hed + att + obj + "\n"
            except Exception as e:
                print(e)
                print(r.json())