-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWord_count.java
More file actions
106 lines (85 loc) · 2.82 KB
/
Word_count.java
File metadata and controls
106 lines (85 loc) · 2.82 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
import streamql.QL;
import streamql.algo.*;
import streamql.query.*;
import java.util.*;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
public class Word_count {
static class Word_data{
private String word;
private int ts;
private Word_data(String word, int t){
this.word = word;
this.ts = t;
}
@Override
public String toString() {
return "{"+word+","+ts+"}";
}
}
static class SigGen {
ArrayList<Word_data> source;
Iterator<Word_data> stream;
public SigGen(){
source = new ArrayList<Word_data>();
String line = "";
try
{
BufferedReader br = new BufferedReader(new FileReader("./data/1_million_word_UNIX.csv"));
br.readLine();
while ((line = br.readLine()) != null)
{
String[] row = line.split(","); // use comma as separator
source.add(new Word_data(row[1],Integer.parseInt(row[0])));
}
br.close();
}
catch (IOException e)
{
e.printStackTrace();
}
stream = source.iterator();
}
public Word_data getWord(){
if (this.stream.hasNext()){
return stream.next();
}
else{
return null;
}
}
}
public static void main(String[] args) {
SigGen src = new SigGen();
// create the sink for detected peaks
Sink<Word_data> sink = new Sink<Word_data> (){
@Override
public void next(Word_data item) {
//System.out.println("peak detected");
//System.out.println("Word: " + item.word + ", " + "Count: " + item.ts);
//System.out.println("hello");
}
@Override
public void end() {
System.out.println("Job Done");
}
};
Q<Word_data, Word_data> count_word = QL.groupBy(x->x.word, QL.reduce(0,(x,y)->x+1), (word,count)->new Word_data(word,count));
//Q<Word_data, Word_data> windowed_count = QL.sWindow(10,1,count_word);
// execution
Algo<Word_data, Word_data> algo = count_word.eval();
algo.connect(sink);
algo.init();
Long startTime = System.nanoTime();
Word_data curr = src.getWord();
while (curr != null) {
//System.out.println(vt.toString());
algo.next(curr);
curr = src.getWord();
} ;
algo.end();
Long endTime = System.nanoTime();
System.out.println(endTime-startTime);
}
}