[7403] | 1 | /*
|
---|
| 2 | * MGPassesWrapper.java
|
---|
| 3 | * Copyright (C) 2002 New Zealand Digital Library, http://www.nzdl.org
|
---|
| 4 | *
|
---|
| 5 | * This program is free software; you can redistribute it and/or modify
|
---|
| 6 | * it under the terms of the GNU General Public License as published by
|
---|
| 7 | * the Free Software Foundation; either version 2 of the License, or
|
---|
| 8 | * (at your option) any later version.
|
---|
| 9 | *
|
---|
| 10 | * This program is distributed in the hope that it will be useful,
|
---|
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 13 | * GNU General Public License for more details.
|
---|
| 14 | *
|
---|
| 15 | * You should have received a copy of the GNU General Public License
|
---|
| 16 | * along with this program; if not, write to the Free Software
|
---|
| 17 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
| 18 | */
|
---|
| 19 | package org.greenstone.mg;
|
---|
| 20 |
|
---|
| 21 |
|
---|
[7460] | 22 | /** java wrapper class for access to gs3_mg_passes in C
|
---|
[7403] | 23 | *
|
---|
| 24 | * the native side implemented in MGPassesWrapperImpl.c
|
---|
| 25 | */
|
---|
| 26 |
|
---|
| 27 | public class MGPassesWrapper
|
---|
| 28 | {
|
---|
| 29 | static {
|
---|
| 30 | System.loadLibrary("mgpassjni");
|
---|
| 31 | initIDs();
|
---|
| 32 | }
|
---|
| 33 |
|
---|
[7460] | 34 | static final public char INVF_LEVEL_1 = '1';
|
---|
| 35 | static final public char INVF_LEVEL_2 = '2';
|
---|
| 36 | static final public char INVF_LEVEL_3 = '3';
|
---|
| 37 |
|
---|
| 38 | static final public int TEXT_PASS_1 = 0;
|
---|
| 39 | static final public int TEXT_PASS_2 = 1;
|
---|
| 40 | static final public int INDEX_PASS_1 = 2;
|
---|
| 41 | static final public int INDEX_PASS_2 = 3;
|
---|
| 42 | static final public int SPECIAL_PASS = 4;
|
---|
[7403] | 43 |
|
---|
[7460] | 44 | static final public int NO_STEM_OR_CASE = 0;
|
---|
| 45 | static final public int CASE_ONLY = 1;
|
---|
| 46 | static final public int STEM_ONLY = 2;
|
---|
| 47 | static final public int STEM_AND_CASE = 3;
|
---|
| 48 |
|
---|
| 49 | static final public String STEMMER_ENGLISH = "english";
|
---|
| 50 | static final public String STEMMER_FRENCH = "french";
|
---|
| 51 | static final public String STEMMER_LOVIN = "lovin";
|
---|
| 52 | static final public String STEMMER_SIMPLE_FRENCH = "simple-french";
|
---|
| 53 |
|
---|
| 54 | static final private char END_OF_DOCUMENT = (char) 2;
|
---|
| 55 |
|
---|
[7403] | 56 | public MGPassesWrapper() {
|
---|
| 57 | initCSide();
|
---|
| 58 | }
|
---|
| 59 |
|
---|
| 60 | /** initialise the pass through the documents */
|
---|
| 61 | public native boolean init();
|
---|
| 62 |
|
---|
| 63 | /** add a pass declaration */
|
---|
[7460] | 64 | public void addPass(int pass) {
|
---|
| 65 | switch (pass) {
|
---|
| 66 | case TEXT_PASS_1:
|
---|
| 67 | addPass('T','1');
|
---|
| 68 | break;
|
---|
| 69 | case TEXT_PASS_2:
|
---|
| 70 | addPass('T','2');
|
---|
| 71 | break;
|
---|
| 72 | case INDEX_PASS_1:
|
---|
| 73 | addPass('I','1');
|
---|
| 74 | break;
|
---|
| 75 | case INDEX_PASS_2:
|
---|
| 76 | addPass('I','2');
|
---|
| 77 | break;
|
---|
| 78 | case SPECIAL_PASS:
|
---|
| 79 | addPass('S','1');
|
---|
| 80 | break;
|
---|
| 81 | }
|
---|
| 82 | }
|
---|
[7452] | 83 | /** set the base path */
|
---|
| 84 | public native void setBasePath(String basepath);
|
---|
| 85 | /** set the file name */
|
---|
| 86 | public native void setFileName(String filename);
|
---|
[7403] | 87 |
|
---|
| 88 | public native void setStemOptions(String stemmer_type, int stem_method);
|
---|
| 89 |
|
---|
| 90 | public native void setInvfLevel(char level);
|
---|
| 91 |
|
---|
[7460] | 92 | /** Specify the size of the document buffer in kilobytes.
|
---|
| 93 | If any document is larger than bufsize, the program
|
---|
| 94 | will abort with an error message.
|
---|
| 95 | */
|
---|
| 96 | public native void setBufferSize(long bufsize);
|
---|
| 97 |
|
---|
| 98 | /** Maximum amount of memory to use for the index pass-2 file
|
---|
| 99 | inversion in megabytes.
|
---|
| 100 | */
|
---|
| 101 | public native void setInversionMemLimit(int limit);
|
---|
[7403] | 102 |
|
---|
[7460] | 103 | /** If true, treat SGML tags as non-words when building the
|
---|
| 104 | inverted file.
|
---|
| 105 | */
|
---|
| 106 | public native void ignoreSGMLTags(boolean ignore);
|
---|
| 107 |
|
---|
| 108 | /** if mg_passes fails, the document that caused teh failure will be
|
---|
| 109 | output to teh trace file or STDERR.
|
---|
| 110 | */
|
---|
| 111 | public native void dumpFailedDocument(boolean dump);
|
---|
| 112 |
|
---|
| 113 | /** output statistics on the compression performance to a file
|
---|
| 114 | called *.compression.stats. frequency specifies the interval
|
---|
| 115 | (in kilobytes of source text) between outputting each line of
|
---|
| 116 | statistics.
|
---|
| 117 | */
|
---|
| 118 | public native void outputCompStats(int frequency);
|
---|
| 119 |
|
---|
| 120 | /** activate tracing, a line will be output every tracepos input bytes */
|
---|
| 121 | public native void enableTracing(int tracepos);
|
---|
[7403] | 122 | /** process a Greenstone document, which may consist of many MG documents (seeparated by ^B */
|
---|
| 123 | public boolean processDocument(String docs_text) {
|
---|
| 124 | String [] docs = docs_text.split(String.valueOf(END_OF_DOCUMENT));
|
---|
[7440] | 125 | System.err.println("num docs split into "+docs.length);
|
---|
[7403] | 126 | for (int i=0; i<docs.length; i++) {
|
---|
| 127 | try {
|
---|
| 128 | processMGDocument(docs[i].getBytes("UTF-8"));
|
---|
| 129 | } catch (Exception e) {
|
---|
| 130 | e.printStackTrace();
|
---|
| 131 | }
|
---|
| 132 | }
|
---|
| 133 | return true;
|
---|
| 134 | }
|
---|
| 135 |
|
---|
| 136 | /** finalise the pass through the documents */
|
---|
| 137 | public native boolean finish();
|
---|
[7460] | 138 |
|
---|
| 139 |
|
---|
| 140 | /** initialises field and method IDs for java side to enable access on C side */
|
---|
| 141 | private static native void initIDs();
|
---|
| 142 |
|
---|
| 143 | /** initialises any C side stuff */
|
---|
| 144 | private native boolean initCSide();
|
---|
| 145 |
|
---|
| 146 | private native void addPass(char pass_type, char pass_num);
|
---|
| 147 |
|
---|
| 148 | /** process a MG document */
|
---|
| 149 | private native boolean processMGDocument(byte[] text);
|
---|
| 150 |
|
---|
[7403] | 151 | }
|
---|