<reponame>robertchenbao/twitter-analytic-program<gh_stars>0
# This is the backend code for the entire United states.
# The goal is building a pipeline with all the functions in the project.

from bot_process import bot_app
from preprocess_tweet import data_clean
from location import location
import os
import pandas as pd
import pickle

pd.set_option('display.max_columns', None)


def select_model(file_name):
    DIR = os.path.dirname('/Users/robertbao/Documents/2019_IF/')
    MODEL_DIR = os.path.join(DIR, "models")
    return os.path.join(MODEL_DIR, file_name)


def select_data(file_name):
    DATA_DIR = os.path.dirname('/Users/robertbao/Documents/2019_SF/')
    HA = os.path.join(DATA_DIR, "data")
    return os.path.join(HA, file_name)


def classification(df, clf):
    if clf == 'sgd':
        model_choice = select_model('tf_idf_SGD.pickle')
    elif clf == 'mnb':
        model_choice = select_model('tf_idf_MNB.pickle')
    elif clf == 'bnb':
        model_choice = select_model('tf_idf_BNB.pickle')
    else:
        model_choice = select_model('tf_idf_Logistic.pickle')

    with open(select_model('tf_idf.pickle'), 'rb') as file:
        vec = pickle.load(file)
    with open(model_choice, 'rb') as file:
        clif = pickle.load(file)
    X_new = vec.transform(df['text'])
    df['sentiment'] = clif.predict(X_new)
    return df


# Create a pipeline that applies the functions
def pipeline(data, clf):
    return (data
            .pipe(bot_app)
            .pipe(data_clean)
            .pipe(classification, clf=clf)
            .pipe(location)
            )

# This is the backend code for the entire United states.
# The goal is building a pipeline with all the functions in the project.

from bot_process import bot_app
from preprocess_tweet import data_clean
from location import location
import os
import pandas as pd
import pickle

pd.set_option('display.max_columns', None)


def select_model(file_name):
    DIR = os.path.dirname('/Users/robertbao/Documents/2019_IF/')
    MODEL_DIR = os.path.join(DIR, "models")
    return os.path.join(MODEL_DIR, file_name)


def select_data(file_name):
    DATA_DIR = os.path.dirname('/Users/robertbao/Documents/2019_SF/')
    HA = os.path.join(DATA_DIR, "data")
    return os.path.join(HA, file_name)


def classification(df, clf):
    if clf == 'sgd':
        model_choice = select_model('tf_idf_SGD.pickle')
    elif clf == 'mnb':
        model_choice = select_model('tf_idf_MNB.pickle')
    elif clf == 'bnb':
        model_choice = select_model('tf_idf_BNB.pickle')
    else:
        model_choice = select_model('tf_idf_Logistic.pickle')

    with open(select_model('tf_idf.pickle'), 'rb') as file:
        vec = pickle.load(file)
    with open(model_choice, 'rb') as file:
        clif = pickle.load(file)
    X_new = vec.transform(df['text'])
    df['sentiment'] = clif.predict(X_new)
    return df


# Create a pipeline that applies the functions
def pipeline(data, clf):
    return (data
            .pipe(bot_app)
            .pipe(data_clean)
            .pipe(classification, clf=clf)
            .pipe(location)
            )
# This is the backend code for the entire United states. # The goal is building a pipeline with all the functions in the project. # Create a pipeline that applies the functions