Beispiel #1
0
def get_dbinfo(slot1,slot2, choose):
    client = db.MongoClient(DB_IP, DB_PORT)

    collection_division = client[DB_NAME]["division"]
    collection_disease = client[DB_NAME]["disease"]
    doctor_list = []
    #use disease to find division
    if slot2 == "department":
        for data in collection_disease.find({"disease_c": {"$regex": slot1}}):
            return  data['department']
    #use disease to find doctors
    elif slot2 == "doctor" and choose == 0:
        for data in collection_division.find({"$and": [{"disease": {"$regex": slot1}},
                                                       {"department": {"$regex": ""}}]}):
            for name in data['doctor']:
                if name not in doctor_list:
                    doctor_list.append(name)
        return doctor_list
    #use division to find doctors
    elif slot2 == "doctor" and choose == 1:
        for data in collection_division.find({"$and": [{"disease": {"$regex": ''}},
                                                       {"department": {"$regex": slot1}}]}):
            for name in data['doctor']:
                if name not in doctor_list:
                    doctor_list.append(name)
        return doctor_list
Beispiel #2
0
    def __init__(self):
        client = db.MongoClient(DB_IP, DB_PORT)
        collection_division = client[DB_NAME]["division"]
        collection_disease = client[DB_NAME]["disease"]

        disease_list = [line.rstrip('\n') for line in open("../data_resource/disease_dict.txt", "r")]
        #print(disease_list)

        notfind = True
        while notfind :
            notfind = False

            disease = disease_list[random.randint(0, len(disease_list)-1)]
            #print(disease)
            while collection_division.find({"disease": disease}).count() < 1:
                disease = disease_list[random.randint(0, len(disease_list) - 1)]

            #print(disease)
            for collection in collection_disease.find({"disease_c": disease}):
                division = collection['department'][0]

            doctor_list = []
            for collection in collection_division.find({"disease": disease}):
                doctor_list.extend(collection['doctor'])

            #print(doctor_list)
            if len(doctor_list) is 0:
                notfind = True
            elif len(doctor_list) > 1:
                name = doctor_list[random.randint(0, len(doctor_list)-1)]
            else:
                name = doctor_list[0]

            if not notfind:
                time_list = CrawlerTimeTable.Timetable(name).get_time()
                #print(time_list)
                if len(time_list) is 0:
                    notfind = True
                elif len(time_list) > 1:
                    time = time_list[random.randint(0, len(time_list)-1)]
                else:
                    time = time_list[0]

        self.goal = {'intent': random.randint(1, 5),
                     'slot': {'disease': disease, 'division': division, 'doctor': name, 'time': time}}
Beispiel #3
0
#sys.path.append('../../../doctorbot')
#from doctorbot import settings
#from fb_doctor_chatbot import models
#setup_environ(settings)
#os.environ['DJANGO_SETTINGS_MODULE'] = 'doctorbot.settings'

DIR_NAME = '../../../../DoctorBot/doctorbot/'
import sqlite3
conn = sqlite3.connect(DIR_NAME + 'db.sqlite3')
#fb = conn.cursor()


DB_IP = "104.199.131.158"  # doctorbot GCP ip
DB_PORT = 27017  # default MongoDB port
DB_NAME = "doctorbot"  # use the collection
client = db.MongoClient(DB_IP, DB_PORT)
collection_division = client[DB_NAME]["division"]
collection_disease = client[DB_NAME]["disease"]

def initialize():
    state = {"intent": None, "disease": None, "division": None, "doctor": None, "time": None}
    DM = {"Request": None, "Intent": None, "Slot": None, "State": state}
    #if os.path.exists("DM.json"):
        #os.remove("DM.json")
    with open("DM.json", 'w') as f:
        json.dump(DM,f)
    return DM
#################################################################################################
#                   search for division or doctor from database                                 #
#################################################################################################
def get_dbinfo(slot1,slot2, choose):
Beispiel #4
0
            '//div[@id="link-report"]//div[@class="intro"]/p/text()')
        jianjie = ''.join(jianjie_list)

        author_jianjie_list = html.xpath(
            '//div[@class="indent "]//div[@class="intro"]/p/text()')
        author_jianjie = ''.join(author_jianjie_list)

        nianduBandan = 'https://book.douban.com/annual/2018?source=navigation#1'

        save_res = bookName + ',' + url + ',' + authors + ',' + isbn + ',' + tags + ',' + publishDate + ',' + chubanshe + ',' + jianjie + ',' + author_jianjie + ',' + nianduBandan + '\n'
        print(save_res)

        results = {
            'bookName': bookName,
            'url': url,
            'authors': authors,
            'isbn': isbn,
            'tags': tags,
            'publishDate': publishDate,
            'chubanshe': chubanshe,
            'jianjie': jianjie,
            'author_jianjie': author_jianjie,
            'nianduBandan': nianduBandan,
        }

        dbCli.save(results)


