Révision 3780
TXM/trunk/bundles/org.txm.treesearch.rcp/src/org/txm/treesearch/rcp/tester/TreeSearchTester.java (revision 3780) | ||
---|---|---|
1 | 1 |
package org.txm.treesearch.rcp.tester; |
2 | 2 |
|
3 |
import java.io.File; |
|
4 | 3 |
import java.util.List; |
5 | 4 |
|
6 | 5 |
import org.eclipse.core.expressions.PropertyTester; |
7 |
import org.txm.searchengine.cqp.corpus.MainCorpus;
|
|
6 |
import org.txm.searchengine.cqp.corpus.CQPCorpus;
|
|
8 | 7 |
import org.txm.treesearch.command.ComputeTreeSearch; |
9 | 8 |
|
10 | 9 |
/** |
... | ... | |
39 | 38 |
} |
40 | 39 |
|
41 | 40 |
receiver = l.get(0); |
42 |
if (!(receiver instanceof MainCorpus)) return false;
|
|
41 |
if (!(receiver instanceof CQPCorpus)) return false;
|
|
43 | 42 |
|
44 |
MainCorpus corpus = (MainCorpus) receiver;
|
|
45 |
if (!(receiver instanceof MainCorpus)) {
|
|
43 |
CQPCorpus corpus = (CQPCorpus) receiver;
|
|
44 |
if (!(receiver instanceof CQPCorpus)) {
|
|
46 | 45 |
return false; |
47 | 46 |
} |
48 | 47 |
|
TXM/trunk/bundles/org.txm.tigersearch.rcp/src/org/txm/function/tigersearch/TIGERSearch.java (revision 3780) | ||
---|---|---|
246 | 246 |
pQuery = new TIGERQuery("root(#n1)"); //$NON-NLS-1$ |
247 | 247 |
} |
248 | 248 |
|
249 |
tsresult = tscorpus.query(pQuery.getQueryString()); |
|
249 |
// tsresult = tscorpus.query(pQuery.getQueryString()); |
|
250 |
tsresult = TIGERSearchEngine.getInstance().queryTIGER(this.getCorpus(), pQuery); |
|
250 | 251 |
tsresult.getFirst(); |
251 | 252 |
|
252 | 253 |
pIndex = 0; |
TXM/trunk/bundles/org.txm.tigersearch.rcp/src/org/txm/searchengine/ts/TSCorpus.java (revision 3780) | ||
---|---|---|
71 | 71 |
boolean initok = false; |
72 | 72 |
|
73 | 73 |
/** The results. */ |
74 |
HashMap<Integer, TSResult> results = new HashMap<>();
|
|
74 |
HashMap<String, TSResult> results = new HashMap<>();
|
|
75 | 75 |
|
76 | 76 |
// Additional data for corpus alignment with TXM base corpus (CQP corpus) |
77 | 77 |
RandomAccessFile offsetsRAFile = null; |
... | ... | |
303 | 303 |
* @throws Exception |
304 | 304 |
*/ |
305 | 305 |
public TSResult query(String query, int sent_min, int sent_max, int match_max) throws Exception { |
306 |
if (results.containsKey(query.hashCode())) |
|
307 |
return results.get(query.hashCode()); |
|
306 |
String skey = query+ " "+sent_min+" "+sent_max+" "+match_max; |
|
307 |
if (results.containsKey(skey)) { |
|
308 |
return results.get(skey); |
|
309 |
} |
|
308 | 310 |
|
309 | 311 |
TSResult rez = new TSResult(query, this, sent_min, sent_max, match_max); |
310 |
results.put(query.hashCode(), rez);
|
|
312 |
results.put(skey, rez);
|
|
311 | 313 |
return rez; |
312 | 314 |
} |
313 | 315 |
|
TXM/trunk/bundles/org.txm.tigersearch.rcp/src/org/txm/searchengine/ts/TIGERSearchEngine.java (revision 3780) | ||
---|---|---|
1 | 1 |
package org.txm.searchengine.ts; |
2 | 2 |
|
3 | 3 |
import java.io.File; |
4 |
import java.io.FileFilter; |
|
5 | 4 |
import java.io.FileNotFoundException; |
6 | 5 |
import java.io.IOException; |
7 | 6 |
import java.io.PrintWriter; |
... | ... | |
10 | 9 |
import java.nio.MappedByteBuffer; |
11 | 10 |
import java.nio.channels.FileChannel; |
12 | 11 |
import java.util.ArrayList; |
13 |
import java.util.Arrays; |
|
14 | 12 |
import java.util.HashMap; |
15 | 13 |
import java.util.LinkedHashSet; |
16 | 14 |
import java.util.List; |
... | ... | |
27 | 25 |
import org.txm.searchengine.core.Query; |
28 | 26 |
import org.txm.searchengine.core.SearchEngine; |
29 | 27 |
import org.txm.searchengine.core.SearchEngineProperty; |
28 |
import org.txm.searchengine.core.SearchEnginesManager; |
|
30 | 29 |
import org.txm.searchengine.core.Selection; |
31 | 30 |
import org.txm.searchengine.cqp.AbstractCqiClient; |
32 | 31 |
import org.txm.searchengine.cqp.CQPSearchEngine; |
... | ... | |
62 | 61 |
HashMap<CorpusBuild, TSCorpus> corpora = null; |
63 | 62 |
|
64 | 63 |
public TSCorpus getTSCorpus(CorpusBuild corpus) { |
64 |
|
|
65 | 65 |
CorpusBuild root = corpus.getRootCorpusBuild(); |
66 | 66 |
TSCorpus tscorpus = corpora.get(root); |
67 | 67 |
if (tscorpus != null) { |
... | ... | |
183 | 183 |
public Selection query(CorpusBuild corpus, IQuery query, String name, boolean saveQuery) throws Exception { |
184 | 184 |
|
185 | 185 |
TSCorpus tcorpus = this.getTSCorpus(corpus); |
186 |
TSResult result = queryTIGER(corpus, query); |
|
187 |
|
|
188 |
if (result == null) { // no result |
|
189 |
return new EmptySelection(query); |
|
190 |
} |
|
191 |
|
|
192 |
return fromTIGERMatchToSelection(tcorpus, result, query, corpus); |
|
193 |
} |
|
194 |
|
|
195 |
public TSResult queryTIGER(CorpusBuild corpus, IQuery query) throws Exception { |
|
196 |
|
|
197 |
TSCorpus tcorpus = this.getTSCorpus(corpus); |
|
186 | 198 |
TSResult result = null; |
187 | 199 |
if (corpus == corpus.getRootCorpusBuild() || !(corpus instanceof CQPCorpus)) { // root corpus or something not a CQPCorpus |
188 | 200 |
result = tcorpus.query(query.getQueryString().replace("\n", " ")); |
... | ... | |
192 | 204 |
AbstractCqiClient CQI = CQPSearchEngine.getCqiClient(); |
193 | 205 |
List<? extends Match> matches = cqpCorpus.getMatches(); |
194 | 206 |
if (matches.size() == 0) { |
195 |
return new EmptySelection(query);
|
|
207 |
return result;
|
|
196 | 208 |
} |
197 | 209 |
int[] cpos = { matches.get(0).getStart(), matches.get(matches.size() - 1).getEnd() }; |
198 |
int[] structs = CQI.cpos2Struc(cqpCorpus.getStructuralUnit("s").getProperty("n").getQualifiedName(), cpos); |
|
199 |
if (structs.length == 0) { |
|
200 |
return new EmptySelection(query); |
|
210 |
|
|
211 |
int[] starts = tcorpus.getSentenceStartPositions(); |
|
212 |
int sent_max = starts.length; |
|
213 |
int sent_min = 0; |
|
214 |
for (int i = 0 ; i < starts.length ; i++) { |
|
215 |
if (starts[i] < cpos[0]) { |
|
216 |
sent_min = i; |
|
217 |
} else if (starts[i] > cpos[1]) { |
|
218 |
sent_max = i; |
|
219 |
break; |
|
220 |
} |
|
201 | 221 |
} |
202 |
int sent_min = structs[0]; |
|
203 |
int sent_max = structs[structs.length - 1]; |
|
222 |
|
|
204 | 223 |
Log.finest("QUERYING sentences: " + sent_min + " -> " + sent_max); |
205 |
result = tcorpus.query(query.getQueryString().replace("\n", " "), sent_min, sent_max + 1, -1);
|
|
224 |
result = tcorpus.query(query.getQueryString().replace("\n", " "), sent_min, sent_max, -1); |
|
206 | 225 |
} |
207 | 226 |
|
208 |
return fromTIGERMatchToSelection(tcorpus, result, query, corpus);
|
|
227 |
return result;
|
|
209 | 228 |
} |
210 | 229 |
|
211 | 230 |
public static Selection fromTIGERMatchToSelection(TSCorpus tcorpus, TSResult result, IQuery query, CorpusBuild corpus) throws IndexException { |
... | ... | |
621 | 640 |
} |
622 | 641 |
return null; |
623 | 642 |
} |
643 |
|
|
644 |
public static TIGERSearchEngine getInstance() { |
|
645 |
return (TIGERSearchEngine) SearchEnginesManager.getTIGERSearchEngine(); |
|
646 |
} |
|
624 | 647 |
} |
Formats disponibles : Unified diff