Ejemplo n.º 1
0
def get_summary(data):
    document = data.get("document")
    input_sentence = [[document]]
    rjson = translate(encoder, decoder, decoder_init_state, input_sentence,
                      ctx, max_seq_len)
    document = rjson["0"]["input"]
    ori_summary = rjson["0"]["output"]
    res = ""

    for word in ori_summary:
        if word != "<" and word != ">" and word not in [
                "p", "a", "d", "<pad>", " "
        ]:
            res += word

    with session_scope() as db_session:
        deeplearning = Deeplearning()
        deeplearning.document = data.get("document")
        deeplearning.method = "deeplearning"
        deeplearning.summary = res
        deeplearning.create_time = int(time.time())
        deeplearning.user_id = data.get('id')
        db_session.add(deeplearning)

    return res
Ejemplo n.º 2
0
def deeplearning_history(user):
    with session_scope() as db_session:
        summary = db_session.query(Deeplearning).filter(
            Deeplearning.user_id == user["id"]).all()
        ans = []
        for sum in summary:
            ans.append(sum.to_dict())
        return ans
def update_user(data):
    with session_scope() as db_session:
        username = data.get("username")
        user = db_session.query(User).filter(User.username == username).first()
        nickname = data.get("nickname")
        user.nickname = nickname
        db_session.commit()
        res_user = user.to_dict(exclude_columns=["password", "create_time", "last_login_time"])
        g.user = res_user
        return res_user
Ejemplo n.º 4
0
def mmr_history(data):
    with session_scope() as db_session:
        res = {}
        sum = db_session.query(func.count(Mmr.id)).scalar()
        summary = db_session.query(Mmr).filter(Mmr.user_id == data["id"]).all()
        ans = []
        for _summary in summary:
            ans.append(_summary.to_dict())
        res["sum"] = sum
        res["data"] = ans

        return ans
def textrank_history_page(data, start, end):
    with session_scope() as db_session:
        res = {}
        sum = db_session.query(func.count(Textrank.id)).scalar()
        summary = db_session.query(Textrank).filter(Textrank.user_id == data["id"]).slice(start, end).all()
        ans = []
        for _summary in summary:
            ans.append(_summary.to_dict())
        res["sum"] = sum
        res["data"] = ans

        return res
def auth_password(username, password):
    with session_scope() as db_session:
        query_password = db_session.query(User).filter(User.username == username).first()
        if query_password is None:
            raise exceptions.UserNotExist
        if encrypt.auth_password(username, password):
            user = query_password.to_dict(exclude_columns=["password", "create_time", "last_login_time"])
            g.user = user
            query_password.last_login_time = int(time.time())
            db_session.commit()
            return user
    return False
def create_user(data):
    with session_scope() as db_session:
        username, password = data.get("username"), data.get("password")
        nickname = data.get("nickname")
        create_time = int(time.time())
        encrypted_password = encrypt.encrypt(password, create_time)
        user = User()
        user.username = username
        user.nickname = nickname
        user.password = encrypted_password
        user.create_time = create_time
        user.last_login_time = create_time
        db_session.add(user)
        db_session.commit()
def get_summary(data, compress_rate):
    compress_rate_val = float(compress_rate[:len(compress_rate) - 1]) / 100
    res = ",".join(_get_summary(data.get("document"), compress_rate_val))

    with session_scope() as db_session:
        textrank = Textrank()
        textrank.document = data.get("document")
        textrank.method = "textrank"
        textrank.summary = res
        textrank.create_time = int(time.time())
        textrank.user_id = data.get('id')
        textrank.compress_rate = compress_rate
        db_session.add(textrank)

    return res
Ejemplo n.º 9
0
def get_summary(data, compress_rate):
    compress_rate_val = float(compress_rate[:len(compress_rate) - 1]) / 100
    sentences_list = document_cutting(data.get("document"))
    summary_list = _get_summary(sentences_list, compress_rate_val)
    ans = []
    for sentence in sentences_list:
        if sentence in summary_list:
            ans.append(sentence)

    res = ",".join(ans)

    with session_scope() as db_session:
        mmr = Mmr()
        mmr.document = data.get("document")
        mmr.method = "mmr"
        mmr.summary = res
        mmr.create_time = int(time.time())
        mmr.user_id = data.get('id')
        mmr.compress_rate = compress_rate
        db_session.add(mmr)

    return res