Showing results for 
Search instead for 
Did you mean: 

Alteryx designer Discussions

Find answers, ask questions, and share expertise about Alteryx Designer.

The highly anticipated Alteryx Community tradition is back! We hope you'll join us!

Learn More

NLP Sentiment tool in other languages


Hi everyone


I was following the Comparing Sentiment Analysis Algorithms article, but when trying to use the StandfordCoreNLP Sentiment tool I was getting the error "The external program "java" returned an error code: 2", just like in this post, being unable to run Java using the RunCommand.


The solution, posted here, worked fine, being able to solve the problem by wraping the java command in a cmd shell. 


However, I am unable to get the CoreNLP running in other languages,as explained here. Any idea on how to modify the macro to achieve this? I have been toying with the configuration of some Formula tools but I am back to Java errors.



Javi Calvo 





Hi @jcalvo92 


It looks like quite a bit of work needs to be done to get that tool to run with other languages based on the dependencies listed. One alternative would be to run your text through a translation API as part of your workflow to then be run through an English sentiment analysis process. That way you could run the tool as is.


Hi @BrandonB


That’s actually a solid alternative, but it moves the problem to how to translate texts in Alteryx. I am only able to find solutions that use the Cognitive Services Text Translation macro. This uses the same Microsoft paid services than the Cognitive Services Text Analytics macro, which already provides sentiment analysis in multiple languages at the same price.


So instead of paying for a translation, you can pay directly for a sentiment analysis in your language of choice.


The "Comparing Sentiment Analysis Algorithms" article that I mentioned explored different open source solutions, but all of them are in English only, or difficult to adapt to Alteryx.


Do you know an open source solution to translate texts in Alteryx? That would solve the problem.


Thank you for your feedback


I haven't used it yet myself, but there are quite a few free Python libraries that offer free text translation like the following:




Thanks, will have a look at it


Just to update this topic...


I tried translating to English and then use the Stanford core. Also tried other packages such as TextBlob & Vader. At the end, I got the best results with a package called 'Spanish Sentiment Analysis', with everything in Spanish from scratch


Attached is a macro that gets a text field and returns the score 0..1


The second best option was translating the texts and moving to TextBlob. Here is some code for your python tool to use both TB and SpanishSA:


from ayx import Package
from ayx import Alteryx

# TextBlob

from textblob import TextBlob
from textblob.sentiments import NaiveBayesAnalyzer

def traducir(text):
        return TextBlob(text).translate(from_lang = 'es', to='en')
        return None
def calcular_sentimientos(textBlob):
        return textBlob.sentiment
        return None

def calcular_polaridad(textBlob):
        return textBlob.sentiment.polarity
        return None
def calcular_subjetividad(textBlob):
        return textBlob.sentiment.subjectivity
        return None

# Spanish Sentiment Analysis
# Necesita permisos y conex abierta.
# Necesita Microsoft Visual C++ Build Tools 

from classifier import *
clf = SentimentClassifier()

def score_spa(text):
        return clf.predict(text)
        return None

# Procesar todas las líneas
texto ="#1")
texto2 = texto
texto2['salida'] = texto['entrada'].apply(traducir)
texto2['tb_polaridad'] = texto2['salida'].apply(calcular_polaridad)
texto2['tb_subjetividad'] = texto2['salida'].apply(calcular_subjetividad)
# Es necesario cambiar el tipo de la salida
texto2['salida'] = texto['salida'].apply(str)
texto2['spa_score'] = texto['entrada'].apply(score_spa)

# Salida
import pandas as pd
# Necesario para modificar el tipo de datos
b = pd.DataFrame(texto2)


The solution is not optimal, you need to tune it to your needs, by finding specific expressions or words in your use-case and adapting the wf