def tweet_to_vector_posnegneutral(self, tweet_token, posbow, negbow): """ Convert tweet to vector [posvalue, negvalue, neutralvalue]""" tweetstring = ' '.join(tweet_token) # for comparison value tuples in string posvalue = 0 negvalue = 0 neutralvalue = 0 # Get all single words from bag of words poswords = helpers.unfold_tuples(posbow) negwords = helpers.unfold_tuples(negbow) totalwords = list(set(poswords + negwords)) for x in posbow: if (' '.join(x) in tweetstring): posvalue += posbow[x] for x in negbow: if (' '.join(x) in tweetstring): negvalue += negbow[x] for word in tweet_token: if ( word not in totalwords ): # neutral words neutralvalue += 1 vec = [float(posvalue), float(negvalue), float(neutralvalue)] return vec
def tweet_to_specialvector(self, tweet_token, posbow, negbow): """ Convert tweet to posnegneutral vector""" tweetstring = ' '.join(tweet_token) # for comparison value tuples in string posvalue = 0 negvalue = 0 neutralvalue = 0 poswords = helpers.unfold_tuples(posbow) negwords = helpers.unfold_tuples(negbow) totalwords = list(set(poswords + negwords)) for x in posbow: if (' '.join(x) in tweetstring): posvalue += posbow[x] for x in negbow: if (' '.join(x) in tweetstring): negvalue += negbow[x] for word in tweet_token: if ( word not in totalwords ): neutralvalue += 1 # TODO: differences?? #vec = [float(posvalue/len(totalwords)), float(negvalue/len(totalwords)), float(neutralvalue/float(len(totalwords)))] vec = [float(posvalue), float(negvalue), float(neutralvalue)] return vec