-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTweetsParser.java
More file actions
65 lines (61 loc) · 1.99 KB
/
Copy pathTweetsParser.java
File metadata and controls
65 lines (61 loc) · 1.99 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
package twitter;
import java.util.regex.Pattern;
import java.util.regex.Matcher;
import java.util.Date;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
public class TweetsParser {
private Double coordX;
private Double coordY;
private Date date;
private String text;
public void TweetsReader(String s) {
StringBuffer str = new StringBuffer();
Pattern regExpression;
String regex;
Matcher regMatcher;
regex = "\\d{2}\\.\\d+,";
regExpression = Pattern.compile(regex);
regMatcher = regExpression.matcher(s);
while (regMatcher.find()) {
str.append(s.substring(regMatcher.start(), regMatcher.end() - 1));
coordX = Double.parseDouble(str.toString());
}
str.delete(0, str.length());
regex = "\\-\\d{2,3}\\.\\d+";
regExpression = Pattern.compile(regex);
regMatcher = regExpression.matcher(s);
while (regMatcher.find()) {
str.append(s.substring(regMatcher.start(), regMatcher.end()));
coordY = Double.parseDouble(str.toString());
}
str.delete(0, str.length());
regex = "(\\d{4}(\\-\\d{2}){2}) (\\d{2}(:\\d{2}){2})";
regExpression = Pattern.compile(regex);
regMatcher = regExpression.matcher(s);
while (regMatcher.find()) {
str.append(s.substring(regMatcher.start(), regMatcher.end()));
}
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
try {
date = dateFormat.parse(str.toString());
} catch (ParseException e) {
e.getMessage();
}
str.delete(0, str.length());
regex = "[a-zA-Z#@].*";
regExpression = Pattern.compile(regex);
regMatcher = regExpression.matcher(s);
while (regMatcher.find()) {
str.append(s.substring(regMatcher.start(), regMatcher.end()));
}
text = str.toString();
str.delete(0, str.length());
}
public void ShowTweet() {
System.out.println("(" + coordX.toString() + ", " + coordY.toString() + ")");
System.out.println("Date: " + date.toString());
System.out.println("Text: " + text);
}
}