-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCompareWorker.java
More file actions
53 lines (46 loc) · 1.28 KB
/
CompareWorker.java
File metadata and controls
53 lines (46 loc) · 1.28 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
import java.util.ArrayList;
import java.util.HashMap;
public class CompareWorker extends Thread {
WorkPool wp;
ArrayList<CompareResult> result;
public CompareWorker(WorkPool wp) {
this.wp = wp;
result = new ArrayList<CompareResult>();
}
public void processPartialSolution(CompareTask task) {
double sim = 0;
double h1_words_nr = 0, h2_words_nr = 0;
HashMap<String, Integer> h1 = task.getH1();
HashMap<String, Integer> h2 = task.getH2();
for (String key : h1.keySet()) {
h1_words_nr = h1_words_nr + h1.get(key);
}
for (String key : h2.keySet()) {
h2_words_nr = h2_words_nr + h2.get(key);
}
System.out.println(h1_words_nr + " " + h2_words_nr);
for (String key : h1.keySet()) {
if (h2.containsKey(key)) {
sim = sim + ((double)h1.get(key)/h1_words_nr) * ((double)h2.get(key)/h2_words_nr);
}
}
if (sim * 100 > task.getX()) {
result.add(new CompareResult(task.getDoc1(), task.getDoc2(), sim * 100));
}
}
public ArrayList<CompareResult> getResults() {
return result;
}
@Override
public void run() {
//System.out.println("Thread-ul worker " + this.getName() + " a pornit...");
CompareTask task;
while (true) {
task = (CompareTask)wp.getWork();
if (task == null){
break;
}
processPartialSolution(task);
}
}
}