Exemplo n.º 1
0
def subjective_measure(filepath, subject_list):
    pool = Pool()
    subject_score = 0
    subject_score_dic = {}
    xml_file = etree.parse(filepath)
    root_node = xml_file.getroot()[0]
    process_res = {}
    logger.info('subject' + str(subject_list) + '!!!!!!!!!!!!!!')
    if 'copy_detect_index' in subject_list:
        # tmp_score, copy_detect_res = copy_detect_index(root_node)
        # subject_score += tmp_score
        # subject_score_dic['copy_detect_index'] = [tmp_score, cf.copy_detect_score]
        process_res['copy_detect_index'] = pool.apply_async(
            copy_detect_index, (root_node, ))
    else:
        subject_score += cf.copy_detect_score
        print('copy_dect:', cf.copy_detect_score)
    if 'sentiment_index' in subject_list:
        # tmp_score, sentiment_res = sentiment_index(root_node)
        process_res['sentiment_index'] = pool.apply_async(
            sentiment_index, (root_node, ))
        # subject_score += tmp_score
        # subject_score_dic['sentiment_index'] = [tmp_score, cf.sentiment_classify_score]
    else:
        # subject_score_dic['sentiment_index'] = [cf.sentiment_classify_score, cf.sentiment_classify_score]
        subject_score += cf.sentiment_classify_score
        print('sentiment_index:', cf.sentiment_classify_score)
    if 'text_style_classification' in subject_list:
        process_res['text_style_classification'] = pool.apply_async(
            text_style_classification, (root_node, ))
        # subject_score += tmp_score
        # subject_score_dic['text_style_classification'] = [tmp_score, cf.text_style_classify_score]
    else:
        # subject_score_dic['text_style_classification'] = [cf.text_style_classify_score,
        #                                                       cf.text_style_classify_score]
        subject_score += cf.text_style_classify_score
        print('text_style_classification:', cf.text_style_classify_score)
    if 'law_articles_rational' in subject_list:
        process_res['law_articles_rational'] = pool.apply_async(
            law_index, (filepath, ))
        # tmp_score, law_articles_res = law_index(filepath)
        # subject_score += tmp_score
        # subject_score_dic['law_articles_rational'] = [tmp_score, cf.law_articles_rational_score]
    else:
        # if 'law_articles_rational_' not in index_dic.keys():
        #     subject_score_dic['law_articles_rational'] = [cf.law_articles_rational_score,
        #                                                   cf.law_articles_rational_score]
        subject_score += cf.law_articles_rational_score
        print('law_article_index:', cf.law_articles_rational_score)
    pool.close()
    pool.join()
    law_articles_res, sentiment_res, text_style_res, copy_detect_res, subject_score_dic, subject_score, res = func_process(
        subject_score_dic, subject_score, process_res)

    return subject_score, subject_score_dic, law_articles_res, sentiment_res, text_style_res, copy_detect_res
Exemplo n.º 2
0
def extra():
    if request.method == 'GET':
        news = request.args.get('s')
    elif request.method == 'POST':
        news = request.form['news']
    else:
        news = ''
    logger.info(news)
    if not news:
        # return '<script>alert("没有输入内容!")</script>'
        news = "国台办表示中国必然统一。会尽最大努力争取和平统一,但绝不承诺放弃使用武力。台湾人民说回归中国好啊"
    news_parse = ltp_manager.get_sentences_json_result(news)
    logger.info(news_parse)
    if isinstance(news_parse, list):
        infos_type = "list"
        logger.info('parse is list')
    else:
        infos_type = 'str'
        logger.info('parse is str')
        logger.info(infos_type)
    return render_template('extra.html', infos=news_parse, infos_type=infos_type, fly_str=base64_encode(news[:500]))
Exemplo n.º 3
0
def home():
    logger.info('访问/home 主页')
    return render_template('home.html')
Exemplo n.º 4
0
@app.route('/extra', methods=['GET', 'POST'])
def extra():
    if request.method == 'GET':
        news = request.args.get('s')
    elif request.method == 'POST':
        news = request.form['news']
    else:
        news = ''
    logger.info(news)
    if not news:
        # return '<script>alert("没有输入内容!")</script>'
        news = "国台办表示中国必然统一。会尽最大努力争取和平统一,但绝不承诺放弃使用武力。台湾人民说回归中国好啊"
    news_parse = ltp_manager.get_sentences_json_result(news)
    logger.info(news_parse)
    if isinstance(news_parse, list):
        infos_type = "list"
        logger.info('parse is list')
    else:
        infos_type = 'str'
        logger.info('parse is str')
        logger.info(infos_type)
    return render_template('extra.html', infos=news_parse, infos_type=infos_type, fly_str=base64_encode(news[:500]))


if __name__ == "__main__":
    logger.info('初始化pyLtpModel')
    ltp_manager = LtpModel(LTP_DATA_DIR)
    logger.info('初始化jiebaModel')
    jieba.initialize()
    app.run(host='0.0.0.0', port=8088)