Esempio n. 1
0
    def answer_room_floor_h(cls,entity_dict,graph):
        room_in_question = entity_dict['room']
        floor_in_question = entity_dict['floor'][0][0]
        #print(room_in_question)
        respons_str = ''

        ans=[]

        #print(father)
        count_yes = 0
        count_no = 0
        #print(len(room_in_question[:-1]))
        for target in room_in_question:
            if (len(target)) == 0:
                continue
            if (len(rdfPrepare.rdf_query_relation(target[0], "rel_part_of_floor", graph))<=0):
                ans.append(0)
                continue
            if (rdfPrepare.rdf_query_relation(target[0], "rel_part_of_floor", graph)[0] == floor_in_question):
                ans.append(1)
            else :
                ans.append(0)
        #print(ans)

        index = 0
        for target in room_in_question:
            if (len(target)) == 0:
                continue
            if ans[index]:
                if count_yes == 0:
                    count_yes = count_yes + 1
                    respons_str += (floor_in_question+'有'+target[0])

                else:
                    respons_str += '和'+target[0]

            index = index + 1
        if count_yes>0:
            respons_str += ("。")

        index = 0
        for target in room_in_question:
            if (len(target)) == 0:
                continue
            #print(index)
            if ans[index] == 0:
                if count_no == 0:
                    count_no = count_no+1

                    respons_str += (floor_in_question + '没有' + target[0])

                else:
                    respons_str += '和' + target[0]

            index = index + 1
        if count_no > 0:
            respons_str += ("。")


        return respons_str+'\n'
Esempio n. 2
0
    def answer_res_room_l(cls,entity_dict,graph):
        res_in_question = entity_dict['res']
        room_in_question = entity_dict['room']
        #print(res_in_question)
        #print(room_in_question)
        respons_str = ''

        ans=[]
        count_yes = 0
        count_no = 0
        #print(len(room_in_question[:-1]))
        for target in res_in_question:
            if (len(target)) == 0:
                continue
            if (len(rdfPrepare.rdf_query_relation(target[0], "rel_part_of_room", graph))<=0):
                ans.append(0)
                continue
            if (rdfPrepare.rdf_query_relation(target[0], "rel_part_of_room", graph)[0] == room_in_question[0][0]):
                ans.append(1)
            else :
                ans.append(0)
        #print(ans)

        index = 0
        for target in res_in_question:
            if (len(target)) == 0:
                continue
            if ans[index]:
                if count_yes == 0:
                    count_yes = count_yes + 1
                    respons_str += target[0]

                else:
                    respons_str += '和'+target[0]

            index = index + 1
        if count_yes>0:
            respons_str += ('在' + room_in_question[0][0]+"。")

        index = 0
        for target in res_in_question:
            if (len(target)) == 0:
                continue
            #print(index)
            if ans[index] == 0:
                if count_no == 0:
                    count_no = count_no+1
                    respons_str += target[0]

                else:
                    respons_str += '和' + target[0]

            index = index + 1
        if count_no > 0:
            respons_str += ('不在' + room_in_question[0][0]+"。")


        return respons_str+'\n'
Esempio n. 3
0
 def answer_res_room(cls, entity_dict, graph):
     respons_str = ''
     if len(entity_dict['res'])!=0:
         for i in range(len(entity_dict['res'])):
             res_in_question = entity_dict['res'][i]
             if res_in_question:
                 for target_res in res_in_question:
                     if (len(rdfPrepare.rdf_query_relation(target_res, "rel_part_of_source", graph)) != 0):
                         respons_str += "属于" + rdfPrepare.rdf_query_relation(target_res, "rel_part_of_source", graph)[0]+'。\n'
                     if (len(rdfPrepare.rdf_query_relation(target_res, "rel_part_of_room", graph)) != 0):
                         res_part_room = rdfPrepare.rdf_query_relation(target_res, "rel_part_of_room", graph)[0]
                         respons_str += '存于' + res_part_room+'。\n'
                     else:
                         respons_str += '呀,我不知道了!'
         return respons_str
     else:
         return None
