I have written code to do Sentiment Analysis, therefore I use two different dictionaries in which sentences are tagges as negative oder positive. My code snippet so far Looks like this:
def format_sentence(sentence):
return {word: True for word in word_tokenize(satz) }
pos_data = []
with open('Positiv.txt') as f:
for line in f:
pos_data.append([format_sentence(line), 'pos'])
neg_data = []
with open('Negativ.txt') as f:
for line in f:
neg_data.append([format_sentence(line), 'neg'])
training_data = pos_data[:3] + neg_data[:3]
test_data = pos_data[3:] + neg_data[3:]
model = NaiveBayesClassifier.train(training_data)
Now I would like the code to elimate all Stopwords from the sentences in the dictionary but I don't know how to implement that into my code as I am a beginner in Python programming. I would be very thankful if anyone could help me with this :)