source: trunk/indexers/mg/jni/MGPassesWrapperImpl.c@ 9987

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

added in an exitValue/get_exit_value method to the MGPassesWrapper

  • Property svn:keywords set to Author Date Id Revision
File size: 6.8 KB
Line 
1/*
2 * MGPassesWrapperImpl.c
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
20
21#include <jni.h>
22#include <assert.h>
23#include "sysfuncs.h"
24#include "org_greenstone_mg_MGPassesWrapper.h"
25
26#include "mg_passes_4jni.h"
27#include "mg_files.h"
28
29/* if we need to use java objects, we should initialise their field ids here*/
30JNIEXPORT void JNICALL
31Java_org_greenstone_mg_MGPassesWrapper_initIDs(JNIEnv *j_env, jclass j_cls)
32{
33 return;
34}
35
36JNIEXPORT jboolean JNICALL
37Java_org_greenstone_mg_MGPassesWrapper_initCSide(JNIEnv *j_env, jobject j_obj)
38{
39 clear_variables();
40 return 1; /* true - no errors */
41}
42
43/* add a pass type T1, T2, I1, I2, S */
44JNIEXPORT void JNICALL
45Java_org_greenstone_mg_MGPassesWrapper_addPass(JNIEnv *j_env,
46 jobject j_obj,
47 jchar j_pass_type,
48 jchar j_pass_num)
49{
50 /* get the level as a c char */
51 const char pass_type = j_pass_type;
52 const char pass_num = j_pass_num;
53 add_pass(pass_type, pass_num);
54
55}
56
57/* Set the filename */
58JNIEXPORT void JNICALL
59Java_org_greenstone_mg_MGPassesWrapper_setFileName(JNIEnv *j_env,
60 jobject j_obj,
61 jstring j_filename)
62{
63 /* Get the filename as a C string */
64 const char* filename = (*j_env)->GetStringUTFChars(j_env, j_filename, NULL);
65
66 assert(filename != NULL);
67 set_filename(filename);
68
69 /* Release the string */
70 (*j_env)->ReleaseStringUTFChars(j_env, j_filename, filename);
71
72}
73
74/* Set the base path */
75JNIEXPORT void JNICALL
76Java_org_greenstone_mg_MGPassesWrapper_setBasePath(JNIEnv *j_env,
77 jobject j_obj,
78 jstring j_basepath)
79{
80 /* Get the base_path as a C string */
81 const char* basepath = (*j_env)->GetStringUTFChars(j_env, j_basepath, NULL);
82 assert(basepath != NULL);
83
84 set_basepath(basepath);
85
86 /* Release the string */
87 (*j_env)->ReleaseStringUTFChars(j_env, j_basepath, basepath);
88
89}
90
91/* set the level for the inverted file */
92JNIEXPORT void JNICALL
93Java_org_greenstone_mg_MGPassesWrapper_setInvfLevel(JNIEnv *j_env,
94 jobject j_obj,
95 jchar j_level)
96{
97 /* get the level as a c char */
98 const char level = j_level;
99 set_invf_level(level);
100
101}
102
103/* set the stemmer and stem method */
104JNIEXPORT void JNICALL
105Java_org_greenstone_mg_MGPassesWrapper_setStemOptions(JNIEnv *j_env,
106 jobject j_obj,
107 jstring j_stemmer,
108 jint j_method)
109{
110
111 const char* stemmer = (*j_env)->GetStringUTFChars(j_env, j_stemmer, NULL);
112 int method = j_method;
113
114 assert(stemmer != NULL);
115 set_stem_options(stemmer, method);
116
117 /* Release the string */
118 (*j_env)->ReleaseStringUTFChars(j_env, j_stemmer, stemmer);
119 }
120
121/** Specify the size of the document buffer in kilobytes.
122 If any document is larger than bufsize, the program
123 will abort with an error message.
124*/
125JNIEXPORT void JNICALL
126Java_org_greenstone_mg_MGPassesWrapper_setBufferSize(JNIEnv *j_env,
127 jobject j_obj,
128 jlong j_bufsize){
129 long buffer = j_bufsize;
130 set_buffer_size(buffer);
131}
132
133/** Maximum amount of memory to use for the index pass-2 file
134 inversion in megabytes.
135*/
136JNIEXPORT void JNICALL
137Java_org_greenstone_mg_MGPassesWrapper_setInversionMemLimit(JNIEnv *j_env,
138 jobject j_obj,
139 jint j_limit) {
140 int limit = j_limit;
141 set_inversion_limit(limit);
142}
143
144/** If true, treat SGML tags as non-words when building the
145 inverted file.
146*/
147JNIEXPORT void JNICALL
148Java_org_greenstone_mg_MGPassesWrapper_ignoreSGMLTags(JNIEnv *j_env,
149 jobject j_obj,
150 jboolean j_ignore){
151 int ignore = j_ignore;
152 ignore_sgml_tags(ignore);
153}
154
155/** if mg_passes fails, the document that caused the failure will be
156 output to the trace file or STDERR.
157*/
158JNIEXPORT void JNICALL
159Java_org_greenstone_mg_MGPassesWrapper_dumpFailedDocument(JNIEnv *j_env,
160 jobject j_obj,
161 jboolean j_dump) {
162 int dump = j_dump;
163 dump_failed_document(dump);
164}
165
166/** output statistics on the compression performance to a file
167 called *.compression.stats. frequency specifies the interval
168 (in kilobytes of source text) between outputting each line of
169 statistics.
170*/
171JNIEXPORT void JNICALL
172Java_org_greenstone_mg_MGPassesWrapper_outputCompStats(JNIEnv *j_env,
173 jobject j_obj,
174 jint j_frequency){
175 int comp_stat_point = j_frequency;
176 set_comp_stat_point(comp_stat_point);
177
178}
179/** activate tracing, a line will be output every tracepos input bytes */
180JNIEXPORT void JNICALL
181Java_org_greenstone_mg_MGPassesWrapper_enableTracing(JNIEnv *j_env,
182 jobject j_obj,
183 jint j_tracepos){
184 int tracepos = j_tracepos;
185 set_trace_point(tracepos);
186}
187
188/** specify the name of the trace file */
189JNIEXPORT void JNICALL
190Java_org_greenstone_mg_MGPassesWrapper_setTraceFile(JNIEnv *j_env,
191 jobject j_obj,
192 jstring j_tracefile){
193
194 const char* tracefile = (*j_env)->GetStringUTFChars(j_env, j_tracefile, NULL);
195 assert(tracefile != NULL);
196 set_trace_file(tracefile);
197 /* Release the string */
198 (*j_env)->ReleaseStringUTFChars(j_env, j_tracefile, tracefile);
199}
200
201/* initialise the pass through the documents. must be called after all
202 the set methods
203*/
204JNIEXPORT jboolean JNICALL
205Java_org_greenstone_mg_MGPassesWrapper_init(JNIEnv *j_env,
206 jobject j_obj) {
207
208 init_driver();
209 return 1;
210}
211
212
213/* process one document */
214JNIEXPORT jboolean JNICALL
215Java_org_greenstone_mg_MGPassesWrapper_processMGDocument(JNIEnv *j_env,
216 jobject j_obj,
217 jbyteArray j_doc_text) {
218 /* Get the text as a C string */
219 int length = (*j_env)->GetArrayLength(j_env, j_doc_text);
220 u_char * text_buffer = (u_char *)(*j_env)->GetByteArrayElements(j_env, j_doc_text, NULL);
221 process_document(text_buffer, length);
222 /* Release the string */
223 (*j_env)->ReleaseByteArrayElements(j_env, j_doc_text, text_buffer,0);
224 return 1;
225}
226
227/* finalise the pass through the documents */
228JNIEXPORT jboolean JNICALL
229Java_org_greenstone_mg_MGPassesWrapper_finish(JNIEnv *j_env,
230 jobject j_obj) {
231
232 finalise_driver();
233 return 1;
234}
235
236/** get the exit value once finished */
237JNIEXPORT jint JNICALL
238Java_org_greenstone_mg_MGPassesWrapper_exitValue(JNIEnv *j_env,
239 jobject j_obj) {
240
241 return get_exit_value();
242}
243
Note: See TracBrowser for help on using the repository browser.