-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.py
42 lines (31 loc) · 1.09 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# -*- coding: utf-8 -*-
import sys
sys.path.append('./semantictweets')
sys.path.append('./lib')
from semtweets import *
from kmeans import *
# load the tweets from the corpus
print "Loading tweets from file..."
sem_tweets = SemanticTweets()
# run the model, this should take no more than 15 min
# (tested on a 2 year old Mac)
print "Computing model... \nThis can take a while (10-15min), please sit back..."
clusters = sem_tweets.run_model()
# prepare clusters to save them in a file
c = 0
bar = '******************************************************************************************************************************************************\n'
output = bar
for cluster in clusters:
output += "* Cluster: %d. Total tweets: %d\n" % (c, len(cluster.documents))
for document in cluster.documents:
output += "* tweet: %s\n" % sem_tweets.tweets[document.index]
output += bar
c += 1
# save results in a file
import os
file_path = './clusters.txt'
if os.path.exists(file_path):
os.remove(file_path)
file = open(file_path, 'w')
file.write(output.encode('utf-8'))
file.close()