示例#1
0
def classify(X):
    global classifier
    model_name = 'TC_GENERAL_V131'
    model_path = ModelFetcher.get_model_path(model_name)

    if not classifier:
        if not os.path.exists(model_path):
            ModelFetcher.download(model_name)
        classifier = TextClassifier.load(model_path)

    sentence = Sentence(X)
    classifier.predict(sentence)
    labels = sentence.labels
    return labels
示例#2
0
def sentiment(X):
    global classifier
    model_name = 'SA_BANK_V131'
    model_path = ModelFetcher.get_model_path(model_name)

    if not classifier:
        if not os.path.exists(model_path):
            ModelFetcher.download(model_name)
        classifier = TextClassifier.load(model_path)

    sentence = Sentence(X)
    classifier.predict(sentence)
    labels = sentence.labels
    if not labels:
        return None
    labels = [label.value for label in labels]
    return labels
示例#3
0
def sentiment(X):
    global classifier
    model_name = 'SA_GENERAL_V131'
    model_path = ModelFetcher.get_model_path(model_name)

    if not classifier:
        if not os.path.exists(model_path):
            ModelFetcher.download(model_name)
        classifier = TextClassifier.load(model_path)

    sentence = Sentence(X)
    classifier.predict(sentence)
    labels = sentence.labels
    try:
        label_map = {'POS': 'positive', 'NEG': 'negative'}
        label = label_map[labels[0]]
        return label
    except Exception:
        return None
示例#4
0
def download_model(model):
    ModelFetcher.download(model)