Esempio n. 4
0
 def answer_room_contact(cls, entity_dict, graph):
     if len(entity_dict['room'])!= 0:
         respons_str = ''
         for i in range(len(entity_dict['room'])):
             room_in_question = entity_dict['room'][i]
             if room_in_question:
                 for target_room in room_in_question:
                     if(len(rdfPrepare.rdf_query_propertiy(target_room, "pro_contact_phone", graph))!=0):
                         respons_str += "_".join(target_room.split('_')[0:3]) +"的电话:"+rdfPrepare.rdf_query_propertiy(target_room, "pro_contact_phone", graph)[0]+"。\n"
                     elif(len(rdfPrepare.rdf_query_relation(target_room, "rel_part_of_room", graph))!=0):
                         parent_room = rdfPrepare.rdf_query_relation(target_room, "rel_part_of_room", graph)
                         for p_room in parent_room:
                             if(rdfPrepare.rdf_query_propertiy(p_room, "pro_contact_phone", graph)):
                                 respons_str += target_room + '位于' + p_room.split('_')[2] + ',可致电' + p_room.split('_')[2]+":" + rdfPrepare.rdf_query_propertiy(p_room, "pro_contact_phone", graph)[0] + '。\n'
         return respons_str
     else:
         return None
Esempio n. 5
0
 def answer_room_pos(cls, entity_dict, graph, tag):
     if tag:
         respons_str = '您当前位置是' + GraphBaseConfig['now_floor'] + '。\n'
     else:
         respons_str = ''
     if len(entity_dict['room'])!=0:
         for i in range(len(entity_dict['room'])):
             room_in_question = entity_dict['room'][i]
             if room_in_question:
                 for target_room in room_in_question:
                     respons_str += "_".join(target_room.split('_')[0:3])+"位于:"
                     if(len(rdfPrepare.rdf_query_relation(target_room, "rel_part_of_floor", graph))!=0):
                         respons_str += rdfPrepare.rdf_query_relation(target_room, "rel_part_of_floor", graph)[0]+','
                     if(len(rdfPrepare.rdf_query_propertiy(target_room, "pro_position_describe", graph))!=0):
                         respons_str += "位置在" + rdfPrepare.rdf_query_propertiy(target_room, "pro_position_describe", graph)[0]
                     respons_str += '。\n'
         return respons_str
     else:
         return None
Esempio n. 6
0
 def answer_room_time_openday(cls, entity_dict, graph):
     '''
     馆室开放日
     :param entity_dict:
     :param graph:
     :return:
     '''
     room_in_question = entity_dict['room']
     respons_str =''
     if room_in_question:
         for target_room in room_in_question:
             if (len(rdfPrepare.rdf_query_propertiy(target_room, "pro_open_day", graph)) != 0):
                 respons_str += "_".join(target_room.split('_')[0:3]) + "开放日是:" + \
                                rdfPrepare.rdf_query_propertiy(target_room, "pro_open_day", graph)[0] + "。\n"
             elif (len(rdfPrepare.rdf_query_relation(target_room, "rel_part_of_room", graph)) != 0):
                 parent_room = rdfPrepare.rdf_query_relation(target_room, "rel_part_of_room", graph)
                 for p_room in parent_room:
                     if (rdfPrepare.rdf_query_propertiy(p_room, "pro_open_day", graph)):
                         respons_str += target_room + '位于' + p_room.split('_')[2] + ',开放日是:' + \
                                        rdfPrepare.rdf_query_propertiy(p_room, "pro_open_day", graph)[0] + '。\n'
         return respons_str
     else:
         return None
Esempio n. 7
0
 def answer_res_pos(cls, entity_dict, graph, tag):
     if tag:
         respons_str = '您当前位置是' + GraphBaseConfig['now_floor'] + '。\n'
     else:
         respons_str = ''
     if len(entity_dict['res'])!=0:
         for i in range(len(entity_dict['res'])):
             res_in_question = entity_dict['res'][i]
             if res_in_question:
                 for target_res in res_in_question:
                     respons_str += target_res
                     if (len(rdfPrepare.rdf_query_relation(target_res, "rel_part_of_source", graph)) != 0):
                         respons_str += "属于" + rdfPrepare.rdf_query_relation(target_res, "rel_part_of_source", graph)[0]+'。\n'
                     if (len(rdfPrepare.rdf_query_relation(target_res, "rel_part_of_room", graph)) != 0):
                         res_part_room = rdfPrepare.rdf_query_relation(target_res, "rel_part_of_room", graph)[0]
                         respons_str += '存于' + res_part_room+'。\n'
                         dict_list = {'room': [[res_part_room]]}
                         new_answer = cls.answer_room_pos(dict_list,graph,0)
                         if new_answer is not None:
                             respons_str += new_answer
         return respons_str
     else:
         return None