if __name__ == '__main__':
    dbCli = db.MongoClient()
    start()
Beispiel #5
0
def main():
    client = db.MongoClient(DB_IP, DB_PORT)

    collection_division = client[DB_NAME]["division"]
    collection_disease = client[DB_NAME]["disease"]
    sys.stdout.flush()
    print("您好,我是Seek Doctor Bot,如果您想要\n" + "1.查詢某疾病相關症狀,您可以問我:請問青光眼會怎樣\n" +
          "2.知道某疾病屬於什麼科別,您可以問我:青光眼是哪科\n" + "3.查詢某疾病或科別主治醫師,您可以問我:青光眼要看哪些醫生\n" +
          "4.查詢某疾病,科別或醫生的門診時間,您可以說:給我青光眼門診時刻表\n" +
          "5.預約掛號某疾病,科別或醫生的門診,您可以說:我要掛號眼科")

    while True:
        sentence = input('\n\n請輸入: ')
        slot_dictionary = LU.SlotFilling().decode(sentence)
        print("[ Slot ]")
        for slot, value in slot_dictionary.items():
            print(slot, ": ", value)

        intent = LU.IntentPredict().get_intent(sentence)
        intent_index = intent.index(max(intent))
        intents = [
            'greeting', 'search_symptom', 'search_division', 'search_doctor',
            'search_timetable', 'register'
        ]
        print('[ Intent ] ' + intents[intent_index])

        print('\n\n')
        if intent_index == 1:  # search_symptom
            print("好的,您想查詢" + slot_dictionary['disease'] + "會有什麼症狀,以下為相關可能症狀:")
            for data in collection_disease.find(
                {"disease_c": {
                    "$regex": slot_dictionary['disease']
                }}):
                print(", ".join(data['symptom']))
        elif intent_index == 2:  # search_division
            print("好的,您想查詢" + slot_dictionary['disease'] + "是屬於哪一科,以下為相關科別:")
            for data in collection_disease.find(
                {"disease_c": {
                    "$regex": slot_dictionary['disease']
                }}):
                print(", ".join(data['department']))
        elif intent_index == 3:  # search_doctor
            print("好的,您想查詢" + slot_dictionary['division'] +
                  slot_dictionary['disease'] + "有哪些醫生可以掛號,以下為醫生表列:")
            for data in collection_division.find({
                    "$and": [{
                        "disease": {
                            "$regex": slot_dictionary['disease']
                        }
                    }, {
                        "department": {
                            "$regex": slot_dictionary['division']
                        }
                    }]
            }):
                print(data['department'] + " 醫師: " + ", ".join(data['doctor']))
        elif intent_index == 4:  # search_timetable
            print("好的,您想查詢" + slot_dictionary['division'] +
                  slot_dictionary['disease'] + slot_dictionary['doctor'] +
                  slot_dictionary['time'] + "的門診時間")
        elif intent_index == 5:  # register
            print("好的,幫您預約掛號" + " " + slot_dictionary['division'] + " " +
                  slot_dictionary['disease'] + " " +
                  slot_dictionary['doctor'] + " " + slot_dictionary['time'] +
                  "的門診")
        else:
            print("不好意思,我不確定您的意思")
Beispiel #6
0
        start_url = URL.format(keyword=keyword,pageToken=i,startDate=startDate,endDate=endDate)
        print(start_url)
        response = down.get_html(start_url)
        if response:
            # print(response.text):
            parse(item,response)
        else:
            print('网络请求失败')
            continue

    #获取文章
    wenzhang_url = 'https://s.weibo.com/article?q={keyword}&Refer=weibo_article&page={pageToken}'
    for i in range(1,wenzhangPageNum+1):
        start_url = wenzhang_url.format(keyword=keyword,pageToken=i)
        print(start_url)
        response = down.get_html(start_url)
        if response:
            # print(response.text)
            parse_wenzhang(item,response)
        else:
            print('网络请求失败')
            continue


if __name__ == '__main__':
    down = download.Download()
    mongoClient = db.MongoClient()
    item_list = read()
    for obj in item_list:
        print('当前关键词:'+obj['keyword'])
        main(obj)