Beispiel #1
0
def NER_predict(msg):
    # 这里指定了模型路径
    model_path = '/Users/charlesxu/PycharmProjects/Chatbot_CN/Chatbot_Data/Info_Extraction_save/1562204195/checkpoints'
    ckpt_file = tf.train.latest_checkpoint(model_path)
    # print('>>>>>>>>>>>',ckpt_file)
    paths['model_path'] = ckpt_file
    model = BiLSTM_CRF(args,
                       embeddings,
                       tag2label,
                       word2id,
                       paths,
                       config=config)
    model.build_graph()
    saver = tf.train.Saver()

    with tf.Session(config=config) as sess:
        print('============= demo =============')
        saver.restore(sess, ckpt_file)

        demo_sent = msg
        if demo_sent == '' or demo_sent.isspace():
            print('See you next time!')
        else:
            demo_sent = list(demo_sent.strip())
            demo_data = [(demo_sent, ['O'] * len(demo_sent))]
            tag = model.demo_one(sess, demo_data)
            PER, LOC, ORG = get_entity(tag, demo_sent)
            print('PER: {}\nLOC: {}\nORG: {}'.format(PER, LOC, ORG))
Beispiel #2
0
    paths['model_path'] = ckpt_file
    model = BiLSTM_CRF(args, embeddings, tag2label, word2id, paths, config=config)
    model.build_graph()
    saver = tf.train.Saver()

    with tf.Session(config=config) as sess:
        print('============= demo =============')
        saver.restore(sess, ckpt_file)

        try:
            for one_text in get_MONGO_data():
                addr = one_text['addr']  # 归属地
                charge = one_text['charge'] # 犯罪原因
                judgementId = one_text['judgementId'] # 判决Id,唯一标示
                print(judgementId)
                keywords = one_text['keywords']      # 关键词
                court = one_text['court']           # 法院信息
                text = one_text['judge_text']  # 判决结果,是一个列表,继续循环
                proponents = one_text['proponents']   # 原告
                opponents = one_text['opponents']     # 被告

                if text:
                    demo_data = [(text, ['O'] * len(text))]
                    tag = model.demo_one(sess, demo_data)
                    PER, LOC, ORG, TIM= get_entity(tag, text)
                    MON = get_MON_entity(text)
                    print('PER: {}\nLOC: {}\nORG: {}\nMON: {}\n'.format(PER, LOC, ORG, MON))


        except Exception as e:
            print('Info Error is', e)
Beispiel #3
0
def judge_owner():
    LOC = get_entity()
    pass
Beispiel #4
0
        # print('Please input your sentence:')
        # demo_sent = input()

        all_texts = get_datas()  # 数据库返回的按“一、二、三、四、”切割返回的文本
        for one_text in all_texts:
            uuid = one_text[0]  # 获取每条数据的uuid
            obligors = one_text[1]  # 原告
            creditors = one_text[2]  # 被告
            texts = one_text[3]
            text_sent = split_sentence.split_sentence_thr(texts)  # 分句
            for text in text_sent:
                print(text)
                text_strip = list(text.strip())  #
                demo_data = [(text, ['O'] * len(text))]
                tag = model.demo_one(sess, demo_data)
                PER, LOC, ORG = get_entity(tag, text)
                LOC_RE = get_add(text)
                # 调用money处理方法,获取金额实体
                MON = get_MON_entity(text)

                print('PER: {}\nLOC: {}\nORG: {}\nMON: {}\n'.format(
                    PER, LOC, ORG, MON))
                print('LOC_RE :{}'.format(LOC_RE))

                # 将数据写入ES
                es.index(
                    index='chatbot',
                    doc_type='test_type',
                    body={
                        'uuid': uuid,
                        'text': text,  # 原文