1 | package org.greenstone.mgpp;
|
---|
2 |
|
---|
3 | import java.util.Vector;
|
---|
4 |
|
---|
5 | /** a java version of QueryResult for mgpp
|
---|
6 | *
|
---|
7 | * contains get methods for the java side, and simple
|
---|
8 | * set methods to be called from c++ side
|
---|
9 | *
|
---|
10 | */
|
---|
11 | public class MGPPQueryResult {
|
---|
12 |
|
---|
13 | /** the list of MGPPDocInfo */
|
---|
14 | protected Vector docs_=null;
|
---|
15 | /** the list of MGPPTermInfo */
|
---|
16 | protected Vector terms_=null;
|
---|
17 | /** the total number of docs found - not likely to be the size of docs_*/
|
---|
18 | protected long total_num_docs_=0;
|
---|
19 | /** whether a syntax error has occurred */
|
---|
20 | protected boolean syntax_error_ = false;
|
---|
21 |
|
---|
22 | MGPPQueryResult() {
|
---|
23 | docs_ = new Vector();
|
---|
24 | terms_ = new Vector();
|
---|
25 | }
|
---|
26 | /** clear the info from the last query - should be called before setting any new docs/terms */
|
---|
27 | public void clear() {
|
---|
28 | total_num_docs_=0;
|
---|
29 | docs_.clear();
|
---|
30 | terms_.clear();
|
---|
31 | syntax_error_ = false;
|
---|
32 | }
|
---|
33 | /** returns the result as a String - useful for printing out results */
|
---|
34 | public String toString() {
|
---|
35 |
|
---|
36 | String result = "";
|
---|
37 | result += "docs (ranks): ";
|
---|
38 | for (int i=0; i<docs_.size(); i++) {
|
---|
39 | result += ((MGPPDocInfo)docs_.elementAt(i)).toString()+", ";
|
---|
40 | }
|
---|
41 | result += "\nterms: ";
|
---|
42 | for (int i=0; i<terms_.size(); i++) {
|
---|
43 | result += ((MGPPTermInfo)terms_.elementAt(i)).toString()+", ";
|
---|
44 | }
|
---|
45 | result += "\nactual number of docs found = "+total_num_docs_;
|
---|
46 |
|
---|
47 | return result;
|
---|
48 | }
|
---|
49 | /** a shorter representation - just terms and total docs - not the
|
---|
50 | individual docnums and ranks */
|
---|
51 | public String toShortString() {
|
---|
52 | String result = "";
|
---|
53 | result += "\nterms: ";
|
---|
54 | for (int i=0; i<terms_.size(); i++) {
|
---|
55 | result += ((MGPPTermInfo)terms_.elementAt(i)).toString()+", ";
|
---|
56 | }
|
---|
57 | result += "\nactual number of docs found = "+total_num_docs_;
|
---|
58 | return result;
|
---|
59 | }
|
---|
60 |
|
---|
61 | // set methods used by c++ code
|
---|
62 |
|
---|
63 | public void setTotalDocs(long num) {
|
---|
64 | total_num_docs_=num;
|
---|
65 | }
|
---|
66 |
|
---|
67 | public void addDoc(long doc, float rank) {
|
---|
68 | MGPPDocInfo doc_info = new MGPPDocInfo(doc, rank);
|
---|
69 | docs_.add(doc_info);
|
---|
70 | }
|
---|
71 |
|
---|
72 | public void addTerm(String term, String tag, int stem, long match, long freq, String[] equivs) {
|
---|
73 | MGPPTermInfo ti = new MGPPTermInfo();
|
---|
74 | ti.term_=term;
|
---|
75 | ti.tag_=tag;
|
---|
76 | ti.stem_method_=stem;
|
---|
77 | ti.match_docs_=match;
|
---|
78 | ti.term_freq_=freq;
|
---|
79 | if (equivs!=null) {
|
---|
80 | for (int i=0; i<equivs.length; i++) {
|
---|
81 | ti.equiv_terms_.add(equivs[i]);
|
---|
82 | }
|
---|
83 | }
|
---|
84 | terms_.add(ti);
|
---|
85 | }
|
---|
86 |
|
---|
87 | // get methods for the java side
|
---|
88 | public Vector getDocs() {
|
---|
89 | return docs_;
|
---|
90 | }
|
---|
91 |
|
---|
92 | public Vector getTerms() {
|
---|
93 | return terms_;
|
---|
94 | }
|
---|
95 |
|
---|
96 | public long getTotalDocs() {
|
---|
97 | return total_num_docs_;
|
---|
98 | }
|
---|
99 |
|
---|
100 | public void setSyntaxError(boolean error) {
|
---|
101 | syntax_error_ = error;
|
---|
102 | }
|
---|
103 |
|
---|
104 | public boolean hasSyntaxError() {
|
---|
105 | return syntax_error_;
|
---|
106 | }
|
---|
107 | }
|
---|
108 |
|
---|