Example #1
0
                        word_counter += 1
                if word_counter >= 1:
                    outputfile.write(line + newline)
            written = True
    except FileExistsError:
        file_counter += 1

print("Ranking tweets...")

# Create the Tweet Ranker:
ranked_tweets_list = []
tweet_ranker = TweetRank(None)
for ut in ut_cooccurrences.keys():
    ranked_tweets = tweet_ranker.TweetRank({ut})
    for (tweetid, score) in ranked_tweets:
        tweet = tweet_indexer.GetTweetForTweetid(tweetid)
        ranked_tweets_list.append(str(ut) + tab + str(tweet))
    print("Ranked ut: ", ut)

print("Writing ranking file...")

written = False
file_counter = 0
while not written:
    try:
        # The 'w' means open for exclusive creation, failing if the file already exists.
        with open(ranking_output_filename + str(file_counter) + output_extension, 'x') as outputfile:
            for tweet in ranked_tweets_list:
                outputfile.write(str(tweet) + newline)
            written = True
    except FileExistsError: