Exemplo n.º 1
0
 def __init__(self):
     self.splitter = Splitter()
     self.postagger = POSTagger()
     self.dicttagger = DictionaryTagger([
         '/home/msinghal/PycharmProjects/basic_sentiment_analysis/dicts/positive.yml',
         '/home/msinghal/PycharmProjects/basic_sentiment_analysis/dicts/negative.yml',
         '/home/msinghal/PycharmProjects/basic_sentiment_analysis/dicts/morePositive.yml',
         '/home/msinghal/PycharmProjects/basic_sentiment_analysis/dicts/moreNegative.yml',
         '/home/msinghal/PycharmProjects/basic_sentiment_analysis/dicts/invert.yml'
     ])
Exemplo n.º 2
0
def main(keys='keys.ini',
         raw_tweets_file='twitter_data.txt',
         no_tweets=1000,
         tracked_words_file='tracks.csv',
         formatted_tweets_file='formatted_tweets.txt',
         dictionaries=['misoginy_dictionary.yml', 'curses_dictionary.yml']):
    """Perform an analyisis to find sexist and rude words in tweets

    This module employs every other module to perform a full analysis on data
    retrieved from the Twitter stream. First a TwitterMiner retrieves data and
    dumps it, then a TweetFormatter parses the data into a list of tweets that
    are lists of words. Then it uses the spaghetti tagger to POStag every word,
    yielding a list of tweets that are lists with elements with the form (word,
    [tags]). A DictionaryTagger adds our custom tags to the [tags] list. Finally
    a TagCounter perform a count of every tag found in tweets. This program 
    prints the number of coincidences of our custom tags.
    """

    miner = TwitterMiner(keys, raw_tweets_file, no_tweets)
    miner.mine(tracked_words_file)

    formatter = TweetFormatter(raw_tweets_file)
    tweets = formatter.convert2json()
    tweets = formatter.convert2text(tweets, formatted_tweets_file)
    tweets = formatter.clean_tweets(tweets)
    tweets = [tweet.split() for tweet in tweets]

    tagger = DictionaryTagger(dictionaries)
    postagged_sents = spgt.pos_tag_sents(tweets)
    tagged_sents = tagger.tag(postagged_sents)

    counter = TagCounter(tagged_sents)
    res = counter.count()

    try:
        print("Palabras misóginas: {}".format(res['misóginia']))
    except KeyError:
        pass

    try:
        print("Palabras groseras: {}".format(res['grosería']))
    except KeyError:
        pass