Beispiel #1
0
def predict(essay):
    with open('/Users/inciboduroglu/Code/gradr/learn/rbfmodel.pkl', 'rb') as f:
        model = pickle.load(f)

    # preproc returns {'essay_list': essay_list, 'essay_set': essay_set, 'no_punc_list': no_punc_list, 'low_list': low_
    # list, 'no_stop_list': no_stop_list, 'gradr_no_stop_list': gradr_no_stop_list}
    prep_res = pr.preproc(essay)

    # featext returns {'lexical_div': lex_div, 'word_cnt': w_cnt, 'long_word_cnt': lng_w_cnt, 'spell_err_cnt': spl,
    # 'distinct_word_cnt': dst_wrd_cnt, 'stem_cnt': stm_cnt}
    feat = fe.featext(prep_res)

    feat_mtx = np.zeros((1, 6))
    feat_mtx[0, 0] = feat['word_cnt']
    feat_mtx[0, 1] = feat['long_word_cnt']
    feat_mtx[0, 2] = feat['spell_err_cnt']
    feat_mtx[0, 3] = feat['lexical_div']
    feat_mtx[0, 4] = feat['distinct_word_cnt']
    feat_mtx[0, 5] = feat['stem_cnt']

    feat_mtx.reshape((1, 6))
    print('feature matrix: ')
    print(feat_mtx)

    grade = model.predict(feat_mtx.reshape((1, 6)))
    print(grade * 100)

    if feat['spell_err_cnt'] / feat['word_cnt'] > 0.3:
        return 0
    else:
        return grade * 100
Beispiel #2
0
def predict(essay):
    with open('/Users/inciboduroglu/Code/gradr/learn/rbfmodel.pkl', 'rb') as f:
        model = pickle.load(f)

    # preproc returns {'essay_list': essay_list, 'essay_set': essay_set, 'no_punc_list': no_punc_list, 'low_list': low_
    # list, 'no_stop_list': no_stop_list, 'gradr_no_stop_list': gradr_no_stop_list}
    prep_res = pr.preproc(essay)

    # featext returns {'lexical_div': lex_div, 'word_cnt': w_cnt, 'long_word_cnt': lng_w_cnt, 'spell_err_cnt': spl,
    # 'distinct_word_cnt': dst_wrd_cnt, 'stem_cnt': stm_cnt}
    feat = fe.featext(prep_res)

    feat_mtx = np.zeros((1, 6))
    feat_mtx[0, 0] = feat['word_cnt']
    feat_mtx[0, 1] = feat['long_word_cnt']
    feat_mtx[0, 2] = feat['spell_err_cnt']
    feat_mtx[0, 3] = feat['lexical_div']
    feat_mtx[0, 4] = feat['distinct_word_cnt']
    feat_mtx[0, 5] = feat['stem_cnt']

    feat_mtx.reshape((1, 6))
    print('feature matrix: ')
    print(feat_mtx)

    grade = model.predict(feat_mtx.reshape((1, 6)))
    print(grade*100)

    if feat['spell_err_cnt'] / feat['word_cnt'] > 0.3:
        return 0
    else:
        return grade * 100
Beispiel #3
0
def check(essay):
    prep = pr.preproc(essay)

    essay_list = prep['essay_list']

    err = [word for word in essay_list if d.check(word) == False]
    sug = [d.suggest(word) for word in err]

    return [err, sug]
Beispiel #4
0
def check(essay):
    prep = pr.preproc(essay)

    essay_list = prep['essay_list']

    err = [word for word in essay_list if d.check(word)==False]
    sug = [d.suggest(word) for word in err]

    return [err, sug]
Beispiel #5
0
feat_num = 6 + 1  # 6 features one label
feat_mtx = np.zeros((data_10, feat_num), dtype=np.double)

rubric_range = [[2, 12], [1, 6], [0, 3], [0, 3], [0, 4], [0, 4], [0, 30], [0, 60]]
i = 0
for j in range(data_num):
    # get essay from dataset
    set = sheet.cell(j + 1, 1).value
    set = int(set)

    if set in [2, 3, 4, 6, 8]:
        essay = sheet.cell(i + 1, 2).value
        label = sheet.cell(i + 1, 6).value

        # pre process and extract features
        essay = pr.preproc(essay)
        feat = fe.featext(essay)

        # {'lexical_div': lex_div, 'word_cnt': w_cnt, 'long_word_cnt': lng_w_cnt, 'spell_err_cnt': spl,
        #        'distinct_word_cnt': dst_wrd_cnt, 'stem_cnt': stm_cnt}

        feat_mtx[i, 0] = feat['word_cnt']
        feat_mtx[i, 1] = feat['long_word_cnt']
        feat_mtx[i, 2] = feat['spell_err_cnt']
        feat_mtx[i, 3] = feat['lexical_div']
        feat_mtx[i, 4] = feat['distinct_word_cnt']
        feat_mtx[i, 5] = feat['stem_cnt']

        # calculate new label
        xmin = rubric_range[set - 1][0]
        xmax = rubric_range[set - 1][1]
Beispiel #6
0
from procEssay import preproc as pr
from procEssay import featExt as fe

prep_res = pr.preproc('Where do I begin there wasn’t ever. A time when I was patient. '
                      'I was alway rushing people do something and getting mad cause they '
                      'wouldn’t do it fast enough or go fast enough for me. I would just get '
                      'attitude. That why I cant be patient and now you know why. The end. The '
                      'teaching on the way people coming i.e ???.')
features = fe.featext(prep_res)
print(features)
Beispiel #7
0
from procEssay import preproc as pr
from procEssay import featExt as fe

prep_res = pr.preproc(
    'Where do I begin there wasn’t ever. A time when I was patient. '
    'I was alway rushing people do something and getting mad cause they '
    'wouldn’t do it fast enough or go fast enough for me. I would just get '
    'attitude. That why I cant be patient and now you know why. The end. The '
    'teaching on the way people coming i.e ???.')
features = fe.featext(prep_res)
print(features)