Sentiment Analysis con Python
Violeta Misheva
Data Scientist
Lo stemming trasforma le parole nella loro radice, anche se lo stem non è una parola valida nella lingua.
staying, stays, stayed ----> stay
house, houses, housing ----> hous
La lemmatizzazione è simile allo stemming ma, a differenza di questo, riduce le parole a radici che sono parole valide nella lingua.
stay, stays, staying, stayed ----> stay
house, houses, housing ----> house
Stemming
Lemmatizzazione
from nltk.stem import PorterStemmer
porter = PorterStemmer()
porter.stem('wonderful')
'wonder'
Snowball Stemmer: Danish, Dutch, English, Finnish, French, German, Hungarian, Italian, Norwegian, Portuguese, Romanian, Russian, Spanish, Swedish
from nltk.stem.snowball import SnowballStemmer
DutchStemmer = SnowballStemmer("dutch")
DutchStemmer.stem("beginnen")
'begin'
porter.stem('Today is a wonderful day!')
'today is a wonderful day!'
tokens = word_tokenize('Today is a wonderful day!')
stemmed_tokens = [porter.stem(token) for token in tokens]
stemmed_tokens
['today', 'is', 'a', 'wonder', 'day', '!']
from nltk.stem import WordNetLemmatizer
WNlemmatizer = WordNetLemmatizer()
WNlemmatizer.lemmatize('wonderful', pos='a')
'wonderful'
Sentiment Analysis con Python