-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSearch.java
More file actions
64 lines (53 loc) · 1.89 KB
/
Copy pathSearch.java
File metadata and controls
64 lines (53 loc) · 1.89 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
package prog11;
import prog02.GUI;
import java.util.*;
import javax.xml.stream.events.StartDocument;
public class Search {
public static void main(String[] args) {
String pageDiskName = "pagedisk-1-ranked.txt";
String wordDiskName = "worddisk-1.txt";
Browser browser = new BetterBrowser();
SearchEngine notGPT = new NotGPT();
NotGPT g = (NotGPT) notGPT;
g.pageDisk.read(pageDiskName);
for (Map.Entry<Long,InfoFile> entry : g.pageDisk.entrySet())
g.indexOfURL.put(entry.getValue().data, entry.getKey().toString());
g.wordDisk.read(wordDiskName);
for (Map.Entry<Long,InfoFile> entry : g.wordDisk.entrySet())
g.indexOfWord.put(entry.getValue().data, entry.getKey());
System.out.println("map from URL to page index");
System.out.println(g.indexOfURL);
System.out.println("map from page index to page disk");
System.out.println(g.pageDisk);
System.out.println("map from word to word index");
System.out.println(g.indexOfWord);
System.out.println("map from word index to word file");
System.out.println(g.wordDisk);
List<String> keyWords = new ArrayList<String>();
if (false) { // CHANGE THIS LINE
keyWords.add("mary");
keyWords.add("jack");
keyWords.add("jill");
} else {
GUI gui = new GUI("NotGPT");
while (true) {
String input = gui.getInfo("Enter search words.");
if (input == null)
return;
String[] words = input.split("\\s", 0);
keyWords.clear();
for (String word : words)
keyWords.add(word);
String[] urls = notGPT.search(keyWords, 5);
String res = "Found " + keyWords + " on";
for (int i = 0; i < urls.length; i++)
res = res + "\n" + BetterBrowser.inverseReversePathURL(urls[i]);
gui.sendMessage(res);
}
}
String[] urls = notGPT.search(keyWords, 5);
System.out.println("Found " + keyWords + " on");
for (int i = 0; i < urls.length; i++)
System.out.println(BetterBrowser.inverseReversePathURL(urls[i]));
}
}