示例#1
0
def get_combine_info2(conn_func, redis_db, conf, knowledge, related_knowledge,
                      origin):
    '''
    针对大题有难度,而小题没有难度,得到大题对应知识点表示
    '''
    conn = conn_func()
    cursor = conn.cursor()
    context_conf = conf['context_conf']
    question_conf = conf['question_conf']

    context_type = context_conf['qtype']
    table = context_conf['table']
    context_id = context_conf['cid']
    context_sql = ('select %s, difficulty from %s where question_type=%s '
                   'and state=%s')
    cursor.execute(context_sql % (context_id, table, context_type, K_APPROVED))
    diff_dict = dict([(cid, diff) for cid, diff in cursor.fetchall()])

    question_type = question_conf['qtype']
    table = question_conf['table']
    context_id = question_conf['cid']
    question_id = question_conf['qid']
    question_sql = 'select %s,%s from %s where question_type=%s'
    param = (context_id, question_id, table, question_type)
    cursor.execute(question_sql % param)

    info = {}
    for cid, qid in cursor.fetchall():
        ktags = knowledge.get(question_type, {}).get(qid, [])
        rktags = related_knowledge.get(question_type, {}).get(qid, [])
        if cid not in diff_dict: continue  # 只考虑审核过的大题
        diff = diff_dict[cid]
        # 将大题的难度当作小题各知识点难度
        ktags = [(tag, diff) for tag in ktags]
        rktags = [(tag, diff) for tag in rktags]
        qfac = KnowledgeFactor(ktags, rktags)
        info.setdefault(cid, []).append(qfac)

    combine_info = {}
    for cid, factors in info.iteritems():
        diff = diff_dict[cid]
        ktags = knowledge.get(context_type, {}).get(cid, [])
        rktags = related_knowledge.get(context_type, {}).get(cid, [])
        ktags = [(tag, diff) for tag in ktags]
        rktags = [(tag, diff) for tag in rktags]
        context_fac = KnowledgeFactor(ktags, rktags)
        question_fac = KnowledgeFactor.merge(factors)
        combine_info[cid] = KnowledgeFactor.merge([context_fac, question_fac])
    cursor.close()
    return dump_factor(redis_db, context_type, combine_info, origin)
示例#2
0
def get_combine_info2(conn_func, banker_conn_func, redis_db, conf,
                      knowledge, related_knowledge, origin):
    '''
    针对大题有难度,而小题没有难度,得到大题对应知识点表示
    '''
    banker_conn = banker_conn_func()
    cursor = banker_conn.cursor()
    context_conf = conf['context_conf']
    question_conf = conf['question_conf']

    context_type = context_conf['qtype']
    table = context_conf['table']
    context_id = context_conf['cid']
    context_sql = ('select %s, difficulty from %s where question_type=%s '
                   'and state=%s')
    cursor.execute(context_sql % (context_id, table, context_type, K_APPROVED))
    diff_dict = dict([(cid, diff) for cid, diff in cursor.fetchall()])

    question_type = question_conf['qtype']
    table = question_conf['table']
    context_id = question_conf['cid']
    question_id = question_conf['qid']
    question_sql = 'select %s,%s from %s where question_type=%s'
    param = (context_id, question_id, table, question_type)
    cursor.execute(question_sql % param)

    info = {}
    for cid, qid in cursor.fetchall():
        ktags = knowledge.get(question_type, {}).get(qid, [])
        rktags = related_knowledge.get(question_type, {}).get(qid, [])
        if cid not in diff_dict: continue  # 只考虑审核过的大题
        diff = diff_dict[cid]
        # 将大题的难度当作小题各知识点难度
        ktags = [(tag, diff) for tag in ktags]
        rktags = [(tag, diff) for tag in rktags]
        qfac = KnowledgeFactor(ktags, rktags)
        info.setdefault(cid, []).append(qfac)

    combine_info = {}
    for cid, factors in info.iteritems():
        diff = diff_dict[cid]
        ktags = knowledge.get(context_type, {}).get(cid, [])
        rktags = related_knowledge.get(context_type, {}).get(cid, [])
        ktags = [(tag, diff) for tag in ktags]
        rktags = [(tag, diff) for tag in rktags]
        context_fac = KnowledgeFactor(ktags, rktags)
        question_fac = KnowledgeFactor.merge(factors)
        combine_info[cid] = KnowledgeFactor.merge([context_fac, question_fac])
    cursor.close()
    return dump_factor(redis_db, context_type, combine_info, origin)
