source: main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/GoogleNgramMGPPSearch.java@ 24394

Last change on this file since 24394 was 24394, checked in by davidb, 13 years ago

Through the audioDB extension we now support a form of content-based audio/music searching. These commited changes reflect this generalization in our Service inheritance hierarchy for searching. Basically, what used to be thought of as a search service implied a *text* search service.

File size: 4.8 KB
Line 
1/*
2 * GS2MGPPSearch.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 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 */
18package org.greenstone.gsdl3.service;
19
20
21// Greenstone classes
22import org.greenstone.mgpp.*;
23import org.greenstone.gsdl3.util.*;
24import org.w3c.dom.Element;
25
26import java.util.Vector;
27import java.util.ArrayList;
28import java.util.Collections;
29import org.apache.log4j.*;
30
31/**
32 *
33 * @author <a href="mailto:[email protected]">Shaoqun Wu</a>
34 */
35
36public class GoogleNgramMGPPSearch
37 extends GS2MGPPSearch {
38 static Logger logger = Logger.getLogger(org.greenstone.gsdl3.service.GoogleNgramMGPPSearch.class.getName());
39
40 /** constructor */
41 public GoogleNgramMGPPSearch(){
42 super();
43 }
44
45 /** configure this service */
46 public boolean configure(Element info, Element extra_info) {
47 if (!super.configure(info, extra_info)){
48 return false;
49 }
50
51 this.default_max_docs = "-1";
52 this.default_hits_per_page = "30";
53 this.does_stem = false;
54 this.does_paging = true;
55 return true;
56 }
57
58 // sort the doc_nums by their frequency
59 protected String [] getDocIDs(Object query_result) {
60 try{
61 Vector docs = ((MGPPQueryResult)query_result).getDocs();
62 //ArrayList docList_past = new ArrayList();
63 //ArrayList docList_future = new ArrayList();
64 //ArrayList docList_present = new ArrayList();
65
66 ArrayList docList = new ArrayList();
67
68 for (int d = 0; d < docs.size(); d++) {
69 String num = Long.toString((((MGPPDocInfo) docs.elementAt(d)).num_));
70 String doc_id = internalNum2OID(num);
71 DBInfo dbInfo = this.gs_doc_db.getInfo(doc_id);
72 String fre = (String)dbInfo.getInfo("Frequency");
73 String tense = (String)dbInfo.getInfo("Tense");
74
75 if(!fre.equals("")){
76 // if (tense.equals("past")){
77 // docList_past.add(new DocWrapper(num,Integer.parseInt(fre),tense));
78 // }
79 // else{
80 // if (tense.equals("future")){
81 // docList_future.add(new DocWrapper(num,Integer.parseInt(fre),tense));
82 // }
83 // else{
84 // if(tense.equals("present")){
85 // docList_present.add(new DocWrapper(num,Integer.parseInt(fre),tense));
86 // }
87 // }
88 //}
89 docList.add(new DocWrapper(num,Integer.parseInt(fre),tense));
90 }
91
92 }
93
94
95 //Collections.sort(docList_past);
96 //Collections.sort(docList_future);
97 //Collections.sort(docList_present);
98
99 Collections.sort(docList);
100 int i_pa = 0;
101 int i_f = 0;
102 int i_pre = 0;
103
104 //String [] doc_nums = new String [docList_past.size()+docList_future.size()+docList_present.size()];
105 String [] doc_nums = new String [docList.size()];
106 int interval = 10;
107
108 for(int d = 0; d < doc_nums.length; d++){
109
110 // for(;i_pre < docList_present.size() && interval > 0;i_pre++){
111// doc_nums[d] = ((DocWrapper)docList_present.get(i_pre)).num;
112// d++;
113// interval--;
114// }
115
116// interval = 10+interval;
117
118// for(;i_pa < docList_past.size() && interval > 0;i_pa++){
119// doc_nums[d] = ((DocWrapper)docList_past.get(i_pa)).num;
120// d++;
121// interval--;
122// }
123
124
125// interval = 10+interval;
126
127// for(;i_f < docList_future.size() && interval > 0;i_f++){
128// doc_nums[d] = ((DocWrapper)docList_future.get(i_f)).num;
129// d++;
130// interval--;
131// }
132
133// interval = 10;
134
135 doc_nums[d] = ((DocWrapper)docList.get(d)).num;
136
137 }
138
139 return doc_nums;
140 }
141 catch(Exception e){
142 e.printStackTrace();
143 }
144
145 return null;
146 }
147
148 static class DocWrapper implements Comparable{
149 public int fre = 0;
150 public String num = "";
151 public String tense = "";
152
153
154 public DocWrapper(String num, int fre, String tense){
155 this.fre = fre;
156 this.num = num;
157 this.tense = tense;
158 }
159
160 public int compareTo(Object o){
161
162 if (!(o instanceof DocWrapper)) return -1;
163 DocWrapper docIn = (DocWrapper)o;
164 if (num.equals(docIn.num)){
165 return 0;
166 }
167
168 if (fre > docIn.fre) return -1;
169 return 1;
170 }
171
172 public boolean equals(Object o){
173 if (!(o instanceof DocWrapper)) return false;
174 DocWrapper docIn = (DocWrapper)o;
175 if (num.equals(docIn.num)){
176 return true;
177 }
178 return false;
179 }
180
181
182 }
183
184
185}
186
187
Note: See TracBrowser for help on using the repository browser.