Ejemplo n.º 1
0
def predict_2():
    '''
    For rendering results on HTML GUI
    '''
    if request.method == 'POST':
        input_text = request.form['about']
        print(input_text)
        text = lower(input_text)
        text = cleanHtml(text)
        text = cleanPunc(text)
        text = keepAlpha(text)
        tfidf = model.best_estimator_.named_steps['tfidf']
        final_features = tfidf.transform([text])
        clf = model.best_estimator_.named_steps['clf']
        prediction = clf.predict(final_features)

    output = prediction

    # target = {output[:,0]:'Goal 1', output[:,1]:'Goal 2', output[:,2]:'Goal 3', output[:,3]:'Goal 4',
    #           output[:,4]:'Goal 5', output[:,5]:'Goal 6', output[:,6]:'Goal 7', output[:,7]:'Goal 8',
    #           output[:,8]:'Goal 9', output[:,9]:'Goal 10', output[:,10]:'Goal 11', output[:,11]:'Goal 12',
    #           output[:,12]:'Goal 13', output[:,13]:'Goal 14', output[:,14]:'Goal 15', output[:,15]:'Goal 16',
    #           output[:,16]:'Goal 17'}

    #print(text)
    o = ''
    for i in range(1, 18):
        if output[0][i - 1] == 1:
            x = 'Goal' + str(i) + '; '
            o = o + " " + x
    return render_template('prediction_page_2.html',
                           prediction_text='sdgs can be {}{}'.format(
                               output, o))
Ejemplo n.º 2
0
def predict_api():
    '''
    For direct API calls trought request
    '''
    data = request.get_json(force=True)
    text = lower(data)
    text = cleanHtml(text)
    text = cleanPunc(text)
    text = keepAlpha(text)
    tfidf = model.best_estimator_.named_steps['tfidf']
    final_features = tfidf.transform([text])
    clf = model.best_estimator_.named_steps['clf']
    prediction = clf.predict(final_features)

    output = prediction
    return jsonify(output)
Ejemplo n.º 3
0
def predict():
    '''
    For rendering results on HTML GUI
    '''
    if request.method == 'POST':
        input_text = request.form['about']
        print(input_text)
        text = lower(input_text)
        text = cleanHtml(text)
        text = cleanPunc(text)
        text = keepAlpha(text)
        tfidf = model.best_estimator_.named_steps['tfidf']
        final_features = tfidf.transform([text])
        clf = model.best_estimator_.named_steps['clf']
        prediction = clf.predict(final_features)

    output = prediction

    # target = {output[:,0]:'Goal 1', output[:,1]:'Goal 2', output[:,2]:'Goal 3', output[:,3]:'Goal 4',
    #           output[:,4]:'Goal 5', output[:,5]:'Goal 6', output[:,6]:'Goal 7', output[:,7]:'Goal 8',
    #           output[:,8]:'Goal 9', output[:,9]:'Goal 10', output[:,10]:'Goal 11', output[:,11]:'Goal 12',
    #           output[:,12]:'Goal 13', output[:,13]:'Goal 14', output[:,14]:'Goal 15', output[:,15]:'Goal 16',
    #           output[:,16]:'Goal 17'}

    #print(text)
    o = ''
    sdg_list = [
        "No poverty", "Zero hunger", "Good health and well being",
        "Quality education", "Gender equality", "Clean water and sanitation",
        "Affordable and clean energy", "Decent work and economic growth",
        "Industry, innovation and infrastructure", "Reduced inequalities",
        "Sustainable cities and communities",
        "Responsible consumption and production", "Climate action",
        "Life below water", "Life on land",
        "Peace, justice and strong intuitions", "Partnerships for the goals"
    ]
    for i in range(1, 18):
        if output[0][i - 1] == 1:
            x = 'Goal ' + str(i) + ": " + sdg_list[i - 1] + '; '
            o = o + x + " "
    return render_template('prediction_page.html',
                           prediction_text=' \n {}\n'.format(o))
Ejemplo n.º 4
0
def query(id, lang, terms, txn = None):
    import preprocess as p
    terms = map(lambda x: p.lower(lang, x), terms)
    return ctx.invidx[id][lang].query(terms, txn)
Ejemplo n.º 5
0
def query_terms(id, lang, terms, repo = None, txn = None):
    terms = map(lambda x: p.lower(lang, x), terms)
    return ctx.invidx[id][lang].query(terms, repo = repo, txn = txn)
Ejemplo n.º 6
0
def query_terms(id, lang, terms, repo=None, txn=None):
    terms = map(lambda x: p.lower(lang, x), terms)
    return ctx.invidx[id][lang].query(terms, repo=repo, txn=txn)