-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTweet.java
More file actions
132 lines (111 loc) · 3 KB
/
Tweet.java
File metadata and controls
132 lines (111 loc) · 3 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import java.util.ArrayList;
public class Tweet {
long tweetID;
int clusterID;
String tweetString;
ArrayList<String> words = new ArrayList<String>();
double jaccardDistance;
public static ArrayList<String> symbols = new ArrayList<String>();
void setSymbols(){
symbols.add("RT");
symbols.add("-");
symbols.add("|");
symbols.add("\n");
symbols.add(" ");
symbols.add("");
symbols.add("@");
}
Tweet(){
this.tweetID = 0;
this.clusterID = -5;
this.tweetString = "OOPS";
this.jaccardDistance = 0.0;
}
Tweet(long tID, String tString){
this.tweetID = tID;
this.tweetString = tString;
this.clusterID = -4;
this.jaccardDistance = 0.0;
}
void setClusterID(int clustID){
this.clusterID = clustID;
}
void setJaccardDist(double dist){
this.jaccardDistance = dist;
}
void setTweetID(long tweetID){
this.tweetID = tweetID;
}
void setTweetString(String tweet){
tweet = tweet.replaceAll("@\\p{L}+", "");
this.tweetString = tweet.replaceAll("[!.+,:()\"\']", "");
setTweetWords(this.tweetString);
}
void setTweetWords(String tweet){
String[] lines = tweet.split("\n");
for(String line : lines){
String[] arr = line.split(" ");
for( String word : arr){
// word = removeSymbols(word);
this.words.add(word);
}
}
removeRTWords(words);
}
void removeRTWords(ArrayList<String> words){
setSymbols();
words.removeAll(symbols);
}
void setTweet(long tweetID, String tweet){
setTweetID(tweetID);
setTweetString(tweet);
}
void printTweet(){
System.out.println("------------------------------------------------------------------------");
System.out.println("User/Tweet ID :"+this.tweetID);
System.out.println("Cluster ID :"+this.clusterID);
System.out.println("Tweet String :"+this.tweetString);
System.out.println("Jaccardian Dist:"+this.jaccardDistance);
printTweetWords();
printTweetWordsSize();
}
//delete this after testing
void printTweetWordsSize(){
System.out.println(this.words.size());
}
//delete this after testing
void printTweetWords(){
System.out.println(this.words);
}
double getCommonWordCount(Tweet t1){
ArrayList<String> tweetStringOne = t1.words;
ArrayList<String> realCopyOfTweetStringTwo = this.words;
ArrayList<String> tweetStringTwo = (ArrayList<String>) realCopyOfTweetStringTwo.clone();
int commonWordCount = 0;
for(int i = 0; i < tweetStringOne.size() ; i++){
for(int j = 0; j < tweetStringTwo.size() ; j++){
if(tweetStringOne.get(i).equals(tweetStringTwo.get(j))){
tweetStringTwo.remove(j);
commonWordCount++;
break;
}
}
}
return commonWordCount;
}
double getTotalWordCount(Tweet t1){
return (t1.words.size() + this.words.size());
}
double getJaccardianDistance(Tweet centeroidTweet){
return( 1 -( this.getCommonWordCount(centeroidTweet) / this.getTotalWordCount(centeroidTweet)));
}
long getTweetID(){
return this.tweetID;
}
ArrayList<String> getWords(){
return this.words;
}
int getClusterID(){
return this.clusterID;
}
}