Esempio n. 8
0
 def answer_res_time(cls, entity_dict, graph,day):
     '''
     资源开放时间
     :param entity_dict:
     :param graph:
     :return:
     '''
     res_in_question = entity_dict['res']
     respons_str=''
     if day=="today":
         respons_str = '今天是' + GraphBaseConfig['now_day'] + ','
         week_str = time.strftime("%w", time.localtime())
         if str(week_str) == '1':
             week_str = "pro_Monday_opentime"
             respons_str = respons_str.replace('星期1', '星期一')
         elif str(week_str) == '2':
             week_str = "pro_Tuesday_opentime"
             respons_str = respons_str.replace('星期2', '星期二')
         elif str(week_str) == '3':
             week_str = "pro_Wednesday_opentime"
             respons_str = respons_str.replace('星期3', '星期三')
         elif str(week_str) == '4':
             week_str = "pro_Thursday_opentime"
             respons_str = respons_str.replace('星期4', '星期四')
         elif str(week_str) == '5':
             week_str = "pro_Friday_opentime"
             respons_str = respons_str.replace('星期5', '星期五')
         elif str(week_str) == '6':
             week_str = "pro_Saturday_opentime"
             respons_str = respons_str.replace('星期6', '星期六')
         elif str(week_str) == '日':
             week_str = "pro_Sunday_opentime"
     elif day=="tomorrow":
         respons_str = '明天是' + GraphBaseConfig['now_day'] + ','
         week_str = time.strftime("%w", time.localtime())
         if str(week_str) == '1':
             week_str = "pro_Tuesday_opentime"
             respons_str = respons_str.replace('星期1', '星期二')
         elif str(week_str) == '2':
             week_str = "pro_Wednesday_opentime"
             respons_str = respons_str.replace('星期2', '星期三')
         elif str(week_str) == '3':
             week_str = "pro_Thursday_opentime"
             respons_str = respons_str.replace('星期3', '星期四')
         elif str(week_str) == '4':
             week_str = "pro_Friday_opentime"
             respons_str = respons_str.replace('星期4', '星期五')
         elif str(week_str) == '5':
             week_str = "pro_Saturday_opentime"
             respons_str = respons_str.replace('星期5', '星期六')
         elif str(week_str) == '6':
             week_str = "pro_Sunday_opentime"
             respons_str = respons_str.replace('星期6', '星期日')
         elif str(week_str) == '日':
             week_str = "pro_Monday_opentime"
             respons_str = respons_str.replace('星期日', '星期一')
     elif day=="Monday":
         respons_str = '星期一,'
         week_str = "pro_Monday_opentime"
     elif day=="Tuesday":
         respons_str = '星期二,'
         week_str = "pro_Tuesday_opentime"
     elif day=="Wednesday":
         respons_str = '星期三,'
         week_str = "pro_Wednesday_opentime"
     elif day=="Thursday":
         respons_str = '星期四,'
         week_str = "pro_Thursday_opentime"
     elif day=="Friday":
         respons_str = '星期五,'
         week_str = "pro_Friday_opentime"
     elif day == "Saturday":
         respons_str = '星期六,'
         week_str = "pro_Saturday_opentime"
     elif day == "Sunday":
         respons_str = '星期日,'
         week_str = "pro_Sunday_opentime"
     if res_in_question:
         for target_res in res_in_question:
             room=rdfPrepare.rdf_query_relation(target_res, "rel_part_of_room", graph)
             if(len(room)!=0):
                 if(len(rdfPrepare.rdf_query_propertiy(room[0], week_str, graph))!=0):
                     # print(rdfPrepare.rdf_query_propertiy(room[0], week_str, graph))
                     respons_str += target_res +"开放时间是:"+rdfPrepare.rdf_query_propertiy(room[0], week_str, graph)[0]+"。\n"
             elif(len(rdfPrepare.rdf_query_relation(room[0], "rel_part_of_room", graph))!=0):
                 parent_room = rdfPrepare.rdf_query_relation(room[0], "rel_part_of_room", graph)
                 for p_room in parent_room:
                     if(rdfPrepare.rdf_query_propertiy(p_room, week_str, graph)):
                         respons_str += target_res + '位于' + p_room.split('_')[2] + ',开放时间是:' + rdfPrepare.rdf_query_propertiy(p_room, week_str, graph)[0] + '。\n'
         return respons_str
     else:
         return None