Révision 3990
TXM/trunk/bundles/org.txm.querycooccurrences.rcp/src/org/txm/rcp/commands/function/ComputeQueryAutoCooccurrence.java (revision 3990) | ||
---|---|---|
30 | 30 |
import java.io.File; |
31 | 31 |
import java.util.ArrayList; |
32 | 32 |
|
33 |
import org.eclipse.core.commands.AbstractHandler; |
|
34 | 33 |
import org.eclipse.core.commands.ExecutionEvent; |
35 | 34 |
import org.eclipse.core.commands.ExecutionException; |
36 | 35 |
import org.eclipse.core.runtime.IProgressMonitor; |
... | ... | |
63 | 62 |
import org.txm.rcp.utils.JobHandler; |
64 | 63 |
import org.txm.rcp.views.QueriesView; |
65 | 64 |
import org.txm.rcp.views.corpora.CorporaView; |
65 |
import org.txm.searchengine.core.IQuery; |
|
66 | 66 |
import org.txm.searchengine.cqp.CQPSearchEngine; |
67 | 67 |
import org.txm.searchengine.cqp.clientExceptions.CqiClientException; |
68 | 68 |
import org.txm.searchengine.cqp.core.messages.CQPSearchEngineCoreMessages; |
... | ... | |
87 | 87 |
*/ |
88 | 88 |
@Override |
89 | 89 |
public Object execute(ExecutionEvent event) throws ExecutionException { |
90 |
|
|
90 |
|
|
91 | 91 |
IStructuredSelection selection = this.getCorporaViewSelection(event); |
92 | 92 |
final Object element = selection.getFirstElement(); |
93 | 93 |
|
94 |
final Shell shell = HandlerUtil.getActiveWorkbenchWindowChecked(event) |
|
95 |
.getShell(); |
|
94 |
final Shell shell = HandlerUtil.getActiveWorkbenchWindowChecked(event).getShell(); |
|
96 | 95 |
|
97 | 96 |
JobHandler jobhandler = new JobHandler("Computing cooccurrences matrix") { |
98 | 97 |
@Override |
... | ... | |
107 | 106 |
} |
108 | 107 |
QueryIndex qi = ((QueryIndex)element); |
109 | 108 |
CQPCorpus corpus = qi.getCorpus(); |
110 |
|
|
109 |
|
|
111 | 110 |
final CoocMatrixDialog dialog = new ComputeQueryAutoCooccurrence.CoocMatrixDialog(shell, corpus); |
112 | 111 |
syncExec(new Runnable() { |
113 | 112 |
@Override |
... | ... | |
123 | 122 |
this.releaseSemaphore(); |
124 | 123 |
|
125 | 124 |
if (cooc == null) return null; |
126 |
|
|
125 |
|
|
127 | 126 |
Log.info(TXMCoreMessages.bind(TXMUIMessages.coocMatrixColonP0, cooc.getSymbol())); |
128 | 127 |
|
129 | 128 |
syncExec(new Runnable() { |
... | ... | |
157 | 156 |
|
158 | 157 |
|
159 | 158 |
private QueryAutoCooccurrence computeCooc(Shell shell, CQPCorpus corpus, QueryIndex element, CoocMatrixDialog dialog) { |
159 |
|
|
160 | 160 |
ArrayList<CQLQuery> queries = new ArrayList<CQLQuery>(); |
161 | 161 |
ArrayList<String> names = new ArrayList<String>(); |
162 | 162 |
|
... | ... | |
167 | 167 |
boolean oriented = dialog.getOriented(); |
168 | 168 |
|
169 | 169 |
for (QueryIndexLine line : element.getLines()) { |
170 |
queries.add(line.getQuery()); |
|
171 |
names.add(line.getName()); |
|
170 |
if (line.getQuery() instanceof CQLQuery) { |
|
171 |
queries.add((CQLQuery) line.getQuery()); |
|
172 |
names.add(line.getName()); |
|
173 |
} |
|
172 | 174 |
} |
173 | 175 |
|
174 | 176 |
System.out.println(TXMCoreMessages.bind(TXMCoreMessages.common_queriesColonP0, queries)); |
... | ... | |
182 | 184 |
System.out.println("Estimated time: "+(nqueries*reqtime/1000)+" secs"); |
183 | 185 |
cooc = new QueryAutoCooccurrence(corpus); |
184 | 186 |
cooc.setParameters(queries, names, dist, min, struct, oriented, new ConsoleProgressBar(nqueries)); |
185 |
|
|
187 |
|
|
186 | 188 |
Log.info(TXMCoreMessages.bind(TXMUIMessages.numberOfNodesP0, cooc.getNNodes())); |
187 | 189 |
Log.info(TXMCoreMessages.bind(TXMUIMessages.numberOfEdgesP0, cooc.getNEdges())); |
188 | 190 |
Log.info(TXMCoreMessages.bind(TXMUIMessages.wordsDistanceP0, dist)); |
189 | 191 |
|
190 | 192 |
if (outfile != null) { |
191 | 193 |
cooc.toGraphml(outfile); |
192 |
|
|
194 |
|
|
193 | 195 |
Log.info(TXMCoreMessages.bind(TXMUIMessages.writingCoocMatrixInGRAPHMLFileColonP0, outfile)); |
194 | 196 |
} |
195 | 197 |
|
... | ... | |
292 | 294 |
minSpinner.setMinimum(1); |
293 | 295 |
minSpinner.setMaximum(1000); |
294 | 296 |
minSpinner.setSelection(20); |
295 |
|
|
297 |
|
|
296 | 298 |
Label orientedLabel = new Label(composite, SWT.NONE); |
297 | 299 |
orientedLabel.setText("Oriented"); |
298 | 300 |
orientedLabel.setLayoutData(new GridData(GridData.END, GridData.CENTER, |
TXM/trunk/bundles/org.txm.querycooccurrences.rcp/src/org/txm/functions/coocmatrix/QueryAutoCooccurrence.java (revision 3990) | ||
---|---|---|
9 | 9 |
import org.eclipse.ui.model.IWorkbenchAdapter; |
10 | 10 |
import org.txm.ca.core.functions.CA; |
11 | 11 |
import org.txm.ca.core.functions.ICAComputable; |
12 |
import org.txm.core.results.TXMParameters; |
|
13 | 12 |
import org.txm.core.results.TXMResult; |
14 | 13 |
import org.txm.lexicaltable.core.functions.LexicalTable; |
15 | 14 |
import org.txm.lexicaltable.core.statsengine.r.data.LexicalTableImpl; |
16 | 15 |
import org.txm.rcp.IImageKeys; |
16 |
import org.txm.searchengine.core.IQuery; |
|
17 | 17 |
import org.txm.searchengine.cqp.clientExceptions.CqiClientException; |
18 | 18 |
import org.txm.searchengine.cqp.corpus.CQPCorpus; |
19 | 19 |
import org.txm.searchengine.cqp.corpus.Partition; |
20 | 20 |
import org.txm.searchengine.cqp.corpus.Property; |
21 | 21 |
import org.txm.searchengine.cqp.corpus.QueryResult; |
22 | 22 |
import org.txm.searchengine.cqp.corpus.query.CQLQuery; |
23 |
import org.txm.statsengine.core.StatException; |
|
24 | 23 |
import org.txm.statsengine.r.core.RWorkspace; |
25 | 24 |
import org.txm.statsengine.r.core.exceptions.RWorkspaceException; |
26 | 25 |
import org.txm.utils.TXMProgressMonitor; |
... | ... | |
28 | 27 |
|
29 | 28 |
public class QueryAutoCooccurrence extends TXMResult implements ICAComputable, IAdaptable { |
30 | 29 |
|
31 |
protected CQPCorpus corpus; |
|
32 |
|
|
33 | 30 |
protected int[][] coocs; |
34 | 31 |
|
35 | 32 |
protected ArrayList<CQLQuery> queries; |
... | ... | |
58 | 55 |
super(corpus); |
59 | 56 |
} |
60 | 57 |
|
61 |
public void setParameters(ArrayList<CQLQuery> queries, |
|
58 |
public void setParameters(ArrayList<CQLQuery> queries2,
|
|
62 | 59 |
ArrayList<String> names, int dist, int minCooc, String struct, boolean oriented, IProgressMonitor monitor) throws CqiClientException, RWorkspaceException { |
63 |
this.queries = queries; |
|
60 |
this.queries = queries2;
|
|
64 | 61 |
this.names = names; |
65 | 62 |
this.dist = dist; |
66 | 63 |
this.minCooc = minCooc; |
... | ... | |
70 | 67 |
else |
71 | 68 |
this.struct = "within text"; |
72 | 69 |
|
73 |
nNodes = queries.size(); |
|
70 |
nNodes = queries2.size();
|
|
74 | 71 |
} |
75 | 72 |
|
76 | 73 |
@Override |
77 | 74 |
public boolean _compute(TXMProgressMonitor monitor) throws Exception { |
75 |
|
|
78 | 76 |
coocs = new int[queries.size()][queries.size()]; |
79 | 77 |
|
80 | 78 |
monitor.setTask("Querying cooccurrences..."); |
... | ... | |
94 | 92 |
} |
95 | 93 |
|
96 | 94 |
Log.info("ListCooc: query " + query); |
97 |
QueryResult result = corpus.query(new CQLQuery(query), "tmp", false);
|
|
95 |
QueryResult result = getParent().query(new CQLQuery(query), "tmp", false);
|
|
98 | 96 |
coocs[i][j] = result.getNMatch(); |
99 | 97 |
if (coocs[i][j] >= minCooc) { |
100 | 98 |
nEdges++; |
... | ... | |
119 | 117 |
|
120 | 118 |
@Override |
121 | 119 |
public String getName() { |
122 |
return corpus.getName() + " d=" + dist + " min=" + minCooc;
|
|
120 |
return getParent().getName() + " d=" + dist + " min=" + minCooc;
|
|
123 | 121 |
} |
124 | 122 |
|
125 | 123 |
@Override |
126 | 124 |
public CQPCorpus getParent() { |
127 |
return corpus;
|
|
125 |
return (CQPCorpus) super.getParent();
|
|
128 | 126 |
} |
129 | 127 |
|
130 | 128 |
public String getSymbol() { |
... | ... | |
160 | 158 |
rw.eval("LT<-LT[, colSums(LT) != 0]"); |
161 | 159 |
rw.eval(this.getSymbol() + "LT<-LT"); |
162 | 160 |
rw.eval("rm(LT)"); |
161 |
|
|
163 | 162 |
// TODO: use Table fmin preference |
164 |
LexicalTable table = new LexicalTable(corpus);
|
|
165 |
table.setUnitProperty(corpus.getProperty("word"));
|
|
163 |
LexicalTable table = new LexicalTable(getParent());
|
|
164 |
table.setUnitProperty(getParent().getProperty("word"));
|
|
166 | 165 |
table.setData(new LexicalTableImpl(this.getSymbol() + "LT")); |
167 | 166 |
return table; |
168 | 167 |
} |
... | ... | |
215 | 214 |
|
216 | 215 |
return outfile.exists(); |
217 | 216 |
} |
218 |
|
|
219 |
@Override |
|
220 |
public CQPCorpus getCorpus() { |
|
221 |
return corpus; |
|
222 |
} |
|
223 |
|
|
217 |
|
|
224 | 218 |
public int[][] getCoocs() { |
225 | 219 |
return coocs; |
226 | 220 |
} |
... | ... | |
283 | 277 |
|
284 | 278 |
@Override |
285 | 279 |
public Partition getPartition() { |
280 |
|
|
286 | 281 |
return null; |
287 | 282 |
} |
288 | 283 |
|
... | ... | |
317 | 312 |
|
318 | 313 |
@Override |
319 | 314 |
public Object getAdapter(Class adapter) { |
315 |
|
|
320 | 316 |
return coocMatrixAdapter; |
321 | 317 |
} |
322 | 318 |
|
323 | 319 |
@Override |
324 | 320 |
public String getSimpleName() { |
321 |
|
|
325 | 322 |
return "QueryCooccurrence"; |
326 | 323 |
} |
327 | 324 |
|
328 | 325 |
@Override |
329 | 326 |
public String getDetails() { |
327 |
|
|
330 | 328 |
return queries.toString(); |
331 | 329 |
} |
332 | 330 |
|
333 | 331 |
@Override |
334 | 332 |
public boolean canCompute() { |
335 |
return corpus != null; |
|
333 |
|
|
334 |
return names != null && names.size() > 0 && queries != null && queries.size() > 0; |
|
336 | 335 |
} |
337 | 336 |
|
338 | 337 |
@Override |
... | ... | |
351 | 350 |
|
352 | 351 |
@Override |
353 | 352 |
public String getResultType() { |
353 |
|
|
354 | 354 |
return "Query auto cooccurrence"; |
355 | 355 |
} |
356 |
|
|
357 |
@Override |
|
358 |
public CQPCorpus getCorpus() { |
|
359 |
|
|
360 |
return getParent(); |
|
361 |
} |
|
356 | 362 |
|
357 | 363 |
} |
TXM/trunk/bundles/org.txm.querycooccurrences.rcp/plugin.xml (revision 3990) | ||
---|---|---|
9 | 9 |
<adapter |
10 | 10 |
type="org.eclipse.ui.model.IWorkbenchAdapter"> |
11 | 11 |
</adapter> |
12 |
<adapter |
|
13 |
type="org.eclipse.ui.model.IWorkbenchAdapter2"> |
|
14 |
</adapter> |
|
15 | 12 |
</factory> |
16 | 13 |
<factory |
17 | 14 |
adaptableType="org.txm.functions.coocmatrix.QueryCooccurrence" |
... | ... | |
19 | 16 |
<adapter |
20 | 17 |
type="org.eclipse.ui.model.IWorkbenchAdapter"> |
21 | 18 |
</adapter> |
22 |
<adapter |
|
23 |
type="org.eclipse.ui.model.IWorkbenchAdapter2"> |
|
24 |
</adapter> |
|
25 | 19 |
</factory> |
26 | 20 |
</extension> |
27 | 21 |
<extension |
TXM/trunk/bundles/org.txm.rcp/src/main/java/org/txm/rcp/swt/widget/NamedAssistedQueryWidget.java (revision 3990) | ||
---|---|---|
56 | 56 |
Button magicstick; |
57 | 57 |
|
58 | 58 |
/** The querywidget. */ |
59 |
QueryWidget querywidget; |
|
59 |
AssistedChoiceQueryWidget querywidget;
|
|
60 | 60 |
Text nameField; |
61 | 61 |
|
62 | 62 |
/** |
... | ... | |
76 | 76 |
|
77 | 77 |
nameField = new Text(this, SWT.BORDER); |
78 | 78 |
nameField.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, true)); |
79 |
|
|
80 |
l = new Label(this, SWT.NONE); |
|
81 |
l.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, false, true)); |
|
82 |
l.setText(TXMCoreMessages.common_query); |
|
83 |
|
|
84 |
magicstick = new Button(this, SWT.PUSH); |
|
85 |
magicstick.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, false, true)); |
|
86 |
magicstick.setImage(IImageKeys.getImage(IImageKeys.ACTION_ASSISTQUERY)); |
|
87 |
magicstick.setToolTipText(TXMUIMessages.openTheQueryAssistant); |
|
88 |
magicstick.addSelectionListener(new SelectionListener() { |
|
89 |
@Override |
|
90 |
public void widgetSelected(SelectionEvent e) { |
|
91 |
QueryAssistDialog d = new QueryAssistDialog(e.display.getActiveShell(), corpus); |
|
92 |
// System.out.println(d); |
|
93 |
if (d.open() == Window.OK) { |
|
94 |
querywidget.setText(d.getQuery()); |
|
95 |
} |
|
96 |
} |
|
97 |
|
|
98 |
@Override |
|
99 |
public void widgetDefaultSelected(SelectionEvent e) { } |
|
100 |
}); |
|
101 |
|
|
102 |
querywidget = new QueryWidget(this, style, corpus.getProject(), CQPSearchEngine.getEngine()); |
|
79 |
|
|
80 |
querywidget = new AssistedChoiceQueryWidget(this, SWT.NONE, corpus); |
|
103 | 81 |
querywidget.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, true)); |
104 | 82 |
} |
105 | 83 |
|
TXM/trunk/bundles/org.txm.queryindex.rcp/src/org/txm/queryindex/rcp/commands/ComputeQueryIndex.java (revision 3990) | ||
---|---|---|
63 | 63 |
*/ |
64 | 64 |
@Override |
65 | 65 |
public Object execute(ExecutionEvent event) throws ExecutionException { |
66 |
|
|
66 | 67 |
Log.info("Compute QueryIndex: start"); |
67 | 68 |
selection = this.getCorporaViewSelection(event); |
68 | 69 |
|
... | ... | |
73 | 74 |
} else if (s instanceof Partition) { |
74 | 75 |
final Partition partition = (Partition) s; |
75 | 76 |
openEditor(partition); |
77 |
} else if (s instanceof QueryIndex) { |
|
78 |
final QueryIndex qi = (QueryIndex) s; |
|
79 |
openEditor(qi); |
|
76 | 80 |
} else { |
77 | 81 |
Log.severe("Can not compute QueryIndex with: "+s); |
78 | 82 |
} |
... | ... | |
80 | 84 |
return null; |
81 | 85 |
} |
82 | 86 |
|
87 |
public static void openEditor(QueryIndex qi) { |
|
88 |
IWorkbenchPage page = TXMWindows.getActiveWindow().getActivePage(); |
|
89 |
TXMResultEditorInput<QueryIndex> editorInput = new TXMResultEditorInput<QueryIndex>(qi); |
|
90 |
try { |
|
91 |
StatusLine.setMessage(IndexUIMessages.openingIndexResults); |
|
92 |
IEditorPart editor = page.openEditor(editorInput,QueryIndexEditor.ID); |
|
93 |
if (editor instanceof QueryIndexEditor) { |
|
94 |
QueryIndexEditor voceditor = (QueryIndexEditor)editor; |
|
95 |
voceditor.initializeFields(); |
|
96 |
} |
|
97 |
} catch (Exception e) { |
|
98 |
Log.printStackTrace(e); |
|
99 |
} |
|
100 |
} |
|
101 |
|
|
83 | 102 |
public static void openEditor(CQPCorpus corpus) { |
84 | 103 |
IWorkbenchPage page = TXMWindows.getActiveWindow().getActivePage(); |
85 | 104 |
TXMResultEditorInput<QueryIndex> editorInput = new TXMResultEditorInput<QueryIndex>(new QueryIndex(corpus)); |
TXM/trunk/bundles/org.txm.queryindex.rcp/src/org/txm/queryindex/rcp/editors/LineLabelProvider.java (revision 3990) | ||
---|---|---|
60 | 60 |
case 2: |
61 | 61 |
return "" + line.getFrequency(); //$NON-NLS-1$ |
62 | 62 |
default: |
63 |
if (line.getFreqs().length > 1 |
|
64 |
&& columnIndex - 3 < line.getFreqs().length) |
|
63 |
if (line.getFreqs().length > 1 && columnIndex - 3 < line.getFreqs().length) { |
|
65 | 64 |
return "" + line.getFrequency(columnIndex - 3); //$NON-NLS-1$ |
66 |
else
|
|
65 |
} else {
|
|
67 | 66 |
return "";//$NON-NLS-1$ |
67 |
} |
|
68 | 68 |
} |
69 | 69 |
} |
70 | 70 |
|
TXM/trunk/bundles/org.txm.queryindex.rcp/src/org/txm/queryindex/rcp/editors/QueryIndexEditor.java (revision 3990) | ||
---|---|---|
33 | 33 |
import java.util.List; |
34 | 34 |
|
35 | 35 |
import org.eclipse.core.runtime.IProgressMonitor; |
36 |
import org.eclipse.core.runtime.IStatus; |
|
37 |
import org.eclipse.core.runtime.Status; |
|
38 | 36 |
import org.eclipse.jface.action.MenuManager; |
39 | 37 |
import org.eclipse.jface.viewers.ISelection; |
40 | 38 |
import org.eclipse.jface.viewers.StructuredSelection; |
41 | 39 |
import org.eclipse.jface.viewers.TableViewer; |
42 |
import org.eclipse.osgi.util.NLS; |
|
43 | 40 |
import org.eclipse.swt.SWT; |
44 | 41 |
import org.eclipse.swt.events.KeyEvent; |
45 | 42 |
import org.eclipse.swt.events.KeyListener; |
... | ... | |
71 | 68 |
import org.txm.queryindex.core.functions.Messages; |
72 | 69 |
import org.txm.queryindex.core.functions.QueryIndex; |
73 | 70 |
import org.txm.queryindex.core.functions.QueryIndexLine; |
74 |
import org.txm.rcp.JobsTimer; |
|
75 | 71 |
import org.txm.rcp.StatusLine; |
76 | 72 |
import org.txm.rcp.editors.TXMEditor; |
77 | 73 |
import org.txm.rcp.editors.TXMResultEditorInput; |
78 | 74 |
import org.txm.rcp.editors.TableKeyListener; |
79 |
import org.txm.rcp.messages.TXMUIMessages; |
|
80 | 75 |
import org.txm.rcp.swt.GLComposite; |
81 | 76 |
import org.txm.rcp.swt.dialog.LastOpened; |
82 | 77 |
import org.txm.rcp.swt.widget.NamedAssistedQueryWidget; |
83 | 78 |
import org.txm.rcp.swt.widget.NavigationWidget; |
84 |
import org.txm.rcp.utils.JobHandler; |
|
85 | 79 |
import org.txm.rcp.views.QueriesView; |
86 | 80 |
import org.txm.rcp.views.corpora.CorporaView; |
87 |
import org.txm.searchengine.cqp.CQPSearchEngine; |
|
88 | 81 |
import org.txm.searchengine.cqp.clientExceptions.CqiClientException; |
89 |
import org.txm.searchengine.cqp.core.messages.CQPSearchEngineCoreMessages; |
|
90 | 82 |
import org.txm.searchengine.cqp.corpus.CQPCorpus; |
91 | 83 |
import org.txm.searchengine.cqp.corpus.Partition; |
92 | 84 |
import org.txm.searchengine.cqp.corpus.Property; |
... | ... | |
95 | 87 |
import org.txm.utils.logger.Log; |
96 | 88 |
|
97 | 89 |
/** |
98 |
* display the query index parameters and result.
|
|
90 |
* Display the query index parameters and result.
|
|
99 | 91 |
* |
100 | 92 |
* @author mdecorde |
101 | 93 |
*/ |
... | ... | |
210 | 202 |
/** |
211 | 203 |
* Inits the. |
212 | 204 |
* |
213 |
* @param site |
|
214 |
* the site |
|
215 |
* @param input |
|
216 |
* the input |
|
217 |
* @throws PartInitException |
|
218 |
* the part init exception |
|
219 |
* @see org.eclipse.ui.part.EditorPart#init(org.eclipse.ui.IEditorSite, |
|
220 |
* org.eclipse.ui.IEditorInput) |
|
205 |
* @param site the site |
|
206 |
* @param input the input |
|
207 |
* @throws PartInitException the part init exception |
|
208 |
* @see org.eclipse.ui.part.EditorPart#init(org.eclipse.ui.IEditorSite, org.eclipse.ui.IEditorInput) |
|
221 | 209 |
*/ |
222 | 210 |
@Override |
223 |
public void init(IEditorSite site, IEditorInput input) |
|
224 |
throws PartInitException { |
|
211 |
public void init(IEditorSite site, IEditorInput input) throws PartInitException { |
|
225 | 212 |
setSite(site); |
226 | 213 |
setInput(input); |
227 | 214 |
|
... | ... | |
253 | 240 |
return false; |
254 | 241 |
} |
255 | 242 |
|
256 |
private QueryIndex createQueryIndex() { |
|
257 |
if (queryindex == null) { |
|
258 |
if (partition != null) { |
|
259 |
queryindex = new QueryIndex(partition); |
|
260 |
title = NLS.bind(Messages.QueryIndexEditor_0, partition.getName()); |
|
261 |
} |
|
262 |
else { |
|
263 |
queryindex = new QueryIndex(corpus); |
|
264 |
title = NLS.bind(Messages.QueryIndexEditor_0, corpus); |
|
265 |
} |
|
266 |
} |
|
267 |
return queryindex; |
|
268 |
} |
|
269 |
|
|
270 | 243 |
@Override |
271 | 244 |
public void updateResultFromEditor() { |
245 |
|
|
272 | 246 |
System.out.println("QueryIndexEditor.updateResultFromEditor(): not implemented."); //$NON-NLS-1$ |
273 | 247 |
} |
274 | 248 |
|
... | ... | |
277 | 251 |
*/ |
278 | 252 |
@Override |
279 | 253 |
public void updateEditorFromResult(boolean update) { |
280 |
System.out.println("QueryIndexEditor.updateEditorFromResult(): not implemented."); //$NON-NLS-1$ |
|
281 |
if (1 == 1) return; |
|
282 | 254 |
|
283 |
// createQueryIndex(); |
|
284 |
|
|
285 |
StatusLine.setMessage(IndexUIMessages.computingIndex); |
|
286 |
|
|
287 |
final CQLQuery query; // if the query is empty then we put "[]" instead |
|
288 |
if (!queryWidget.getQueryString().equals("\"\"")) {//$NON-NLS-1$ |
|
289 |
query = new CQLQuery(queryWidget.getQueryString()); |
|
290 |
} |
|
291 |
else { |
|
292 |
Log.severe(IndexUIMessages.indexColonQueryIsEmpty); |
|
293 |
return; |
|
294 |
} |
|
295 |
|
|
296 |
final String name; |
|
297 |
if (queryWidget.getQueryName().length() == 0) { |
|
298 |
name = query.toString(); |
|
299 |
} |
|
300 |
else { |
|
301 |
name = queryWidget.getQueryName(); |
|
302 |
} |
|
303 |
|
|
304 |
title = "Computing QueryIndex..."; |
|
305 |
|
|
306 | 255 |
try { |
307 |
JobHandler jobhandler = new JobHandler(title) { |
|
308 |
|
|
309 |
@Override |
|
310 |
protected IStatus run(IProgressMonitor monitor) { |
|
311 |
this.runInit(monitor); |
|
312 |
JobsTimer.start(); |
|
313 |
final QueryIndexLine line; |
|
314 |
try { |
|
315 |
try { |
|
316 |
if (queryindex.hasLine(name)) { |
|
317 |
System.out.println(TXMCoreMessages.bind(Messages.QueryIndexEditor_1, name)); |
|
318 |
queryindex.removeLine(name); |
|
319 |
} |
|
320 |
line = queryindex.addLine(name, query); |
|
321 |
} |
|
322 |
catch (CqiClientException e2) { |
|
323 |
Log.severe(TXMCoreMessages.bind(Messages.error_QueryIndexEditor_2, query)); |
|
324 |
Log.printStackTrace(e2); |
|
325 |
return Status.CANCEL_STATUS; |
|
326 |
} |
|
327 |
|
|
328 |
if (line == null) { |
|
329 |
Log.severe(TXMCoreMessages.bind(Messages.error_QueryIndexEditor_2, query)); |
|
330 |
return Status.CANCEL_STATUS; |
|
331 |
} |
|
332 |
|
|
333 |
if (monitor.isCanceled()) { |
|
334 |
return Status.CANCEL_STATUS; |
|
335 |
} |
|
336 |
queryindex.sortLines(SortMode.FREQUNIT, true); |
|
337 |
|
|
338 |
if (monitor.isCanceled()) { |
|
339 |
return Status.CANCEL_STATUS; |
|
340 |
} |
|
341 |
this.acquireSemaphore(); |
|
342 |
this.releaseSemaphore(); |
|
343 |
|
|
344 |
final String message = Messages.QueryIndexEditor_3; |
|
345 |
|
|
346 |
if (monitor.isCanceled()) { |
|
347 |
return Status.CANCEL_STATUS; |
|
348 |
} |
|
349 |
monitor.worked(95); |
|
350 |
// refresh ui |
|
351 |
syncExec(new Runnable() { |
|
352 |
|
|
353 |
@Override |
|
354 |
public void run() { |
|
355 |
|
|
356 |
System.out.println(message); |
|
357 |
StatusLine.setMessage(message); |
|
358 |
|
|
359 |
CorporaView.refresh(); |
|
360 |
CorporaView.expand(queryindex.getParent()); |
|
361 |
QueriesView.refresh(); |
|
362 |
RVariablesView.refresh(); |
|
363 |
|
|
364 |
setPartName(title); |
|
365 |
|
|
366 |
queryWidget.memorize(); |
|
367 |
nblinesperpage = NLignePPageSpinner.getSelection(); |
|
368 |
|
|
369 |
fillDisplayArea(0, NLignePPageSpinner.getSelection()); |
|
370 |
|
|
371 |
if (line != null) { |
|
372 |
queryWidget.setText(""); //$NON-NLS-1$ |
|
373 |
queryWidget.setName(""); //$NON-NLS-1$ |
|
374 |
queryWidget.focus(); |
|
375 |
} |
|
376 |
} |
|
377 |
}); |
|
378 |
} |
|
379 |
catch (Exception e) { |
|
380 |
System.out.println(e.getLocalizedMessage()); |
|
381 |
try { |
|
382 |
Log.severe(TXMCoreMessages.bind(CQPSearchEngineCoreMessages.lastCQPErrorP0, CQPSearchEngine.getCqiClient().getLastCQPError())); |
|
383 |
} |
|
384 |
catch (Exception e1) { |
|
385 |
Log.severe(TXMCoreMessages.bind(CQPSearchEngineCoreMessages.cQPErrorColonP0, e1)); |
|
386 |
Log.printStackTrace(e1); |
|
387 |
} |
|
388 |
Log.severe(TXMCoreMessages.bind("Error while computing QueryIndex: {0}.", e.getLocalizedMessage())); |
|
389 |
} |
|
390 |
catch (ThreadDeath td) { |
|
391 |
return Status.CANCEL_STATUS; |
|
392 |
} |
|
393 |
finally { |
|
394 |
monitor.done(); |
|
395 |
JobsTimer.stopAndPrint(); |
|
396 |
} |
|
397 |
return Status.OK_STATUS; |
|
398 |
} |
|
399 |
}; |
|
400 |
jobhandler.startJob(); |
|
401 |
|
|
256 |
fillDisplayArea(0, NLignePPageSpinner.getSelection()); |
|
257 |
} catch (Exception e) { |
|
258 |
// TODO Auto-generated catch block |
|
259 |
e.printStackTrace(); |
|
402 | 260 |
} |
403 |
catch (Exception e1) { |
|
404 |
Log.printStackTrace(e1); |
|
405 |
} |
|
261 |
|
|
406 | 262 |
} |
407 | 263 |
|
408 | 264 |
/** |
... | ... | |
413 | 269 |
@Override |
414 | 270 |
public void _createPartControl() { |
415 | 271 |
|
416 |
|
|
417 | 272 |
final Group paramArea = getExtendedParametersGroup(); |
418 | 273 |
|
419 | 274 |
GLComposite resultArea = getResultArea(); |
... | ... | |
446 | 301 |
public void keyPressed(KeyEvent e) { |
447 | 302 |
// System.out.println("key pressed : "+e.keyCode); |
448 | 303 |
if (e.keyCode == SWT.CR || e.keyCode == SWT.KEYPAD_CR) { |
449 |
compute(true); |
|
304 |
try { |
|
305 |
addQuery(); |
|
306 |
} catch (Exception e1) { |
|
307 |
// TODO Auto-generated catch block |
|
308 |
e1.printStackTrace(); |
|
309 |
} |
|
450 | 310 |
} |
451 | 311 |
} |
452 | 312 |
|
... | ... | |
457 | 317 |
Button loadFromFile = new Button(queryArea, SWT.BOLD); |
458 | 318 |
loadFromFile.setEnabled(true); |
459 | 319 |
loadFromFile.setText(Messages.QueryIndexEditor_4); |
460 |
loadFromFile |
|
461 |
.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_CENTER)); |
|
320 |
loadFromFile.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_CENTER)); |
|
462 | 321 |
loadFromFile.addSelectionListener(new SelectionListener() { |
463 | 322 |
|
464 | 323 |
@Override |
... | ... | |
477 | 336 |
String path = dialog.open(); |
478 | 337 |
if (path != null) { |
479 | 338 |
propFile = new File(path); |
480 |
// compute(); |
|
481 | 339 |
// System.out.println("TODO: load from file "+propFile); |
482 |
createQueryIndex(); |
|
483 | 340 |
try { |
484 |
queryindex.addLinesFromFile(propFile); |
|
341 |
try { |
|
342 |
queryindex.addLinesFromFile(propFile); |
|
343 |
} catch (Exception e1) { |
|
344 |
// TODO Auto-generated catch block |
|
345 |
e1.printStackTrace(); |
|
346 |
} |
|
485 | 347 |
queryindex.sortLines(SortMode.FREQUNIT, true); |
486 | 348 |
|
487 | 349 |
stored = true; |
... | ... | |
497 | 359 |
|
498 | 360 |
queryWidget.focus(); |
499 | 361 |
} |
500 |
catch (CqiClientException e1) { |
|
501 |
// TODO Auto-generated catch block |
|
502 |
Log.printStackTrace(e1); |
|
503 |
} |
|
504 |
catch (IOException e1) { |
|
362 |
catch (Exception e1) { |
|
505 | 363 |
Log.severe(TXMCoreMessages.bind(Messages.error_QueryIndexEditor_6, propFile)); |
506 | 364 |
Log.printStackTrace(e1); |
507 | 365 |
} |
... | ... | |
512 | 370 |
public void widgetDefaultSelected(SelectionEvent e) {} |
513 | 371 |
}); |
514 | 372 |
|
515 |
Button go = new Button(queryArea, SWT.BOLD);
|
|
516 |
go.setText(Messages.QueryIndexEditor_12);
|
|
373 |
Button addQueryButton = new Button(queryArea, SWT.BOLD);
|
|
374 |
addQueryButton.setText(Messages.QueryIndexEditor_12);
|
|
517 | 375 |
|
518 |
Font f = go.getFont();
|
|
519 |
FontData defaultFont = f.getFontData()[0]; |
|
520 |
defaultFont.setStyle(SWT.BOLD); |
|
521 |
Font newf = new Font(Display.getCurrent(), defaultFont); |
|
522 |
go.setFont(newf);
|
|
376 |
// Font f = addQueryButton.getFont();
|
|
377 |
// FontData defaultFont = f.getFontData()[0];
|
|
378 |
// defaultFont.setStyle(SWT.BOLD);
|
|
379 |
// Font newf = new Font(Display.getCurrent(), defaultFont);
|
|
380 |
// addQueryButton.setFont(newf);
|
|
523 | 381 |
|
524 | 382 |
layoutData = new GridData(GridData.VERTICAL_ALIGN_CENTER); |
525 | 383 |
layoutData.horizontalAlignment = GridData.FILL; |
526 | 384 |
layoutData.grabExcessHorizontalSpace = false; |
527 |
go.setLayoutData(layoutData);
|
|
385 |
addQueryButton.setLayoutData(layoutData);
|
|
528 | 386 |
|
529 |
go.addSelectionListener(new SelectionListener() {
|
|
387 |
addQueryButton.addSelectionListener(new SelectionListener() {
|
|
530 | 388 |
|
531 | 389 |
@Override |
532 | 390 |
public void widgetSelected(SelectionEvent e) { |
533 |
compute(true); |
|
391 |
try { |
|
392 |
addQuery(); |
|
393 |
} catch (Exception e1) { |
|
394 |
// TODO Auto-generated catch block |
|
395 |
e1.printStackTrace(); |
|
396 |
} |
|
534 | 397 |
} |
535 | 398 |
|
536 | 399 |
@Override |
... | ... | |
547 | 410 |
|
548 | 411 |
Label lNLigneppage = new Label(filtercontrols, SWT.NONE); |
549 | 412 |
lNLigneppage.setText(IndexUIMessages.pageSize); |
550 |
lNLigneppage.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, |
|
551 |
false)); |
|
413 |
lNLigneppage.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false)); |
|
552 | 414 |
|
553 | 415 |
NLignePPageSpinner = new Spinner(filtercontrols, SWT.BORDER); |
554 | 416 |
NLignePPageSpinner.setMinimum(0); |
... | ... | |
645 | 507 |
|
646 | 508 |
lFminInfo = new Label(filtercontrols, SWT.NONE); |
647 | 509 |
lFminInfo.setText(""); //$NON-NLS-1$ |
648 |
lFminInfo |
|
649 |
.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false)); |
|
510 |
lFminInfo.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false)); |
|
650 | 511 |
|
651 | 512 |
lFmaxInfo = new Label(filtercontrols, SWT.NONE); |
652 | 513 |
lFmaxInfo.setText(""); //$NON-NLS-1$ |
653 |
lFmaxInfo |
|
654 |
.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false)); |
|
514 |
lFmaxInfo.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false)); |
|
655 | 515 |
|
656 | 516 |
// results |
657 | 517 |
viewer = new TableViewer(resultArea, SWT.MULTI | SWT.FULL_SELECTION | SWT.BORDER | SWT.VIRTUAL); |
... | ... | |
680 | 540 |
// IndexToConcordance.link(self, |
681 | 541 |
// (IStructuredSelection) viewer |
682 | 542 |
// .getSelection()); |
683 |
System.out.println(Messages.QueryIndexEditor_7);
|
|
543 |
Log.warning(Messages.QueryIndexEditor_7);
|
|
684 | 544 |
} |
685 | 545 |
else if (col == 2) { |
686 |
System.out.println(Messages.QueryIndexEditor_8);
|
|
546 |
Log.warning(Messages.QueryIndexEditor_8);
|
|
687 | 547 |
} |
688 | 548 |
} |
689 | 549 |
}); |
... | ... | |
696 | 556 |
@Override |
697 | 557 |
public void keyPressed(KeyEvent e) { |
698 | 558 |
if (e.keyCode == SWT.DEL) { |
699 |
System.out.println(Messages.QueryIndexEditor_9);
|
|
559 |
Log.info(Messages.QueryIndexEditor_9);
|
|
700 | 560 |
ISelection sel = viewer.getSelection(); |
701 | 561 |
if (sel instanceof StructuredSelection) { |
702 | 562 |
List<?> lines = ((StructuredSelection) sel).toList(); |
... | ... | |
843 | 703 |
viewer.getTable().pack(); |
844 | 704 |
} |
845 | 705 |
|
706 |
protected boolean addQuery() throws Exception { |
|
707 |
|
|
708 |
final CQLQuery query; // if the query is empty then we put "[]" instead |
|
709 |
if (queryWidget.getQueryString().length() > 0) {//$NON-NLS-1$ |
|
710 |
query = new CQLQuery(queryWidget.getQueryString()); |
|
711 |
} |
|
712 |
else { |
|
713 |
Log.warning(IndexUIMessages.indexColonQueryIsEmpty); |
|
714 |
return false; |
|
715 |
} |
|
716 |
|
|
717 |
final String name; |
|
718 |
if (queryWidget.getQueryName().length() == 0) { |
|
719 |
name = query.toString(); |
|
720 |
} |
|
721 |
else { |
|
722 |
name = queryWidget.getQueryName(); |
|
723 |
} |
|
724 |
|
|
725 |
queryWidget.memorize(); |
|
726 |
nblinesperpage = NLignePPageSpinner.getSelection(); |
|
727 |
|
|
728 |
try { |
|
729 |
if (queryindex.hasLine(name)) { |
|
730 |
Log.info(TXMCoreMessages.bind(Messages.QueryIndexEditor_1, this)); |
|
731 |
queryindex.removeLine(name); |
|
732 |
} |
|
733 |
QueryIndexLine line = queryindex.addLine(name, query); |
|
734 |
|
|
735 |
if (line != null) { |
|
736 |
queryWidget.setText(""); //$NON-NLS-1$ |
|
737 |
queryWidget.setName(""); //$NON-NLS-1$ |
|
738 |
queryWidget.focus(); |
|
739 |
} else { |
|
740 |
Log.warning(TXMCoreMessages.bind(Messages.error_QueryIndexEditor_2, this)); |
|
741 |
return false; |
|
742 |
} |
|
743 |
|
|
744 |
updateEditorFromResult(false); |
|
745 |
} |
|
746 |
catch (CqiClientException e2) { |
|
747 |
Log.severe(TXMCoreMessages.bind(Messages.error_QueryIndexEditor_2, this)); |
|
748 |
Log.printStackTrace(e2); |
|
749 |
return false; |
|
750 |
} |
|
751 |
return false; |
|
752 |
} |
|
753 |
|
|
846 | 754 |
/** |
847 | 755 |
* Gets the pointed column. |
848 | 756 |
* |
... | ... | |
851 | 759 |
* @return the pointed column |
852 | 760 |
*/ |
853 | 761 |
public int getPointedColumn(Point mouseposition) { |
762 |
|
|
854 | 763 |
int x = mouseposition.x; // + lineTableViewer.getTable().get; |
855 | 764 |
int sumWidthColumn = this.nColumn.getWidth(); |
856 | 765 |
if (x < sumWidthColumn) |
... | ... | |
895 | 804 |
setPartName(queryindex.getPartition().getName() + ": " + queryindex.getName()); //$NON-NLS-1$ |
896 | 805 |
else |
897 | 806 |
setPartName(queryindex.getCorpus().getName() + ": " + queryindex.getName()); //$NON-NLS-1$ |
807 |
|
|
898 | 808 |
queryWidget.setFocus(); |
899 | 809 |
|
900 | 810 |
queryindex.sortLines(SortMode.FREQUNIT, true); |
... | ... | |
933 | 843 |
lines = queryindex.getLines(from, to); |
934 | 844 |
} |
935 | 845 |
else { |
936 |
lines = new ArrayList<>(); |
|
846 |
lines = new ArrayList<>(); // no result
|
|
937 | 847 |
} |
938 |
navigationArea.setInfoLineText("" + (from + 1), //$NON-NLS-1$ |
|
939 |
"-" + (to) + " / " + queryindex.getV()); //$NON-NLS-1$ //$NON-NLS-2$ |
|
848 |
navigationArea.setInfoLineText("" + (from + 1), "-" + (to) + " / " + queryindex.getV()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ |
|
940 | 849 |
navigationArea.setPreviousEnabled(from > 0); |
941 | 850 |
navigationArea.setFirstEnabled(from > 0); |
942 | 851 |
navigationArea.setNextEnabled(to < queryindex.getV() - 1); |
943 | 852 |
navigationArea.setLastEnabled(to < queryindex.getV() - 1); |
944 | 853 |
|
945 |
lFminInfo.setText(String.valueOf(queryindex.getFmin())); |
|
946 |
lFmaxInfo.setText(String.valueOf(queryindex.getFmax())); |
|
947 |
lTInfo.setText(String.valueOf(queryindex.getT())); |
|
948 |
lVInfo.setText(String.valueOf(queryindex.getV())); |
|
854 |
try { |
|
855 |
lFminInfo.setText(String.valueOf(queryindex.getFmin())); |
|
856 |
lFmaxInfo.setText(String.valueOf(queryindex.getFmax())); |
|
857 |
lTInfo.setText(String.valueOf(queryindex.getT())); |
|
858 |
lVInfo.setText(String.valueOf(queryindex.getV())); |
|
859 |
} catch (Exception e) { |
|
860 |
// TODO Auto-generated catch block |
|
861 |
e.printStackTrace(); |
|
862 |
} |
|
949 | 863 |
|
950 | 864 |
lVInfo.getParent().layout(); |
951 | 865 |
|
TXM/trunk/bundles/org.txm.queryindex.rcp/src/org/txm/queryindex/core/functions/QueryIndexLine.java (revision 3990) | ||
---|---|---|
1 | 1 |
package org.txm.queryindex.core.functions; |
2 | 2 |
|
3 |
import org.txm.searchengine.core.IQuery; |
|
4 |
import org.txm.searchengine.core.Selection; |
|
3 | 5 |
import org.txm.searchengine.cqp.clientExceptions.CqiClientException; |
4 | 6 |
import org.txm.searchengine.cqp.corpus.QueryResult; |
5 | 7 |
import org.txm.searchengine.cqp.corpus.query.CQLQuery; |
6 | 8 |
|
7 | 9 |
public class QueryIndexLine { |
8 | 10 |
String name; |
9 |
private CQLQuery query;
|
|
10 |
QueryResult[] qresults;
|
|
11 |
private IQuery query;
|
|
12 |
Selection[] qresults;
|
|
11 | 13 |
int[] freqs; |
12 | 14 |
int total; |
13 | 15 |
|
14 | 16 |
|
15 |
public QueryIndexLine(String name, CQLQuery query, QueryResult[] qresults) {
|
|
16 |
this.qresults = qresults; |
|
17 |
this.query = query; |
|
17 |
public QueryIndexLine(String name, IQuery query2, Selection[] qresults2) {
|
|
18 |
this.qresults = qresults2;
|
|
19 |
this.query = query2;
|
|
18 | 20 |
this.name = name; |
19 | 21 |
} |
20 | 22 |
|
... | ... | |
22 | 24 |
return name; |
23 | 25 |
} |
24 | 26 |
|
25 |
public CQLQuery getQuery() {
|
|
27 |
public IQuery getQuery() {
|
|
26 | 28 |
return query; |
27 | 29 |
} |
28 | 30 |
|
29 | 31 |
public int[] getFreqs() { |
30 |
computeFreqsAndTotal(); |
|
32 |
|
|
33 |
try { |
|
34 |
computeFreqsAndTotal(); |
|
35 |
} catch (Exception e) { |
|
36 |
// TODO Auto-generated catch block |
|
37 |
e.printStackTrace(); |
|
38 |
} |
|
31 | 39 |
return freqs; |
32 | 40 |
} |
33 | 41 |
|
34 |
private void computeFreqsAndTotal() { |
|
42 |
private void computeFreqsAndTotal() throws Exception {
|
|
35 | 43 |
if (freqs == null) { |
36 | 44 |
//System.out.println("compute freqs"); |
37 | 45 |
total = 0; |
... | ... | |
58 | 66 |
} |
59 | 67 |
|
60 | 68 |
public int getFrequency() { |
61 |
computeFreqsAndTotal(); |
|
69 |
|
|
70 |
try { |
|
71 |
computeFreqsAndTotal(); |
|
72 |
} catch (Exception e) { |
|
73 |
// TODO Auto-generated catch block |
|
74 |
e.printStackTrace(); |
|
75 |
} |
|
62 | 76 |
return total; |
63 | 77 |
} |
64 | 78 |
|
65 | 79 |
public int getFrequency(int i) { |
66 |
computeFreqsAndTotal(); |
|
67 |
return freqs[i]; |
|
80 |
|
|
81 |
try { |
|
82 |
computeFreqsAndTotal(); |
|
83 |
return freqs[i]; |
|
84 |
} catch (Exception e) { |
|
85 |
// TODO Auto-generated catch block |
|
86 |
e.printStackTrace(); |
|
87 |
} |
|
88 |
return 0; |
|
68 | 89 |
} |
69 | 90 |
|
70 | 91 |
public void setFrequencies(int[] freqs) { |
TXM/trunk/bundles/org.txm.queryindex.rcp/src/org/txm/queryindex/core/functions/QueryIndex.java (revision 3990) | ||
---|---|---|
4 | 4 |
import java.io.File; |
5 | 5 |
import java.io.FileInputStream; |
6 | 6 |
import java.io.FileOutputStream; |
7 |
import java.io.IOException; |
|
8 | 7 |
import java.io.InputStreamReader; |
9 | 8 |
import java.io.OutputStreamWriter; |
10 | 9 |
import java.util.ArrayList; |
... | ... | |
12 | 11 |
import java.util.Collection; |
13 | 12 |
import java.util.Collections; |
14 | 13 |
import java.util.Comparator; |
14 |
import java.util.HashMap; |
|
15 | 15 |
import java.util.LinkedHashMap; |
16 | 16 |
import java.util.List; |
17 | 17 |
import java.util.Map; |
... | ... | |
20 | 20 |
import org.eclipse.jface.resource.ImageDescriptor; |
21 | 21 |
import org.eclipse.ui.model.IWorkbenchAdapter; |
22 | 22 |
import org.txm.core.messages.TXMCoreMessages; |
23 |
import org.txm.core.preferences.TXMPreferences; |
|
24 |
import org.txm.core.results.Parameter; |
|
23 | 25 |
import org.txm.core.results.TXMResult; |
24 | 26 |
import org.txm.index.core.functions.LineComparator.SortMode; |
25 | 27 |
import org.txm.index.core.messages.IndexCoreMessages; |
28 |
import org.txm.index.rcp.messages.IndexUIMessages; |
|
26 | 29 |
import org.txm.lexicaltable.core.functions.LexicalTable; |
27 | 30 |
import org.txm.lexicaltable.core.statsengine.r.data.LexicalTableImpl; |
28 | 31 |
import org.txm.rcp.IImageKeys; |
29 |
import org.txm.searchengine.cqp.clientExceptions.CqiClientException; |
|
32 |
import org.txm.rcp.StatusLine; |
|
33 |
import org.txm.searchengine.core.IQuery; |
|
34 |
import org.txm.searchengine.core.Selection; |
|
35 |
import org.txm.searchengine.cqp.CQPSearchEngine; |
|
36 |
import org.txm.searchengine.cqp.core.messages.CQPSearchEngineCoreMessages; |
|
30 | 37 |
import org.txm.searchengine.cqp.corpus.CQPCorpus; |
31 | 38 |
import org.txm.searchengine.cqp.corpus.Part; |
32 | 39 |
import org.txm.searchengine.cqp.corpus.Partition; |
33 |
import org.txm.searchengine.cqp.corpus.QueryResult; |
|
34 | 40 |
import org.txm.searchengine.cqp.corpus.query.CQLQuery; |
35 | 41 |
import org.txm.utils.TXMProgressMonitor; |
36 | 42 |
import org.txm.utils.logger.Log; |
37 | 43 |
|
44 |
import com.google.gson.Gson; |
|
45 |
import com.google.gson.internal.LinkedTreeMap; |
|
46 |
|
|
38 | 47 |
public class QueryIndex extends TXMResult implements IAdaptable { |
39 |
|
|
40 |
CQPCorpus corpus;
|
|
41 |
|
|
42 |
Partition partition; |
|
43 |
|
|
48 |
|
|
49 |
@Parameter(key=TXMPreferences.QUERIES)
|
|
50 |
LinkedHashMap<String, IQuery> queries; |
|
51 |
|
|
52 |
// stores result |
|
44 | 53 |
LinkedHashMap<String, QueryIndexLine> lines = new LinkedHashMap<>(); |
45 |
|
|
46 |
List<String> partnames; |
|
47 | 54 |
|
48 |
|
|
49 |
/** The writer. */ |
|
50 |
private OutputStreamWriter writer; |
|
51 |
|
|
52 |
public int getT() { |
|
53 |
|
|
55 |
public int getT() throws Exception { |
|
56 |
|
|
54 | 57 |
int t = 0; |
55 | 58 |
for (QueryIndexLine line : lines.values()) { |
56 | 59 |
t += line.getFrequency(); |
57 | 60 |
} |
58 | 61 |
return t; |
59 | 62 |
} |
60 |
|
|
61 |
public int getFmin() { |
|
62 |
|
|
63 |
|
|
64 |
public int getFmin() throws Exception {
|
|
65 |
|
|
63 | 66 |
int t = Integer.MAX_VALUE; |
64 | 67 |
for (QueryIndexLine line : lines.values()) { |
65 | 68 |
int f = line.getFrequency(); |
66 |
if (f < t) t = f; |
|
69 |
if (f < t) |
|
70 |
t = f; |
|
67 | 71 |
} |
68 | 72 |
return t; |
69 | 73 |
} |
70 |
|
|
71 |
public int getFmax() { |
|
72 |
|
|
74 |
|
|
75 |
public int getFmax() throws Exception {
|
|
76 |
|
|
73 | 77 |
int t = 0; |
74 | 78 |
for (QueryIndexLine line : lines.values()) { |
75 | 79 |
int f = line.getFrequency(); |
76 |
if (f > t) t = f; |
|
80 |
if (f > t) |
|
81 |
t = f; |
|
77 | 82 |
} |
78 | 83 |
return t; |
79 | 84 |
} |
80 |
|
|
85 |
|
|
81 | 86 |
public int getV() { |
82 | 87 |
return lines.values().size(); |
83 | 88 |
} |
84 |
|
|
89 |
|
|
90 |
public QueryIndex(String id) { |
|
91 |
|
|
92 |
super(id, null); |
|
93 |
} |
|
94 |
|
|
95 |
public QueryIndex(String id, CQPCorpus corpus) { |
|
96 |
|
|
97 |
super(id, corpus); |
|
98 |
} |
|
99 |
|
|
85 | 100 |
public QueryIndex(CQPCorpus corpus) { |
86 |
|
|
101 |
|
|
87 | 102 |
super(corpus); |
88 |
this.corpus = corpus; |
|
89 |
partnames = Arrays.asList(corpus.getName()); |
|
90 |
this.setVisible(true); |
|
91 | 103 |
} |
92 |
|
|
104 |
|
|
93 | 105 |
@Override |
94 | 106 |
public String getName() { |
95 |
|
|
96 |
if (partition != null) { |
|
97 |
return partition.getName(); |
|
98 |
} |
|
99 |
return corpus.getName(); |
|
107 |
|
|
108 |
return getParent().getName() + (queries != null?queries.toString():""); |
|
100 | 109 |
} |
101 |
|
|
110 |
|
|
102 | 111 |
public QueryIndex(Partition partition) { |
103 |
|
|
112 |
|
|
104 | 113 |
super(partition); |
105 |
this.corpus = partition.getParent(); |
|
106 |
this.partition = partition; |
|
107 |
partnames = partition.getPartNames(); |
|
108 |
this.setVisible(true); |
|
109 | 114 |
} |
110 |
|
|
115 |
|
|
111 | 116 |
public CQPCorpus getCorpus() { |
112 |
|
|
113 |
return corpus; |
|
117 |
|
|
118 |
if (getParent() instanceof Partition) { |
|
119 |
return ((Partition)getParent()).getCorpus(); |
|
120 |
} |
|
121 |
return (CQPCorpus) getParent(); |
|
114 | 122 |
} |
115 |
|
|
123 |
|
|
116 | 124 |
public Partition getPartition() { |
117 |
|
|
118 |
return partition; |
|
125 |
|
|
126 |
if (getParent() instanceof Partition) { |
|
127 |
return ((Partition)getParent()); |
|
128 |
} |
|
129 |
return null; |
|
119 | 130 |
} |
120 |
|
|
131 |
|
|
121 | 132 |
public Collection<QueryIndexLine> getLines() { |
122 |
|
|
133 |
|
|
123 | 134 |
return lines.values(); |
124 | 135 |
} |
125 |
|
|
136 |
|
|
126 | 137 |
public LinkedHashMap<String, QueryIndexLine> getLinesHash() { |
127 | 138 |
return lines; |
128 | 139 |
} |
129 |
|
|
140 |
|
|
130 | 141 |
// public void filterLines(int fmin, int fmax) { |
131 | 142 |
// System.out.println("filter lines fmin="+fmin +" fmax="+fmax ); |
132 | 143 |
// this.FilterFmin = fmin; |
133 | 144 |
// this.FilterFmax = fmax; |
134 | 145 |
// } |
135 | 146 |
int multi = 1; |
136 |
|
|
147 |
|
|
137 | 148 |
public void sortLines(SortMode mode, boolean revert) { |
138 |
|
|
149 |
|
|
139 | 150 |
multi = 1; |
140 |
if (revert) multi = -1; |
|
151 |
if (revert) |
|
152 |
multi = -1; |
|
141 | 153 |
List<Map.Entry<String, QueryIndexLine>> entries = new ArrayList<>(lines.entrySet()); |
142 |
|
|
154 |
|
|
143 | 155 |
if (mode == SortMode.FREQUNIT) { |
144 | 156 |
Collections.sort(entries, new Comparator<Map.Entry<String, QueryIndexLine>>() { |
145 |
|
|
157 |
|
|
146 | 158 |
@Override |
147 | 159 |
public int compare(Map.Entry<String, QueryIndexLine> a, Map.Entry<String, QueryIndexLine> b) { |
148 |
int ret = multi * (a.getValue().getFrequency() - b.getValue().getFrequency()); |
|
160 |
int ret = 0; |
|
161 |
try { |
|
162 |
ret = multi * (a.getValue().getFrequency() - b.getValue().getFrequency()); |
|
163 |
} catch (Exception e) { |
|
164 |
// TODO Auto-generated catch block |
|
165 |
e.printStackTrace(); |
|
166 |
} |
|
149 | 167 |
if (ret == 0) { |
150 | 168 |
return multi * a.getValue().getName().compareTo(b.getValue().getName()); |
151 | 169 |
} |
152 | 170 |
return ret; |
153 | 171 |
} |
154 | 172 |
}); |
155 |
} |
|
156 |
else if (mode == SortMode.FREQ) { |
|
173 |
} else if (mode == SortMode.FREQ) { |
|
157 | 174 |
Collections.sort(entries, new Comparator<Map.Entry<String, QueryIndexLine>>() { |
158 |
|
|
175 |
|
|
159 | 176 |
@Override |
160 | 177 |
public int compare(Map.Entry<String, QueryIndexLine> a, Map.Entry<String, QueryIndexLine> b) { |
161 |
return multi * (a.getValue().getFrequency() - b.getValue().getFrequency()); |
|
178 |
try { |
|
179 |
return multi * (a.getValue().getFrequency() - b.getValue().getFrequency()); |
|
180 |
} catch (Exception e) { |
|
181 |
// TODO Auto-generated catch block |
|
182 |
e.printStackTrace(); |
|
183 |
return 0; |
|
184 |
} |
|
162 | 185 |
} |
163 | 186 |
}); |
164 |
} |
|
165 |
else if (mode == SortMode.UNIT) { |
|
187 |
} else if (mode == SortMode.UNIT) { |
|
166 | 188 |
Collections.sort(entries, new Comparator<Map.Entry<String, QueryIndexLine>>() { |
167 |
|
|
189 |
|
|
168 | 190 |
@Override |
169 | 191 |
public int compare(Map.Entry<String, QueryIndexLine> a, Map.Entry<String, QueryIndexLine> b) { |
170 | 192 |
return multi * a.getValue().getName().compareTo(b.getValue().getName()); |
171 | 193 |
} |
172 | 194 |
}); |
173 |
} |
|
174 |
else if (mode == SortMode.UNITFREQ) { |
|
195 |
} else if (mode == SortMode.UNITFREQ) { |
|
175 | 196 |
Collections.sort(entries, new Comparator<Map.Entry<String, QueryIndexLine>>() { |
176 |
|
|
197 |
|
|
177 | 198 |
@Override |
178 | 199 |
public int compare(Map.Entry<String, QueryIndexLine> a, Map.Entry<String, QueryIndexLine> b) { |
179 | 200 |
int ret = multi * a.getValue().getName().compareTo(b.getValue().getName()); |
180 | 201 |
if (ret == 0) { |
181 |
return multi * (a.getValue().getFrequency() - b.getValue().getFrequency()); |
|
202 |
try { |
|
203 |
return multi * (a.getValue().getFrequency() - b.getValue().getFrequency()); |
|
204 |
} catch (Exception e) { |
|
205 |
// TODO Auto-generated catch block |
|
206 |
e.printStackTrace(); |
|
207 |
} |
|
182 | 208 |
} |
183 | 209 |
return ret; |
184 | 210 |
} |
185 | 211 |
}); |
186 | 212 |
} |
187 |
|
|
213 |
|
|
188 | 214 |
LinkedHashMap<String, QueryIndexLine> sortedMap = new LinkedHashMap<>(); |
189 | 215 |
for (Map.Entry<String, QueryIndexLine> entry : entries) { |
190 | 216 |
sortedMap.put(entry.getKey(), entry.getValue()); |
191 | 217 |
} |
192 |
|
|
218 |
|
|
193 | 219 |
lines = sortedMap; |
194 | 220 |
} |
195 |
|
|
221 |
|
|
196 | 222 |
public boolean isComputedWithPartition() { |
197 |
|
|
198 |
return partition != null;
|
|
223 |
|
|
224 |
return getParent() instanceof Partition;
|
|
199 | 225 |
} |
200 |
|
|
201 |
public void addLinesFromFile(File propFile) throws CqiClientException, IOException {
|
|
202 |
|
|
226 |
|
|
227 |
public void addLinesFromFile(File propFile) throws Exception { |
|
228 |
|
|
203 | 229 |
BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(propFile), "UTF-8")); //$NON-NLS-1$ |
204 |
|
|
230 |
|
|
205 | 231 |
String line = reader.readLine(); |
206 | 232 |
while (line != null) { |
207 | 233 |
String[] split = line.split("=", 2); //$NON-NLS-1$ |
208 | 234 |
if (split.length == 2) { |
209 | 235 |
if (hasLine(split[0])) { |
210 | 236 |
Log.finest(TXMCoreMessages.bind(TXMCoreMessages.warningColonDuplicateQueryEntryColonP0, line)); |
211 |
} |
|
212 |
else { |
|
237 |
} else { |
|
213 | 238 |
if (addLine(split[0], new CQLQuery(split[1])) == null) { |
214 | 239 |
Log.finest(TXMCoreMessages.bind(TXMCoreMessages.warningColonQueryFailedColonP0, line)); |
215 | 240 |
} |
... | ... | |
219 | 244 |
} |
220 | 245 |
reader.close(); |
221 | 246 |
} |
222 |
|
|
247 |
|
|
223 | 248 |
/** |
224 | 249 |
* Write all the lines on a writer. |
225 | 250 |
* |
226 |
* @param outfile the outfile |
|
227 |
* @param encoding the encoding |
|
251 |
* @param outfile the outfile
|
|
252 |
* @param encoding the encoding
|
|
228 | 253 |
* @param colseparator the colseparator |
229 | 254 |
* @param txtseparator the txtseparator |
230 | 255 |
* @return true, if successful |
231 | 256 |
*/ |
232 | 257 |
@Override |
233 | 258 |
public boolean _toTxt(File outfile, String encoding, String colseparator, String txtseparator) { |
234 |
|
|
259 |
|
|
235 | 260 |
try { |
236 | 261 |
toTxt(outfile, 0, lines.size(), encoding, colseparator, txtseparator); |
237 |
} |
|
238 |
catch (Exception e) { |
|
262 |
} catch (Exception e) { |
|
239 | 263 |
Log.severe(TXMCoreMessages.bind(IndexCoreMessages.error_failedToExportLexiconColonP0, Log.toString(e))); |
240 | 264 |
return false; |
241 | 265 |
} |
242 | 266 |
return true; |
243 | 267 |
} |
244 |
|
|
268 |
|
|
245 | 269 |
/** |
246 | 270 |
* Write the lines between from and to on a writer. |
247 | 271 |
* |
248 |
* @param outfile the outfile |
|
249 |
* @param from The first line to be written |
|
250 |
* @param to The last line to be writen |
|
251 |
* @param encoding the encoding |
|
272 |
* @param outfile the outfile
|
|
273 |
* @param from The first line to be written
|
|
274 |
* @param to The last line to be writen
|
|
275 |
* @param encoding the encoding
|
|
252 | 276 |
* @param colseparator the colseparator |
253 | 277 |
* @param txtseparator the txtseparator |
254 |
* @throws CqiClientException the cqi client exception |
|
255 |
* @throws IOException Signals that an I/O exception has occurred. |
|
278 |
* @throws Exception |
|
256 | 279 |
*/ |
257 | 280 |
public void toTxt(File outfile, int from, int to, String encoding, String colseparator, String txtseparator) |
258 |
throws CqiClientException, IOException {
|
|
259 |
|
|
260 |
// NK: writer declared as class attribute to perform a clean if the operation is interrupted
|
|
261 |
this.writer = new OutputStreamWriter(new FileOutputStream(outfile),
|
|
262 |
encoding);
|
|
281 |
throws Exception { |
|
282 |
|
|
283 |
// NK: writer declared as class attribute to perform a clean if the operation is |
|
284 |
// interrupted
|
|
285 |
OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(outfile), encoding);
|
|
263 | 286 |
String header = "Queries"; //$NON-NLS-1$ |
264 | 287 |
header = txtseparator + header.substring(0, header.length() - 1) + txtseparator; |
265 | 288 |
header += colseparator + txtseparator + "F" + txtseparator; //$NON-NLS-1$ |
266 |
|
|
289 |
|
|
290 |
List<String> partnames = getPartnames(); |
|
267 | 291 |
if (partnames.size() > 1) |
268 | 292 |
for (int j = 0; j < partnames.size(); j++) |
269 |
header += colseparator + txtseparator + partnames.get(j).replace(txtseparator, txtseparator + txtseparator) + txtseparator; |
|
293 |
header += colseparator + txtseparator |
|
294 |
+ partnames.get(j).replace(txtseparator, txtseparator + txtseparator) + txtseparator; |
|
270 | 295 |
header += "\n"; //$NON-NLS-1$ |
271 | 296 |
writer.write(header); |
272 |
|
|
273 |
// for(Line ligne: lines)
|
|
297 |
|
|
298 |
// for(Line line: lines) |
|
274 | 299 |
for (String name : lines.keySet()) { |
275 | 300 |
QueryIndexLine ligne = lines.get(name); |
276 |
writer.write(txtseparator + ligne.getName().replace(txtseparator, txtseparator + txtseparator) + txtseparator + colseparator + ligne.getFrequency()); |
|
301 |
writer.write(txtseparator + ligne.getName().replace(txtseparator, txtseparator + txtseparator) |
|
302 |
+ txtseparator + colseparator + ligne.getFrequency()); |
|
277 | 303 |
if (partnames.size() > 1) |
278 | 304 |
for (int j = 0; j < partnames.size(); j++) |
279 |
writer.write(colseparator + ligne.getFrequency(j)); |
|
305 |
writer.write(colseparator + ligne.getFrequency(j));
|
|
280 | 306 |
writer.write("\n"); //$NON-NLS-1$ |
281 | 307 |
} |
282 | 308 |
writer.flush(); |
283 | 309 |
writer.close(); |
284 | 310 |
} |
285 |
|
|
311 |
|
|
286 | 312 |
public List<String> getPartnames() { |
287 |
|
|
313 |
|
|
314 |
List<String> partnames = null; |
|
315 |
if (getParent() instanceof Partition) { |
|
316 |
partnames = ((Partition)getParent()).getPartNames(); |
|
317 |
} else { |
|
318 |
partnames = Arrays.asList(getParent().getName()); |
|
319 |
} |
|
288 | 320 |
return partnames; |
289 | 321 |
} |
290 |
|
|
291 |
public QueryIndexLine addLine(String name, CQLQuery query) throws CqiClientException { |
|
292 |
|
|
293 |
if (lines.containsKey(name)) return null; |
|
294 |
QueryResult[] qresults; |
|
295 |
if (partition != null) { |
|
296 |
qresults = new QueryResult[partition.getPartsCount()]; |
|
322 |
|
|
323 |
public QueryIndexLine addLine(String name, IQuery query) throws Exception { |
|
324 |
|
|
325 |
if (lines.containsKey(name)) { |
|
326 |
return lines.get(name); |
|
327 |
} |
|
328 |
|
|
329 |
Selection[] qresults; |
|
330 |
if (getParent() instanceof Partition) { |
|
331 |
Partition partition = (Partition) getParent(); |
|
332 |
qresults = new Selection[partition.getPartsCount()]; |
|
297 | 333 |
List<Part> parts = partition.getParts(); |
298 | 334 |
for (int i = 0; i < parts.size(); i++) { |
299 |
qresults[i] = parts.get(i).query(query, "tmp", true); //$NON-NLS-1$ |
|
335 |
|
|
336 |
qresults[i] = query.getSearchEngine().query(getCorpus(), query, "tmp", false); |
|
337 |
|
|
338 |
//qresults[i] = parts.get(i).query(query, "tmp", true); //$NON-NLS-1$ |
|
300 | 339 |
// qresults[i].drop(); // free mem done later |
301 | 340 |
} |
302 |
} |
|
303 |
else {
|
|
304 |
qresults = new QueryResult[1];
|
|
305 |
qresults[0] = corpus.query(query, "tmp", true); //$NON-NLS-1$
|
|
341 |
} else {
|
|
342 |
qresults = new Selection[1];
|
|
343 |
qresults[0] = query.getSearchEngine().query(getCorpus(), query, "tmp", false);
|
|
344 |
//qresults[0] = getCorpus().query(query, "tmp", true); //$NON-NLS-1$
|
|
306 | 345 |
// qresults[0].drop(); // free mem done later |
307 | 346 |
} |
308 |
|
|
347 |
|
|
309 | 348 |
QueryIndexLine line = new QueryIndexLine(name, query, qresults); |
310 | 349 |
lines.put(name, line); |
350 |
queries.put(name, query); |
|
311 | 351 |
return line; |
312 | 352 |
} |
313 |
|
|
314 |
public LexicalTable toLexicalTable() { |
|
315 |
|
|
316 |
if (partition == null) return null; |
|
317 |
|
|
353 |
|
|
354 |
public LexicalTable toLexicalTable() throws Exception { |
|
355 |
|
|
356 |
if (!(getParent() instanceof Partition)) { |
|
357 |
return null; |
|
358 |
} |
|
359 |
|
|
360 |
Partition partition = (Partition) getParent(); |
|
318 | 361 |
int npart = partition.getPartsCount(); |
319 | 362 |
int[][] freqs = new int[lines.size()][npart]; |
320 | 363 |
String[] rownames = new String[lines.size()]; |
321 | 364 |
String[] colnames = new String[npart]; |
322 |
|
|
365 |
|
|
323 | 366 |
int i = 0; |
324 | 367 |
for (String key : lines.keySet()) { |
325 |
|
|
368 |
|
|
326 | 369 |
QueryIndexLine line = lines.get(key); |
327 | 370 |
int[] linefreqs = line.getFreqs(); |
328 | 371 |
rownames[i] = line.getName(); |
... | ... | |
335 | 378 |
for (int j = 0; j < npart; j++) { |
336 | 379 |
colnames[j] = parts.get(j).getName(); |
337 | 380 |
} |
338 |
|
|
381 |
|
|
339 | 382 |
try { |
340 | 383 |
LexicalTableImpl lt = new LexicalTableImpl(freqs, rownames, colnames); |
341 | 384 |
LexicalTable table = new LexicalTable(partition); |
342 | 385 |
table.setParameters(partition.getCorpus().getDefaultProperty(), 1, Integer.MAX_VALUE, this.getV(), null); |
343 | 386 |
table.setData(lt); |
344 | 387 |
return table; |
345 |
} |
|
346 |
catch (Exception e) { |
|
388 |
} catch (Exception e) { |
|
347 | 389 |
Log.printStackTrace(e); |
348 | 390 |
} |
349 | 391 |
return null; |
350 | 392 |
} |
351 |
|
|
393 |
|
|
352 | 394 |
public boolean removeLine(String name) { |
353 |
|
|
395 |
|
|
354 | 396 |
if (lines.containsKey(name)) { |
355 | 397 |
lines.remove(name); |
398 |
queries.remove(name); |
|
356 | 399 |
return true; |
357 |
} |
|
358 |
else { |
|
400 |
} else { |
|
359 | 401 |
return false; |
360 | 402 |
} |
Formats disponibles : Unified diff