1 | package org.greenstone.gsdl3.gs3build.indexers;
|
---|
2 |
|
---|
3 | import java.util.List;
|
---|
4 | import java.util.ArrayList;
|
---|
5 | import java.util.Iterator;
|
---|
6 |
|
---|
7 | import java.io.File;
|
---|
8 | import java.io.InputStream;
|
---|
9 | import java.io.OutputStream;
|
---|
10 | import java.io.IOException;
|
---|
11 |
|
---|
12 | import org.w3c.dom.*;
|
---|
13 |
|
---|
14 | import org.greenstone.gsdl3.gs3build.doctypes.DocumentID;
|
---|
15 | import org.greenstone.gsdl3.gs3build.doctypes.DocumentInterface;
|
---|
16 | import org.greenstone.gsdl3.gs3build.doctypes.HTMLDocument;
|
---|
17 | import org.greenstone.gsdl3.gs3build.metadata.*;
|
---|
18 | import org.greenstone.gsdl3.gs3build.xpointer.XPointer;
|
---|
19 |
|
---|
20 | public class MGIndexer extends AbstractIndexer
|
---|
21 | {
|
---|
22 | int pass;
|
---|
23 | int documentSeqNo;
|
---|
24 | int sectionSeqNo;
|
---|
25 | boolean firstDocument;
|
---|
26 | String outputDirectory;
|
---|
27 | InputStream indexerFeedback;
|
---|
28 | InputStream indexerErrors;
|
---|
29 | OutputStream indexerTextfeed;
|
---|
30 | Process mg_passes;
|
---|
31 | File textDirectory;
|
---|
32 | File indexDirectory;
|
---|
33 | String indexStem;
|
---|
34 | String textStem;
|
---|
35 | List indexes;
|
---|
36 | String indexName;
|
---|
37 | String level;
|
---|
38 | String field;
|
---|
39 | String name;
|
---|
40 |
|
---|
41 | static final char END_OF_DOCUMENT = (char) 2;
|
---|
42 | static final char END_OF_SECTION = (char) 3;
|
---|
43 | static final char END_OF_STREAM = (char) 4;
|
---|
44 |
|
---|
45 | public static final String MG_INDEX_TYPE = "mg";
|
---|
46 |
|
---|
47 | class MGIndex
|
---|
48 | { String name;
|
---|
49 | String level;
|
---|
50 | String field;
|
---|
51 |
|
---|
52 | public MGIndex(String name, String level, String field)
|
---|
53 | { this.name = name;
|
---|
54 | this.level = level;
|
---|
55 | this.field = field;
|
---|
56 | }
|
---|
57 |
|
---|
58 | public MGIndex(String indexLabel)
|
---|
59 | { int colonAt = indexLabel.indexOf(':');
|
---|
60 |
|
---|
61 | if (colonAt >= 0)
|
---|
62 | { this.field = indexLabel.substring(colonAt+1);
|
---|
63 | this.level = indexLabel.substring(0, colonAt);
|
---|
64 | }
|
---|
65 | this.name = null;
|
---|
66 | }
|
---|
67 |
|
---|
68 | public String getLevel()
|
---|
69 | { return this.level;
|
---|
70 | }
|
---|
71 |
|
---|
72 | public String getField()
|
---|
73 | { return this.field;
|
---|
74 | }
|
---|
75 |
|
---|
76 | public String getName()
|
---|
77 | { return this.name;
|
---|
78 | }
|
---|
79 | }
|
---|
80 |
|
---|
81 | public MGIndexer(String name)
|
---|
82 | { this.indexes = new ArrayList();
|
---|
83 | this.name = name;
|
---|
84 | }
|
---|
85 |
|
---|
86 | public String getIndexType()
|
---|
87 | { return MG_INDEX_TYPE;
|
---|
88 | }
|
---|
89 |
|
---|
90 | public String getName()
|
---|
91 | { return this.name;
|
---|
92 | }
|
---|
93 |
|
---|
94 | private String getIndexDirectory(String level, String field)
|
---|
95 | { StringBuffer directory = new StringBuffer();
|
---|
96 | directory.append(Character.toLowerCase((char) level.charAt(0)));
|
---|
97 |
|
---|
98 | int c, w;
|
---|
99 | w = 0;
|
---|
100 | c = 0;
|
---|
101 | while (c < field.length() && w < 2) {
|
---|
102 | char ch = field.charAt(c);
|
---|
103 |
|
---|
104 | ch = Character.toLowerCase(ch);
|
---|
105 | if (Character.isLetter(ch)) {
|
---|
106 | if (ch != 'a' && ch != 'e' && ch != 'i' &&
|
---|
107 | ch != 'o' && ch != 'u') {
|
---|
108 | directory.append(ch);
|
---|
109 | w++;
|
---|
110 | }
|
---|
111 | }
|
---|
112 | c ++;
|
---|
113 | }
|
---|
114 | return directory.toString();
|
---|
115 | }
|
---|
116 |
|
---|
117 | /**
|
---|
118 | * The output directory should be (collection)/building/text/ for
|
---|
119 | * normal Greenstone builds.
|
---|
120 | *
|
---|
121 | * @param <code>String</code> the label to configure
|
---|
122 | * @param <code>String</code> the value...
|
---|
123 | */
|
---|
124 | public boolean configure(String label, String value)
|
---|
125 | {
|
---|
126 | if (label.equals(IndexerManager.outputDir)) {
|
---|
127 | this.outputDirectory = value;
|
---|
128 | this.textStem = value + "/text/index";
|
---|
129 | this.pass = 0;
|
---|
130 |
|
---|
131 | // attempt to ensure that the text subdirectory exists
|
---|
132 | this.textDirectory = new File(outputDirectory, "text");
|
---|
133 | if (!textDirectory.exists()) {
|
---|
134 | if (!textDirectory.mkdir()) {
|
---|
135 | return false;
|
---|
136 | }
|
---|
137 | }
|
---|
138 | else if (!textDirectory.isDirectory()) {
|
---|
139 | return false;
|
---|
140 | }
|
---|
141 |
|
---|
142 | // Sign to the user which mg directory is being used...
|
---|
143 | System.out.println("Output MG directory is " + this.textStem);
|
---|
144 | }
|
---|
145 | else if (label.equals(IndexerInterface.GS2_INDEX_LABEL)) {
|
---|
146 | this.indexes.add(new MGIndex(value));
|
---|
147 | }
|
---|
148 |
|
---|
149 | return true;
|
---|
150 | }
|
---|
151 |
|
---|
152 | public boolean addIndex(String name, String level, String field)
|
---|
153 | {
|
---|
154 | MGIndex index = new MGIndex(name, level, field);
|
---|
155 | this.indexes.add(index);
|
---|
156 | return true;
|
---|
157 | }
|
---|
158 |
|
---|
159 | private Node recurseDOM(DocumentInterface metsDoc, Node node,
|
---|
160 | AbstractStructure structure, StringBuffer textBuffer,
|
---|
161 | StringBuffer extraBuffer, String indexName,
|
---|
162 | String namespace, String field)
|
---|
163 | {
|
---|
164 | // send out the ctrl-c...if this is
|
---|
165 | if (structure.getStructureType().equals(METSDivision.DIVISION_TYPE)) {
|
---|
166 | if ((indexName != null) && indexName.startsWith("s")) {
|
---|
167 | METSDivision division = (METSDivision) structure;
|
---|
168 |
|
---|
169 | // get the division metadata block
|
---|
170 | METSDescriptive descriptive;
|
---|
171 | String metadataId = division.getDefaultMetadataReference();
|
---|
172 | if (metadataId == null) {
|
---|
173 | descriptive = metsDoc.getDocumentMetadata().createDescriptive(division.getLabel());
|
---|
174 | division.addMetadataReference(descriptive.getID());
|
---|
175 | }
|
---|
176 | else {
|
---|
177 | // Get the descriptive item...
|
---|
178 | descriptive = metsDoc.getDocumentMetadata().getDescriptiveById(metadataId);
|
---|
179 | }
|
---|
180 |
|
---|
181 | descriptive.addMetadata("gsdl3", "mgseqno", indexName + "." + Integer.toString(this.sectionSeqNo));
|
---|
182 | metsDoc.setModified(true);
|
---|
183 | // System.out.println("Assigning " + this.sectionSeqNo + " to " + metsDoc.getID() + " " + division.getLabel());
|
---|
184 | }
|
---|
185 |
|
---|
186 | // append an 'end of section' marker
|
---|
187 | textBuffer.append(END_OF_SECTION);
|
---|
188 | this.sectionSeqNo ++;
|
---|
189 |
|
---|
190 | // for document-level indexes, always append an 'end of document' tag at the
|
---|
191 | // end of the document for each section. Otherwise, each section is followed
|
---|
192 | // by an end of document character. This ensures that all indexes use the
|
---|
193 | // same document numbering...
|
---|
194 | if (this.level == null ||
|
---|
195 | this.level.equals(IndexerInterface.DOCUMENT_LEVEL)) {
|
---|
196 | extraBuffer.append(END_OF_DOCUMENT);
|
---|
197 | }
|
---|
198 | else {
|
---|
199 | textBuffer.append(END_OF_DOCUMENT);
|
---|
200 | this.documentSeqNo ++;
|
---|
201 | }
|
---|
202 |
|
---|
203 | // produce the body here for metadata output of divisions - in the case of
|
---|
204 | // text output, that will happen below...
|
---|
205 | if (!this.field.equals("text"))
|
---|
206 | { METSDescriptive descriptive;
|
---|
207 |
|
---|
208 | METSDivision division = (METSDivision) structure;
|
---|
209 |
|
---|
210 | String metadataId = division.getDefaultMetadataReference();
|
---|
211 |
|
---|
212 | descriptive = metsDoc.getDocumentMetadata().getDescriptiveById(metadataId);
|
---|
213 | if (descriptive != null) {
|
---|
214 | List values = descriptive.getMetadata(namespace, field);
|
---|
215 |
|
---|
216 | if (values != null) {
|
---|
217 | Iterator valueIter = values.iterator();
|
---|
218 | while (valueIter.hasNext()) {
|
---|
219 | String value = valueIter.next().toString();
|
---|
220 |
|
---|
221 | textBuffer.append(value);
|
---|
222 | if (valueIter.hasNext()) {
|
---|
223 | textBuffer.append(END_OF_SECTION);
|
---|
224 | }
|
---|
225 | }
|
---|
226 | }
|
---|
227 | }
|
---|
228 | }
|
---|
229 | }
|
---|
230 |
|
---|
231 | // go through our children as required...
|
---|
232 | Iterator children = structure.getChildIterator();
|
---|
233 | while (children.hasNext()) {
|
---|
234 | AbstractStructure child = (AbstractStructure) children.next();
|
---|
235 |
|
---|
236 | // get xpointer for child
|
---|
237 | // get start position node
|
---|
238 | Node startNode = ((HTMLDocument) metsDoc).getSectionStartNode((METSDivision) child);
|
---|
239 |
|
---|
240 | // while this node isn't the child's start node, produce the HTML node text, if
|
---|
241 | // in text field mode...
|
---|
242 | if (field.equals("text")) {
|
---|
243 | while (node != startNode) {
|
---|
244 | XPointer.printNode(node, textBuffer, false);
|
---|
245 |
|
---|
246 | // print buffer to node
|
---|
247 | node = XPointer.getNextNode(node, (field.equals("text") ? textBuffer : null));
|
---|
248 | }
|
---|
249 | }
|
---|
250 |
|
---|
251 | // recurse to child
|
---|
252 | node = this.recurseDOM(metsDoc, node, child, textBuffer, extraBuffer, indexName, namespace, field);
|
---|
253 | }
|
---|
254 |
|
---|
255 | // close a document - the actual closing \B will be done by the main
|
---|
256 | // loop, so only a required \C is printed here...
|
---|
257 | if (structure.getStructureType().equals(METSStructure.STRUCTURE_TYPE)) {
|
---|
258 | while (node != null) {
|
---|
259 | if (field.equals("text")) {
|
---|
260 | XPointer.printNode(node, textBuffer, false);
|
---|
261 | }
|
---|
262 | node = XPointer.getNextNode(node, (field.equals("text") ? textBuffer : null));
|
---|
263 | }
|
---|
264 | /*
|
---|
265 | textBuffer.append(END_OF_SECTION);
|
---|
266 | this.sectionSeqNo ++;
|
---|
267 | */
|
---|
268 | }
|
---|
269 | return node;
|
---|
270 | }
|
---|
271 |
|
---|
272 | private String prepareDOM(DocumentInterface metsDoc, Document document, METSStructure structure,
|
---|
273 | String indexName, String namespace, String field)
|
---|
274 | { StringBuffer extraBuffer = new StringBuffer();
|
---|
275 | Node node = document.getDocumentElement();
|
---|
276 | StringBuffer textBuffer = new StringBuffer();
|
---|
277 |
|
---|
278 | this.recurseDOM(metsDoc, node, structure, textBuffer, extraBuffer, indexName, namespace, field);
|
---|
279 | textBuffer.append(extraBuffer.toString());
|
---|
280 | return textBuffer.toString();
|
---|
281 | }
|
---|
282 |
|
---|
283 | /**
|
---|
284 | * Index a single document; the document interface can be used to extract individual
|
---|
285 | * metadata items etc. as required or desired and index those instead or as well as
|
---|
286 | * the body text of the document.
|
---|
287 | */
|
---|
288 | public boolean indexDocument(DocumentID docID, DocumentInterface document)
|
---|
289 | {
|
---|
290 | if (this.pass == 0) {
|
---|
291 | document.removeAllMetadata("gsdl3", "mgseqno");
|
---|
292 | }
|
---|
293 |
|
---|
294 | if (!this.firstDocument)
|
---|
295 | { // Send a 'CTRL-B' before the document itself
|
---|
296 | try {
|
---|
297 | this.indexerTextfeed.write(END_OF_DOCUMENT);
|
---|
298 | }
|
---|
299 | catch (IOException ex)
|
---|
300 | { System.out.println("Bad output on end of document" + ex);
|
---|
301 | ex.printStackTrace();
|
---|
302 | return false;
|
---|
303 | }
|
---|
304 | }
|
---|
305 |
|
---|
306 | String docText = null;
|
---|
307 |
|
---|
308 | int startSeqNo = this.sectionSeqNo;
|
---|
309 | this.sectionSeqNo ++;
|
---|
310 |
|
---|
311 | Document domDocument = document.getDOMDocument();
|
---|
312 | if (domDocument != null) {
|
---|
313 | METSStructure sections = document.getDocumentStructure().getStructure("Section");
|
---|
314 | if (sections != null) {
|
---|
315 | docText = this.prepareDOM(document, domDocument, sections, this.indexName, "gsdl3", this.field);
|
---|
316 | // System.out.println(docText);
|
---|
317 | }
|
---|
318 | }
|
---|
319 | if (docText == null) {
|
---|
320 | if (this.field.equals("text")) {
|
---|
321 | docText = Character.toString(END_OF_DOCUMENT) + Character.toString(END_OF_SECTION) +
|
---|
322 | document.getDocumentText();
|
---|
323 | }
|
---|
324 | else {
|
---|
325 | StringBuffer textBuffer = new StringBuffer();
|
---|
326 | textBuffer.append(END_OF_DOCUMENT);
|
---|
327 | textBuffer.append(END_OF_SECTION);
|
---|
328 | List values = document.getDocumentMetadataItem("gsdl3", this.field);
|
---|
329 | if (values != null) {
|
---|
330 | Iterator valueIter = values.iterator();
|
---|
331 | while (valueIter.hasNext()) {
|
---|
332 | String value = valueIter.next().toString();
|
---|
333 |
|
---|
334 | textBuffer.append(value);
|
---|
335 | if (valueIter.hasNext()) {
|
---|
336 | textBuffer.append(END_OF_SECTION);
|
---|
337 | // sectionSeqNo ++;
|
---|
338 | }
|
---|
339 | }
|
---|
340 | }
|
---|
341 | else {
|
---|
342 | textBuffer.append("No data");
|
---|
343 | }
|
---|
344 | docText = textBuffer.toString();
|
---|
345 | }
|
---|
346 | sectionSeqNo ++;
|
---|
347 | }
|
---|
348 |
|
---|
349 | /* if (this.pass == 0) {
|
---|
350 | System.err.println(docText);
|
---|
351 | }
|
---|
352 | */
|
---|
353 |
|
---|
354 | byte [] bytes = docText.getBytes();
|
---|
355 | int pos = 0, end = bytes.length;
|
---|
356 |
|
---|
357 | try {
|
---|
358 | while (pos < end) {
|
---|
359 | this.indexerTextfeed.write(bytes, pos, (end - pos > 512 ? 512 : end - pos));
|
---|
360 | pos = pos + 512;
|
---|
361 |
|
---|
362 | try {
|
---|
363 | while (this.indexerFeedback.available() > 0)
|
---|
364 | { byte b[] = new byte[this.indexerFeedback.available()];
|
---|
365 | System.out.println("Feedback of " + this.indexerFeedback.available());
|
---|
366 | this.indexerFeedback.read(b);
|
---|
367 | System.out.println(b);
|
---|
368 | }
|
---|
369 | }
|
---|
370 | catch (IOException ex)
|
---|
371 | { System.out.println(ex);
|
---|
372 | }
|
---|
373 |
|
---|
374 |
|
---|
375 | try {
|
---|
376 | while (this.indexerErrors.available() > 0)
|
---|
377 | { byte b[] = new byte[this.indexerErrors.available()];
|
---|
378 | System.out.println("Feedback of " + this.indexerErrors.available());
|
---|
379 | this.indexerErrors.read(b);
|
---|
380 | System.out.println(new String(b));
|
---|
381 | }
|
---|
382 | }
|
---|
383 | catch (IOException ex)
|
---|
384 | { System.out.println(ex);
|
---|
385 | }
|
---|
386 | }
|
---|
387 | }
|
---|
388 | catch (IOException ex)
|
---|
389 | { System.out.println("Bad output during document write " + ex + " " + pos + " " + end);
|
---|
390 | ex.printStackTrace();
|
---|
391 | return false;
|
---|
392 | }
|
---|
393 |
|
---|
394 | // remember that we're not on the first document, assign the sequence number
|
---|
395 | // on the first pass only, and increment the sequence number.
|
---|
396 | this.firstDocument = false;
|
---|
397 | if (this.pass == 0) {
|
---|
398 | document.addDocumentMetadata("gsdl3", "mgseqno", "dtx."+Integer.toString(startSeqNo));
|
---|
399 | //System.out.println("Assigning " + startSeqNo + " to " + document.getID());
|
---|
400 | }
|
---|
401 | this.documentSeqNo += 1;
|
---|
402 |
|
---|
403 | try {
|
---|
404 | while (this.indexerErrors.available() > 0)
|
---|
405 | { char c = (char) this.indexerErrors.read();
|
---|
406 | System.out.println(c);
|
---|
407 | }
|
---|
408 | while (this.indexerFeedback.available() > 0)
|
---|
409 | { byte b[] = new byte[this.indexerFeedback.available()];
|
---|
410 | System.out.println("Feedback of " + this.indexerFeedback.available());
|
---|
411 | this.indexerFeedback.read(b);
|
---|
412 | }
|
---|
413 | }
|
---|
414 | catch (IOException ex)
|
---|
415 | {
|
---|
416 | }
|
---|
417 | return true;
|
---|
418 | }
|
---|
419 |
|
---|
420 | /**
|
---|
421 | * Initialise the pass: open required files, check status
|
---|
422 | */
|
---|
423 | public boolean startPass(int passNumber)
|
---|
424 | {
|
---|
425 | this.pass = passNumber;
|
---|
426 | this.firstDocument = true;
|
---|
427 | this.documentSeqNo = 1;
|
---|
428 | this.sectionSeqNo = 1;
|
---|
429 |
|
---|
430 | int indexNo = (this.pass - 2) / 2;
|
---|
431 | if (this.pass >= 2) {
|
---|
432 | MGIndex index = (MGIndex) this.indexes.get(indexNo);
|
---|
433 |
|
---|
434 | // attempt to ensure that the text subdirectory exists
|
---|
435 | this.indexDirectory = new File(outputDirectory, this.getIndexDirectory(index.getLevel(), index.getField()));
|
---|
436 | if (!indexDirectory.exists()) {
|
---|
437 | if (!indexDirectory.mkdir()) {
|
---|
438 | return false;
|
---|
439 | }
|
---|
440 | }
|
---|
441 | else if (!indexDirectory.isDirectory()) {
|
---|
442 | return false;
|
---|
443 | }
|
---|
444 |
|
---|
445 | this.level = index.getLevel();
|
---|
446 | this.field = index.getField();
|
---|
447 | this.indexName = index.getName();
|
---|
448 | if (this.indexName == null || this.indexName.length() == 0) {
|
---|
449 | this.indexName = this.getIndexDirectory(index.getLevel(), index.getField());
|
---|
450 | }
|
---|
451 | this.indexStem = this.outputDirectory + File.separatorChar +
|
---|
452 | this.indexName + File.separatorChar + "index"; // TODO: modify for index
|
---|
453 | if (this.pass % 2 == 1) {
|
---|
454 | this.indexName = null;
|
---|
455 | }
|
---|
456 | }
|
---|
457 | else {
|
---|
458 | this.field = "text";
|
---|
459 | this.level = "section";
|
---|
460 | this.indexName = null;
|
---|
461 | }
|
---|
462 | System.out.println("level is " + this.level);
|
---|
463 | System.out.println("field is " + this.field);
|
---|
464 | System.out.println("index name is " + this.indexName);
|
---|
465 |
|
---|
466 | // get the parameters for this execution of mg_passes
|
---|
467 | String pathParams = "-f index -d " + (this.pass < 2 ? this.textDirectory.toString() : this.indexDirectory.toString());
|
---|
468 |
|
---|
469 | int mgPass = this.pass < 2 ? this.pass : ((this.pass % 2) + 2);
|
---|
470 |
|
---|
471 | try {
|
---|
472 | switch (mgPass) {
|
---|
473 | case 0:
|
---|
474 | mg_passes = Runtime.getRuntime().exec("mg_passes " + pathParams + " -b 100000 -T1");
|
---|
475 | break;
|
---|
476 |
|
---|
477 | case 1:
|
---|
478 | mg_passes = Runtime.getRuntime().exec("mg_passes " + pathParams +" -b 100000 -T2");
|
---|
479 | break;
|
---|
480 |
|
---|
481 | case 2:
|
---|
482 | mg_passes = Runtime.getRuntime().exec("mg_passes " + pathParams + " -b 100000 -2 -m 32 -s 0 -G -t 10 -N1");
|
---|
483 | break;
|
---|
484 |
|
---|
485 | case 3:
|
---|
486 | Process p = Runtime.getRuntime().exec("mg_perf_hash_build -f index -d " + this.indexDirectory.toString());
|
---|
487 | p.waitFor();
|
---|
488 | if (p.exitValue() == 0) {
|
---|
489 | System.out.println("Perfect hashes completed");
|
---|
490 | }
|
---|
491 |
|
---|
492 | mg_passes = Runtime.getRuntime().exec("mg_passes " + pathParams +" -b 100000 -2 -c 3 -G -t 10 -N2");
|
---|
493 | break;
|
---|
494 | }
|
---|
495 |
|
---|
496 | this.indexerFeedback = mg_passes.getInputStream();
|
---|
497 | this.indexerErrors = mg_passes.getErrorStream();
|
---|
498 | this.indexerTextfeed = mg_passes.getOutputStream();
|
---|
499 | }
|
---|
500 | catch (IOException ex)
|
---|
501 | { System.out.println(ex);
|
---|
502 | ex.printStackTrace();
|
---|
503 | return false;
|
---|
504 | }
|
---|
505 | catch (InterruptedException ex)
|
---|
506 | { System.out.println(ex);
|
---|
507 | ex.printStackTrace();
|
---|
508 | return false;
|
---|
509 | }
|
---|
510 | System.out.println("Pass " + this.pass);
|
---|
511 | return true;
|
---|
512 | }
|
---|
513 |
|
---|
514 | /**
|
---|
515 | * Complete a pass - reset file counters, close files, etc.
|
---|
516 | */
|
---|
517 | public boolean endPass(int passNumber)
|
---|
518 | { Process p;
|
---|
519 |
|
---|
520 | try {
|
---|
521 | this.indexerTextfeed.write(END_OF_DOCUMENT);
|
---|
522 | this.indexerTextfeed.write(END_OF_STREAM);
|
---|
523 | while (this.indexerErrors.available() > 0)
|
---|
524 | { char c = (char) this.indexerErrors.read();
|
---|
525 | System.out.print(c);
|
---|
526 | }
|
---|
527 | while (this.indexerFeedback.available() > 0)
|
---|
528 | { byte b[] = new byte[this.indexerFeedback.available()];
|
---|
529 | System.out.print("Feedback of " + this.indexerFeedback.available());
|
---|
530 | this.indexerFeedback.read(b);
|
---|
531 | }
|
---|
532 |
|
---|
533 | this.indexerTextfeed.close();
|
---|
534 | Thread.sleep(1000);
|
---|
535 | this.mg_passes.waitFor();
|
---|
536 | }
|
---|
537 | catch (IOException ex)
|
---|
538 | { System.out.println(ex);
|
---|
539 | }
|
---|
540 | catch (InterruptedException ex)
|
---|
541 | { System.out.println(ex);
|
---|
542 | }
|
---|
543 | System.out.println("Pass " + this.pass + " completed with " + this.mg_passes.exitValue());
|
---|
544 |
|
---|
545 | int mgPass = this.pass < 2 ? this.pass : ((this.pass % 2) + 2);
|
---|
546 |
|
---|
547 | try {
|
---|
548 | switch (mgPass)
|
---|
549 | {
|
---|
550 | case 0:
|
---|
551 | System.out.println("Compressing dictionary");
|
---|
552 | p = Runtime.getRuntime().exec("mg_compression_dict -f index -d " + this.textDirectory.toString() + " -S -H -2 -k 5120");
|
---|
553 | p.waitFor();
|
---|
554 | if (p.exitValue() != 0) {
|
---|
555 | System.out.println("Error from mg_compression_dict: " + p.exitValue());
|
---|
556 | }
|
---|
557 | else {
|
---|
558 | System.out.println("Compressed dictionary successfully written");
|
---|
559 | }
|
---|
560 | break;
|
---|
561 |
|
---|
562 | case 3:
|
---|
563 | System.out.println("Writing weights file");
|
---|
564 | p = Runtime.getRuntime().exec("mg_weights_build -f " + this.indexStem + " -t " + this.textStem + " -d /");
|
---|
565 | p.waitFor();
|
---|
566 | if (p.exitValue() == 0) {
|
---|
567 | System.out.println("Weights file successfully written");
|
---|
568 | }
|
---|
569 | else {
|
---|
570 | System.out.println("Unable to create weights file " + "mg_weights_build -f " + this.indexStem + " -t " + this.textStem + " -d /");
|
---|
571 | }
|
---|
572 |
|
---|
573 | p = Runtime.getRuntime().exec("mg_invf_dict -f index -d " + this.indexDirectory.toString());
|
---|
574 | p.waitFor();
|
---|
575 | if (p.exitValue() == 0) {
|
---|
576 | System.out.println("Inverted dictionary file successfully written");
|
---|
577 | }
|
---|
578 | else {
|
---|
579 | System.out.println("Unable to create inverted dictionary file");
|
---|
580 | }
|
---|
581 |
|
---|
582 | p = Runtime.getRuntime().exec("mg_stem_idx -b 4096 -s1 -f index -d " + this.indexDirectory.toString());
|
---|
583 | p.waitFor();
|
---|
584 | if (p.exitValue() == 0) {
|
---|
585 | System.out.println("Stemmed index successfully written");
|
---|
586 | }
|
---|
587 | else {
|
---|
588 | System.out.println("Unable to create stemmed index");
|
---|
589 | }
|
---|
590 |
|
---|
591 | p = Runtime.getRuntime().exec("mg_stem_idx -b 4096 -s2 -f index -d " + this.indexDirectory.toString());
|
---|
592 | p.waitFor();
|
---|
593 | if (p.exitValue() == 0) {
|
---|
594 | System.out.println("Stemmed index successfully written");
|
---|
595 | }
|
---|
596 | else {
|
---|
597 | System.out.println("Unable to create stemmed index");
|
---|
598 | }
|
---|
599 |
|
---|
600 | p = Runtime.getRuntime().exec("mg_stem_idx -b 4096 -s3 -f index -d " + this.indexDirectory.toString());
|
---|
601 | p.waitFor();
|
---|
602 | if (p.exitValue() == 0) {
|
---|
603 | System.out.println("Stemmed index successfully written");
|
---|
604 | }
|
---|
605 | else {
|
---|
606 | System.out.println("Unable to create stemmed index");
|
---|
607 | }
|
---|
608 | break;
|
---|
609 | }
|
---|
610 | }
|
---|
611 | catch (IOException ex)
|
---|
612 | { System.out.println(ex);
|
---|
613 | ex.printStackTrace();
|
---|
614 | return false;
|
---|
615 | }
|
---|
616 | catch (InterruptedException ex)
|
---|
617 | { System.out.println(ex);
|
---|
618 | ex.printStackTrace();
|
---|
619 | return false;
|
---|
620 | }
|
---|
621 | return true;
|
---|
622 | }
|
---|
623 |
|
---|
624 | /**
|
---|
625 | * Do any tidying up
|
---|
626 | */
|
---|
627 | public void tidyup()
|
---|
628 | {
|
---|
629 | }
|
---|
630 |
|
---|
631 | /**
|
---|
632 | * Return the number of passes required for this index.
|
---|
633 | */
|
---|
634 | public int getNumberOfPasses()
|
---|
635 | { return 2 + this.indexes.size() * 2;
|
---|
636 | }
|
---|
637 | }
|
---|