-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDictionary.java
More file actions
111 lines (67 loc) · 1.82 KB
/
Copy pathDictionary.java
File metadata and controls
111 lines (67 loc) · 1.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
/*
Ori Paso - 209493683
*/
package test;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Scanner;
import java.util.stream.Stream;
public class Dictionary {
String[] filenames;
CacheManager lru;
CacheManager lfu;
BloomFilter bl;
ArrayList<String> saveTheFiles = new ArrayList<>();
public Dictionary(String... args) {
filenames = args;
lru = new CacheManager(400, new LRU());
lfu = new CacheManager(100, new LFU());
bl = new BloomFilter(256, "MD5", "Sh1");
for (String Files : args) {
loadFiles(Files);
saveTheFiles.add(Files);
}
}
public void loadFiles(String filename) {
try {
Stream<String> stringStream = Files.lines(Paths.get(filename));
stringStream.forEach(lines -> {
Stream.of(lines.split("\\W+")).forEach(word -> bl.add(word));
});
stringStream.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public boolean query(String word) {
if (lru.query(word)) {
return true;
}
if (lfu.query(word)) {
return false;
}
if (bl.contains(word)) {
lru.add(word);
return true;
}
else{
lfu.add(word);
return false;
}
}
public boolean challenge(String word) {
for (String s : saveTheFiles) {
if(IOSearcher.search(word, s)) {
lru.add(word);
return true;
}
}
lfu.add(word);
return false;
}
}