[3365] | 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
|
---|
[4214] | 43 | * text_path path should provide
|
---|
[3365] | 44 | * the absolute location of the mgpp text files eg ..../index/text/demo
|
---|
[4214] | 45 | * returns the doc in utf-8
|
---|
[3365] | 46 | */
|
---|
[4214] | 47 | public native String getDocument(String text_path,
|
---|
[3365] | 48 | String level,
|
---|
| 49 | long docnum );
|
---|
| 50 |
|
---|
| 51 | /** the public method - converts between utf-8 and unicode
|
---|
| 52 | */
|
---|
[4214] | 53 | // public String getDocument(String text_path,
|
---|
[3365] | 54 | // String level,
|
---|
| 55 | // long docnum ) {
|
---|
| 56 |
|
---|
| 57 | //String utf8_doc = getUtF8Document(base_dir, text_path, level, docnum);
|
---|
| 58 |
|
---|
| 59 | /** load up the data structure for index
|
---|
| 60 | * - maintains state between requests as can be slow
|
---|
[4214] | 61 | * index_path should provide
|
---|
[3365] | 62 | * the absolute location of the mgpp index files eg ..../index/tt/demo
|
---|
| 63 | */
|
---|
[4214] | 64 | public native boolean loadIndexData(String index_path);
|
---|
[3365] | 65 | /** unloads the data */
|
---|
| 66 | public native boolean unloadIndexData();
|
---|
| 67 |
|
---|
| 68 | // query param methods
|
---|
| 69 |
|
---|
| 70 | /** if on=true, sets default stemming on - its off by default*/
|
---|
| 71 | public native void setStem(boolean on);
|
---|
[13481] | 72 |
|
---|
| 73 | /** if on=true, sets default accentfolding on - its off by default*/
|
---|
| 74 | public native void setAccentFold(boolean on);
|
---|
| 75 |
|
---|
| 76 | /** if on=true, sets default casefolding on - its off by default */
|
---|
| 77 | public native void setCase(boolean on);
|
---|
[3365] | 78 | /** default is 50 */
|
---|
| 79 | public native void setMaxDocs(int num);
|
---|
| 80 | /** if on=true, sorts by rank, otherwise returns in build order -
|
---|
| 81 | default is on */
|
---|
| 82 | public native void setSortByRank(boolean on);
|
---|
| 83 | /** if on=true, a query returns term freq info - default is on */
|
---|
| 84 | public native void setReturnTerms(boolean on);
|
---|
[3447] | 85 | /** sets the granularity of the query - default 'Document' */
|
---|
[3365] | 86 | public native void setQueryLevel(String level);
|
---|
[3447] | 87 | /** sets the granularity of the result - default 'Document' */
|
---|
[3365] | 88 | public native void setReturnLevel(String level);
|
---|
| 89 | /** sets the default boolean operator - AND(=1)/OR(=0) */
|
---|
| 90 | public native void setMatchMode(int mode);
|
---|
| 91 |
|
---|
[12324] | 92 | /** sets maxnumeric */
|
---|
| 93 | public native void setMaxNumeric(int maxnumeric);
|
---|
[3365] | 94 | /** returns a string with all the current query param settings */
|
---|
| 95 | public native String getQueryParams();
|
---|
| 96 |
|
---|
| 97 | /** actually carry out the query. Use the set methods to set any query
|
---|
| 98 | params
|
---|
| 99 | * writes the result to query_result
|
---|
| 100 | */
|
---|
| 101 | public native void runQuery(String query_string);
|
---|
| 102 |
|
---|
| 103 | /** get the result out of the wrapper */
|
---|
| 104 | public MGPPQueryResult getQueryResult() {
|
---|
| 105 | return mgpp_query_result_;
|
---|
| 106 | }
|
---|
| 107 |
|
---|
| 108 | }
|
---|