-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDatabaseViewer.java
194 lines (157 loc) · 4.87 KB
/
DatabaseViewer.java
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
package PROJECT;
import java.util.*;
import IRUtilities.*;
import java.io.*;
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.HashSet;
import java.util.Vector;
import java.util.HashMap;
import java.lang.Math;
import jdbm.htree.HTree;
import java.io.Serializable;
import jdbm.RecordManager;
import jdbm.RecordManagerFactory;
import jdbm.helper.FastIterator;
import jdbm.helper.Tuple;
import jdbm.helper.TupleBrowser;
public class DatabaseViewer {
private static Porter porter;
private static HashSet<String> stopWords;
private static Vector<String> searchTerms;
private static HTree urlToId;
private static HTree idToUrl;
private static HTree wordToId;
private static HTree idToWord;
private static HTree titleForwardIndex;
private static HTree docForwardIndex;
private static HTree titleInvertedIndex;
private static HTree docInvertedIndex;
private static RecordManager recman;
private static HTree bigram;
private static HTree trigram;
private static HTree unigram;
private static HTree metadata;
private static HTree parentLinkIndex;
private static long recid;
public DatabaseViewer() throws IOException {
try {
// Create stemmer and stop words
porter = new Porter();
stopWords = new HashSet<String>();
FileReader fs = new FileReader("stopwords.txt");
BufferedReader bs = new BufferedReader(fs);
String word = bs.readLine();
while(word != null){
stopWords.add(word);
word = bs.readLine();
}
// Load invertedIndexDoc
recman = RecordManagerFactory.createRecordManager("Database");
recid = recman.getNamedObject("invertedindex");
if(recid == 0) {
throw new IOException ("docInvertedIndex does not exist");
} else {
docInvertedIndex = HTree.load(recman, recid);
}
// Load forwardIndexDoc
long recid = recman.getNamedObject("forwardindex");
if(recid == 0) {
throw new IOException ("docForwardIndex does not exist");
} else {
docForwardIndex = HTree.load(recman, recid);
}
// Load invertedIndexTitle
recid = recman.getNamedObject("titleInvertedindex");
if(recid == 0) {
throw new IOException ("titleInvertedIndex does not exist");
} else {
titleInvertedIndex = HTree.load(recman, recid);
}
// Load forwardIndexTitle
recid = recman.getNamedObject("titleForwardindex");
if(recid == 0) {
throw new IOException ("titleForwardIndex does not exist");
} else {
titleForwardIndex = HTree.load(recman, recid);
}
// Load docMappings
recid = recman.getNamedObject("urlToId");
if(recid == 0) {
throw new IOException ("urlToId does not exist");
} else {
urlToId = HTree.load(recman, recid);
}
recid = recman.getNamedObject("idToUrl");
if(recid == 0) {
throw new IOException ("idToUrl does not exist");
} else {
idToUrl = HTree.load(recman, recid);
}
//
// Load wordMappings
recid = recman.getNamedObject("wordToId");
if(recid == 0) {
throw new IOException ("wordToId does not exist");
} else {
wordToId = HTree.load(recman, recid);
}
recid = recman.getNamedObject("idToWord");
if(recid == 0) {
throw new IOException ("idToWord does not exist");
} else {
idToWord = HTree.load(recman, recid);
}
recid = recman.getNamedObject("bigram");
if(recid == 0) {
throw new IOException ("bigram does not exist");
} else {
bigram = HTree.load(recman, recid);
}
recid = recman.getNamedObject("trigram");
if(recid == 0) {
throw new IOException ("trigram does not exist");
} else {
trigram = HTree.load(recman, recid);
}
recid = recman.getNamedObject("unigram");
if(recid == 0) {
throw new IOException ("unigram does not exist");
} else {
unigram = HTree.load(recman, recid);
}
recid = recman.getNamedObject("metadata");
if(recid == 0) {
throw new IOException ("metadata does not exist");
} else {
metadata = HTree.load(recman, recid);
}
recid = recman.getNamedObject("parentLinks");
if(recid == 0) {
throw new IOException ("parentLinks does not exist");
} else {
parentLinkIndex = HTree.load(recman, recid);
}
} catch (IOException e) {
System.out.println(e);
System.out.println("Error: A JDBM Database required for search funciton is missing");
}
}
public static void view(HTree tree) throws IOException {
System.out.println("Viewing entries");
FastIterator iter = tree.keys();
Object key;
while ((key = iter.next())!=null) {
Object value = tree.get(key);
System.out.println("Key: " + key + ", Value: " + value);
}
}
public static void main(String[] args) throws IOException {
DatabaseViewer dbv = new DatabaseViewer();
dbv.view(parentLinkIndex);
}
}