source: trunk/indexers/mgpp/java/org/greenstone/mgpp/MGPPPassesWrapper.java@ 8950

Last change on this file since 8950 was 8950, checked in by kjdon, 19 years ago

first stab at Java/JNI wrapper around mgpp_passes

  • Property svn:keywords set to Author Date Id Revision
File size: 4.3 KB
Line 
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 */
19package org.greenstone.mgpp;
20
21
22/** java wrapper class for access to gs3_mgpp_passes in C
23 *
24 * the native side implemented in MGPPPassesWrapperImpl.c
25 */
26
27public class MGPPPassesWrapper
28{
29 static {
30 System.loadLibrary("mgpppassjni");
31 initIDs();
32 }
33
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;
43
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
56 public MGPPPassesWrapper() {
57 initCSide();
58 }
59
60 /** initialise the pass through the documents */
61 public native boolean init();
62
63 /** add a pass declaration */
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 }
83 /** set the base path */
84 public native void setBasePath(String basepath);
85 /** set the file name */
86 public native void setFileName(String filename);
87
88 /** set the Document tag */
89 public native void setDocumentTag(String tag);
90
91 /** add a level tag */
92 public native void addLevelTag(String tag);
93
94 /** set the index level (default word level) */
95 public native void setIndexLevel(String tag);
96
97 /** Maximum amount of memory to use for the index pass-2 file
98 inversion in megabytes.
99 */
100 public native void setInversionMemLimit(int limit);
101
102 /** process one or more MGPP documents */
103 public boolean processDocument(String doc_text) {
104 try {
105 processMGPPDocument(doc_text.getBytes("UTF-8"));
106 } catch (Exception e) {
107 e.printStackTrace();
108 return false;
109 }
110 return true;
111 }
112
113 /** finalise the pass through the documents */
114 public native boolean finish();
115
116 /** get the exit value once finished */
117 public native int exitValue();
118
119 /** initialises field and method IDs for java side to enable access on C side */
120 private static native void initIDs();
121
122 /** initialises any C side stuff */
123 private native boolean initCSide();
124
125 private native void addPass(char pass_type, char pass_num);
126
127 /** process a MGPP document */
128 private native boolean processMGPPDocument(byte[] text);
129
130 public static void main(String []args) {
131
132 String doc = "<Document>hello there kath<Title>this is a title</Title></Document><Document>my name is helen</Document>";
133
134 MGPPPassesWrapper wrapper = new MGPPPassesWrapper();
135 wrapper.addPass(TEXT_PASS_1);
136 wrapper.addPass(TEXT_PASS_2);
137 wrapper.setDocumentTag("Document");
138 wrapper.setBasePath("/tmp/kjdon/index");
139 wrapper.setFileName("idx");
140
141 wrapper.init();
142 wrapper.processDocument(doc);
143 wrapper.finish();
144
145 }
146}
Note: See TracBrowser for help on using the repository browser.