Beispiel #1
0
import os
import sys
sys.path.append(os.path.realpath('../../'))

import twittercriteria as twc

sentiments = ['angry', 'fearful', 'calm', 'excited', 'sad', 'positive', 'negative', 'neutral']

for s in sentiments:
  tweets = []
  with open(s + 'Training.txt') as infile:
    for line in infile:
      line.rstrip('\n')
      tweets.append(twc.cleanForSentiment(line))
  with open(s + 'Not.txt', 'w') as out:
    out.write('\n'.join(tweets))
positive = []
calm = []
negative = []
neutral = []

relevant = []
irrelevant = []

sents = ['c', 'e', 'a', 'f', 's', 'p', 'n', 'u', 'o']
rels = ['r', 'i', 'n']

with open(name + "_" + str(num) + ".txt", "r") as inFile:
  for tweet in inFile:
    tweet = tweet.rstrip('\n')
    print tweet
    tweet = twc.cleanForSentiment(tweet)
    sentiment = ''
    while (not sentiment in sents):
        sentiment = raw_input("Enter the tweets sentiment: (c-alm, e-xcited, a-angry, f-earful, s-ad, p-ositive, n-egative, u-neutral, or o-ther (not English)): ")
        if sentiment != "":
          sentiment = sentiment.lower()[0]
        else:
          sentiment = ''

    if sentiment == 'c':
      calm.append(tweet)
    elif sentiment == 'a':
      angry.append(tweet)
    elif sentiment == 'f':
      fearful.append(tweet)
    elif sentiment == 's':
 def classify(self, tweet_text):
     return self.classifier.classify(self.extractFeatures(twc.cleanForSentiment(tweet_text).split()))