Exemplo n.º 1
0
def test_lbsa():
    reviews = [
        'You should get this game, because in this game you can destroy other cars with really AWESOME guns like a acid thrower',
        'A great dev, but a mediocre app. You just tap the screen . In a word : BORING . Don\'t get this app.',
        'Even at free it was too expensive. Total waste of time and space. Save yourself the trouble of having to remove it by not downloading it in the first place.',
        'Works flawlessly with my favorite stations. I highly recommend this app as it makes finding a stream for your favorite local radio stations a breeze.'
    ]

    afinn_lexicon = lbsa.get_lexicon('opinion',
                                     language='english',
                                     source='afinn')
    mpqa_lexicon = lbsa.get_lexicon('opinion',
                                    language='english',
                                    source='mpqa')

    extractor = lbsa.FeatureExtractor(afinn_lexicon, mpqa_lexicon)
    extractor.process(reviews)
Exemplo n.º 2
0
def sentiment_analysis_func(movie_dataframe):
	#load the lexicon
	sa_lexicon = lbsa.get_lexicon('sa', language='english', source='nrc')
	movie_dataframe["sentiment_vector"]	= (
			movie_dataframe.text
			.str.lower()
			.map(remove_punctuation)
			.map(remove_whitespace)
			.map(lemmatization_and_stopwords)
			.map(" ".join)
			.map(lambda x : sa_lexicon.process(x)) #gets the sentiment vector
			)

	movie_dataframe["max_sentiment"] = movie_dataframe["sentiment_vector"].map(lambda x : max(x, key=x.get) if x[max(x, key=x.get)] >= 1 else "Neutral") #gets the key with max value
	json_data_SA = json.loads(movie_dataframe.to_json(orient = 'table'))
	return(json_data_SA,movie_dataframe) 
# -*- coding: utf-8 -*-
# tweets.py
# author : Antoine Passemiers

import lbsa

tweet = """
The Budget Agreement today is so important for our great Military.
It ends the danger sequester and gives Secretary Mattis what he needs to keep America Great.
Republicans and Democrats must support our troops and support this Bill!
"""

print('\nUse NRC lexicon')
lexicon = lbsa.get_lexicon('opinion', language='english', source='nrc')
print(lexicon.process(tweet))

print('\nUse afinn lexicon')
lexicon = lbsa.get_lexicon('opinion', language='english', source='afinn')
print(lexicon.process(tweet))

print('\nUse mpqa lexicon')
lexicon = lbsa.get_lexicon('opinion', language='english', source='mpqa')
print(lexicon.process(tweet))

tweet2 = """
A la suite de la tempête #Eunice et à la demande du Président de la République,
l’Etat décrétera dans les meilleurs délais l’état de catastrophe naturelle partout
où cela s’avérera nécessaire.
"""
print('\nAuto-detect languages')
lexicon = lbsa.get_lexicon('sa', language='auto', source='nrc')
Exemplo n.º 4
0
# -*- coding: utf-8 -*-
# tweets.py
# author : Antoine Passemiers

import lbsa

reviews = [
    'You should get this game, because in this game you can destroy other cars with really AWESOME guns like a acid thrower',
    'A great dev, but a mediocre app. You just tap the screen . In a word : BORING . Don\'t get this app.',
    'Even at free it was too expensive. Total waste of time and space. Save yourself the trouble of having to remove it by not downloading it in the first place.',
    'Works flawlessly with my favorite stations. I highly recommend this app as it makes finding a stream for your favorite local radio stations a breeze.'
]

afinn_lexicon = lbsa.get_lexicon('opinion', language='english', source='afinn')
nrc_lexicon = lbsa.get_lexicon('opinion', language='english', source='nrc')
nrc_sa_lexicon = lbsa.get_lexicon('sa', language='english', source='nrc')
mpqa_lexicon = lbsa.get_lexicon('opinion', language='english', source='mpqa')

extractor = lbsa.FeatureExtractor(afinn_lexicon, nrc_lexicon, nrc_sa_lexicon,
                                  mpqa_lexicon)

print('Feature names:')
print('{}\n'.format(extractor.feature_names))

print(extractor.process(reviews))