示例#3
0
def get_combine_info1(conn_func, banker_conn_func, redis_db, conf, knowledge,
                      related_knowledge, origin):
    '''
    针对大题没有难度,而小题有难度,得到大题对应知识点表示
    '''
    banker_conn = banker_conn_func()
    cursor = banker_conn.cursor()
    context_conf = conf['context_conf']
    question_conf = conf['question_conf']

    context_type = context_conf['qtype']
    table = context_conf['table']
    context_id = context_conf['cid']
    context_sql = 'select %s from %s where question_type=%s and state=%s'
    cursor.execute(context_sql % (context_id, table, context_type, K_APPROVED))
    valid_cids = set([cid for cid, in cursor.fetchall()])

    question_type = question_conf['qtype']
    table = question_conf['table']
    context_id = question_conf['cid']
    question_id = question_conf['qid']
    question_sql = 'select %s,%s,difficulty from %s where question_type=%s'
    param = (context_id, question_id, table, question_type)
    cursor.execute(question_sql % param)

    info = {}
    for cid, qid, diff in cursor.fetchall():
        if cid not in valid_cids: continue  # 只考虑审核过的大题
        ktags = knowledge.get(question_type, {}).get(qid, [])
        rktags = related_knowledge.get(question_type, {}).get(qid, [])
        ktags = [(tag, diff) for tag in ktags]
        rktags = [(tag, diff) for tag in rktags]
        qfac = KnowledgeFactor(ktags, rktags)
        info.setdefault(cid, []).append(qfac)

    combine_info = {}
    for cid, factors in info.iteritems():
        question_fac = KnowledgeFactor.merge(factors)
        # 使用小题知识点的平均难度作为大题的难度
        diff = question_fac.difficulty()
        ktags = knowledge.get(context_type, {}).get(cid, [])
        rktags = related_knowledge.get(context_type, {}).get(cid, [])
        ktags = [(tag, diff) for tag in ktags]
        rktags = [(tag, diff) for tag in rktags]
        context_fac = KnowledgeFactor(ktags, rktags)
        combine_info[cid] = KnowledgeFactor.merge([context_fac, question_fac])
    cursor.close()
    return dump_factor(redis_db, context_type, combine_info, origin)
示例#4
0
def get_combine_info1(conn_func, redis_db, conf,
                      knowledge, related_knowledge, origin):
    '''
    针对大题没有难度,而小题有难度,得到大题对应知识点表示
    '''
    conn = conn_func()
    cursor = conn.cursor()
    context_conf = conf['context_conf']
    question_conf = conf['question_conf']

    context_type = context_conf['qtype']
    table = context_conf['table']
    context_id = context_conf['cid']
    context_sql = 'select %s from %s where question_type=%s and state=%s'
    cursor.execute(context_sql % (context_id, table, context_type, K_APPROVED))
    valid_cids = set([cid for cid, in cursor.fetchall()])

    question_type = question_conf['qtype']
    table = question_conf['table']
    context_id = question_conf['cid']
    question_id = question_conf['qid']
    question_sql = 'select %s,%s,difficulty from %s where question_type=%s'
    param = (context_id, question_id, table, question_type)
    cursor.execute(question_sql % param)

    info = {}
    for cid, qid, diff in cursor.fetchall():
        if cid not in valid_cids: continue # 只考虑审核过的大题
        ktags = knowledge.get(question_type, {}).get(qid, [])
        rktags = related_knowledge.get(question_type, {}).get(qid, [])
        ktags = [(tag, diff) for tag in ktags]
        rktags = [(tag, diff) for tag in rktags]
        qfac = KnowledgeFactor(ktags, rktags)
        info.setdefault(cid, []).append(qfac)

    combine_info = {}
    for cid, factors in info.iteritems():
        question_fac = KnowledgeFactor.merge(factors)
        # 使用小题知识点的平均难度作为大题的难度
        diff = question_fac.difficulty()
        ktags = knowledge.get(context_type, {}).get(cid, [])
        rktags = related_knowledge.get(context_type, {}).get(cid, [])
        ktags = [(tag, diff) for tag in ktags]
        rktags = [(tag, diff) for tag in rktags]
        context_fac = KnowledgeFactor(ktags, rktags)
        combine_info[cid] = KnowledgeFactor.merge([context_fac, question_fac])
    cursor.close()
    return dump_factor(redis_db, context_type, combine_info, origin)