def __call__(self):
        self.tokenize_normalize()
        return self.create_embedding()


def convert_to_neg_pos(score):
    """
    Apply linear conversion to change into -1 to 1 range.
    :param score: float
    :return: float
    """
    new_value = ((score - 0) / (1 - 0)) * (1 + 1) + -1
    return round(new_value, 3)


SentimentScorer_span = sentiment_analysis.SentimentAnalysisSpanish()
SentimentScorer_eng = SentimentIntensityAnalyzer()


def sentiment_score(word_list, lang):
    """
    Helper function to calculate sentiment associated with word_list
    :param word_list: list of words to score
    :param lang: string with en or es
    :return sentiment: float with sentiment score for words
    """
    SentimentScorer_eng = SentimentIntensityAnalyzer()

    if lang == 'es':
        sentiment_total = [SentimentScorer_span.sentiment(word) for word in word_list]
        sentiment = convert_to_neg_pos(np.mean(sentiment_total))
Exemplo n.º 2
0
#libraries
import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
from sentiment_analysis_spanish import sentiment_analysis
import pandas as pd
import numpy as np

from math import sin
from time import time

#source code
initial_time = time()

sentiment = sentiment_analysis.SentimentAnalysisSpanish()
data_cleaning = []
analyzed_data = []

print('Reading data...')
df = pd.read_csv("data/data-test.csv")

file = open("data/list_art_pron.txt", "r", encoding="utf-8")
text = file.read()
art_pron = text.split(",")

print('Removing articles and pronouns...')
for row in df.message:
    for art in art_pron:
        row = row.replace(' ' + art + ' ', ' ')
    data_cleaning.append(row)

print('Sentiment analysis...')
Exemplo n.º 3
0
import sys
import src.config.urls as urls
import pandas as pd
import numpy as np
from sentiment_analysis_spanish import sentiment_analysis as s_a

# Initialize variables
sentiment = s_a.SentimentAnalysisSpanish()


def read_files():
    try:
        df = pd.read_csv(urls.url_csv)
        file = open(urls.url_stopword, "r", encoding="utf-8")
        text = file.read()
        art_pron = text.split(",")

        return [df, file, text, art_pron]
    except:
        print("An exception ocurred in method read_files", sys.exc_info()[0])


def remove_stopwords(df, art_pron):
    try:
        data_cleansing = []

        for row in df.message:
            for art in art_pron:
                row = row.replace(' ' + art + ' ', ' ')
            data_cleansing.append(row)
Exemplo n.º 4
0
 def __init__(self):
     self._model = sentiment_analysis.SentimentAnalysisSpanish()
Exemplo n.º 5
0
def analyze(text):
    sentiment = sentiment_analysis.SentimentAnalysisSpanish()
    result = sentiment.sentiment(text)
    return result