I'm having an issue checking to see if a stemmed word exists in a dictionary. This is for some sentiment analysis work that I am doing. All I am getting back is this error here:
Traceback (most recent call last):
File "sentiment.py", line 369, in <module>
score += int(senti_word_dict.get(get_stem(word)))
TypeError: int() argument must be a string or a number, not 'NoneType'
Here is my code for the method to look for a stemmed word through NLTK:
def get_stem(word):
st = SnowballStemmer("english")
stemmed_word = st.stem(word)
return '' if stemmed_word is None else stemmed_word
Here is the code for checking for that word against the dictionary:
for comment in all_comments:
score = 0
tokens = tokenize(comment)
for word in tokens:
if word in senti_word_dict:
score += int(senti_word_dict.get(get_stem(word)))
print(str(score)+" "+comment)
print('\n')
For now I am just getting the score. Is there a way that I can pass that stemmed word as a string to see what the score is in the dictionary? If there is anything I am doing wrong or could do better let me know! Thanks!