1 |
|
---|
2 | package org.greenstone.mgpp;
|
---|
3 |
|
---|
4 | import java.util.Vector;
|
---|
5 |
|
---|
6 | /** java wrapper class for access to mgpp in C++
|
---|
7 | *
|
---|
8 | * the native side implemented in MGPPWrapperImpl.cpp
|
---|
9 | * uses MGPPQueryResult to hold the result of a query. the
|
---|
10 | * result of a getDocument is a String
|
---|
11 | * uses the jni
|
---|
12 | *
|
---|
13 | *@see MGPPQueryResult
|
---|
14 | */
|
---|
15 | public class MGPPWrapper {
|
---|
16 |
|
---|
17 | /** the query result
|
---|
18 | * will be filled in by runQuery
|
---|
19 | */
|
---|
20 | protected MGPPQueryResult mgpp_query_result_=null;
|
---|
21 | /** pointer to c++ MGPPWrapperData class - cached indexData and queryInfo
|
---|
22 | */
|
---|
23 | protected long mgpp_data_ptr_=0;
|
---|
24 |
|
---|
25 | static {
|
---|
26 | System.loadLibrary("mgppjni");
|
---|
27 | initIDs();
|
---|
28 | }
|
---|
29 |
|
---|
30 | public MGPPWrapper() {
|
---|
31 | mgpp_query_result_ = new MGPPQueryResult();
|
---|
32 | initCppSide();
|
---|
33 | }
|
---|
34 |
|
---|
35 | /** initialises field and method IDs for java side to enable access on
|
---|
36 | C++ side */
|
---|
37 | private static native void initIDs();
|
---|
38 |
|
---|
39 | /** initialises the mgpp_data_ptr_ */
|
---|
40 | private native boolean initCppSide();
|
---|
41 |
|
---|
42 | /** returns a document: number docnum at level level
|
---|
43 | * the base_dir and text_path paths should join together to provide
|
---|
44 | * the absolute location of the mgpp text files eg ..../index/text/demo
|
---|
45 | * returns teh doc in utf-8
|
---|
46 | */
|
---|
47 | public native String getDocument(String base_dir,
|
---|
48 | String text_path,
|
---|
49 | String level,
|
---|
50 | long docnum );
|
---|
51 |
|
---|
52 | /** the public method - converts between utf-8 and unicode
|
---|
53 | */
|
---|
54 | // public String getDocument(String base_dir,
|
---|
55 | // String text_path,
|
---|
56 | // String level,
|
---|
57 | // long docnum ) {
|
---|
58 |
|
---|
59 | //String utf8_doc = getUtF8Document(base_dir, text_path, level, docnum);
|
---|
60 |
|
---|
61 | /** load up the data structure for index
|
---|
62 | * - maintains state between requests as can be slow
|
---|
63 | * base_dir and text_path should join together to provide
|
---|
64 | * the absolute location of the mgpp index files eg ..../index/tt/demo
|
---|
65 | */
|
---|
66 | public native boolean loadIndexData(String base_dir,
|
---|
67 | String index_path);
|
---|
68 | /** unloads the data */
|
---|
69 | public native boolean unloadIndexData();
|
---|
70 |
|
---|
71 | // query param methods
|
---|
72 |
|
---|
73 | /** if on=true, sets default stemming on - its off by default*/
|
---|
74 | public native void setStem(boolean on);
|
---|
75 | /** if on=true, sets default casefolding on - its off by default */
|
---|
76 | public native void setCase(boolean on);
|
---|
77 | /** default is 50 */
|
---|
78 | public native void setMaxDocs(int num);
|
---|
79 | /** if on=true, sorts by rank, otherwise returns in build order -
|
---|
80 | default is on */
|
---|
81 | public native void setSortByRank(boolean on);
|
---|
82 | /** if on=true, a query returns term freq info - default is on */
|
---|
83 | public native void setReturnTerms(boolean on);
|
---|
84 | /** sets the granularity of the query - default 'Section' */
|
---|
85 | public native void setQueryLevel(String level);
|
---|
86 | /** sets the granularity of the result - default 'Section' */
|
---|
87 | public native void setReturnLevel(String level);
|
---|
88 | /** sets the default boolean operator - AND(=1)/OR(=0) */
|
---|
89 | public native void setMatchMode(int mode);
|
---|
90 |
|
---|
91 | /** returns a string with all the current query param settings */
|
---|
92 | public native String getQueryParams();
|
---|
93 |
|
---|
94 | /** actually carry out the query. Use the set methods to set any query
|
---|
95 | params
|
---|
96 | * writes the result to query_result
|
---|
97 | */
|
---|
98 | public native void runQuery(String query_string);
|
---|
99 |
|
---|
100 | /** get the result out of the wrapper */
|
---|
101 | public MGPPQueryResult getQueryResult() {
|
---|
102 | return mgpp_query_result_;
|
---|
103 | }
|
---|
104 |
|
---|
105 | }
|
---|