Révision 786
tmp/org.txm.statsengine.core/src/org/txm/statsengine/core/StatsEnginesManager.java (revision 786) | ||
---|---|---|
11 | 11 |
* @author sjacquot |
12 | 12 |
* |
13 | 13 |
*/ |
14 |
//FIXME: useless class, the type and priority/order should be defined in org.txm.core.engines.EnginesManager extension point |
|
14 | 15 |
public class StatsEnginesManager extends EnginesManager<StatsEngine> { |
15 | 16 |
|
16 | 17 |
public static StatsEngine getREngine() { |
tmp/org.txm.statsengine.core/src/org/txm/statsengine/core/StatsEngine.java (revision 786) | ||
---|---|---|
2 | 2 |
|
3 | 3 |
import org.txm.core.engines.Engine; |
4 | 4 |
|
5 |
//FIXME: useless class |
|
5 | 6 |
public abstract class StatsEngine implements Engine { |
6 | 7 |
|
7 | 8 |
public static final String EXTENSION_POINT_ID = "org.txm.statsengine.core.StatsEngine"; //$NON-NLS-1$ |
tmp/org.txm.oriflamms.rcp/src/org/txm/oriflamms/functions/AbbreviationsAndLines.java (revision 786) | ||
---|---|---|
6 | 6 |
|
7 | 7 |
import org.txm.Toolbox; |
8 | 8 |
import org.txm.searchengine.cqp.AbstractCqiClient; |
9 |
import org.txm.searchengine.cqp.CQPEngine; |
|
9 |
import org.txm.searchengine.cqp.CQPSearchEngine;
|
|
10 | 10 |
import org.txm.searchengine.cqp.clientExceptions.CqiClientException; |
11 | 11 |
import org.txm.searchengine.cqp.clientExceptions.UnexpectedAnswerException; |
12 | 12 |
import org.txm.searchengine.cqp.corpus.Corpus; |
... | ... | |
73 | 73 |
|
74 | 74 |
int[] positions = new int[length]; |
75 | 75 |
for (int i = 0 ; i < length ; i++) positions[i] = from++; |
76 |
AbstractCqiClient CQI = CQPEngine.getCqiClient(); |
|
76 |
AbstractCqiClient CQI = CQPSearchEngine.getCqiClient();
|
|
77 | 77 |
|
78 | 78 |
String[] abbrNs = CQI.cpos2Str(abbrn.getQualifiedName(), positions); |
79 | 79 |
String[] allLetters = CQI.cpos2Str(lettersAll.getQualifiedName(), positions); |
tmp/org.txm.oriflamms.rcp/src/org/txm/oriflamms/functions/OriflammsFunction.java (revision 786) | ||
---|---|---|
11 | 11 |
|
12 | 12 |
import org.txm.Toolbox; |
13 | 13 |
import org.txm.searchengine.cqp.AbstractCqiClient; |
14 |
import org.txm.searchengine.cqp.CQPEngine; |
|
14 |
import org.txm.searchengine.cqp.CQPSearchEngine;
|
|
15 | 15 |
import org.txm.searchengine.cqp.clientExceptions.CqiClientException; |
16 | 16 |
import org.txm.searchengine.cqp.clientExceptions.UnexpectedAnswerException; |
17 | 17 |
import org.txm.searchengine.cqp.corpus.Corpus; |
... | ... | |
31 | 31 |
protected Corpus corpus; |
32 | 32 |
protected File tsvFile; |
33 | 33 |
|
34 |
protected AbstractCqiClient CQI = CQPEngine.getCqiClient(); |
|
34 |
protected AbstractCqiClient CQI = CQPSearchEngine.getCqiClient();
|
|
35 | 35 |
|
36 | 36 |
protected StructuralUnit text_su; |
37 | 37 |
protected StructuralUnitProperty text_id; |
tmp/org.txm.rcp/src/main/java/org/txm/rcp/handlers/BaseAbstractHandler.java (revision 786) | ||
---|---|---|
18 | 18 |
import org.eclipse.ui.handlers.IHandlerService; |
19 | 19 |
import org.txm.core.preferences.TXMPreferences; |
20 | 20 |
import org.txm.rcp.views.corpora.CorporaView; |
21 |
import org.txm.searchengine.cqp.CQPEngine; |
|
21 |
import org.txm.searchengine.cqp.CQPSearchEngine;
|
|
22 | 22 |
import org.txm.statsengine.r.core.RStatsEngine; |
23 | 23 |
import org.txm.statsengine.r.core.messages.RCoreMessages; |
24 | 24 |
import org.txm.utils.logger.Log; |
... | ... | |
58 | 58 |
* @return true if the corpus engine is available |
59 | 59 |
*/ |
60 | 60 |
public boolean checkCorpusEngine() { |
61 |
if (!CQPEngine.isInitialized()) { |
|
61 |
if (!CQPSearchEngine.isInitialized()) {
|
|
62 | 62 |
System.out.println("Corpus Engine is not ready, canceling command."); |
63 | 63 |
Log.severe("Corpus Engine is not ready, canceling command."); |
64 | 64 |
return false; |
tmp/org.txm.rcp/src/main/java/org/txm/rcp/handlers/scripts/ExecuteImportScript.java (revision 786) | ||
---|---|---|
65 | 65 |
import org.txm.rcp.utils.GSERunner; |
66 | 66 |
import org.txm.rcp.utils.JobHandler; |
67 | 67 |
import org.txm.rcp.views.corpora.CorporaView; |
68 |
import org.txm.searchengine.cqp.CQPEngine; |
|
68 |
import org.txm.searchengine.cqp.CQPSearchEngine;
|
|
69 | 69 |
import org.txm.searchengine.cqp.corpus.Corpus; |
70 | 70 |
import org.txm.searchengine.cqp.corpus.MainCorpus; |
71 | 71 |
import org.txm.tokenizer.TokenizerClasses; |
... | ... | |
205 | 205 |
} |
206 | 206 |
} |
207 | 207 |
|
208 |
if (CQPEngine.isInitialized()) Toolbox.getEngineManager(EngineType.SEARCH).stopEngines(); |
|
208 |
if (CQPSearchEngine.isInitialized()) Toolbox.getEngineManager(EngineType.SEARCH).stopEngines();
|
|
209 | 209 |
final BaseParameters p = params; |
210 | 210 |
JobHandler jobhandler = new JobHandler(TXMUIMessages.RunGroovyScript_0 |
211 | 211 |
+ script.getAbsolutePath()) { //$NON-NLS-1$ |
... | ... | |
294 | 294 |
System.out.println(NLS.bind(TXMUIMessages.RunGroovyScript_8, e)); |
295 | 295 |
org.txm.rcp.utils.Logger.printStackTrace(e); |
296 | 296 |
} finally { |
297 |
if (!CQPEngine.isInitialized()) { // the import failed |
|
297 |
if (!CQPSearchEngine.isInitialized()) { // the import failed
|
|
298 | 298 |
monitor.setTaskName("Restarting Toolbox search engine"); //$NON-NLS-1$ |
299 | 299 |
Toolbox.getEngineManager(EngineType.SEARCH).restartEngines(); |
300 | 300 |
|
tmp/org.txm.rcp/src/main/java/org/txm/rcp/testers/ToolboxTester.java (revision 786) | ||
---|---|---|
4 | 4 |
import org.txm.Toolbox; |
5 | 5 |
import org.txm.Toolbox; |
6 | 6 |
import org.txm.core.engines.EngineType; |
7 |
import org.txm.searchengine.cqp.CQPEngine; |
|
7 |
import org.txm.searchengine.cqp.CQPSearchEngine;
|
|
8 | 8 |
|
9 | 9 |
/** |
10 | 10 |
* PropertyTester to check Toolbox states |
... | ... | |
30 | 30 |
//System.out.println("TEST: "+property+" = "+Toolbox.getEngineManager(EngineType.STAT).getEngine("R").getState()); //$NON-NLS-1$ //$NON-NLS-2$ |
31 | 31 |
return Toolbox.getEngineManager(EngineType.STATS).getEngine("R").getState(); |
32 | 32 |
} else if (PROPERTY_SEARCH_ENGINE_READY.equals(property)) { |
33 |
System.out.println("TEST: "+property+" = "+CQPEngine.isInitialized()); //$NON-NLS-1$ //$NON-NLS-2$ |
|
34 |
return CQPEngine.isInitialized(); |
|
33 |
System.out.println("TEST: "+property+" = "+CQPSearchEngine.isInitialized()); //$NON-NLS-1$ //$NON-NLS-2$
|
|
34 |
return CQPSearchEngine.isInitialized();
|
|
35 | 35 |
} |
36 | 36 |
|
37 | 37 |
return false; |
tmp/org.txm.rcp/src/main/java/org/txm/rcp/commands/function/ComputeIntersection.java (revision 786) | ||
---|---|---|
13 | 13 |
import org.eclipse.ui.handlers.HandlerUtil; |
14 | 14 |
import org.txm.Toolbox; |
15 | 15 |
import org.txm.searchengine.cqp.AbstractCqiClient; |
16 |
import org.txm.searchengine.cqp.CQPEngine; |
|
16 |
import org.txm.searchengine.cqp.CQPSearchEngine;
|
|
17 | 17 |
import org.txm.searchengine.cqp.corpus.Corpus; |
18 | 18 |
import org.txm.searchengine.cqp.corpus.CqpObject; |
19 | 19 |
import org.txm.searchengine.cqp.corpus.MainCorpus; |
... | ... | |
58 | 58 |
String id2 = subcorpora.get(1).getQualifiedCqpId(); |
59 | 59 |
String cqpid = CqpObject.subcorpusNamePrefix + Corpus.getNextSubcorpusCounter(); |
60 | 60 |
String command = "inter"; |
61 |
AbstractCqiClient CQI = CQPEngine.getCqiClient(); |
|
61 |
AbstractCqiClient CQI = CQPSearchEngine.getCqiClient();
|
|
62 | 62 |
|
63 | 63 |
//TODO: finish the command |
64 | 64 |
|
tmp/org.txm.backtomedia.rcp/src/org/txm/backtomedia/commands/function/BackToMedia.java (revision 786) | ||
---|---|---|
41 | 41 |
import org.txm.concordance.core.functions.Line; |
42 | 42 |
import org.txm.concordance.rcp.editors.ConcordanceEditor; |
43 | 43 |
import org.txm.core.preferences.TXMPreferences; |
44 |
import org.txm.searchengine.cqp.CQPEngine; |
|
44 |
import org.txm.searchengine.cqp.CQPSearchEngine;
|
|
45 | 45 |
import org.txm.searchengine.cqp.corpus.Corpus; |
46 | 46 |
import org.txm.searchengine.cqp.corpus.Property; |
47 | 47 |
import org.txm.searchengine.cqp.corpus.StructuralUnit; |
... | ... | |
131 | 131 |
int leftPosition = Math.max(keywordPosition - line.getConcordance().getLeftContextSize(), 0); |
132 | 132 |
int rightPosition = Math.min(keywordPosition + line.getConcordance().getRightContextSize(), corpus.getSize()); |
133 | 133 |
int[] positions = {leftPosition, rightPosition}; |
134 |
String[] times = CQPEngine.getCqiClient().cpos2Str(timeP.getQualifiedName(), positions); |
|
134 |
String[] times = CQPSearchEngine.getCqiClient().cpos2Str(timeP.getQualifiedName(), positions);
|
|
135 | 135 |
sStartTime = times[0]; |
136 | 136 |
sEndTime = times[1]; |
137 | 137 |
} else { |
tmp/org.txm.internalview.rcp/src/org/txm/internalview/rcp/editors/InternalViewEditor.java (revision 786) | ||
---|---|---|
35 | 35 |
import org.txm.rcp.swt.widget.NewNavigationWidget; |
36 | 36 |
import org.txm.rcp.swt.widget.PropertiesSelector; |
37 | 37 |
import org.txm.rcp.swt.widget.structures.StructuralUnitsComboViewer; |
38 |
import org.txm.searchengine.cqp.CQPEngine; |
|
38 |
import org.txm.searchengine.cqp.CQPSearchEngine;
|
|
39 | 39 |
import org.txm.searchengine.cqp.clientExceptions.CqiClientException; |
40 | 40 |
import org.txm.searchengine.cqp.corpus.Corpus; |
41 | 41 |
import org.txm.searchengine.cqp.corpus.Property; |
... | ... | |
364 | 364 |
sup = s; |
365 | 365 |
break; |
366 | 366 |
} |
367 |
n = CQPEngine.getCqiClient().cpos2Struc(sup.getQualifiedName(), cpos); |
|
367 |
n = CQPSearchEngine.getCqiClient().cpos2Struc(sup.getQualifiedName(), cpos);
|
|
368 | 368 |
return goToPage(n[0]); |
369 | 369 |
} catch (Exception e) { |
370 | 370 |
System.out.println("Error while internal view go back to " + line); |
tmp/org.txm.internalview.core/src/org/txm/internalview/core/functions/InternalView.java (revision 786) | ||
---|---|---|
14 | 14 |
import org.txm.core.results.TXMResult; |
15 | 15 |
import org.txm.internalview.core.messages.InternalViewCoreMessages; |
16 | 16 |
import org.txm.internalview.core.preferences.InternalViewPreferences; |
17 |
import org.txm.searchengine.cqp.CQPEngine; |
|
17 |
import org.txm.searchengine.cqp.CQPSearchEngine;
|
|
18 | 18 |
import org.txm.searchengine.cqp.clientExceptions.CqiClientException; |
19 | 19 |
import org.txm.searchengine.cqp.corpus.Corpus; |
20 | 20 |
import org.txm.searchengine.cqp.corpus.Property; |
... | ... | |
262 | 262 |
String str = InternalViewCoreMessages.InternalView_3; |
263 | 263 |
for (Property sup : structuralUnitsProperties) { |
264 | 264 |
int[] array = {getCurrentPage()}; |
265 |
str += " "+sup.getName()+"="+CQPEngine.getCqiClient().struc2Str(sup.getQualifiedName(), array)[0]; //$NON-NLS-1$ //$NON-NLS-2$ |
|
265 |
str += " "+sup.getName()+"="+CQPSearchEngine.getCqiClient().struc2Str(sup.getQualifiedName(), array)[0]; //$NON-NLS-1$ //$NON-NLS-2$
|
|
266 | 266 |
} |
267 | 267 |
return str; |
268 | 268 |
} |
tmp/org.txm.textsbalance.core/src/org/txm/textsbalance/core/functions/TextsBalance.java (revision 786) | ||
---|---|---|
14 | 14 |
import org.txm.core.results.Parameter; |
15 | 15 |
import org.txm.core.results.TXMParameters; |
16 | 16 |
import org.txm.searchengine.cqp.AbstractCqiClient; |
17 |
import org.txm.searchengine.cqp.CQPEngine; |
|
17 |
import org.txm.searchengine.cqp.CQPSearchEngine;
|
|
18 | 18 |
import org.txm.searchengine.cqp.NetCqiClient; |
19 | 19 |
import org.txm.searchengine.cqp.clientExceptions.CqiClientException; |
20 | 20 |
import org.txm.searchengine.cqp.corpus.Corpus; |
... | ... | |
155 | 155 |
} |
156 | 156 |
} |
157 | 157 |
else { |
158 |
AbstractCqiClient CQI = CQPEngine.getCqiClient(); |
|
158 |
AbstractCqiClient CQI = CQPSearchEngine.getCqiClient();
|
|
159 | 159 |
if (CQI instanceof NetCqiClient) { |
160 | 160 |
System.out.println("Error: CQP eval method only available with CQP memory mode"); |
161 | 161 |
return false; |
tmp/org.txm.querycooccurrences.rcp/src/org/txm/rcp/commands/function/ComputeQueryAutoCooccurrence.java (revision 786) | ||
---|---|---|
62 | 62 |
import org.txm.rcp.utils.JobHandler; |
63 | 63 |
import org.txm.rcp.views.QueriesView; |
64 | 64 |
import org.txm.rcp.views.corpora.CorporaView; |
65 |
import org.txm.searchengine.cqp.CQPEngine; |
|
65 |
import org.txm.searchengine.cqp.CQPSearchEngine;
|
|
66 | 66 |
import org.txm.searchengine.cqp.clientExceptions.CqiClientException; |
67 | 67 |
import org.txm.searchengine.cqp.corpus.Corpus; |
68 | 68 |
import org.txm.searchengine.cqp.corpus.StructuralUnit; |
... | ... | |
136 | 136 |
return Status.CANCEL_STATUS; |
137 | 137 |
} catch (Exception e) { |
138 | 138 |
Log.printStackTrace(e); |
139 |
try { System.out.println(TXMUIMessages.LastCQPError+CQPEngine.getCqiClient().getLastCQPError()); |
|
139 |
try { System.out.println(TXMUIMessages.LastCQPError+CQPSearchEngine.getCqiClient().getLastCQPError());
|
|
140 | 140 |
} catch (Exception e1) { e1.printStackTrace(); } |
141 | 141 |
} finally { |
142 | 142 |
monitor.done(); |
... | ... | |
187 | 187 |
|
188 | 188 |
} catch (Exception e) { |
189 | 189 |
Log.printStackTrace(e); |
190 |
try { System.out.println(TXMUIMessages.LastCQPError+CQPEngine.getCqiClient().getLastCQPError()); |
|
190 |
try { System.out.println(TXMUIMessages.LastCQPError+CQPSearchEngine.getCqiClient().getLastCQPError());
|
|
191 | 191 |
} catch (Exception e1) { e1.printStackTrace(); } |
192 | 192 |
} |
193 | 193 |
return cooc; |
tmp/org.txm.querycooccurrences.rcp/src/org/txm/rcp/commands/function/ComputeQueryCooccurrence.java (revision 786) | ||
---|---|---|
65 | 65 |
import org.txm.rcp.utils.JobHandler; |
66 | 66 |
import org.txm.rcp.views.QueriesView; |
67 | 67 |
import org.txm.rcp.views.corpora.CorporaView; |
68 |
import org.txm.searchengine.cqp.CQPEngine; |
|
68 |
import org.txm.searchengine.cqp.CQPSearchEngine;
|
|
69 | 69 |
import org.txm.searchengine.cqp.clientExceptions.CqiClientException; |
70 | 70 |
import org.txm.searchengine.cqp.corpus.Corpus; |
71 | 71 |
import org.txm.searchengine.cqp.corpus.StructuralUnit; |
... | ... | |
137 | 137 |
return Status.CANCEL_STATUS; |
138 | 138 |
} catch (Exception e) { |
139 | 139 |
Log.printStackTrace(e); |
140 |
try { System.out.println(TXMUIMessages.LastCQPError+CQPEngine.getCqiClient().getLastCQPError()); |
|
140 |
try { System.out.println(TXMUIMessages.LastCQPError+CQPSearchEngine.getCqiClient().getLastCQPError());
|
|
141 | 141 |
} catch (Exception e1) { e1.printStackTrace(); } |
142 | 142 |
} finally { |
143 | 143 |
monitor.done(); |
... | ... | |
178 | 178 |
} catch (Exception e) { |
179 | 179 |
// TODO Auto-generated catch block |
180 | 180 |
Log.printStackTrace(e); |
181 |
try { System.out.println(TXMUIMessages.LastCQPError+CQPEngine.getCqiClient().getLastCQPError()); |
|
181 |
try { System.out.println(TXMUIMessages.LastCQPError+CQPSearchEngine.getCqiClient().getLastCQPError());
|
|
182 | 182 |
} catch (Exception e1) { e1.printStackTrace(); } |
183 | 183 |
} |
184 | 184 |
return cooc; |
tmp/org.txm.treetagger.rcp/src/org/txm/treetagger/rcp/handlers/Train.java (revision 786) | ||
---|---|---|
34 | 34 |
import org.txm.rcp.swt.widget.parameters.ParametersDialog; |
35 | 35 |
import org.txm.rcp.utils.JobHandler; |
36 | 36 |
import org.txm.searchengine.cqp.AbstractCqiClient; |
37 |
import org.txm.searchengine.cqp.CQPEngine; |
|
37 |
import org.txm.searchengine.cqp.CQPSearchEngine;
|
|
38 | 38 |
import org.txm.searchengine.cqp.corpus.Corpus; |
39 | 39 |
import org.txm.searchengine.cqp.corpus.MainCorpus; |
40 | 40 |
import org.txm.searchengine.cqp.corpus.Property; |
... | ... | |
219 | 219 |
PrintStream ps = new PrintStream(fos); |
220 | 220 |
LinkedHashSet<Integer> positions = new LinkedHashSet<Integer>(); |
221 | 221 |
Property word = corpus.getProperty("word"); |
222 |
AbstractCqiClient CQI = CQPEngine.getCqiClient(); |
|
222 |
AbstractCqiClient CQI = CQPSearchEngine.getCqiClient();
|
|
223 | 223 |
for (Match m : corpus.getMatches()) { |
224 | 224 |
for (int i = m.getStart() ; i <= m.getEnd() ; i++) { // end match must be included |
225 | 225 |
positions.add(i); |
tmp/org.txm.queryindex.rcp/src/org/txm/rcp/editors/queryindex/QueryIndexEditor.java (revision 786) | ||
---|---|---|
89 | 89 |
import org.txm.rcp.views.QueriesView; |
90 | 90 |
import org.txm.rcp.views.corpora.CorporaView; |
91 | 91 |
import org.txm.rcp.editors.input.QueryIndexEditorInput; |
92 |
import org.txm.searchengine.cqp.CQPEngine; |
|
92 |
import org.txm.searchengine.cqp.CQPSearchEngine;
|
|
93 | 93 |
import org.txm.searchengine.cqp.clientExceptions.CqiClientException; |
94 | 94 |
import org.txm.searchengine.cqp.corpus.Corpus; |
95 | 95 |
import org.txm.searchengine.cqp.corpus.Partition; |
... | ... | |
369 | 369 |
System.out.println(e.getLocalizedMessage()); |
370 | 370 |
try { |
371 | 371 |
System.out.println(TXMUIMessages.LastCQPError |
372 |
+ CQPEngine.getCqiClient().getLastCQPError()); |
|
372 |
+ CQPSearchEngine.getCqiClient().getLastCQPError());
|
|
373 | 373 |
} catch (Exception e1) { |
374 | 374 |
System.out.println(IndexUIMessages.IndexEditor_10 |
375 | 375 |
+ e1); |
tmp/org.txm.tigersearch.rcp/src/org/txm/tigersearch/editors/TSIndexEditor.java (revision 786) | ||
---|---|---|
91 | 91 |
import org.txm.rcp.utils.JobHandler; |
92 | 92 |
import org.txm.rcp.views.QueriesView; |
93 | 93 |
import org.txm.rcp.views.corpora.CorporaView; |
94 |
import org.txm.searchengine.cqp.CQPEngine; |
|
94 |
import org.txm.searchengine.cqp.CQPSearchEngine;
|
|
95 | 95 |
import org.txm.searchengine.cqp.clientExceptions.CqiClientException; |
96 | 96 |
import org.txm.searchengine.cqp.corpus.Corpus; |
97 | 97 |
import org.txm.searchengine.cqp.corpus.Partition; |
... | ... | |
403 | 403 |
} catch (Exception e) { |
404 | 404 |
System.out.println(e.getLocalizedMessage()); |
405 | 405 |
try { |
406 |
System.out.println(TXMUIMessages.LastCQPError + CQPEngine.getCqiClient().getLastCQPError()); |
|
406 |
System.out.println(TXMUIMessages.LastCQPError + CQPSearchEngine.getCqiClient().getLastCQPError());
|
|
407 | 407 |
} catch (Exception e1) { |
408 | 408 |
System.out.println(IndexUIMessages.IndexEditor_10+e1); |
409 | 409 |
} |
tmp/org.txm.tigersearch.rcp/src/org/txm/function/tigersearch/TSIndex.java (revision 786) | ||
---|---|---|
20 | 20 |
import org.txm.index.core.functions.Index; |
21 | 21 |
import org.txm.index.core.functions.Line; |
22 | 22 |
import org.txm.searchengine.cqp.AbstractCqiClient; |
23 |
import org.txm.searchengine.cqp.CQPEngine; |
|
23 |
import org.txm.searchengine.cqp.CQPSearchEngine;
|
|
24 | 24 |
import org.txm.searchengine.cqp.clientExceptions.CqiClientException; |
25 | 25 |
import org.txm.searchengine.cqp.corpus.Corpus; |
26 | 26 |
import org.txm.searchengine.cqp.corpus.CorpusManager; |
... | ... | |
352 | 352 |
private ArrayList<Match> buildMatches_CQI(String[] strings) throws CqiClientException, IOException, CqiServerError { |
353 | 353 |
boolean debug = false; |
354 | 354 |
ArrayList<Match> matches = new ArrayList<Match>(); |
355 |
AbstractCqiClient CQI = CQPEngine.getCqiClient(); |
|
355 |
AbstractCqiClient CQI = CQPSearchEngine.getCqiClient();
|
|
356 | 356 |
Property idProperty = getCorpus().getProperty("id"); |
357 | 357 |
|
358 | 358 |
if (debug) System.out.println("Call CQI.str2Id with strings.len="+strings.length); |
tmp/org.txm.index.core/src/org/txm/index/core/functions/Index.java (revision 786) | ||
---|---|---|
48 | 48 |
import org.txm.index.core.functions.LineComparator.SortMode; |
49 | 49 |
import org.txm.index.core.messages.IndexCoreMessages; |
50 | 50 |
import org.txm.index.core.preferences.IndexPreferences; |
51 |
import org.txm.searchengine.cqp.CQPEngine; |
|
51 |
import org.txm.searchengine.cqp.CQPSearchEngine;
|
|
52 | 52 |
import org.txm.searchengine.cqp.ICqiClient; |
53 | 53 |
import org.txm.searchengine.cqp.clientExceptions.CqiClientException; |
54 | 54 |
import org.txm.searchengine.cqp.corpus.Corpus; |
... | ... | |
866 | 866 |
|
867 | 867 |
//long time = System.currentTimeMillis(); |
868 | 868 |
QueryResult result = corpus.query(pQuery, "index", true); //$NON-NLS-1$ |
869 |
boolean isTargetUsed = CQPEngine.getCqiClient().subCorpusHasField(result.getQualifiedCqpId(), ICqiClient.CQI_CONST_FIELD_TARGET); |
|
869 |
boolean isTargetUsed = CQPSearchEngine.getCqiClient().subCorpusHasField(result.getQualifiedCqpId(), ICqiClient.CQI_CONST_FIELD_TARGET);
|
|
870 | 870 |
int nbresults = result.getNMatch(); |
871 | 871 |
this.nTotalTokens += nbresults; // get number of tokens |
872 | 872 |
|
tmp/org.txm.chartsengine.core/src/org/txm/chartsengine/core/ChartsEnginesManager.java (revision 786) | ||
---|---|---|
14 | 14 |
* @author sjacquot |
15 | 15 |
* |
16 | 16 |
*/ |
17 |
//FIXME: useless class, the type and priority/order should be defined in org.txm.core.engines.EnginesManager extension point |
|
17 | 18 |
public class ChartsEnginesManager extends EnginesManager<ChartsEngine> { |
18 | 19 |
|
19 | 20 |
@Override |
... | ... | |
39 | 40 |
|
40 | 41 |
this.setCurrentEngine(TXMPreferences.getString(ChartsEnginePreferences.CURRENT_NAME, ChartsEnginePreferences.PREFERENCES_NODE)); |
41 | 42 |
|
42 |
TXMPreferences.alternativeNodesQualifiers.add(ChartsEnginePreferences.PREFERENCES_NODE); |
|
43 |
//TXMPreferences.alternativeNodesQualifiers.add(ChartsEnginePreferences.PREFERENCES_NODE);
|
|
43 | 44 |
|
44 | 45 |
return true; |
45 | 46 |
} |
tmp/org.txm.chartsengine.core/src/org/txm/chartsengine/core/ChartsEngine.java (revision 786) | ||
---|---|---|
75 | 75 |
//FIXME: this preference is not used at this time, see if it's useless or not. |
76 | 76 |
protected boolean directComputing; |
77 | 77 |
|
78 |
|
|
79 |
static { |
|
80 |
TXMPreferences.alternativeNodesQualifiers.add(ChartsEnginePreferences.PREFERENCES_NODE); |
|
81 |
} |
|
82 |
|
|
78 | 83 |
/** |
79 | 84 |
* Creates a charts engine with the specified name, description and output format. |
80 | 85 |
* @param name |
tmp/org.txm.annotation.core/src/org/txm/annotation/core/CQPAnnotationManager.java (revision 786) | ||
---|---|---|
10 | 10 |
import org.txm.annotation.core.repository.AnnotationType; |
11 | 11 |
import org.txm.annotation.core.repository.KnowledgeRepository; |
12 | 12 |
import org.txm.searchengine.cqp.AbstractCqiClient; |
13 |
import org.txm.searchengine.cqp.CQPEngine; |
|
13 |
import org.txm.searchengine.cqp.CQPSearchEngine;
|
|
14 | 14 |
import org.txm.searchengine.cqp.clientExceptions.CqiClientException; |
15 | 15 |
import org.txm.searchengine.cqp.corpus.MainCorpus; |
16 | 16 |
import org.txm.searchengine.cqp.corpus.Property; |
... | ... | |
122 | 122 |
AnnotationType sup_type = supList.get(sup); |
123 | 123 |
if (sup_type != null) sup_name = sup_type.getId(); |
124 | 124 |
|
125 |
int Nstruct = CQPEngine.getCqiClient().attributeSize(sup.getQualifiedName()); |
|
125 |
int Nstruct = CQPSearchEngine.getCqiClient().attributeSize(sup.getQualifiedName());
|
|
126 | 126 |
|
127 | 127 |
//TODO: can optimize this, to fetch only structure that matches |
128 | 128 |
int[] iStructs = new int[Nstruct]; |
129 | 129 |
for (int iStruct = 0; iStruct < Nstruct; iStruct++) iStructs[iStruct] = iStruct; |
130 |
String svalues[] = CQPEngine.getCqiClient().struc2Str(sup.getQualifiedName(), iStructs); // one position |
|
130 |
String svalues[] = CQPSearchEngine.getCqiClient().struc2Str(sup.getQualifiedName(), iStructs); // one position
|
|
131 | 131 |
|
132 | 132 |
for (int iStruct = 0; iStruct < Nstruct; iStruct++) { |
133 |
int smatch[] = CQPEngine.getCqiClient().struc2Cpos(sup.getQualifiedName(), iStruct); |
|
133 |
int smatch[] = CQPSearchEngine.getCqiClient().struc2Cpos(sup.getQualifiedName(), iStruct);
|
|
134 | 134 |
|
135 | 135 |
if (value != null) { // supplementary test if value is specified |
136 | 136 |
if (!value.equals(svalues[iStruct])) { |
... | ... | |
194 | 194 |
Property prop = corpus.getProperty(type.getId().toLowerCase()); |
195 | 195 |
if (prop == null) return nullAnnotationList(matches.size()); // no property, no annotation :) |
196 | 196 |
|
197 |
AbstractCqiClient cqi = CQPEngine.getCqiClient(); |
|
197 |
AbstractCqiClient cqi = CQPSearchEngine.getCqiClient();
|
|
198 | 198 |
|
199 | 199 |
int positions[] = new int[matches.size()]; |
200 | 200 |
int i = 0; |
... | ... | |
231 | 231 |
StructuralUnitProperty sup = su.getProperty(REF); |
232 | 232 |
if (sup == null) return nullAnnotationList(matches.size()); // no attribute REF, no annotation :) |
233 | 233 |
|
234 |
int Nstruct = CQPEngine.getCqiClient().attributeSize(sup.getQualifiedName()); |
|
234 |
int Nstruct = CQPSearchEngine.getCqiClient().attributeSize(sup.getQualifiedName());
|
|
235 | 235 |
int iMatch = 0; |
236 | 236 |
int iStruct = 0; |
237 | 237 |
int Nmatches = matches.size(); |
... | ... | |
241 | 241 |
if (Nstruct == 0) return new ArrayList<Annotation>(matches.size()); // no annotation |
242 | 242 |
//System.out.println("NUMBER OF STRUCT "+sup+" "+Nstruct); |
243 | 243 |
//System.out.println("MATCHES "+matches); |
244 |
int smatch[] = CQPEngine.getCqiClient().struc2Cpos(sup.getQualifiedName(), iStruct); |
|
244 |
int smatch[] = CQPSearchEngine.getCqiClient().struc2Cpos(sup.getQualifiedName(), iStruct);
|
|
245 | 245 |
//System.out.println(" TEST WITH "+smatch[0]+"-"+smatch[1]); |
246 | 246 |
if (overlap) { |
247 | 247 |
for (iMatch = 0 ; iStruct < Nstruct && iMatch < Nmatches; ) { |
... | ... | |
250 | 250 |
if(smatch[1] < m.getStart()) { // next struct |
251 | 251 |
iStruct++; |
252 | 252 |
if (iStruct < Nstruct) |
253 |
smatch = CQPEngine.getCqiClient().struc2Cpos(sup.getQualifiedName(), iStruct); |
|
253 |
smatch = CQPSearchEngine.getCqiClient().struc2Cpos(sup.getQualifiedName(), iStruct);
|
|
254 | 254 |
//System.out.println(" NEXT STRUCT TEST WITH "+smatch[0]+"-"+smatch[1]); |
255 | 255 |
} else if (m.getEnd() < smatch[0]) { // next match |
256 | 256 |
values.add(null); |
... | ... | |
276 | 276 |
iMatch++; |
277 | 277 |
iStruct++; |
278 | 278 |
if (iStruct < Nstruct) |
279 |
smatch = CQPEngine.getCqiClient().struc2Cpos(sup.getQualifiedName(), iStruct); |
|
279 |
smatch = CQPSearchEngine.getCqiClient().struc2Cpos(sup.getQualifiedName(), iStruct);
|
|
280 | 280 |
} else if(smatch[1] < m.getStart()) { // next struct |
281 | 281 |
iStruct++; |
282 | 282 |
if (iStruct < Nstruct) |
283 |
smatch = CQPEngine.getCqiClient().struc2Cpos(sup.getQualifiedName(), iStruct); |
|
283 |
smatch = CQPSearchEngine.getCqiClient().struc2Cpos(sup.getQualifiedName(), iStruct);
|
|
284 | 284 |
} else if (m.getEnd() < smatch[0]) { // next match |
285 | 285 |
values.add(null); |
286 | 286 |
annotationsStartEnd.add(null); |
... | ... | |
303 | 303 |
} |
304 | 304 |
} |
305 | 305 |
|
306 |
String[] svalues = CQPEngine.getCqiClient().struc2Str(sup.getQualifiedName(), tmp_strucs); |
|
306 |
String[] svalues = CQPSearchEngine.getCqiClient().struc2Str(sup.getQualifiedName(), tmp_strucs);
|
|
307 | 307 |
ArrayList<Annotation> annotations = new ArrayList<Annotation>(); |
308 | 308 |
for (int i = 0 ; i < values.size() ; i++) { // remove the fake values |
309 | 309 |
if (values.get(i) == null) { |
... | ... | |
342 | 342 |
StructuralUnitProperty sup = su.getProperty(REF); |
343 | 343 |
if (sup == null) return null; |
344 | 344 |
int[] cpos = {start, end}; |
345 |
int[] struc = CQPEngine.getCqiClient().cpos2Struc(sup.getQualifiedName(), cpos); |
|
345 |
int[] struc = CQPSearchEngine.getCqiClient().cpos2Struc(sup.getQualifiedName(), cpos);
|
|
346 | 346 |
|
347 | 347 |
if (struc[0] >= 0) { |
348 | 348 |
System.out.println("struct for positions "+start+"-"+end+" -> "+struc[0]+"-"+struc[1]); |
349 | 349 |
if (struc[0] == struc[1]) { // même structure |
350 |
String[] struc_str = CQPEngine.getCqiClient().struc2Str(sup.getQualifiedName(), struc); |
|
350 |
String[] struc_str = CQPSearchEngine.getCqiClient().struc2Str(sup.getQualifiedName(), struc);
|
|
351 | 351 |
return struc_str[0]; |
352 | 352 |
} else { // should not happens |
353 | 353 |
System.out.println("WARNING: FOUND EXISTING ANNOTATION FOR TYPE="+type+" START="+start+" END="+end); |
tmp/org.txm.annotation.core/src/org/txm/annotation/core/AnnotationEnginesManager.java (revision 786) | ||
---|---|---|
6 | 6 |
import org.txm.core.engines.EngineType; |
7 | 7 |
import org.txm.core.engines.EnginesManager; |
8 | 8 |
|
9 |
//FIXME: useless class, the type and priority/order should be defined in org.txm.core.engines.EnginesManager extension point |
|
9 | 10 |
public class AnnotationEnginesManager extends EnginesManager<AnnotationEngine> { |
10 | 11 |
|
11 | 12 |
public AnnotationEnginesManager() { |
tmp/org.txm.annotation.core/src/org/txm/annotation/core/AnnotationEngine.java (revision 786) | ||
---|---|---|
2 | 2 |
|
3 | 3 |
import org.txm.core.engines.Engine; |
4 | 4 |
|
5 |
//FIXME: useless class |
|
5 | 6 |
public abstract class AnnotationEngine implements Engine { |
6 | 7 |
|
7 | 8 |
public static final String EXTENSION_POINT_ID = AnnotationEngine.class.getCanonicalName(); |
tmp/org.txm.synopticeditor.rcp/src/org/txm/synopticedition/rcp/handlers/BackToText.java (revision 786) | ||
---|---|---|
52 | 52 |
import org.txm.rcp.StatusLine; |
53 | 53 |
import org.txm.rcp.utils.SWTEditorsUtils; |
54 | 54 |
import org.txm.searchengine.cqp.AbstractCqiClient; |
55 |
import org.txm.searchengine.cqp.CQPEngine; |
|
55 |
import org.txm.searchengine.cqp.CQPSearchEngine;
|
|
56 | 56 |
import org.txm.searchengine.cqp.corpus.Corpus; |
57 | 57 |
import org.txm.searchengine.cqp.corpus.Property; |
58 | 58 |
import org.txm.searchengine.cqp.corpus.StructuralUnit; |
... | ... | |
130 | 130 |
if (yProperty != null) { |
131 | 131 |
wProperty = corpus.getProperty("w"); |
132 | 132 |
if (wProperty != null) { |
133 |
AbstractCqiClient CQI = CQPEngine.getCqiClient(); |
|
133 |
AbstractCqiClient CQI = CQPSearchEngine.getCqiClient();
|
|
134 | 134 |
int[] cpos = {match.getStart()}; |
135 | 135 |
hProperty = corpus.getProperty("h"); |
136 | 136 |
if (hProperty != null) { |
tmp/org.txm.searchengine.cqp.core/plugin.xml (revision 786) | ||
---|---|---|
4 | 4 |
<extension |
5 | 5 |
point="org.txm.searchengine.core.SearchEngine"> |
6 | 6 |
<SearchEngine |
7 |
class="org.txm.searchengine.cqp.CQPEngine"> |
|
7 |
class="org.txm.searchengine.cqp.CQPSearchEngine">
|
|
8 | 8 |
</SearchEngine> |
9 | 9 |
</extension> |
10 | 10 |
<extension |
tmp/org.txm.searchengine.cqp.core/src/org/txm/searchengine/cqp/CQPEngine.java (revision 786) | ||
---|---|---|
1 |
package org.txm.searchengine.cqp; |
|
2 |
|
|
3 |
import java.io.File; |
|
4 |
import java.io.IOException; |
|
5 |
import java.lang.reflect.Constructor; |
|
6 |
import java.util.ArrayList; |
|
7 |
|
|
8 |
import org.eclipse.core.runtime.IProgressMonitor; |
|
9 |
import org.eclipse.core.runtime.Platform; |
|
10 |
import org.osgi.framework.Bundle; |
|
11 |
import org.txm.Toolbox; |
|
12 |
import org.txm.core.engines.EngineType; |
|
13 |
import org.txm.core.messages.TXMCoreMessages; |
|
14 |
import org.txm.core.preferences.TBXPreferences; |
|
15 |
import org.txm.core.preferences.TXMPreferences; |
|
16 |
import org.txm.importer.cwb.PatchCwbRegistry; |
|
17 |
import org.txm.libs.cqp.CQPLibPreferences; |
|
18 |
import org.txm.objects.Base; |
|
19 |
import org.txm.searchengine.core.SearchEngine; |
|
20 |
import org.txm.searchengine.cqp.clientExceptions.ServerNotFoundException; |
|
21 |
import org.txm.searchengine.cqp.corpus.CorpusManager; |
|
22 |
import org.txm.searchengine.cqp.corpus.MainCorpus; |
|
23 |
import org.txm.utils.OSDetector; |
|
24 |
import org.txm.utils.Sh; |
|
25 |
import org.txm.utils.logger.Log; |
|
26 |
import org.w3c.dom.Element; |
|
27 |
|
|
28 |
public class CQPEngine extends SearchEngine { |
|
29 |
|
|
30 |
/** |
|
31 |
* initialization state |
|
32 |
*/ |
|
33 |
boolean state = false; |
|
34 |
boolean useNetCQi = false; |
|
35 |
|
|
36 |
@Override |
|
37 |
public String getName() { |
|
38 |
return "CQP"; |
|
39 |
} |
|
40 |
|
|
41 |
/** |
|
42 |
* Starts the corpus engine if not remove then launch cqpserver. |
|
43 |
* |
|
44 |
* @return true, if successful |
|
45 |
*/ |
|
46 |
public boolean start(IProgressMonitor monitor) throws Exception { |
|
47 |
|
|
48 |
if (monitor != null) monitor.subTask("Starting Corpus Engine..."); |
|
49 |
|
|
50 |
boolean cqiserverok = false; |
|
51 |
|
|
52 |
useNetCQi = Boolean.parseBoolean(TXMPreferences.getString(CQPLibPreferences.CQI_NETWORK_MODE, CQPLibPreferences.PREFERENCES_NODE)); |
|
53 |
|
|
54 |
Log.warning("Killing CQP and RServe process if any"); |
|
55 |
killSearchEngine(); |
|
56 |
|
|
57 |
|
|
58 |
boolean remote = Boolean.parseBoolean(TXMPreferences.getString(CQPLibPreferences.CQI_SERVER_IS_REMOTE, CQPLibPreferences.PREFERENCES_NODE)); |
|
59 |
state = false; |
|
60 |
// test if must-have properties for CWB are set |
|
61 |
|
|
62 |
|
|
63 |
String reg_path = ""; // new way that concats registry of loaded corpus |
|
64 |
String path_separator = System.getProperty("path.separator"); |
|
65 |
for (Base b : Toolbox.workspace.getProject("default").getBases()) { |
|
66 |
File binDir = b.getBaseDirectory(); |
|
67 |
File registryDir = new File(binDir, "registry"); |
|
68 |
reg_path += path_separator + registryDir.getAbsolutePath(); |
|
69 |
File[] files = registryDir.listFiles(); |
|
70 |
if (files != null) |
|
71 |
for (File registryFile : files) { |
|
72 |
if (registryFile.isHidden()) continue; |
|
73 |
if (registryFile.isDirectory()) continue; |
|
74 |
|
|
75 |
File dataDirectory = new File(binDir, "data/"+registryFile.getName().toUpperCase()); |
|
76 |
if (!dataDirectory.exists())dataDirectory = new File(binDir, "data"); // eventual old corpus |
|
77 |
try { |
|
78 |
PatchCwbRegistry.patch(registryFile, dataDirectory); |
|
79 |
} catch (IOException e) { |
|
80 |
System.out.println("Error while updating registry file "+registryFile+": "+e); |
|
81 |
Log.printStackTrace(e); |
|
82 |
return false; |
|
83 |
} |
|
84 |
} |
|
85 |
} |
|
86 |
if (reg_path.length() > 0) reg_path = reg_path.substring(path_separator.length()); // remove first path_separator |
|
87 |
reg_path = reg_path.replace("\\\\", "//"); // fix the UNC paths for mingw |
|
88 |
|
|
89 |
String init_path = TXMPreferences.getString(CQPLibPreferences.CQI_SERVER_PATH_TO_INIT_FILE, CQPLibPreferences.PREFERENCES_NODE); |
|
90 |
|
|
91 |
|
|
92 |
if (!remote) { |
|
93 |
|
|
94 |
if (!useNetCQi) { |
|
95 |
try { |
|
96 |
cqiServer = new MemCqiServer(reg_path, |
|
97 |
init_path, |
|
98 |
TXMPreferences.getString(CQPLibPreferences.CQI_SERVER_ADDITIONAL_OPTIONS, CQPLibPreferences.PREFERENCES_NODE) |
|
99 |
+ " -P " + TXMPreferences.getString(CQPLibPreferences.CQI_SERVER_PORT, CQPLibPreferences.PREFERENCES_NODE), //$NON-NLS-1$ |
|
100 |
Boolean.parseBoolean(TXMPreferences.getString(CQPLibPreferences.CQI_SERVER_MONITOR_OUTPUT, CQPLibPreferences.PREFERENCES_NODE))); |
|
101 |
} catch (Exception e) { |
|
102 |
// TODO Auto-generated catch block |
|
103 |
org.txm.utils.logger.Log.printStackTrace(e); |
|
104 |
} |
|
105 |
} else { |
|
106 |
|
|
107 |
String exec_path = TXMPreferences.getString(CQPLibPreferences.CQI_SERVER_PATH_TO_EXECUTABLE, CQPLibPreferences.PREFERENCES_NODE); |
|
108 |
|
|
109 |
if (exec_path == null || exec_path.length() == 0) { |
|
110 |
System.out.println("Error: the '"+CQPLibPreferences.CQI_SERVER_PATH_TO_EXECUTABLE+"' preference is not set."); |
|
111 |
} |
|
112 |
if (new File(exec_path).exists()) { |
|
113 |
System.out.println("Error: the '"+CQPLibPreferences.CQI_SERVER_PATH_TO_EXECUTABLE+"' preference is not set."); |
|
114 |
} |
|
115 |
|
|
116 |
cqiServer = new NetCqiServer(exec_path, |
|
117 |
reg_path, |
|
118 |
init_path, |
|
119 |
TXMPreferences.getString(CQPLibPreferences.CQI_SERVER_ADDITIONAL_OPTIONS, CQPLibPreferences.PREFERENCES_NODE) |
|
120 |
+ " -P " + TXMPreferences.getString(CQPLibPreferences.CQI_SERVER_PORT, CQPLibPreferences.PREFERENCES_NODE), //$NON-NLS-1$ |
|
121 |
Boolean.parseBoolean(TXMPreferences.getString(CQPLibPreferences.CQI_SERVER_MONITOR_OUTPUT, CQPLibPreferences.PREFERENCES_NODE))); |
|
122 |
} |
|
123 |
|
|
124 |
if (cqiServer != null) |
|
125 |
cqiserverok = cqiServer.start(); |
|
126 |
|
|
127 |
} |
|
128 |
|
|
129 |
// create cqi client |
|
130 |
try { |
|
131 |
if (cqiserverok) { |
|
132 |
if (!useNetCQi) { |
|
133 |
try { |
|
134 |
cqiClient = new MemCqiClient((MemCqiServer) cqiServer); |
|
135 |
} catch(Exception e) { |
|
136 |
Log.severe(TXMCoreMessages.Toolbox_28+e); |
|
137 |
cqiserverok = false; |
|
138 |
} |
|
139 |
} else { |
|
140 |
int port = Integer.parseInt(TXMPreferences.getString(CQPLibPreferences.CQI_SERVER_PORT, CQPLibPreferences.PREFERENCES_NODE)); |
|
141 |
String host = TXMPreferences.getString(CQPLibPreferences.CQI_SERVER_HOST, CQPLibPreferences.PREFERENCES_NODE); |
|
142 |
cqiClient = new NetCqiClient(host, port); |
|
143 |
} |
|
144 |
} |
|
145 |
} catch (NumberFormatException e1) { |
|
146 |
Log.severe(TXMCoreMessages.Toolbox_wrong_port + TXMPreferences.getString(CQPLibPreferences.CQI_SERVER_PORT, CQPLibPreferences.PREFERENCES_NODE)); |
|
147 |
} catch (ServerNotFoundException e1) { |
|
148 |
Log.severe(TXMCoreMessages.Error_CONNECTION_FAILED + TXMPreferences.getString(CQPLibPreferences.CQI_SERVER_HOST, CQPLibPreferences.PREFERENCES_NODE) |
|
149 |
+ TXMCoreMessages.Toolbox_27 + TXMPreferences.getString(CQPLibPreferences.CQI_SERVER_PORT, CQPLibPreferences.PREFERENCES_NODE)); |
|
150 |
} |
|
151 |
|
|
152 |
// try connecting to the CWB server |
|
153 |
try { |
|
154 |
if (cqiserverok) { |
|
155 |
String login = TXMPreferences.getString(CQPLibPreferences.CQI_SERVER_LOGIN, CQPLibPreferences.PREFERENCES_NODE); |
|
156 |
String password = TXMPreferences.getString(CQPLibPreferences.CQI_SERVER_PASSWORD, CQPLibPreferences.PREFERENCES_NODE); |
|
157 |
state = cqiClient.connect(login, password); |
|
158 |
} |
|
159 |
} catch (Exception e1) { |
|
160 |
Log.severe(Log.toString(e1)); |
|
161 |
} |
|
162 |
|
|
163 |
if (state == false) { |
|
164 |
System.out.println(TXMCoreMessages.Toolbox_29); |
|
165 |
if (cqiClient instanceof NetCqiClient) System.out.println(TXMCoreMessages.Toolbox_30 + TXMPreferences.getString(CQPLibPreferences.CQI_SERVER_LOGIN, CQPLibPreferences.PREFERENCES_NODE) + " " + TXMPreferences.getString(CQPLibPreferences.CQI_SERVER_PASSWORD, CQPLibPreferences.PREFERENCES_NODE) + TXMPreferences.getString(CQPLibPreferences.CQI_SERVER_HOST, CQPLibPreferences.PREFERENCES_NODE) + " " + Integer.parseInt(TXMPreferences.getString(CQPLibPreferences.CQI_SERVER_PORT, CQPLibPreferences.PREFERENCES_NODE))); //$NON-NLS-1$ //$NON-NLS-2$ |
|
166 |
if (cqiServer != null && cqiServer instanceof NetCqiServer) |
|
167 |
System.out.println(TXMCoreMessages.Toolbox_33 + cqiServer.getLastCmdLine()); |
|
168 |
} else { |
|
169 |
if (cqiServer == null || cqiServer instanceof NetCqiServer) |
|
170 |
System.out.println(TXMCoreMessages.Toolbox_connected_to_corpus_sever); |
|
171 |
} |
|
172 |
|
|
173 |
CorpusManager.setCqiClient(cqiClient); |
|
174 |
|
|
175 |
// wait for CQPSERVER TO BE READY |
|
176 |
int scount = 0; |
|
177 |
try { |
|
178 |
CorpusManager.getCorpusManager().getCorpora(); |
|
179 |
do { |
|
180 |
Thread.sleep(100); |
|
181 |
CorpusManager.cleanCorpora();// to be sure to call cqpserver |
|
182 |
CorpusManager.getCorpusManager().getCorpora(); |
|
183 |
scount++; |
|
184 |
if (scount >= 10) { |
|
185 |
Log.warning(TXMCoreMessages.Toolbox_17); |
|
186 |
break; |
|
187 |
} |
|
188 |
} while (CorpusManager.getCorpusManager().getCorpora().size() == 0); |
|
189 |
} catch (Exception e) { |
|
190 |
org.txm.utils.logger.Log.printStackTrace(e); |
|
191 |
Log.severe(TXMCoreMessages.Toolbox_18 + e); |
|
192 |
} |
|
193 |
|
|
194 |
if (Toolbox.workspace == null) { |
|
195 |
System.out.println("Can't start CQP with workspace not ready."); |
|
196 |
return false; |
|
197 |
} |
|
198 |
|
|
199 |
// initialize pre-configured subcorpus and partition of corpus registered in the default.xml workspace file |
|
200 |
System.out.print(TXMCoreMessages.Toolbox_workspace_init); |
|
201 |
for (Base b : Toolbox.workspace.getProject("default").getBases()) { |
|
202 |
if (!loadCQPCorpora(b, monitor)) { |
|
203 |
System.out.println("Failed to load CQP corpora of "+b.getName()+" corpus."); |
|
204 |
} |
|
205 |
} |
|
206 |
|
|
207 |
System.out.println(TXMCoreMessages.common_done); |
|
208 |
|
|
209 |
return state; |
|
210 |
} |
|
211 |
|
|
212 |
public boolean loadCQPCorpora(Base base, IProgressMonitor monitor) { |
|
213 |
//System.out.println("Load corpus from params: "+params.corpora); |
|
214 |
for (String corpusname : base.getBaseParameters().corpora.keySet()) { |
|
215 |
Element c = base.getBaseParameters().corpora.get(corpusname); |
|
216 |
try { |
|
217 |
MainCorpus corp = CorpusManager.getCorpusManager().getCorpus(corpusname); |
|
218 |
if (monitor != null) monitor.subTask("Loading "+corp+" subcorpora and partitions..."); |
|
219 |
corp.setSelfElement(c); |
|
220 |
corp.setParent(base); |
|
221 |
corp.load(); // don't load corpus right now, wait for the search engine to be ready |
|
222 |
base.addChild(corp); |
|
223 |
if (!corp.getMetadatas().containsKey("lang")) { //$NON-NLS-1$ |
|
224 |
corp.setAttribute("lang", c.getAttribute("lang")); //$NON-NLS-1$ //$NON-NLS-2$ |
|
225 |
} |
|
226 |
} catch (Exception e) { |
|
227 |
System.out.println(e.getLocalizedMessage()); |
|
228 |
org.txm.utils.logger.Log.printStackTrace(e); |
|
229 |
return false; |
|
230 |
} |
|
231 |
} |
|
232 |
return true; |
|
233 |
} |
|
234 |
|
|
235 |
@Override |
|
236 |
public boolean initialize() { |
|
237 |
// all initialization done in the start method because we need CQP executable/lib to restart from the beginning |
|
238 |
return true; |
|
239 |
} |
|
240 |
|
|
241 |
/** The CQI server. */ |
|
242 |
private static AbstractCqiServer cqiServer; |
|
243 |
|
|
244 |
/** The CQI client. */ |
|
245 |
private static AbstractCqiClient cqiClient; |
|
246 |
|
|
247 |
/** |
|
248 |
* Sets the CQI server. |
|
249 |
* |
|
250 |
* @param cqiServer the new cqi server |
|
251 |
*/ |
|
252 |
public static void setCqiServer(AbstractCqiServer cqiServer) { |
|
253 |
CQPEngine.cqiServer = cqiServer; |
|
254 |
} |
|
255 |
|
|
256 |
/** |
|
257 |
* Gets the cqi client. |
|
258 |
* |
|
259 |
* @return the cqi client |
|
260 |
*/ |
|
261 |
public static AbstractCqiClient getCqiClient() { |
|
262 |
return cqiClient; |
|
263 |
} |
|
264 |
|
|
265 |
/** |
|
266 |
* Sets the cqi client. |
|
267 |
* |
|
268 |
* @param cqiClient the new cqi client |
|
269 |
*/ |
|
270 |
public static void setCqiClient(NetCqiClient cqiClient) { |
|
271 |
CQPEngine.cqiClient = cqiClient; |
|
272 |
} |
|
273 |
|
|
274 |
/** |
|
275 |
* Gets the CQI server. |
|
276 |
* |
|
277 |
* @return the CQI server |
|
278 |
*/ |
|
279 |
public static AbstractCqiServer getCqiServer() { |
|
280 |
return cqiServer; |
|
281 |
} |
|
282 |
|
|
283 |
/** |
|
284 |
* Shut the toolbox searchengine down. |
|
285 |
*/ |
|
286 |
public boolean stop() { |
|
287 |
try { |
|
288 |
if (cqiClient instanceof MemCqiClient) { |
|
289 |
try { |
|
290 |
} catch(Exception e) {} |
|
291 |
for (String name : ((MemCqiClient)cqiClient).listCorpora()) { |
|
292 |
((MemCqiClient)cqiClient).dropCorpus(name); |
|
293 |
} |
|
294 |
} |
|
295 |
cqiClient.disconnect(); |
|
296 |
cqiServer.stop(); |
|
297 |
|
|
298 |
CorpusManager.clean(); |
|
299 |
if (cqiServer instanceof NetCqiServer) |
|
300 |
killSearchEngine(); |
|
301 |
|
|
302 |
state = false; |
|
303 |
} catch (Exception e) { |
|
304 |
Log.severe("Error while closing CQP: "+e.getLocalizedMessage()); |
|
305 |
return false; |
|
306 |
} |
|
307 |
return true; |
|
308 |
} |
|
309 |
|
|
310 |
/** |
|
311 |
* kill cqpserver process. |
|
312 |
*/ |
|
313 |
private static void killSearchEngine() { |
|
314 |
if (!TXMPreferences.getBoolean(CQPLibPreferences.CQI_SERVER_IS_REMOTE, CQPLibPreferences.PREFERENCES_NODE)) |
|
315 |
// Windows OS |
|
316 |
if (OSDetector.isFamilyWindows()) { |
|
317 |
try { |
|
318 |
Process p = Runtime.getRuntime().exec( |
|
319 |
"taskkill /IM cqpserver.exe /F"); //$NON-NLS-1$ |
|
320 |
p.waitFor(); |
|
321 |
p = Runtime.getRuntime().exec("taskkill /IM cqpserver.exe /F"); //$NON-NLS-1$ |
|
322 |
p.waitFor(); |
|
323 |
} catch (IOException e) { |
|
324 |
Log.severe(TXMCoreMessages.Toolbox_31+Log.toString(e)); |
|
325 |
System.out.println(TXMCoreMessages.Toolbox_31+Log.toString(e)); |
|
326 |
try { |
|
327 |
Process p = Runtime.getRuntime().exec( |
|
328 |
"tskill cqpserver.exe"); //$NON-NLS-1$ |
|
329 |
p.waitFor(); |
|
330 |
p = Runtime.getRuntime().exec("tskill cqpserver.exe"); //$NON-NLS-1$ |
|
331 |
p.waitFor(); |
|
332 |
} catch (IOException e2) { |
|
333 |
Log.severe(TXMCoreMessages.Toolbox_34+Log.toString(e2)); |
|
334 |
System.out.println(TXMCoreMessages.Toolbox_34+Log.toString(e2)); |
|
335 |
} catch (InterruptedException e3) { |
|
336 |
Log.severe(Log.toString(e3)); |
|
337 |
System.out.println(Log.toString(e3)); |
|
338 |
} |
|
339 |
} catch (InterruptedException e) { |
|
340 |
Log.severe("Error while closing CQP: "+e.getLocalizedMessage()); |
|
341 |
System.out.println(Log.toString(e)); |
|
342 |
} |
|
343 |
; |
|
344 |
} |
|
345 |
// Mac, Linux |
|
346 |
else { |
|
347 |
String cmd = TXMCoreMessages.Toolbox_37 + TXMPreferences.getString(CQPLibPreferences.CQI_SERVER_PORT, CQPLibPreferences.PREFERENCES_NODE) + TXMCoreMessages.Toolbox_38; |
|
348 |
try { |
|
349 |
//Process p = Runtime.getRuntime().exec("killall -9 cqpserver"); //$NON-NLS-1$ |
|
350 |
// System.out.println("kill `ps aux | grep cqpserver | awk '/-P " |
|
351 |
// + TXMPreferences.getString(CQPPreferences.PREFERENCES_NODE, CQI_SERVER_PORT) + "/ {print $2}'`"); |
|
352 |
// String[] args = |
|
353 |
// {"kill","`ps aux | grep cqpserver | awk '/-P " + |
|
354 |
// TXMPreferences.getString(CQPPreferences.PREFERENCES_NODE, CQI_SERVER_PORT) + "/ {print $2}'`"}; |
|
355 |
// System.out.println("before Sh constructor"); |
|
356 |
Sh sh = new Sh(""); //$NON-NLS-1$ |
|
357 |
// System.out.println("after Sh constructor"); |
|
358 |
// System.out.println("EXECUTE SH : "+"kill `ps aux | grep cqpserver | awk '/-P " |
|
359 |
// + TXMPreferences.getString(CQPPreferences.PREFERENCES_NODE, CQI_SERVER_PORT) + "/ {print $2}'`"); |
|
360 |
sh.setIsc(cmd); |
|
361 |
sh.sh(); |
|
362 |
// Runtime.getRuntime().exec("sh kill `ps aux | grep cqpserver | awk '/-P " |
|
363 |
// + TXMPreferences.getString(CQPPreferences.PREFERENCES_NODE, CQI_SERVER_PORT) + "/ {print $2}'`"); |
|
364 |
|
|
365 |
} catch (Exception e) { |
|
366 |
Log.severe(TXMCoreMessages.Toolbox_39+cmd+TXMCoreMessages.Toolbox_40+Log.toString(e)); |
|
367 |
System.out.println(TXMCoreMessages.Toolbox_39+cmd+TXMCoreMessages.Toolbox_40+Log.toString(e)); |
|
368 |
org.txm.utils.logger.Log.printStackTrace(e); |
|
369 |
} |
|
370 |
} |
|
371 |
} |
|
372 |
|
|
373 |
/** |
|
374 |
* Restart the toolbox's searchengine. |
|
375 |
* |
|
376 |
* @return true, if successful |
|
377 |
*/ |
|
378 |
public boolean restart() { |
|
379 |
try { |
|
380 |
boolean ret = stop(); |
|
381 |
Thread.sleep(10); |
|
382 |
ret = ret && start(null); |
|
383 |
return ret; |
|
384 |
} catch (Exception e) { |
|
385 |
Log.severe("Error while restarting CQP: "+e.getLocalizedMessage()); |
|
386 |
} |
|
387 |
return false; |
|
388 |
} |
|
389 |
|
|
390 |
/** |
|
391 |
* test if searchEngine is initialized. |
|
392 |
* |
|
393 |
* @return true, if is initialized |
|
394 |
*/ |
|
395 |
public static boolean isInitialized() { |
|
396 |
return Toolbox.getEngineManager(EngineType.SEARCH).getEngine("CQP").getState(); |
|
397 |
} |
|
398 |
|
|
399 |
@Override |
|
400 |
public boolean getState() { |
|
401 |
return state; |
|
402 |
} |
|
403 |
} |
tmp/org.txm.searchengine.cqp.core/src/org/txm/searchengine/cqp/corpus/CorpusManager.java (revision 786) | ||
---|---|---|
33 | 33 |
import org.txm.Toolbox; |
34 | 34 |
import org.txm.core.messages.TXMCoreMessages; |
35 | 35 |
import org.txm.searchengine.cqp.AbstractCqiClient; |
36 |
import org.txm.searchengine.cqp.CQPEngine; |
|
36 |
import org.txm.searchengine.cqp.CQPSearchEngine;
|
|
37 | 37 |
import org.txm.searchengine.cqp.NetCqiClient; |
38 | 38 |
import org.txm.searchengine.cqp.clientExceptions.CqiClientException; |
39 | 39 |
import org.txm.searchengine.cqp.clientExceptions.InvalidCqpIdException; |
... | ... | |
215 | 215 |
public static void deleteCorpus(MainCorpus corpus) { |
216 | 216 |
if (corpora != null) |
217 | 217 |
corpora.remove(corpus); |
218 |
if (CQPEngine.isInitialized()) { |
|
218 |
if (CQPSearchEngine.isInitialized()) {
|
|
219 | 219 |
try { |
220 |
CQPEngine.getCqiClient().dropCorpus(corpus.getName()); |
|
220 |
CQPSearchEngine.getCqiClient().dropCorpus(corpus.getName());
|
|
221 | 221 |
} catch (Exception e) { |
222 | 222 |
Log.warning("Warning while removing corpus: Failed to drop corpus "+corpus); |
223 | 223 |
Log.printStackTrace(e); |
tmp/org.txm.searchengine.cqp.core/src/org/txm/searchengine/cqp/corpus/Partition.java (revision 786) | ||
---|---|---|
45 | 45 |
import org.txm.core.messages.TXMCoreMessages; |
46 | 46 |
import org.txm.core.results.TXMResult; |
47 | 47 |
import org.txm.objects.TxmObject; |
48 |
import org.txm.searchengine.cqp.CQPEngine; |
|
48 |
import org.txm.searchengine.cqp.CQPSearchEngine;
|
|
49 | 49 |
import org.txm.searchengine.cqp.clientExceptions.CqiClientException; |
50 | 50 |
import org.txm.searchengine.cqp.corpus.query.Query; |
51 | 51 |
import org.txm.searchengine.cqp.corpus.query.QueryPart; |
... | ... | |
287 | 287 |
|
288 | 288 |
} catch (Exception e) { |
289 | 289 |
try { |
290 |
throw new CqiClientException(TXMCoreMessages.Partition_9 + partitionName + "_" + partName + e + " last error: " + CQPEngine.getCqiClient().getLastCQPError()); //$NON-NLS-1$ //$NON-NLS-2$ |
|
290 |
throw new CqiClientException(TXMCoreMessages.Partition_9 + partitionName + "_" + partName + e + " last error: " + CQPSearchEngine.getCqiClient().getLastCQPError()); //$NON-NLS-1$ //$NON-NLS-2$
|
|
291 | 291 |
} catch (Exception e1) { |
292 | 292 |
System.out.println(TXMCoreMessages.Partition_18+e1); |
293 | 293 |
org.txm.utils.logger.Log.printStackTrace(e1); |
tmp/org.txm.searchengine.cqp.core/src/org/txm/searchengine/cqp/corpus/MainCorpus.java (revision 786) | ||
---|---|---|
45 | 45 |
import org.txm.objects.Text; |
46 | 46 |
import org.txm.objects.TxmObject; |
47 | 47 |
import org.txm.searchengine.cqp.AbstractCqiClient; |
48 |
import org.txm.searchengine.cqp.CQPEngine; |
|
48 |
import org.txm.searchengine.cqp.CQPSearchEngine;
|
|
49 | 49 |
import org.txm.searchengine.cqp.clientExceptions.CqiClientException; |
50 | 50 |
import org.txm.searchengine.cqp.clientExceptions.InvalidCqpIdException; |
51 | 51 |
import org.txm.searchengine.cqp.corpus.query.Match; |
... | ... | |
387 | 387 |
*/ |
388 | 388 |
public boolean removeFromCWB() { |
389 | 389 |
try { |
390 |
if (CQPEngine.isInitialized()) { |
|
390 |
if (CQPSearchEngine.isInitialized()) {
|
|
391 | 391 |
this.dropAllSubcorpora(); |
392 | 392 |
this.dropAllPartitions(); |
393 | 393 |
} |
tmp/org.txm.searchengine.cqp.core/src/org/txm/searchengine/cqp/corpus/Alignement.java (revision 786) | ||
---|---|---|
7 | 7 |
import org.txm.Toolbox; |
8 | 8 |
import org.txm.objects.Edition; |
9 | 9 |
import org.txm.objects.Page; |
10 |
import org.txm.searchengine.cqp.CQPEngine; |
|
10 |
import org.txm.searchengine.cqp.CQPSearchEngine;
|
|
11 | 11 |
import org.txm.searchengine.cqp.clientExceptions.CqiClientException; |
12 | 12 |
import org.txm.searchengine.cqp.clientExceptions.InvalidCqpIdException; |
13 | 13 |
import org.txm.searchengine.cqp.corpus.query.Match; |
... | ... | |
64 | 64 |
{ |
65 | 65 |
QueryResult rez = src.query(new Query("[_.text_id=\""+textid+"\" & id=\""+wordid+"\"]"), "Align", false); |
66 | 66 |
int[] position = {rez.getMatch(0).getStart()}; |
67 |
int[] struct_align_pos = CQPEngine.getCqiClient().cpos2Struc(align_src.getQualifiedName(), position); |
|
68 |
String[] struct_align_str = CQPEngine.getCqiClient().struc2Str(align_src.getQualifiedName(), struct_align_pos); |
|
67 |
int[] struct_align_pos = CQPSearchEngine.getCqiClient().cpos2Struc(align_src.getQualifiedName(), position);
|
|
68 |
String[] struct_align_str = CQPSearchEngine.getCqiClient().struc2Str(align_src.getQualifiedName(), struct_align_pos);
|
|
69 | 69 |
if(struct_align_str.length > 0) |
70 | 70 |
{ |
71 | 71 |
String aligned_struct = struct_align_str[0]; // the struct align value |
... | ... | |
73 | 73 |
QueryResult rez2 = dest.query(new Query("<"+struct+"_align=\""+aligned_struct+"\">[]"), "Align", false); |
74 | 74 |
int[] position2 = {rez2.getMatch(0).getStart()}; |
75 | 75 |
// get the id of this position |
76 |
int[] struct_text_pos = CQPEngine.getCqiClient().cpos2Struc(text_dest.getQualifiedName(), position2); |
|
77 |
String[] struct_text_str = CQPEngine.getCqiClient().struc2Str(text_dest.getQualifiedName(), struct_text_pos); |
|
76 |
int[] struct_text_pos = CQPSearchEngine.getCqiClient().cpos2Struc(text_dest.getQualifiedName(), position2);
|
|
77 |
String[] struct_text_str = CQPSearchEngine.getCqiClient().struc2Str(text_dest.getQualifiedName(), struct_text_pos);
|
|
78 | 78 |
return Arrays.asList(wordid, struct_text_str[0]); |
79 | 79 |
} |
80 | 80 |
else |
... | ... | |
91 | 91 |
//System.out.println(rez.getMatches()); |
92 | 92 |
int[] position = {rez.getMatch(0).getStart()}; |
93 | 93 |
//get the struct@align value for this position |
94 |
int[] struct_align_pos = CQPEngine.getCqiClient().cpos2Struc(align_src.getQualifiedName(), position); |
|
95 |
String[] struct_align_str = CQPEngine.getCqiClient().struc2Str(align_src.getQualifiedName(), struct_align_pos); |
|
94 |
int[] struct_align_pos = CQPSearchEngine.getCqiClient().cpos2Struc(align_src.getQualifiedName(), position);
|
|
95 |
String[] struct_align_str = CQPSearchEngine.getCqiClient().struc2Str(align_src.getQualifiedName(), struct_align_pos);
|
|
96 | 96 |
if(struct_align_str.length > 0) |
97 | 97 |
{ |
98 | 98 |
String aligned_struct = struct_align_str[0]; // the struct align value |
... | ... | |
101 | 101 |
QueryResult rez2 = dest.query(new Query(query), "Align", false); |
102 | 102 |
int[] position2 = {rez2.getMatch(0).getStart()}; |
103 | 103 |
// get the id of this position |
104 |
String[] ids = CQPEngine.getCqiClient().cpos2Str(id_dest.getQualifiedName(), position2); |
|
104 |
String[] ids = CQPSearchEngine.getCqiClient().cpos2Str(id_dest.getQualifiedName(), position2);
|
|
105 | 105 |
|
106 | 106 |
if(ids.length > 0) |
107 | 107 |
{ |
108 |
int[] struct_text_pos = CQPEngine.getCqiClient().cpos2Struc(text_dest.getQualifiedName(), position2); |
|
109 |
String[] struct_text_str = CQPEngine.getCqiClient().struc2Str(text_dest.getQualifiedName(), struct_text_pos); |
|
108 |
int[] struct_text_pos = CQPSearchEngine.getCqiClient().cpos2Struc(text_dest.getQualifiedName(), position2);
|
|
109 |
String[] struct_text_str = CQPSearchEngine.getCqiClient().struc2Str(text_dest.getQualifiedName(), struct_text_pos);
|
|
110 | 110 |
return Arrays.asList(ids[0], struct_text_str[0]); |
111 | 111 |
} |
112 | 112 |
else |
... | ... | |
146 | 146 |
Corpus src = CorpusManager.getCorpusManager().getCorpus(from); |
147 | 147 |
StructuralUnitProperty align_src = src.getStructuralUnit(struct).getProperty("align"); |
148 | 148 |
int[] position = {idx}; |
149 |
int[] struct_align_pos = CQPEngine.getCqiClient().cpos2Struc(align_src.getQualifiedName(), position); |
|
150 |
String[] struct_align_str = CQPEngine.getCqiClient().struc2Str(align_src.getQualifiedName(), struct_align_pos); |
|
149 |
int[] struct_align_pos = CQPSearchEngine.getCqiClient().cpos2Struc(align_src.getQualifiedName(), position);
|
|
150 |
String[] struct_align_str = CQPSearchEngine.getCqiClient().struc2Str(align_src.getQualifiedName(), struct_align_pos);
|
|
151 | 151 |
if (struct_align_str.length > 0) { |
152 | 152 |
return resolveSeg(struct_align_str[0]); |
153 | 153 |
} |
... | ... | |
166 | 166 |
int[] position = {rez.getMatch(0).getStart()}; |
167 | 167 |
|
168 | 168 |
Property id_dest = dest.getProperty("id"); |
169 |
String[] ids = CQPEngine.getCqiClient().cpos2Str(id_dest.getQualifiedName(), position); |
|
169 |
String[] ids = CQPSearchEngine.getCqiClient().cpos2Str(id_dest.getQualifiedName(), position);
|
|
170 | 170 |
String wordid = ids[0]; |
171 | 171 |
|
172 | 172 |
StructuralUnitProperty text_dest = dest.getStructuralUnit("text").getProperty("id"); |
173 |
int[] struct_text_pos = CQPEngine.getCqiClient().cpos2Struc(text_dest.getQualifiedName(), position); |
|
174 |
String[] struct_text_str = CQPEngine.getCqiClient().struc2Str(text_dest.getQualifiedName(), struct_text_pos); |
|
173 |
int[] struct_text_pos = CQPSearchEngine.getCqiClient().cpos2Struc(text_dest.getQualifiedName(), position);
|
|
174 |
String[] struct_text_str = CQPSearchEngine.getCqiClient().struc2Str(text_dest.getQualifiedName(), struct_text_pos);
|
|
175 | 175 |
String textid = struct_text_str[0]; |
176 | 176 |
|
177 | 177 |
return Arrays.asList(wordid, textid); |
tmp/org.txm.searchengine.cqp.core/src/org/txm/searchengine/cqp/CQPSearchEngine.java (revision 786) | ||
---|---|---|
1 |
package org.txm.searchengine.cqp; |
|
2 |
|
|
3 |
import java.io.File; |
|
4 |
import java.io.IOException; |
|
5 |
import java.lang.reflect.Constructor; |
|
6 |
import java.util.ArrayList; |
|
7 |
|
|
8 |
import org.eclipse.core.runtime.IProgressMonitor; |
|
9 |
import org.eclipse.core.runtime.Platform; |
|
10 |
import org.osgi.framework.Bundle; |
|
11 |
import org.txm.Toolbox; |
|
12 |
import org.txm.core.engines.EngineType; |
|
13 |
import org.txm.core.messages.TXMCoreMessages; |
|
14 |
import org.txm.core.preferences.TBXPreferences; |
|
15 |
import org.txm.core.preferences.TXMPreferences; |
|
16 |
import org.txm.importer.cwb.PatchCwbRegistry; |
|
17 |
import org.txm.libs.cqp.CQPLibPreferences; |
|
18 |
import org.txm.objects.Base; |
|
19 |
import org.txm.searchengine.core.SearchEngine; |
|
20 |
import org.txm.searchengine.cqp.clientExceptions.ServerNotFoundException; |
|
21 |
import org.txm.searchengine.cqp.corpus.CorpusManager; |
|
22 |
import org.txm.searchengine.cqp.corpus.MainCorpus; |
|
23 |
import org.txm.utils.OSDetector; |
|
24 |
import org.txm.utils.Sh; |
|
25 |
import org.txm.utils.logger.Log; |
|
26 |
import org.w3c.dom.Element; |
|
27 |
|
|
28 |
public class CQPSearchEngine extends SearchEngine { |
|
29 |
|
|
30 |
/** |
|
31 |
* initialization state |
|
32 |
*/ |
|
33 |
boolean state = false; |
|
34 |
boolean useNetCQi = false; |
|
35 |
|
|
36 |
@Override |
|
37 |
public String getName() { |
|
38 |
return "CQP"; |
|
39 |
} |
|
40 |
|
|
41 |
/** |
|
42 |
* Starts the corpus engine if not remove then launch cqpserver. |
|
43 |
* |
|
44 |
* @return true, if successful |
|
45 |
*/ |
|
46 |
public boolean start(IProgressMonitor monitor) throws Exception { |
|
47 |
|
|
48 |
if (monitor != null) monitor.subTask("Starting Corpus Engine..."); |
|
49 |
|
|
50 |
boolean cqiserverok = false; |
|
51 |
|
|
52 |
useNetCQi = Boolean.parseBoolean(TXMPreferences.getString(CQPLibPreferences.CQI_NETWORK_MODE, CQPLibPreferences.PREFERENCES_NODE)); |
|
53 |
|
|
54 |
Log.warning("Killing CQP and RServe process if any"); |
|
55 |
killSearchEngine(); |
|
56 |
|
|
57 |
|
|
58 |
boolean remote = Boolean.parseBoolean(TXMPreferences.getString(CQPLibPreferences.CQI_SERVER_IS_REMOTE, CQPLibPreferences.PREFERENCES_NODE)); |
|
59 |
state = false; |
|
60 |
// test if must-have properties for CWB are set |
|
61 |
|
|
62 |
|
|
63 |
String reg_path = ""; // new way that concats registry of loaded corpus |
|
64 |
String path_separator = System.getProperty("path.separator"); |
|
65 |
for (Base b : Toolbox.workspace.getProject("default").getBases()) { |
|
66 |
File binDir = b.getBaseDirectory(); |
|
67 |
File registryDir = new File(binDir, "registry"); |
|
68 |
reg_path += path_separator + registryDir.getAbsolutePath(); |
|
69 |
File[] files = registryDir.listFiles(); |
|
70 |
if (files != null) |
|
71 |
for (File registryFile : files) { |
|
72 |
if (registryFile.isHidden()) continue; |
|
73 |
if (registryFile.isDirectory()) continue; |
|
74 |
|
|
75 |
File dataDirectory = new File(binDir, "data/"+registryFile.getName().toUpperCase()); |
|
76 |
if (!dataDirectory.exists())dataDirectory = new File(binDir, "data"); // eventual old corpus |
|
77 |
try { |
|
78 |
PatchCwbRegistry.patch(registryFile, dataDirectory); |
|
79 |
} catch (IOException e) { |
|
80 |
System.out.println("Error while updating registry file "+registryFile+": "+e); |
|
81 |
Log.printStackTrace(e); |
|
82 |
return false; |
|
83 |
} |
|
84 |
} |
|
85 |
} |
|
86 |
if (reg_path.length() > 0) reg_path = reg_path.substring(path_separator.length()); // remove first path_separator |
|
87 |
reg_path = reg_path.replace("\\\\", "//"); // fix the UNC paths for mingw |
|
88 |
|
|
89 |
String init_path = TXMPreferences.getString(CQPLibPreferences.CQI_SERVER_PATH_TO_INIT_FILE, CQPLibPreferences.PREFERENCES_NODE); |
|
90 |
|
|
91 |
|
|
92 |
if (!remote) { |
|
93 |
|
|
94 |
if (!useNetCQi) { |
|
95 |
try { |
|
96 |
cqiServer = new MemCqiServer(reg_path, |
|
97 |
init_path, |
|
98 |
TXMPreferences.getString(CQPLibPreferences.CQI_SERVER_ADDITIONAL_OPTIONS, CQPLibPreferences.PREFERENCES_NODE) |
|
99 |
+ " -P " + TXMPreferences.getString(CQPLibPreferences.CQI_SERVER_PORT, CQPLibPreferences.PREFERENCES_NODE), //$NON-NLS-1$ |
|
100 |
Boolean.parseBoolean(TXMPreferences.getString(CQPLibPreferences.CQI_SERVER_MONITOR_OUTPUT, CQPLibPreferences.PREFERENCES_NODE))); |
|
101 |
} catch (Exception e) { |
|
102 |
// TODO Auto-generated catch block |
|
103 |
org.txm.utils.logger.Log.printStackTrace(e); |
|
104 |
} |
|
105 |
} else { |
|
106 |
|
|
107 |
String exec_path = TXMPreferences.getString(CQPLibPreferences.CQI_SERVER_PATH_TO_EXECUTABLE, CQPLibPreferences.PREFERENCES_NODE); |
|
108 |
|
|
109 |
if (exec_path == null || exec_path.length() == 0) { |
|
110 |
System.out.println("Error: the '"+CQPLibPreferences.CQI_SERVER_PATH_TO_EXECUTABLE+"' preference is not set."); |
|
111 |
} |
|
112 |
if (new File(exec_path).exists()) { |
|
113 |
System.out.println("Error: the '"+CQPLibPreferences.CQI_SERVER_PATH_TO_EXECUTABLE+"' preference is not set."); |
|
114 |
} |
|
115 |
|
|
116 |
cqiServer = new NetCqiServer(exec_path, |
|
117 |
reg_path, |
|
118 |
init_path, |
|
119 |
TXMPreferences.getString(CQPLibPreferences.CQI_SERVER_ADDITIONAL_OPTIONS, CQPLibPreferences.PREFERENCES_NODE) |
|
120 |
+ " -P " + TXMPreferences.getString(CQPLibPreferences.CQI_SERVER_PORT, CQPLibPreferences.PREFERENCES_NODE), //$NON-NLS-1$ |
|
121 |
Boolean.parseBoolean(TXMPreferences.getString(CQPLibPreferences.CQI_SERVER_MONITOR_OUTPUT, CQPLibPreferences.PREFERENCES_NODE))); |
|
122 |
} |
|
123 |
|
|
124 |
if (cqiServer != null) |
|
125 |
cqiserverok = cqiServer.start(); |
|
126 |
|
|
127 |
} |
|
128 |
|
|
129 |
// create cqi client |
|
130 |
try { |
|
131 |
if (cqiserverok) { |
|
132 |
if (!useNetCQi) { |
|
133 |
try { |
|
134 |
cqiClient = new MemCqiClient((MemCqiServer) cqiServer); |
|
135 |
} catch(Exception e) { |
|
136 |
Log.severe(TXMCoreMessages.Toolbox_28+e); |
|
137 |
cqiserverok = false; |
|
138 |
} |
|
139 |
} else { |
|
140 |
int port = Integer.parseInt(TXMPreferences.getString(CQPLibPreferences.CQI_SERVER_PORT, CQPLibPreferences.PREFERENCES_NODE)); |
|
141 |
String host = TXMPreferences.getString(CQPLibPreferences.CQI_SERVER_HOST, CQPLibPreferences.PREFERENCES_NODE); |
|
142 |
cqiClient = new NetCqiClient(host, port); |
|
143 |
} |
|
144 |
} |
|
145 |
} catch (NumberFormatException e1) { |
|
146 |
Log.severe(TXMCoreMessages.Toolbox_wrong_port + TXMPreferences.getString(CQPLibPreferences.CQI_SERVER_PORT, CQPLibPreferences.PREFERENCES_NODE)); |
|
147 |
} catch (ServerNotFoundException e1) { |
|
148 |
Log.severe(TXMCoreMessages.Error_CONNECTION_FAILED + TXMPreferences.getString(CQPLibPreferences.CQI_SERVER_HOST, CQPLibPreferences.PREFERENCES_NODE) |
|
149 |
+ TXMCoreMessages.Toolbox_27 + TXMPreferences.getString(CQPLibPreferences.CQI_SERVER_PORT, CQPLibPreferences.PREFERENCES_NODE)); |
|
150 |
} |
|
151 |
|
|
152 |
// try connecting to the CWB server |
|
153 |
try { |
|
154 |
if (cqiserverok) { |
|
155 |
String login = TXMPreferences.getString(CQPLibPreferences.CQI_SERVER_LOGIN, CQPLibPreferences.PREFERENCES_NODE); |
|
156 |
String password = TXMPreferences.getString(CQPLibPreferences.CQI_SERVER_PASSWORD, CQPLibPreferences.PREFERENCES_NODE); |
|
157 |
state = cqiClient.connect(login, password); |
|
158 |
} |
|
159 |
} catch (Exception e1) { |
|
160 |
Log.severe(Log.toString(e1)); |
|
161 |
} |
|
162 |
|
|
163 |
if (state == false) { |
|
164 |
System.out.println(TXMCoreMessages.Toolbox_29); |
|
165 |
if (cqiClient instanceof NetCqiClient) System.out.println(TXMCoreMessages.Toolbox_30 + TXMPreferences.getString(CQPLibPreferences.CQI_SERVER_LOGIN, CQPLibPreferences.PREFERENCES_NODE) + " " + TXMPreferences.getString(CQPLibPreferences.CQI_SERVER_PASSWORD, CQPLibPreferences.PREFERENCES_NODE) + TXMPreferences.getString(CQPLibPreferences.CQI_SERVER_HOST, CQPLibPreferences.PREFERENCES_NODE) + " " + Integer.parseInt(TXMPreferences.getString(CQPLibPreferences.CQI_SERVER_PORT, CQPLibPreferences.PREFERENCES_NODE))); //$NON-NLS-1$ //$NON-NLS-2$ |
|
166 |
if (cqiServer != null && cqiServer instanceof NetCqiServer) |
|
167 |
System.out.println(TXMCoreMessages.Toolbox_33 + cqiServer.getLastCmdLine()); |
|
168 |
} else { |
|
169 |
if (cqiServer == null || cqiServer instanceof NetCqiServer) |
|
170 |
System.out.println(TXMCoreMessages.Toolbox_connected_to_corpus_sever); |
|
171 |
} |
|
172 |
|
|
173 |
CorpusManager.setCqiClient(cqiClient); |
|
174 |
|
|
175 |
// wait for CQPSERVER TO BE READY |
|
176 |
int scount = 0; |
|
177 |
try { |
|
178 |
CorpusManager.getCorpusManager().getCorpora(); |
|
179 |
do { |
|
180 |
Thread.sleep(100); |
|
181 |
CorpusManager.cleanCorpora();// to be sure to call cqpserver |
|
182 |
CorpusManager.getCorpusManager().getCorpora(); |
|
183 |
scount++; |
|
184 |
if (scount >= 10) { |
|
185 |
Log.warning(TXMCoreMessages.Toolbox_17); |
|
186 |
break; |
|
187 |
} |
|
188 |
} while (CorpusManager.getCorpusManager().getCorpora().size() == 0); |
|
189 |
} catch (Exception e) { |
|
190 |
org.txm.utils.logger.Log.printStackTrace(e); |
|
191 |
Log.severe(TXMCoreMessages.Toolbox_18 + e); |
|
192 |
} |
|
193 |
|
|
194 |
if (Toolbox.workspace == null) { |
|
195 |
System.out.println("Can't start CQP with workspace not ready."); |
|
196 |
return false; |
|
197 |
} |
|
198 |
|
|
199 |
// initialize pre-configured subcorpus and partition of corpus registered in the default.xml workspace file |
|
200 |
System.out.print(TXMCoreMessages.Toolbox_workspace_init); |
|
201 |
for (Base b : Toolbox.workspace.getProject("default").getBases()) { |
|
202 |
if (!loadCQPCorpora(b, monitor)) { |
|
203 |
System.out.println("Failed to load CQP corpora of "+b.getName()+" corpus."); |
|
204 |
} |
|
205 |
} |
|
206 |
|
|
207 |
System.out.println(TXMCoreMessages.common_done); |
|
208 |
|
|
209 |
return state; |
|
210 |
} |
|
211 |
|
|
212 |
public boolean loadCQPCorpora(Base base, IProgressMonitor monitor) { |
|
213 |
//System.out.println("Load corpus from params: "+params.corpora); |
|
214 |
for (String corpusname : base.getBaseParameters().corpora.keySet()) { |
|
215 |
Element c = base.getBaseParameters().corpora.get(corpusname); |
|
216 |
try { |
|
217 |
MainCorpus corp = CorpusManager.getCorpusManager().getCorpus(corpusname); |
|
218 |
if (monitor != null) monitor.subTask("Loading "+corp+" subcorpora and partitions..."); |
|
219 |
corp.setSelfElement(c); |
|
220 |
corp.setParent(base); |
|
221 |
corp.load(); // don't load corpus right now, wait for the search engine to be ready |
|
222 |
base.addChild(corp); |
|
223 |
if (!corp.getMetadatas().containsKey("lang")) { //$NON-NLS-1$ |
|
224 |
corp.setAttribute("lang", c.getAttribute("lang")); //$NON-NLS-1$ //$NON-NLS-2$ |
|
225 |
} |
|
226 |
} catch (Exception e) { |
|
227 |
System.out.println(e.getLocalizedMessage()); |
|
228 |
org.txm.utils.logger.Log.printStackTrace(e); |
|
229 |
return false; |
|
230 |
} |
|
231 |
} |
|
232 |
return true; |
|
233 |
} |
|
234 |
|
|
235 |
@Override |
|
236 |
public boolean initialize() { |
|
237 |
// all initialization done in the start method because we need CQP executable/lib to restart from the beginning |
|
238 |
return true; |
|
239 |
} |
|
240 |
|
|
241 |
/** The CQI server. */ |
|
242 |
private static AbstractCqiServer cqiServer; |
|
243 |
|
|
244 |
/** The CQI client. */ |
|
245 |
private static AbstractCqiClient cqiClient; |
|
246 |
|
|
247 |
/** |
|
248 |
* Sets the CQI server. |
|
249 |
* |
|
250 |
* @param cqiServer the new cqi server |
|
251 |
*/ |
|
252 |
public static void setCqiServer(AbstractCqiServer cqiServer) { |
|
253 |
CQPSearchEngine.cqiServer = cqiServer; |
|
254 |
} |
|
255 |
|
|
256 |
/** |
|
257 |
* Gets the cqi client. |
|
258 |
* |
|
259 |
* @return the cqi client |
|
260 |
*/ |
|
261 |
public static AbstractCqiClient getCqiClient() { |
|
262 |
return cqiClient; |
|
263 |
} |
|
264 |
|
|
265 |
/** |
|
266 |
* Sets the cqi client. |
|
267 |
* |
|
268 |
* @param cqiClient the new cqi client |
|
269 |
*/ |
|
270 |
public static void setCqiClient(NetCqiClient cqiClient) { |
|
271 |
CQPSearchEngine.cqiClient = cqiClient; |
|
272 |
} |
|
273 |
|
|
274 |
/** |
|
275 |
* Gets the CQI server. |
|
276 |
* |
|
277 |
* @return the CQI server |
|
278 |
*/ |
|
279 |
public static AbstractCqiServer getCqiServer() { |
|
280 |
return cqiServer; |
|
281 |
} |
|
282 |
|
|
283 |
/** |
|
284 |
* Shut the toolbox searchengine down. |
|
285 |
*/ |
|
286 |
public boolean stop() { |
|
287 |
try { |
|
288 |
if (cqiClient instanceof MemCqiClient) { |
|
289 |
try { |
|
290 |
} catch(Exception e) {} |
|
291 |
for (String name : ((MemCqiClient)cqiClient).listCorpora()) { |
|
292 |
((MemCqiClient)cqiClient).dropCorpus(name); |
|
293 |
} |
|
294 |
} |
|
295 |
cqiClient.disconnect(); |
|
296 |
cqiServer.stop(); |
|
297 |
|
|
298 |
CorpusManager.clean(); |
|
299 |
if (cqiServer instanceof NetCqiServer) |
|
300 |
killSearchEngine(); |
|
301 |
|
Formats disponibles : Unified diff