Python Forum
Attach sentiment to each word in a list of tuples
Thread Rating:
  • 3 Vote(s) - 2.33 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Attach sentiment to each word in a list of tuples
#1
Hello.
The input to the below two functions are a list of string sentences delimited by a comma from a csv file. Each list represents negative and positive tweets. When i append the 'negative' and 'positive' string sentiments they are being added to the end of each sentence, however I need to have the sentiment added to the end of each word. The structure I'm aiming for is to have a list of binomial tuples where each tuple consists of a word and the sentiment. Like this [ ('word', 'positive'), ('word2', 'positive'), ('word3, 'positive') ] ...

pos_sentences2 = clean1(pos_sentences)
neg_sentences2 = clean1(neg_sentences)

def append_pos():
temp = []
for row in pos_sentences2:
temp.append((row, 'positive'))
return temp

def append_neg():
temp = []
for row in neg_sentences2:
temp.append((row, 'negative'))
return temp

pos = append_pos()
neg = append_neg()
print(pos)
This is my current output but I would like the sentiment to be attached to each word rather than each sentence.
Output:
[(' omg its already O', 'positive'), (' Juuuuuuuuuuuuuuuuussssst Chillin ', 'positive'), (' handed in my uniform today i miss you already', 'positive'), (' hmmmm i wonder how she my number - ', 'positive')]
Thanks.
Reply


Messages In This Thread
Attach sentiment to each word in a list of tuples - by Casper - Apr-19-2017, 05:49 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Sentiment Analysis Classifier lode 0 1,801 Feb-04-2019, 05:00 AM
Last Post: lode

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020