Index: trunk/gsdl3/src/java/org/greenstone/mgpp/MGPPDocInfo.java
===================================================================
--- trunk/gsdl3/src/java/org/greenstone/mgpp/MGPPDocInfo.java	(revision 3255)
+++ trunk/gsdl3/src/java/org/greenstone/mgpp/MGPPDocInfo.java	(revision 3255)
@@ -0,0 +1,20 @@
+package org.greenstone.mgpp;
+
+/** DocInfo 'struct' class for a search result from mgpp
+ * used by MGPPQueryResult
+ *
+ * @See MGPPQueryResult
+ */
+public class MGPPDocInfo {
+
+    public long num_=0;
+    public float rank_=0;
+
+    public MGPPDocInfo(long doc, float rank) {
+	num_=doc;
+	rank_=rank;
+    }
+    public String toString(){
+	return ""+num_+"("+rank_+")";
+    }
+}
Index: trunk/gsdl3/src/java/org/greenstone/mgpp/MGPPQueryResult.java
===================================================================
--- trunk/gsdl3/src/java/org/greenstone/mgpp/MGPPQueryResult.java	(revision 3255)
+++ trunk/gsdl3/src/java/org/greenstone/mgpp/MGPPQueryResult.java	(revision 3255)
@@ -0,0 +1,97 @@
+package org.greenstone.mgpp;
+
+import java.util.Vector;
+
+/** a java version of QueryResult for mgpp
+ *
+ * contains get methods for the java side, and simple
+ * set methods to be called from c++ side
+ *
+ */
+class MGPPQueryResult {
+
+    /** the list of MGPPDocInfo */
+    protected Vector docs_=null;
+    /** the list of MGPPTermInfo */
+    protected Vector terms_=null;
+    /** the total number of docs found - not likely to be the size of docs_*/
+    protected long total_num_docs_=0;
+    
+    MGPPQueryResult() {
+	docs_ = new Vector();
+	terms_ = new Vector();
+    }
+    /** clear the info from the last query - should be called before setting any new docs/terms */
+    public void clear() {
+	total_num_docs_=0;
+	docs_.clear();
+	terms_.clear();
+    }
+    /** returns the result as a String - useful for printing out results */
+    public String toString() {
+	String result = "";
+	result += "docs (ranks): ";
+	for (int i=0; i<docs_.size(); i++) {
+	    result += ((MGPPDocInfo)docs_.elementAt(i)).toString()+", ";
+	}
+	result += "\nterms: ";
+	for (int i=0; i<terms_.size(); i++) {
+	    result += ((MGPPTermInfo)terms_.elementAt(i)).toString()+", ";
+	}
+	result += "\nactual number of docs found = "+total_num_docs_;
+
+	return result;
+    }
+    /** a shorter representation - just terms and total docs - not the 
+	individual docnums and ranks */
+    public String toShortString() {
+	String result = "";
+	result += "\nterms: ";
+	for (int i=0; i<terms_.size(); i++) {
+	    result += ((MGPPTermInfo)terms_.elementAt(i)).toString()+", ";
+	}
+	result += "\nactual number of docs found = "+total_num_docs_;
+	return result;
+    }
+
+    // set methods used by c++ code
+    
+    public void setTotalDocs(long num) {
+	total_num_docs_=num;
+    }
+
+    public void addDoc(long doc, float rank) {
+	MGPPDocInfo doc_info = new MGPPDocInfo(doc, rank);
+	docs_.add(doc_info);
+    }
+
+    public void addTerm(String term, String tag, int stem, long match, long freq, String[] equivs) {
+	MGPPTermInfo ti = new MGPPTermInfo();
+	ti.term_=term;
+	ti.tag_=tag;
+	ti.stem_method_=stem;
+	ti.match_docs_=match;
+	ti.term_freq_=freq;
+	if (equivs!=null) {
+	  for (int i=0; i<equivs.length; i++) {
+	    ti.equiv_terms_.add(equivs[i]);
+	  }
+	}
+	terms_.add(ti);
+    }
+
+    // get methods for the java side
+    public Vector getDocs() {
+	return docs_;
+    }
+
+    public Vector getTerms() {
+	return terms_;
+    }
+
+    public long getTotalDocs() {
+	return total_num_docs_;
+    }
+       
+}
+
Index: trunk/gsdl3/src/java/org/greenstone/mgpp/MGPPTermInfo.java
===================================================================
--- trunk/gsdl3/src/java/org/greenstone/mgpp/MGPPTermInfo.java	(revision 3255)
+++ trunk/gsdl3/src/java/org/greenstone/mgpp/MGPPTermInfo.java	(revision 3255)
@@ -0,0 +1,46 @@
+package org.greenstone.mgpp;
+
+import java.util.Vector;
+
+/** TermInfo 'struct' class for a search result from mgpp
+ * used by MGPPQueryResult
+ * 
+ *
+ *@see MGPPQueryResult
+ */
+public class MGPPTermInfo {
+
+    /** the term itself */
+    public String term_=null;
+    /** the tag - level or metadata - for which the query was done */
+    public String tag_=null;
+    /** what stem and casefold method was used
+	0 = none
+	1 = casefold only
+	2 = stem only
+	3 = casefold and stem */
+    public int stem_method_=0;
+    /** the number of documents containing this term (where document is defined by the tag data */
+    public long match_docs_=0;
+    /** overall term freq  - word level*/
+    public long term_freq_=0;
+    /** list of stemmed and casefolded equivalent terms - if stem_method_ is non-zero 
+      - Vector of Strings */
+    public Vector equiv_terms_=null;
+
+    public MGPPTermInfo() {
+	equiv_terms_ = new Vector();
+    }
+	
+    /** output the class as a string */
+    public String toString() {
+	String result="";
+	result +="<"+tag_+">\""+term_+"\"stem("+stem_method_+")docs("+match_docs_;
+	result +=")freq("+term_freq_+")equiv terms(";
+	for (int i=0; i<equiv_terms_.size(); i++) {
+	    result += (String)equiv_terms_.elementAt(i)+", ";
+	}
+	result += ")";
+	return result;
+    }
+}
Index: trunk/gsdl3/src/java/org/greenstone/mgpp/MGPPWrapper.java
===================================================================
--- trunk/gsdl3/src/java/org/greenstone/mgpp/MGPPWrapper.java	(revision 3255)
+++ trunk/gsdl3/src/java/org/greenstone/mgpp/MGPPWrapper.java	(revision 3255)
@@ -0,0 +1,94 @@
+package org.greenstone.mgpp;
+
+import java.util.Vector;
+
+/** java wrapper class for access to mgpp in C++
+ *
+ * the native side implemented in MGPPWrapperImpl.cpp
+ * uses MGPPQueryResult to hold the result of a query. the 
+ * result of a getDocument is a String
+ * uses the jni
+ *
+ *@see MGPPQueryResult
+ */
+class MGPPWrapper {
+  
+    /** the query result
+     * will be filled in by runQuery
+     */
+    protected MGPPQueryResult mgpp_query_result_=null; 
+    /** pointer to c++ MGPPWrapperData class - cached indexData and queryInfo
+     */
+    protected long mgpp_data_ptr_;  
+
+    static {
+	System.loadLibrary("mgppjni");
+	initIDs();
+    }
+    
+    public MGPPWrapper() {
+	mgpp_query_result_ = new MGPPQueryResult();
+	initCppSide();
+    }
+
+    /** initialises field and method IDs for java side to enable access on
+	C++ side */
+    private static native void initIDs();
+
+    /** initialises the mgpp_data_ptr_ */
+    private native boolean initCppSide();
+
+    /** returns a document: number docnum at level level 
+     * the base_dir and text_path paths should join together to provide
+     * the absolute location of the mgpp text files eg ..../index/text/demo
+     */
+    public native String getDocument(String base_dir,
+				     String text_path,
+				     String level,
+				     int docnum );
+
+    /** load up the data structure for index 
+     * - maintains state between requests as can be slow  
+     * base_dir and text_path should join together to provide
+     * the absolute location of the mgpp index files eg ..../index/tt/demo 
+     */
+    public native boolean loadIndexData(String base_dir,
+					String index_path);
+    /** unloads the data */
+    public native boolean unloadIndexData();
+
+    // query param methods
+
+    /** if on=true, sets default stemming on  - its off by default*/
+    public native void setStem(boolean on);
+    /** if on=true, sets default casefolding on - its off by default */
+    public native void setCase(boolean on);
+    /** default is 50 */
+    public native void setMaxDocs(int num);
+    /** if on=true, sorts by rank, otherwise returns in build order - 
+	default is on */
+    public native void setSortByRank(boolean on);
+    /** if on=true, a query returns term freq info - default is on */
+    public native void setReturnTerms(boolean on);
+    /** sets the granularity of the  query  - default 'Section' */
+    public native void setQueryLevel(String level);
+    /** sets the granularity of the result - default 'Section' */
+    public native void setReturnLevel(String level);
+    /** sets the default boolean operator - AND(=1)/OR(=0) */
+    public native void setMatchMode(int mode);
+
+    /** returns a string with all the current query param settings */
+    public native String getQueryParams();
+
+    /** actually carry out the query. Use the set methods to set any query
+	params 
+    * writes the result to query_result
+    */
+    public native void runQuery(String query_string); 
+
+    /** get the result out of the wrapper */
+    public MGPPQueryResult getQueryResult() {
+	return mgpp_query_result_;
+    }
+    
+}
Index: trunk/gsdl3/src/java/org/greenstone/mgpp/Makefile
===================================================================
--- trunk/gsdl3/src/java/org/greenstone/mgpp/Makefile	(revision 3255)
+++ trunk/gsdl3/src/java/org/greenstone/mgpp/Makefile	(revision 3255)
@@ -0,0 +1,45 @@
+#############################################################
+#           makefile for Java and JavaCC files ...          #
+#############################################################
+#
+
+# JAVA
+GSDL3HOME=../../../../..
+
+JAVALIBDIR=$(GSDL3HOME)/lib/java
+JAVASRCDIR=$(GSDL3HOME)/src/java
+JNILIBRARYDIR=$(GSDL3HOME)/lib/cpp
+MGPPCPPSRCDIR=$(GSDL3HOME)/src/cpp/jni/mgpp
+
+#the base directory where to put class files
+JAVACLASSDIR=./classes
+
+#name/location of java compiler
+JAVAC=/usr/local/share/j2sdk1.4.0/bin/javac
+JAVAH=/usr/local/share/j2sdk1.4.0/bin/javah
+JAVA=/usr/local/share/j2sdk1.4.0/bin/java
+JAVADOC=/usr/local/share/j2sdk1.4.0/bin/javadoc
+
+JAVACOPTIONS= -deprecation -g -O
+
+CLASSPATH=$(JAVACLASSDIR):
+
+all: compile 
+
+setup:
+	mkdir -p $(JAVACLASSDIR)
+
+compile: setup
+	$(JAVAC) -d $(JAVACLASSDIR) -sourcepath $(JAVASRCDIR) -classpath $(CLASSPATH) $(JAVACOPTIONS) *.java
+	$(JAVAH) -classpath $(CLASSPATH) -d $(MGPPCPPSRCDIR) org.greenstone.mgpp.MGPPWrapper
+	jar cf mgpp.jar -C $(JAVACLASSDIR) org
+
+test: 
+	java -classpath $(CLASSPATH) org.greenstone.mgpp.Queryer /research/kjdon/home/gsdl/collect/mgppdemo/index tt/mgppdemo text/mgppdemo
+
+clean:
+	rm -rf $(JAVACLASSDIR) *.o mgpp.jar $(MGPPCPPSRCDIR)/org_greenstone_mgpp_MGPPWrapper.h
+
+install:
+	cp mgpp.jar $(JAVALIBDIR)/
+
Index: trunk/gsdl3/src/java/org/greenstone/mgpp/Queryer.java
===================================================================
--- trunk/gsdl3/src/java/org/greenstone/mgpp/Queryer.java	(revision 3255)
+++ trunk/gsdl3/src/java/org/greenstone/mgpp/Queryer.java	(revision 3255)
@@ -0,0 +1,176 @@
+package org.greenstone.mgpp;
+
+import java.util.Vector;
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+
+/** Queryer - java port of c++ Queryer 
+ * - uses MGPPWrapper to access mgpp
+ * only has get document and search - full text browse not implemented
+ *
+ * run as:
+ * java org.greenstone.mgpp.Queryer <basedir> <indexdir> <textdir>
+ *@see MGPPWrapper
+ */
+public class Queryer {
+  
+  /** outputs to std out a help message describing the commands used by 
+   * Queryer 
+   */
+  public void printHelp() {
+	
+	System.out.println( "commands available are:\n"+
+			    "\t.q\t\tquit\n"+
+			    "\t.h\t\tprint this help message\n"+
+			    "\t.d\t\tprint the current query parameter settings\n" +
+			    "\t.i<level>\tchange the search level to level\n"+
+			    "\t.l<level>\tchange the result level to level\n"+
+			    "\t.r0/.r1\t\tranking off/on\n"+
+			    "\t.t0/.t1\t\tquery type some/all\n"+
+			    "\t.c0/.c1\t\tcasefolding off/on\n"+
+			    "\t.s0/.s1\t\tstemming off/on\n"+
+			    "\t.o0/.o1\t\tshort output off/on\n"+
+			    "\t.m<num>\t\tset max docs to return to num\n\n"+
+			    "\t.p<docnum>\tprint document docnum\n"+
+			    "\t<query string>\t do a query\n");
+    }
+
+   
+    public static void main(String[] args) {
+	if (args.length != 3) {
+	    System.out.println("Usage: java org.greenstone.mgpp.Queryer <basedir> <indexdir> <textdir>");
+	    return;
+	}
+	
+	Queryer self = new Queryer();
+	
+	String base_dir = args[0];
+	String text_path = args[2];
+	String index_path = args[1];
+
+	// the jni class to access mgpp stuff
+	MGPPWrapper wrapper = new MGPPWrapper();
+	wrapper.loadIndexData(base_dir, index_path);
+	
+	// the return level
+	String level = "Section";
+
+	System.out.println("Welcome to Java Queryer :-)");
+	self.printHelp();
+
+	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
+	boolean shortOutput=false;
+
+	String command; // user input
+	char x; // the command letter
+	String data=null; // any auxiliary input to a command
+	while (true) {
+	  System.out.print(">"); // the prompt
+            try {
+                command = br.readLine();
+                command=command.trim();
+		if (command.startsWith(".")) {
+		    // a system command
+		    x = command.charAt(1);
+		    if (command.length() > 2) {
+			data = command.substring(2);
+			data = data.trim();
+			
+		    }
+		    switch (x) {
+		    case 'q': // clean up and exit
+			wrapper.unloadIndexData();
+			return;  
+		    case 'h': // print help message
+			self.printHelp();
+			break;
+		    case 'd': // print query param settings
+			String info = wrapper.getQueryParams();
+			System.out.println(info);
+			break;
+		    case 'p': // print doc
+			int docnum = Integer.parseInt(data);
+			String doc = wrapper.getDocument(base_dir, text_path, 
+							 level, docnum);
+			System.out.println(doc);
+			break;
+		    case 'm': //match docs
+			int match = Integer.parseInt(data);
+			wrapper.setMaxDocs(match);
+			break;
+		    case 's': // set stem on/off
+			int stem = Integer.parseInt(data);
+			if (stem==0 ){
+			    wrapper.setStem(false);
+			} else if(stem==1) {
+			    wrapper.setStem(true);
+			} else {
+			    System.err.println("Error: stem should be 0 or 1");
+			}
+			break;
+		    case 'c': // set case on/off
+			int casef = Integer.parseInt(data);
+			if (casef==0) {
+			    wrapper.setCase(false);
+			} else if (casef==1) {
+			    wrapper.setCase(true);
+			} else {
+			    System.err.println("Error: case should be 0 or 1");
+			}
+			break;
+		    case 'i': // set search level
+			wrapper.setQueryLevel(data);
+			break;
+		    case 'l': // set result level
+			wrapper.setReturnLevel(data);
+			break; 
+		    case 'r': // set rank on/off
+			int rank = Integer.parseInt(data);
+			if (rank==0) {
+			    wrapper.setSortByRank(false);
+			} else if (rank==1) {
+			    wrapper.setSortByRank(true);
+			} else {
+			    System.err.println("Error: rank should be 0 or 1");
+			}
+			break;
+		    case 't': // set query type some/all
+			int type = Integer.parseInt(data);
+			if (type==0 || type==1) {
+			    wrapper.setMatchMode(type);
+			} else {
+			    System.err.println("Error: type should be 0 (some) or 1 (all)");
+			}
+			break;
+		    case 'o': // set output short/long
+			int output = Integer.parseInt(data);
+			if (output==0) {
+			    shortOutput = false;
+			} else if (output==1) {
+			    shortOutput = true;
+			}else {
+			    System.err.println("Error: output should be 0 or 1");
+			}
+			break;
+		    }
+		}
+		else {
+		    // a query
+		    wrapper.runQuery(command);
+		    MGPPQueryResult res = wrapper.getQueryResult();
+		    if (shortOutput) {
+		      System.out.println(res.toShortString());
+		    } else {
+		      System.out.println(res.toString());
+		    }
+		}
+		    
+	    } catch (Exception e) {
+		System.out.println("Queryer error: "+e.getClass() + " "+e.getMessage());
+	    }
+
+	}
+    }
+
+
+}
