1 | /*
|
---|
2 | * MGQueryResult.java
|
---|
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 | package org.greenstone.mg;
|
---|
20 |
|
---|
21 |
|
---|
22 | import java.util.Vector;
|
---|
23 |
|
---|
24 |
|
---|
25 | /** a java version of QueryResult for mg
|
---|
26 | *
|
---|
27 | * contains get methods for the java side, and simple
|
---|
28 | * set methods to be called from c side
|
---|
29 | *
|
---|
30 | */
|
---|
31 | public class MGQueryResult
|
---|
32 | {
|
---|
33 | /** the list of MGDocInfo */
|
---|
34 | protected Vector docs_ = null;
|
---|
35 | /** the list of MGTermInfo */
|
---|
36 | protected Vector terms_ = null;
|
---|
37 | /** the total number of docs found - not likely to be the size of docs_ */
|
---|
38 | protected long total_num_docs_ = 0;
|
---|
39 |
|
---|
40 |
|
---|
41 | MGQueryResult() {
|
---|
42 | docs_ = new Vector();
|
---|
43 | terms_ = new Vector();
|
---|
44 | }
|
---|
45 |
|
---|
46 |
|
---|
47 | /** clear the info from the last query
|
---|
48 | should be called before setting any new docs/terms */
|
---|
49 | public void clear() {
|
---|
50 | total_num_docs_ = 0;
|
---|
51 | docs_.clear();
|
---|
52 | terms_.clear();
|
---|
53 | }
|
---|
54 |
|
---|
55 |
|
---|
56 | /** returns the result as a String - useful for printing out results */
|
---|
57 | public String toString()
|
---|
58 | {
|
---|
59 | String result = "";
|
---|
60 | result += "docs (ranks): ";
|
---|
61 | for (int i = 0; i < docs_.size(); i++) {
|
---|
62 | if (i > 0) result += ", ";
|
---|
63 | result += ((MGDocInfo) docs_.elementAt(i)).toString();
|
---|
64 | }
|
---|
65 | result += "\nterms: ";
|
---|
66 | for (int i = 0; i < terms_.size(); i++) {
|
---|
67 | if (i > 0) result += ", ";
|
---|
68 | result += ((MGTermInfo) terms_.elementAt(i)).toString();
|
---|
69 | }
|
---|
70 | result += "\nactual number of docs found = " + total_num_docs_;
|
---|
71 | return result;
|
---|
72 | }
|
---|
73 |
|
---|
74 |
|
---|
75 | /** a shorter representation - just terms and total docs - not the
|
---|
76 | individual docnums and ranks */
|
---|
77 | public String toShortString() {
|
---|
78 | String result = "";
|
---|
79 | result += "\nterms: ";
|
---|
80 | for (int i = 0; i < terms_.size(); i++) {
|
---|
81 | if (i > 0) result += ", ";
|
---|
82 | result += ((MGTermInfo) terms_.elementAt(i)).toString();
|
---|
83 | }
|
---|
84 | result += "\nactual number of docs found = "+total_num_docs_;
|
---|
85 | return result;
|
---|
86 | }
|
---|
87 |
|
---|
88 |
|
---|
89 | // set methods used by c++ code
|
---|
90 |
|
---|
91 | public void setTotalDocs(long num) {
|
---|
92 | total_num_docs_=num;
|
---|
93 | }
|
---|
94 |
|
---|
95 |
|
---|
96 | public void addDoc(long doc, float rank) {
|
---|
97 | MGDocInfo doc_info = new MGDocInfo(doc, rank);
|
---|
98 | System.out.println("(Java) Added doc " + doc_info);
|
---|
99 |
|
---|
100 | docs_.add(doc_info);
|
---|
101 | }
|
---|
102 |
|
---|
103 |
|
---|
104 | // public void addTerm(String term, int stem, long match, long freq)
|
---|
105 | public void addTerm(String term, String tag, int stem,
|
---|
106 | long match, long freq, String[] equivs)
|
---|
107 | {
|
---|
108 | MGTermInfo ti = new MGTermInfo();
|
---|
109 | ti.term_ = term;
|
---|
110 | ti.tag_ = tag;
|
---|
111 | ti.stem_method_ = stem;
|
---|
112 | ti.match_docs_ = match;
|
---|
113 | ti.term_freq_ = freq;
|
---|
114 | if (equivs != null) {
|
---|
115 | for (int i = 0; i < equivs.length; i++) {
|
---|
116 | ti.equiv_terms_.add(equivs[i]);
|
---|
117 | }
|
---|
118 | }
|
---|
119 | System.out.println("(Java) Added term " + ti);
|
---|
120 |
|
---|
121 | terms_.add(ti);
|
---|
122 | }
|
---|
123 |
|
---|
124 |
|
---|
125 | // Get methods for the java side - GS2MGSearch.java, GS2MGRetrieve.java
|
---|
126 | public Vector getDocs() {
|
---|
127 | return docs_;
|
---|
128 | }
|
---|
129 |
|
---|
130 |
|
---|
131 | public Vector getTerms() {
|
---|
132 | return terms_;
|
---|
133 | }
|
---|
134 |
|
---|
135 |
|
---|
136 | public long getTotalDocs() {
|
---|
137 | return total_num_docs_;
|
---|
138 | }
|
---|
139 | }
|
---|
140 |
|
---|