Révision 3979
TXM/trunk/bundles/org.txm.rcp/src/main/java/org/txm/rcp/swt/widget/structures/AdvancedSubcorpusPanel.java (revision 3979) | ||
---|---|---|
1 |
// Copyright © 2010-2020 ENS de Lyon., University of Franche-Comté |
|
2 |
// Copyright © 2007-2010 ENS de Lyon, CNRS, INRP, University of |
|
3 |
// Lyon 2, University of Franche-Comté, University of Nice |
|
4 |
// Sophia Antipolis, University of Paris 3. |
|
5 |
// |
|
6 |
// The TXM platform is free software: you can redistribute it |
|
7 |
// and/or modify it under the terms of the GNU General Public |
|
8 |
// License as published by the Free Software Foundation, |
|
9 |
// either version 2 of the License, or (at your option) any |
|
10 |
// later version. |
|
11 |
// |
|
12 |
// The TXM platform is distributed in the hope that it will be |
|
13 |
// useful, but WITHOUT ANY WARRANTY; without even the implied |
|
14 |
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
|
15 |
// PURPOSE. See the GNU General Public License for more |
|
16 |
// details. |
|
17 |
// |
|
18 |
// You should have received a copy of the GNU General |
|
19 |
// Public License along with the TXM platform. If not, see |
|
20 |
// http://www.gnu.org/licenses. |
|
21 |
// |
|
22 |
// |
|
23 |
// |
|
24 |
// $LastChangedDate:$ |
|
25 |
// $LastChangedRevision:$ |
|
26 |
// $LastChangedBy:$ |
|
27 |
// |
|
28 |
package org.txm.rcp.swt.widget.structures; |
|
29 |
|
|
30 |
import org.eclipse.swt.SWT; |
|
31 |
import org.eclipse.swt.layout.GridData; |
|
32 |
import org.eclipse.swt.layout.GridLayout; |
|
33 |
import org.eclipse.swt.widgets.Composite; |
|
34 |
import org.eclipse.swt.widgets.Label; |
|
35 |
import org.txm.rcp.messages.TXMUIMessages; |
|
36 |
import org.txm.rcp.swt.widget.QueryWidget; |
|
37 |
import org.txm.searchengine.cqp.CQPSearchEngine; |
|
38 |
import org.txm.searchengine.cqp.corpus.CQPCorpus; |
|
39 |
|
|
40 |
/** |
|
41 |
* The Class AdvancedSubcorpusPanel : a query. |
|
42 |
*/ |
|
43 |
public class AdvancedSubcorpusPanel extends Composite { |
|
44 |
|
|
45 |
/** The corpus. */ |
|
46 |
CQPCorpus corpus; |
|
47 |
|
|
48 |
/** The query. */ |
|
49 |
String query; |
|
50 |
|
|
51 |
/** The query field. */ |
|
52 |
QueryWidget queryField; |
|
53 |
|
|
54 |
/** |
|
55 |
* Instantiates a new complex subcorpus panel. |
|
56 |
* |
|
57 |
* @param parent the parent |
|
58 |
* @param style the style |
|
59 |
* @param corpus the corpus |
|
60 |
*/ |
|
61 |
public AdvancedSubcorpusPanel(Composite parent, int style, CQPCorpus corpus) { |
|
62 |
|
|
63 |
super(parent, style); |
|
64 |
|
|
65 |
this.setLayout(new GridLayout(2, false)); |
|
66 |
this.corpus = corpus; |
|
67 |
|
|
68 |
Label l = new Label(this, SWT.NONE); |
|
69 |
l.setText(TXMUIMessages.query); |
|
70 |
|
|
71 |
queryField = new QueryWidget(this, SWT.BORDER, corpus.getProject(), CQPSearchEngine.getEngine()); |
|
72 |
queryField.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false)); |
|
73 |
|
|
74 |
} |
|
75 |
|
|
76 |
public void updateQueryField() { |
|
77 |
|
|
78 |
queryField.update(); |
|
79 |
} |
|
80 |
|
|
81 |
/** |
|
82 |
* Update display. |
|
83 |
*/ |
|
84 |
public void updateDisplay() { |
|
85 |
this.layout(); |
|
86 |
} |
|
87 |
|
|
88 |
/** |
|
89 |
* Gets the query string. |
|
90 |
* |
|
91 |
* @return the generated query string |
|
92 |
*/ |
|
93 |
public String getQueryString() { |
|
94 |
|
|
95 |
String q = queryField.getQuery().getQueryString(); |
|
96 |
|
|
97 |
return q; |
|
98 |
} |
|
99 |
|
|
100 |
/** |
|
101 |
* |
|
102 |
* @return the raw query without the context filter |
|
103 |
*/ |
|
104 |
public String getQueryFieldValue() { |
|
105 |
|
|
106 |
String query = this.queryField.getText(); |
|
107 |
if (query == null || query.length() == 0) { |
|
108 |
query = getQueryString(); |
|
109 |
} |
|
110 |
return query; |
|
111 |
} |
|
112 |
|
|
113 |
public String getGeneratedName() { |
|
114 |
|
|
115 |
return null; |
|
116 |
} |
|
117 |
} |
|
0 | 118 |
TXM/trunk/bundles/org.txm.rcp/src/main/java/org/txm/rcp/swt/widget/structures/CrossedPartitionPanel.java (revision 3979) | ||
---|---|---|
1 |
package org.txm.rcp.swt.widget.structures; |
|
2 |
|
|
3 |
import java.util.ArrayList; |
|
4 |
import java.util.List; |
|
5 |
import java.util.UUID; |
|
6 |
|
|
7 |
import org.eclipse.jface.viewers.LabelProvider; |
|
8 |
import org.eclipse.swt.SWT; |
|
9 |
import org.eclipse.swt.events.SelectionEvent; |
|
10 |
import org.eclipse.swt.events.SelectionListener; |
|
11 |
import org.eclipse.swt.layout.GridData; |
|
12 |
import org.eclipse.swt.layout.GridLayout; |
|
13 |
import org.eclipse.swt.widgets.Composite; |
|
14 |
import org.eclipse.swt.widgets.Label; |
|
15 |
import org.eclipse.swt.widgets.Text; |
|
16 |
import org.txm.core.messages.TXMCoreMessages; |
|
17 |
import org.txm.rcp.messages.TXMUIMessages; |
|
18 |
import org.txm.searchengine.cqp.clientExceptions.CqiClientException; |
|
19 |
import org.txm.searchengine.cqp.corpus.CQPCorpus; |
|
20 |
import org.txm.searchengine.cqp.corpus.Partition; |
|
21 |
import org.txm.searchengine.cqp.corpus.StructuralUnit; |
|
22 |
import org.txm.searchengine.cqp.corpus.StructuralUnitProperty; |
|
23 |
import org.txm.searchengine.cqp.corpus.Subcorpus; |
|
24 |
import org.txm.utils.logger.Log; |
|
25 |
|
|
26 |
public class CrossedPartitionPanel extends Composite { |
|
27 |
|
|
28 |
/** The selected structural unit property. */ |
|
29 |
private List<StructuralUnitProperty> selectedStructuralUnitProperties = new ArrayList<>(); |
|
30 |
|
|
31 |
/** The structural units final. */ |
|
32 |
private List<StructuralUnit> structuralUnitsFinal; |
|
33 |
|
|
34 |
private Text separatorText; |
|
35 |
|
|
36 |
/** The property combo. */ |
|
37 |
private SuperListViewer propertyCombo; |
|
38 |
|
|
39 |
private CQPCorpus corpus; |
|
40 |
|
|
41 |
private Text expandText; |
|
42 |
|
|
43 |
public CrossedPartitionPanel(Composite parent, int style, CQPCorpus corpus) { |
|
44 |
super(parent, style); |
|
45 |
|
|
46 |
this.corpus = corpus; |
|
47 |
|
|
48 |
GridLayout layout = new GridLayout(2, false); |
|
49 |
this.setLayout(layout); |
|
50 |
|
|
51 |
// StructuralUnit |
|
52 |
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|
53 |
|
|
54 |
List<StructuralUnit> structuralUnits = null; |
|
55 |
try { |
|
56 |
structuralUnits = corpus.getOrderedStructuralUnits(); |
|
57 |
} |
|
58 |
catch (CqiClientException e) { |
|
59 |
Log.severe(TXMCoreMessages.bind(TXMCoreMessages.error_errorP0, Log.toString(e))); |
|
60 |
} |
|
61 |
structuralUnitsFinal = new ArrayList<>(); |
|
62 |
for (StructuralUnit unit : structuralUnits) { |
|
63 |
if (unit.getName().equals("txmcorpus")) continue; // ignore txmcorpus structure //$NON-NLS-1$ |
|
64 |
|
|
65 |
if (unit.getOrderedProperties() != null && unit.getOrderedProperties().size() != 0) { |
|
66 |
/* |
|
67 |
* if ((unit.getName().equals("text") && |
|
68 |
* unit.getProperties().size() > 3)) //$NON-NLS-1$ { |
|
69 |
* structuralUnitsCombo.add(unit.getName()); |
|
70 |
* structuralUnitsFinal.add(unit); } else |
|
71 |
* if (!unit.getName().equals("text")) //$NON-NLS-1$ { |
|
72 |
*/ |
|
73 |
structuralUnitsFinal.add(unit); |
|
74 |
// } |
|
75 |
} |
|
76 |
} |
|
77 |
|
|
78 |
// StructuralUnitProperty |
|
79 |
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|
80 |
|
|
81 |
Label propertyLabel = new Label(this, SWT.NONE); |
|
82 |
propertyLabel.setText(TXMUIMessages.Structures); |
|
83 |
propertyLabel.setLayoutData(new GridData(GridData.END, GridData.CENTER, false, false)); |
|
84 |
propertyLabel.setToolTipText("Select at least two properties"); |
|
85 |
|
|
86 |
propertyCombo = new SuperListViewer(this, SWT.MULTI); |
|
87 |
propertyCombo.setLabelProvider(new LabelProvider() { |
|
88 |
@Override |
|
89 |
public String getText(Object element) { |
|
90 |
if (element instanceof StructuralUnitProperty) { |
|
91 |
return ""+((StructuralUnitProperty)element).getFullName(); //$NON-NLS-1$ |
|
92 |
} else { |
|
93 |
return ""+element; //$NON-NLS-1$ |
|
94 |
} |
|
95 |
} |
|
96 |
}); |
|
97 |
propertyCombo.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true)); |
|
98 |
|
|
99 |
ArrayList<StructuralUnitProperty> all = new ArrayList<>(); |
|
100 |
for (StructuralUnit su : structuralUnitsFinal) { |
|
101 |
for (StructuralUnitProperty property : su.getOrderedProperties()) { |
|
102 |
if (!(su.getName().equals("text") && //$NON-NLS-1$ |
|
103 |
(property.getName().equals("project") || property.getName().equals("base")))) //$NON-NLS-1$ //$NON-NLS-2$ |
|
104 |
all.add(property); |
|
105 |
} |
|
106 |
} |
|
107 |
|
|
108 |
propertyCombo.getList().addSelectionListener(new SelectionListener() { |
|
109 |
|
|
110 |
@Override |
|
111 |
public void widgetDefaultSelected(SelectionEvent e) {} |
|
112 |
|
|
113 |
@Override |
|
114 |
public void widgetSelected(SelectionEvent event) { |
|
115 |
selectedStructuralUnitProperties = propertyCombo.getSelection().toList(); |
|
116 |
} |
|
117 |
}); |
|
118 |
|
|
119 |
propertyCombo.setInput(all); |
|
120 |
propertyCombo.setToolTipText("Select at least two properties"); |
|
121 |
|
|
122 |
Label separatorLabel = new Label(this, SWT.NONE); |
|
123 |
separatorLabel.setText("Values separator"); |
|
124 |
separatorLabel.setLayoutData(new GridData(GridData.END, GridData.CENTER, false, false)); |
|
125 |
separatorLabel.setToolTipText("The separator is inserted between the values of the part names.\nWarning: spaces are not trimmed."); |
|
126 |
|
|
127 |
separatorText = new Text(this, SWT.BORDER); |
|
128 |
separatorText.setText("x"); |
|
129 |
separatorText.setToolTipText("The separator is inserted between the values of the part names.\nWarning: spaces are not trimmed."); |
|
130 |
|
|
131 |
Label expandLabel = new Label(this, SWT.NONE); |
|
132 |
expandLabel.setText("Expand structure"); |
|
133 |
expandLabel.setLayoutData(new GridData(GridData.END, GridData.CENTER, false, false)); |
|
134 |
expandLabel.setToolTipText("Define the limit structure. If not set, the last selected structure is used"); |
|
135 |
|
|
136 |
expandText = new Text(this, SWT.BORDER); |
|
137 |
expandText.setText(""); |
|
138 |
expandText.setToolTipText("Define the limit structure. If not set, the last selected structure is used"); |
|
139 |
} |
|
140 |
|
|
141 |
/** |
|
142 |
* Gets the structural unit property. |
|
143 |
* |
|
144 |
* @return the structural unit property |
|
145 |
*/ |
|
146 |
public List<StructuralUnitProperty> getStructuralUnitProperties() { |
|
147 |
|
|
148 |
return selectedStructuralUnitProperties; |
|
149 |
} |
|
150 |
|
|
151 |
public Partition createPartition(String name) { |
|
152 |
|
|
153 |
if (selectedStructuralUnitProperties.size() < 2) { |
|
154 |
return null; |
|
155 |
} |
|
156 |
|
|
157 |
String partNamePrefix = ""; |
|
158 |
ArrayList<String> structuralUnits = new ArrayList<>(); |
|
159 |
ArrayList<String> structuralUnitProperties = new ArrayList<>(); |
|
160 |
for (StructuralUnitProperty sup : selectedStructuralUnitProperties) { |
|
161 |
structuralUnits.add(sup.getStructuralUnit().getName()); |
|
162 |
structuralUnitProperties.add(sup.getName()); |
|
163 |
} |
|
164 |
ArrayList<String> structuralUnitToIgnore = new ArrayList<>(); |
|
165 |
String separator = separatorText.getText(); |
|
166 |
String expandTarget = expandText.getText(); |
|
167 |
|
|
168 |
PartitionQueriesGenerator pqg = new PartitionQueriesGenerator(); |
|
169 |
Partition partition; |
|
170 |
try { |
|
171 |
partition = pqg.createPartition(corpus, false, |
|
172 |
name, partNamePrefix, separator, |
|
173 |
structuralUnits, structuralUnitProperties, |
|
174 |
structuralUnitToIgnore, expandTarget); |
|
175 |
|
|
176 |
return partition; |
|
177 |
} catch (Exception e) { |
|
178 |
e.printStackTrace(); |
|
179 |
} |
|
180 |
return null; |
|
181 |
|
|
182 |
} |
|
183 |
|
|
184 |
/** |
|
185 |
* Create a list of queries and part names regarding the structural units, structural units properties, structural units to ignore user defined lists and expand target value specified. |
|
186 |
* @author s |
|
187 |
* |
|
188 |
*/ |
|
189 |
public class PartitionQueriesGenerator { |
|
190 |
|
|
191 |
public boolean DEBUG = false; // si DEBUG, alors les requêtes sont affichées mais la partition n'est pas créée |
|
192 |
|
|
193 |
public String PARTITION_NAME = ""; // Nom de la partition (optionnel) |
|
194 |
public List<String> STRUCTURAL_UNITS = new ArrayList<>(); // Liste des unités structurelles sur lesquelles effectuer la partition, ex: ['text', 'div1'] |
|
195 |
public List<String> STRUCTURAL_UNITS_PROPERTIES = new ArrayList<>(); // Propriétés des unités structurelles sur lesquelles effectuer la partition, ex : ['id', 'name'] |
|
196 |
public List<String> STRUCTURAL_UNITS_TO_IGNORE = new ArrayList<>(); // Structure à ignorer, ex. CQL : !speaker (optionnel) |
|
197 |
public String PART_NAMES_PREFIX = ""; // Prefix pour les noms de partie (optionnel) |
|
198 |
public String EXPAND_TARGET = ""; // Expand to target, englobe les empans jusqu'à la balise parente spécifiée. |
|
199 |
public String VALUES_SEPARATOR = "x"; |
|
200 |
// NOTE : Le expand entre en conflit avec les sections à ignorer. |
|
201 |
// Si la target est à un niveau supérieur aux balises à ignorer, il les remet dans liste de résultats CWB et elles ne sont donc pas ignorées |
|
202 |
|
|
203 |
public List<String> queries = new ArrayList<>(); |
|
204 |
public List<String> partNames = new ArrayList<>(); |
|
205 |
|
|
206 |
/** |
|
207 |
* Init the generator and process. |
|
208 |
* @throws CqiClientException |
|
209 |
* @throws InterruptedException |
|
210 |
*/ |
|
211 |
public Partition createPartition(CQPCorpus corpus, boolean debug, |
|
212 |
String partitionName, String partNamePrefix, String separator, |
|
213 |
List<String> structuralUnits, List<String> structuralUnitProperties, |
|
214 |
List<String> structuralUnitToIgnore, String expandTarget) throws CqiClientException, InterruptedException { |
|
215 |
|
|
216 |
PARTITION_NAME = partitionName; |
|
217 |
STRUCTURAL_UNITS = structuralUnits; |
|
218 |
STRUCTURAL_UNITS_PROPERTIES = structuralUnitProperties; |
|
219 |
STRUCTURAL_UNITS_TO_IGNORE = structuralUnitToIgnore; |
|
220 |
PART_NAMES_PREFIX = partNamePrefix; |
|
221 |
EXPAND_TARGET = expandTarget; |
|
222 |
VALUES_SEPARATOR = separator; |
|
223 |
DEBUG = debug; |
|
224 |
|
|
225 |
if (DEBUG) { |
|
226 |
System.out.println("Arguments: "); |
|
227 |
System.out.println("PARTITION_NAME = $PARTITION_NAME"); |
|
228 |
System.out.println("STRUCTURAL_UNITS = $STRUCTURAL_UNITS"); |
|
229 |
System.out.println("STRUCTURAL_UNITS_PROPERTIES = $STRUCTURAL_UNITS_PROPERTIES"); |
|
230 |
System.out.println("STRUCTURAL_UNITS_TO_IGNORE = $STRUCTURAL_UNITS_TO_IGNORE"); |
|
231 |
System.out.println("PART_NAMES_PREFIX = $PART_NAMES_PREFIX"); |
|
232 |
System.out.println("EXPAND_TARGET = $EXPAND_TARGET"); |
|
233 |
System.out.println("DEBUG = $DEBUG"); |
|
234 |
} |
|
235 |
|
|
236 |
if (STRUCTURAL_UNITS.size() > 0 && STRUCTURAL_UNITS.size() == STRUCTURAL_UNITS_PROPERTIES.size()) { |
|
237 |
|
|
238 |
if (DEBUG) System.out.println("Creating the queries on corpus " + corpus + "\""); ; |
|
239 |
if (DEBUG) System.out.println("PARTITION_NAME: "+ PARTITION_NAME); |
|
240 |
|
|
241 |
//Corpus corpus = CorpusManager.getCorpusManager().getCorpus(corpusName); |
|
242 |
|
|
243 |
// Recursing through the corpus and subcorpus |
|
244 |
process(corpus, 0, "", "", VALUES_SEPARATOR); |
|
245 |
|
|
246 |
// Displaying the queries |
|
247 |
if (DEBUG) { |
|
248 |
System.out.println("Queries processed: "); |
|
249 |
for (int i = 0 ; i < queries.size() ; i++) { |
|
250 |
System.out.println(partNames.get(i) + " = " + queries.get(i)); |
|
251 |
} |
|
252 |
} |
|
253 |
|
|
254 |
// Finalizing the queries |
|
255 |
finalizeQueries(); |
|
256 |
|
|
257 |
// Displaying the queries |
|
258 |
if (DEBUG) { |
|
259 |
System.out.println("Queries finalized: "); |
|
260 |
for (int i = 0 ; i < queries.size() ; i++) { |
|
261 |
System.out.println(partNames.get(i) + " = " + queries.get(i)); |
|
262 |
} |
|
263 |
} |
|
264 |
|
|
265 |
if (DEBUG) System.out.println("Queries created."); |
|
266 |
|
|
267 |
// Creating the partition |
|
268 |
if (!DEBUG && queries.size() == partNames.size()) { |
|
269 |
Partition partition = new Partition(corpus); |
|
270 |
partition.setParameters(PARTITION_NAME, queries, partNames); |
|
271 |
partition.compute(); |
|
272 |
return partition; |
|
273 |
} |
|
274 |
} else { |
|
275 |
System.out.println("Error: Structural units count or structural units properties count error."); |
|
276 |
return null; |
|
277 |
} |
|
278 |
return null; |
|
279 |
} |
|
280 |
|
|
281 |
/** |
|
282 |
* Recurse through structural units and structural units properties of corpus and create the queries and the part names. |
|
283 |
* @param corpus the corpus or subcorpus |
|
284 |
* @param index the index for recursion |
|
285 |
* @param tmpQuery the temporary query for creating subcorpus part |
|
286 |
* @param tmpPartName the temporary part name of the subcorpus part |
|
287 |
* @throws CqiClientException |
|
288 |
*/ |
|
289 |
protected void process(CQPCorpus corpus, int index, String tmpQuery, String tmpPartName, String propertySeparator) throws CqiClientException { |
|
290 |
// End of array |
|
291 |
if (index >= STRUCTURAL_UNITS.size()) { |
|
292 |
|
|
293 |
queries.add(tmpQuery); |
|
294 |
partNames.add(PART_NAMES_PREFIX + tmpPartName); |
|
295 |
|
|
296 |
return; |
|
297 |
} |
|
298 |
|
|
299 |
StructuralUnit su = corpus.getStructuralUnit(STRUCTURAL_UNITS.get(index)); |
|
300 |
StructuralUnitProperty sup = su.getProperty(STRUCTURAL_UNITS_PROPERTIES.get(index)); |
|
301 |
|
|
302 |
if (DEBUG) { |
|
303 |
if (index == 0) { |
|
304 |
System.out.println("Pocessing Structural Unit Property " + sup.getFullName() + " on mother corpus " + corpus.getID()); |
|
305 |
} else { |
|
306 |
System.out.println("Pocessing Structural Unit Property " + sup.getFullName() + " on subcorpus part " + tmpPartName); |
|
307 |
} |
|
308 |
} |
|
309 |
|
|
310 |
|
|
311 |
// Creating the queries parts for each structural units properties values |
|
312 |
// for (supValue in sup.getOrderedValues()) { // TODO : signaler bug Matthieu, on ne devrait pas être obligé de repasser le sous-corpus à la méthode car sup a déjà été créée depuis le sous-corpus ? getValues() bugge aussi |
|
313 |
for (String supValue : sup.getOrderedValues(corpus)) { |
|
314 |
|
|
315 |
if (DEBUG) System.out.println("Value " + supValue); |
|
316 |
|
|
317 |
// Getting the subcorpus linked to the structural unit property value |
|
318 |
Subcorpus tmpSubcorpus = corpus.createSubcorpusWithQueryString(su, sup, supValue, "tmp" + UUID.randomUUID()); |
|
319 |
|
|
320 |
// Partition conditions and part name separators |
|
321 |
String and = ""; |
|
322 |
String underscore = ""; |
|
323 |
if (tmpQuery != "") { |
|
324 |
underscore = propertySeparator; |
|
325 |
and = " & "; |
|
326 |
} |
|
327 |
|
|
328 |
process(tmpSubcorpus, index + 1, (tmpQuery + and + "_." + sup.getFullName() + "=\"" + supValue + "\""), tmpPartName + underscore + supValue, propertySeparator); |
|
329 |
|
|
330 |
// Deleting the temporary subcorpus |
|
331 |
// TODO : bug : cette méthode ne supprime pas le corpus sans doute car il faut que le sous-corpus ne contienne pas d'autres sous-corpus ? le delete() en revanche fonctionne. |
|
332 |
// corpus.dropSubcorpus(tmpSubcorpus); |
|
333 |
tmpSubcorpus.delete(); |
|
334 |
} |
|
335 |
} |
|
336 |
|
|
337 |
|
|
338 |
/** |
|
339 |
* Autoname the partition. |
|
340 |
* @param partitionName |
|
341 |
*/ |
|
342 |
protected void autoNamePartition(String partitionName) { |
|
343 |
|
|
344 |
// Structural units names and properties |
|
345 |
for (int i = 0; i < STRUCTURAL_UNITS.size(); i++) { |
|
346 |
partitionName += STRUCTURAL_UNITS.get(i) + '_' + STRUCTURAL_UNITS_PROPERTIES.get(i) + VALUES_SEPARATOR; |
|
347 |
} |
|
348 |
|
|
349 |
// Structural units to ignore |
|
350 |
for (int i = 0; i < STRUCTURAL_UNITS_TO_IGNORE.size(); i++) { |
|
351 |
partitionName += "NOT_" + STRUCTURAL_UNITS_TO_IGNORE.get(i) + '.'; |
|
352 |
} |
|
353 |
|
|
354 |
// Removing last 'x' in partition name |
|
355 |
PARTITION_NAME = partitionName.substring(0, partitionName.length() - 3); |
|
356 |
} |
|
357 |
|
|
358 |
/** |
|
359 |
* Finalize the queries. |
|
360 |
*/ |
|
361 |
protected void finalizeQueries() { |
|
362 |
|
|
363 |
String expandTo = ""; |
|
364 |
// Expanding to user defined target |
|
365 |
if (EXPAND_TARGET != null && EXPAND_TARGET.length() > 0) { |
|
366 |
expandTo = " expand to " + EXPAND_TARGET; |
|
367 |
} |
|
368 |
// Expanding to last child structural unit in user defined hierarchy |
|
369 |
else if(STRUCTURAL_UNITS_TO_IGNORE.size() == 0) { |
|
370 |
expandTo = " expand to " + STRUCTURAL_UNITS.get(STRUCTURAL_UNITS.size() - 1); |
|
371 |
} |
|
372 |
|
|
373 |
// Autonaming the partition |
|
374 |
if (PARTITION_NAME != null && PARTITION_NAME.length() == 0) { |
|
375 |
autoNamePartition(PARTITION_NAME); |
|
376 |
// Finalizing partition name |
|
377 |
if (EXPAND_TARGET != null && EXPAND_TARGET.length() > 0) |
|
378 |
PARTITION_NAME += expandTo.replace(" expand to", ".EXPAND TO").replace(" ", "_"); |
|
379 |
} |
|
380 |
|
|
381 |
// Finalizing queries |
|
382 |
for (int j = 0; j < queries.size(); j++) { |
|
383 |
|
|
384 |
String queryEnd = ""; |
|
385 |
|
|
386 |
// Removing some sections |
|
387 |
for (String sectionToIgnore : STRUCTURAL_UNITS_TO_IGNORE) { |
|
388 |
queryEnd += " & !" + sectionToIgnore; |
|
389 |
} |
|
390 |
|
|
391 |
queryEnd += ']' + expandTo; |
|
392 |
queries.set(j, '[' + queries.get(j) + queryEnd); |
|
393 |
} |
|
394 |
} |
|
395 |
} |
|
396 |
} |
|
0 | 397 |
TXM/trunk/bundles/org.txm.rcp/src/main/java/org/txm/rcp/swt/widget/structures/ContextsSubcorpusPanel.java (revision 3979) | ||
---|---|---|
1 |
// Copyright © 2010-2020 ENS de Lyon., University of Franche-Comté |
|
2 |
// Copyright © 2007-2010 ENS de Lyon, CNRS, INRP, University of |
|
3 |
// Lyon 2, University of Franche-Comté, University of Nice |
|
4 |
// Sophia Antipolis, University of Paris 3. |
|
5 |
// |
|
6 |
// The TXM platform is free software: you can redistribute it |
|
7 |
// and/or modify it under the terms of the GNU General Public |
|
8 |
// License as published by the Free Software Foundation, |
|
9 |
// either version 2 of the License, or (at your option) any |
|
10 |
// later version. |
|
11 |
// |
|
12 |
// The TXM platform is distributed in the hope that it will be |
|
13 |
// useful, but WITHOUT ANY WARRANTY; without even the implied |
|
14 |
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
|
15 |
// PURPOSE. See the GNU General Public License for more |
|
16 |
// details. |
|
17 |
// |
|
18 |
// You should have received a copy of the GNU General |
|
19 |
// Public License along with the TXM platform. If not, see |
|
20 |
// http://www.gnu.org/licenses. |
|
21 |
// |
|
22 |
// |
|
23 |
// |
|
24 |
// $LastChangedDate:$ |
|
25 |
// $LastChangedRevision:$ |
|
26 |
// $LastChangedBy:$ |
|
27 |
// |
|
28 |
package org.txm.rcp.swt.widget.structures; |
|
29 |
|
|
30 |
import java.util.ArrayList; |
|
31 |
import java.util.HashMap; |
|
32 |
import java.util.LinkedHashSet; |
|
33 |
import java.util.List; |
|
34 |
|
|
35 |
import org.apache.commons.lang.StringUtils; |
|
36 |
import org.eclipse.jface.viewers.ArrayContentProvider; |
|
37 |
import org.eclipse.jface.viewers.IStructuredSelection; |
|
38 |
import org.eclipse.jface.viewers.ListViewer; |
|
39 |
import org.eclipse.swt.SWT; |
|
40 |
import org.eclipse.swt.events.SelectionEvent; |
|
41 |
import org.eclipse.swt.events.SelectionListener; |
|
42 |
import org.eclipse.swt.layout.GridData; |
|
43 |
import org.eclipse.swt.layout.GridLayout; |
|
44 |
import org.eclipse.swt.widgets.Button; |
|
45 |
import org.eclipse.swt.widgets.Combo; |
|
46 |
import org.eclipse.swt.widgets.Composite; |
|
47 |
import org.eclipse.swt.widgets.Group; |
|
48 |
import org.eclipse.swt.widgets.Label; |
|
49 |
import org.eclipse.swt.widgets.Spinner; |
|
50 |
import org.eclipse.swt.widgets.Text; |
|
51 |
import org.txm.core.messages.TXMCoreMessages; |
|
52 |
import org.txm.rcp.messages.TXMUIMessages; |
|
53 |
import org.txm.rcp.swt.widget.QueryWidget; |
|
54 |
import org.txm.rcp.swt.widget.parameters.QueryField; |
|
55 |
import org.txm.searchengine.cqp.CQPSearchEngine; |
|
56 |
import org.txm.searchengine.cqp.clientExceptions.CqiClientException; |
|
57 |
import org.txm.searchengine.cqp.corpus.CQPCorpus; |
|
58 |
import org.txm.searchengine.cqp.corpus.StructuralUnit; |
|
59 |
import org.txm.searchengine.cqp.corpus.StructuralUnitProperty; |
|
60 |
|
|
61 |
/** |
|
62 |
* The Class ComplexSubcorpusPanel. |
|
63 |
*/ |
|
64 |
public class ContextsSubcorpusPanel extends Composite { |
|
65 |
|
|
66 |
/** The corpus. */ |
|
67 |
CQPCorpus corpus; |
|
68 |
|
|
69 |
/** The query. */ |
|
70 |
String query; |
|
71 |
|
|
72 |
/** The structuralunits. */ |
|
73 |
List<String> structuralunits; |
|
74 |
|
|
75 |
/** The query field. */ |
|
76 |
QueryWidget queryField; |
|
77 |
|
|
78 |
Combo structuralUnitCombo; |
|
79 |
|
|
80 |
private Spinner wordContextSize; |
|
81 |
|
|
82 |
/** |
|
83 |
* Instantiates a new complex subcorpus panel. |
|
84 |
* |
|
85 |
* @param parent the parent |
|
86 |
* @param style the style |
|
87 |
* @param corpus the corpus |
|
88 |
*/ |
|
89 |
public ContextsSubcorpusPanel(Composite parent, int style, CQPCorpus corpus) { |
|
90 |
|
|
91 |
super(parent, style); |
|
92 |
|
|
93 |
this.setLayout(new GridLayout(2, false)); |
|
94 |
this.corpus = corpus; |
|
95 |
|
|
96 |
try { |
|
97 |
ArrayList<StructuralUnit> tmp = new ArrayList<>(corpus.getOrderedStructuralUnits()); |
|
98 |
this.structuralunits = new ArrayList<String>(); |
|
99 |
for (StructuralUnit su : tmp) { |
|
100 |
if (!(su.getName().equals("txmcorpus"))) { //$NON-NLS-1$ |
|
101 |
this.structuralunits.add(su.getName()); |
|
102 |
} |
|
103 |
} |
|
104 |
} |
|
105 |
catch (CqiClientException e) { |
|
106 |
org.txm.utils.logger.Log.printStackTrace(e); |
|
107 |
} |
|
108 |
|
|
109 |
Label firstStep = new Label(this, SWT.NONE); |
|
110 |
firstStep.setText("1- set pivot"); |
|
111 |
firstStep = new Label(this, SWT.SEPARATOR | SWT.HORIZONTAL); |
|
112 |
firstStep.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false, 2, 1)); |
|
113 |
|
|
114 |
Label l = new Label(this, SWT.NONE); |
|
115 |
l.setText(TXMUIMessages.query); |
|
116 |
|
|
117 |
queryField = new QueryWidget(this, SWT.BORDER, corpus.getProject(), CQPSearchEngine.getEngine()); |
|
118 |
queryField.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false)); |
|
119 |
|
|
120 |
Label secondStep = new Label(this, SWT.NONE); |
|
121 |
secondStep.setText("2- set context"); |
|
122 |
secondStep = new Label(this, SWT.SEPARATOR | SWT.HORIZONTAL); |
|
123 |
secondStep.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false, 2, 1)); |
|
124 |
|
|
125 |
l = new Label(this, SWT.NONE); |
|
126 |
l.setText("Limit"); |
|
127 |
|
|
128 |
structuralUnitCombo = new Combo(this, SWT.SINGLE|SWT.READ_ONLY); |
|
129 |
structuralUnitCombo.setItems(structuralunits.toArray(new String[structuralunits.size()])); |
|
130 |
structuralUnitCombo.add("<w>", 0); |
|
131 |
|
|
132 |
structuralUnitCombo.setText("text"); |
|
133 |
|
|
134 |
l = new Label(this, SWT.NONE); |
|
135 |
l.setText(TXMUIMessages.contextSize); |
|
136 |
|
|
137 |
wordContextSize = new Spinner(this, SWT.NONE); |
|
138 |
wordContextSize.setMinimum(1); |
|
139 |
} |
|
140 |
|
|
141 |
public void updateQueryField() { |
|
142 |
|
|
143 |
queryField.update(); |
|
144 |
} |
|
145 |
|
|
146 |
/** |
|
147 |
* Update display. |
|
148 |
*/ |
|
149 |
public void updateDisplay() { |
|
150 |
this.layout(); |
|
151 |
} |
|
152 |
|
|
153 |
/** |
|
154 |
* Gets the query string. |
|
155 |
* |
|
156 |
* @return the generated query string |
|
157 |
*/ |
|
158 |
public String getQueryString() { |
|
159 |
|
|
160 |
String q = queryField.getQuery().fixQuery(corpus.getLang()).getQueryString(); |
|
161 |
if (!q.contains(" expand to ") && |
|
162 |
(wordContextSize.getSelection() > 1 || !("<w>".equals(structuralUnitCombo.getText())))) { |
|
163 |
q += " expand to"; |
|
164 |
|
|
165 |
if (wordContextSize.getSelection() > 1) { |
|
166 |
q += " " + wordContextSize.getSelection(); |
|
167 |
} |
|
168 |
|
|
169 |
if (!("<w>".equals(structuralUnitCombo.getText()))) { |
|
170 |
q += " " +structuralUnitCombo.getText(); |
|
171 |
} |
|
172 |
} |
|
173 |
|
|
174 |
return q; |
|
175 |
} |
|
176 |
|
|
177 |
/** |
|
178 |
* |
|
179 |
* @return the raw query without the context filter |
|
180 |
*/ |
|
181 |
public String getQueryFieldValue() { |
|
182 |
|
|
183 |
String query = this.queryField.getText(); |
|
184 |
if (query == null || query.length() == 0) { |
|
185 |
query = getQueryString(); |
|
186 |
} |
|
187 |
return query; |
|
188 |
} |
|
189 |
|
|
190 |
public String getGeneratedName() { |
|
191 |
|
|
192 |
String s = queryField.getQueryString()+">"; |
|
193 |
if ("<w>".equals(structuralUnitCombo.getText())) { |
|
194 |
|
|
195 |
if (wordContextSize.getSelection() > 1) { |
|
196 |
return "<"+wordContextSize.getSelection() +"w "+s; |
|
197 |
} else { |
|
198 |
return "<w "+s; |
|
199 |
} |
|
200 |
} else { |
|
201 |
if (wordContextSize.getSelection() > 1) { |
|
202 |
return "<"+wordContextSize.getSelection()+ structuralUnitCombo.getText()+" "+s; |
|
203 |
} else { |
|
204 |
return "<"+structuralUnitCombo.getText()+" "+s; |
|
205 |
} |
|
206 |
} |
|
207 |
|
|
208 |
} |
|
209 |
} |
|
0 | 210 |
TXM/trunk/bundles/org.txm.rcp/src/main/java/org/txm/rcp/swt/widget/structures/AdvancedPartitionPanel.java (revision 3979) | ||
---|---|---|
1 |
package org.txm.rcp.swt.widget.structures; |
|
2 |
|
|
3 |
import java.io.File; |
|
4 |
import java.util.ArrayList; |
|
5 |
import java.util.List; |
|
6 |
import java.util.Properties; |
|
7 |
|
|
8 |
import org.eclipse.swt.SWT; |
|
9 |
import org.eclipse.swt.custom.ScrolledComposite; |
|
10 |
import org.eclipse.swt.events.ControlAdapter; |
|
11 |
import org.eclipse.swt.events.ControlEvent; |
|
12 |
import org.eclipse.swt.graphics.Rectangle; |
|
13 |
import org.eclipse.swt.layout.GridData; |
|
14 |
import org.eclipse.swt.layout.GridLayout; |
|
15 |
import org.eclipse.swt.widgets.Button; |
|
16 |
import org.eclipse.swt.widgets.Composite; |
|
17 |
import org.eclipse.swt.widgets.Event; |
|
18 |
import org.eclipse.swt.widgets.FileDialog; |
|
19 |
import org.eclipse.swt.widgets.Listener; |
|
20 |
import org.eclipse.swt.widgets.Text; |
|
21 |
import org.txm.core.messages.TXMCoreMessages; |
|
22 |
import org.txm.rcp.messages.TXMUIMessages; |
|
23 |
import org.txm.rcp.swt.widget.QueryWidget; |
|
24 |
import org.txm.searchengine.cqp.CQPSearchEngine; |
|
25 |
import org.txm.searchengine.cqp.corpus.CQPCorpus; |
|
26 |
import org.txm.searchengine.cqp.corpus.Partition; |
|
27 |
import org.txm.utils.io.IOUtils; |
|
28 |
import org.txm.utils.logger.Log; |
|
29 |
|
|
30 |
public class AdvancedPartitionPanel extends Composite { |
|
31 |
|
|
32 |
// for the "advanced" tab |
|
33 |
/** The queries. */ |
|
34 |
private List<QueryWidget> queries = new ArrayList<>(); |
|
35 |
|
|
36 |
/** The part names. */ |
|
37 |
private List<Text> partNames = new ArrayList<>(); |
|
38 |
|
|
39 |
/** The queries string. */ |
|
40 |
List<String> queriesString = new ArrayList<>(); |
|
41 |
|
|
42 |
private CQPCorpus corpus; |
|
43 |
|
|
44 |
private ScrolledComposite scrollComposite; |
|
45 |
|
|
46 |
private Composite compositeForAdvanced; |
|
47 |
|
|
48 |
public AdvancedPartitionPanel(Composite parent, int style, CQPCorpus corpus) { |
|
49 |
super(parent, style); |
|
50 |
|
|
51 |
this.setLayout(new GridLayout(2, false)); |
|
52 |
this.corpus = corpus; |
|
53 |
|
|
54 |
scrollComposite = new ScrolledComposite(this, SWT.V_SCROLL); |
|
55 |
scrollComposite.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true, 2, 1)); |
|
56 |
|
|
57 |
Button importButton = new Button(this, SWT.NONE); |
|
58 |
importButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_CENTER, GridData.FILL, false, false)); |
|
59 |
importButton.setText("+ from properties file..."); //$NON-NLS-1$ |
|
60 |
importButton.addListener(SWT.Selection, new Listener() { |
|
61 |
@Override |
|
62 |
public void handleEvent(Event event) { |
|
63 |
FileDialog d = new FileDialog(event.display.getActiveShell()); |
|
64 |
d.setFilterExtensions(new String[] {"*.properties"}); |
|
65 |
d.setText("Select a .properties file containing CQL queries"); |
|
66 |
String path = d.open(); |
|
67 |
if (path != null) { |
|
68 |
Properties props = new Properties(); |
|
69 |
try { |
|
70 |
props.load(IOUtils.getReader(new File(path))); |
|
71 |
for (Object key : props.keySet()) { |
|
72 |
String value = props.getProperty(key.toString()); |
|
73 |
QueryWidget qw = addQueryField(key.toString().substring(0, Math.min(20, key.toString().length())), value); |
|
74 |
} |
|
75 |
} catch (Exception e) { |
|
76 |
// TODO Auto-generated catch block |
|
77 |
e.printStackTrace(); |
|
78 |
} |
|
79 |
} |
|
80 |
|
|
81 |
} |
|
82 |
}); |
|
83 |
|
|
84 |
compositeForAdvanced = new Composite(scrollComposite, SWT.NONE); |
|
85 |
GridLayout layoutForAdvanced = new GridLayout(4, false); |
|
86 |
compositeForAdvanced.setLayout(layoutForAdvanced); |
|
87 |
|
|
88 |
scrollComposite.setContent(compositeForAdvanced); |
|
89 |
scrollComposite.setExpandVertical(true); |
|
90 |
scrollComposite.setExpandHorizontal(true); |
|
91 |
scrollComposite.addControlListener(new ControlAdapter() { |
|
92 |
|
|
93 |
@Override |
|
94 |
public void controlResized(ControlEvent e) { |
|
95 |
|
|
96 |
Rectangle r = scrollComposite.getClientArea(); |
|
97 |
scrollComposite.setMinSize(compositeForAdvanced.computeSize(r.width, SWT.DEFAULT)); |
|
98 |
} |
|
99 |
}); |
|
100 |
|
|
101 |
createAdvancedQueryField(); |
|
102 |
} |
|
103 |
|
|
104 |
/** |
|
105 |
* Creates the advanced query field. |
|
106 |
* |
|
107 |
*/ |
|
108 |
private void createAdvancedQueryField() { |
|
109 |
|
|
110 |
addQueryField(); |
|
111 |
Rectangle r = scrollComposite.getClientArea(); |
|
112 |
scrollComposite.setMinSize(compositeForAdvanced.computeSize(r.width, SWT.DEFAULT)); |
|
113 |
} |
|
114 |
|
|
115 |
/** |
|
116 |
* Adds the query field. |
|
117 |
* |
|
118 |
*/ |
|
119 |
private QueryWidget addQueryField() { |
|
120 |
|
|
121 |
return addQueryField(null, null); |
|
122 |
} |
|
123 |
|
|
124 |
/** |
|
125 |
* Adds the query field. |
|
126 |
* |
|
127 |
* @param name the query name |
|
128 |
* @param value the query |
|
129 |
*/ |
|
130 |
private QueryWidget addQueryField(String name, String value) { |
|
131 |
|
|
132 |
final Text advancedPartLabel = new Text(compositeForAdvanced, SWT.BORDER); |
|
133 |
advancedPartLabel.setText(TXMUIMessages.part + (partNames.size() + 1)); |
|
134 |
advancedPartLabel.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, false, false)); |
|
135 |
if (name != null && name.length() > 0) { |
|
136 |
advancedPartLabel.setText(name); |
|
137 |
} |
|
138 |
partNames.add(advancedPartLabel); |
|
139 |
|
|
140 |
final QueryWidget queryText; |
|
141 |
queryText = new QueryWidget(compositeForAdvanced, SWT.DROP_DOWN, corpus.getProject(), CQPSearchEngine.getEngine()); |
|
142 |
queryText.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false)); |
|
143 |
GridData gridData = new GridData(GridData.FILL, GridData.FILL, true, false); |
|
144 |
// gridData.widthHint = convertHeightInCharsToPixels(20); |
|
145 |
queryText.setLayoutData(gridData); |
|
146 |
queries.add(queryText); |
|
147 |
if (value != null) { |
|
148 |
queryText.setText(value); |
|
149 |
} |
|
150 |
|
|
151 |
Button plusButton = new Button(compositeForAdvanced, SWT.NONE); |
|
152 |
plusButton.setText("+"); //$NON-NLS-1$ |
|
153 |
plusButton.addListener(SWT.Selection, new Listener() { |
|
154 |
|
|
155 |
@Override |
|
156 |
public void handleEvent(Event event) { |
|
157 |
addQueryField(); |
|
158 |
} |
|
159 |
}); |
|
160 |
|
|
161 |
final Button minusButton = new Button(compositeForAdvanced, SWT.NONE); |
|
162 |
minusButton.setText("-"); //$NON-NLS-1$ |
|
163 |
minusButton.addListener(SWT.Selection, new Listener() { |
|
164 |
|
|
165 |
@Override |
|
166 |
public void handleEvent(Event event) { |
|
167 |
if (queries.size() <= 1) return; |
|
168 |
queries.remove(queryText); |
|
169 |
partNames.remove(advancedPartLabel); |
|
170 |
advancedPartLabel.dispose(); |
|
171 |
queryText.dispose(); |
|
172 |
minusButton.dispose(); |
|
173 |
plusButton.dispose(); |
|
174 |
compositeForAdvanced.layout(true); |
|
175 |
} |
|
176 |
}); |
|
177 |
Rectangle r = scrollComposite.getClientArea(); |
|
178 |
scrollComposite.setMinSize(compositeForAdvanced.computeSize(r.width, SWT.DEFAULT)); |
|
179 |
scrollComposite.update(); |
|
180 |
scrollComposite.layout(); |
|
181 |
compositeForAdvanced.update(); |
|
182 |
compositeForAdvanced.layout(); |
|
183 |
|
|
184 |
return queryText; |
|
185 |
} |
|
186 |
|
|
187 |
/** |
|
188 |
* Gets the advance part names. |
|
189 |
* |
|
190 |
* @return the advance part names |
|
191 |
*/ |
|
192 |
private List<String> getAdvancePartNames() { |
|
193 |
|
|
194 |
ArrayList<String> values = new ArrayList<>(); |
|
195 |
int count = 0; |
|
196 |
for (Text t : partNames) { |
|
197 |
String name = t.getText().trim(); |
|
198 |
if (name.length() == 0) { |
|
199 |
name = TXMUIMessages.part + count++; |
|
200 |
} |
|
201 |
values.add(name); |
|
202 |
} |
|
203 |
return values; |
|
204 |
} |
|
205 |
|
|
206 |
/** |
|
207 |
* Gets the queries. |
|
208 |
* |
|
209 |
* @return the queries |
|
210 |
*/ |
|
211 |
public List<String> getQueries() { |
|
212 |
|
|
213 |
return queriesString; |
|
214 |
} |
|
215 |
|
|
216 |
/** |
|
217 |
* Return true if no query is currently given in the "advanced" tab (ie if |
|
218 |
* all Text field opened are empty). |
|
219 |
* |
|
220 |
* @return true, if successful |
|
221 |
*/ |
|
222 |
public boolean isQueriesSet() { |
|
223 |
|
|
224 |
for (QueryWidget query : queries) { |
|
225 |
if (query.getText().length() == 0) { |
|
226 |
return true; |
|
227 |
} |
|
228 |
} |
|
229 |
return false; |
|
230 |
} |
|
231 |
|
|
232 |
public Partition createPartition(String name) { |
|
233 |
|
|
234 |
queriesString.clear(); |
|
235 |
for (QueryWidget query : queries) { |
|
236 |
queriesString.add(query.getQueryString()); |
|
237 |
//query.memorize(); |
|
238 |
} |
|
239 |
|
|
240 |
Partition partition = null; |
|
241 |
|
|
242 |
try { |
|
243 |
// auto-naming if needed |
|
244 |
if (name.isEmpty()) { |
|
245 |
name = "partition" + (this.corpus.getPartitions().size() + 1); //$NON-NLS-1$ |
|
246 |
Log.info(TXMCoreMessages.bind(TXMUIMessages.noPartitionNameWasSpecifiedTheNameIsP0, name)); |
|
247 |
} |
|
248 |
|
|
249 |
partition = new Partition(this.corpus); |
|
250 |
partition.setParameters(name, this.getQueries(), this.getAdvancePartNames()); |
|
251 |
} |
|
252 |
catch (Exception e) { |
|
253 |
org.txm.utils.logger.Log.printStackTrace(e); |
|
254 |
return null; |
|
255 |
} |
|
256 |
|
|
257 |
return partition; |
|
258 |
} |
|
259 |
} |
|
0 | 260 |
TXM/trunk/bundles/org.txm.rcp/src/main/java/org/txm/rcp/swt/widget/structures/SimplePartitionPanel.java (revision 3979) | ||
---|---|---|
1 |
package org.txm.rcp.swt.widget.structures; |
|
2 |
|
|
3 |
import java.util.ArrayList; |
|
4 |
import java.util.List; |
|
5 |
|
|
6 |
import org.eclipse.swt.SWT; |
|
7 |
import org.eclipse.swt.events.SelectionEvent; |
|
8 |
import org.eclipse.swt.events.SelectionListener; |
|
9 |
import org.eclipse.swt.layout.GridData; |
|
10 |
import org.eclipse.swt.layout.GridLayout; |
|
11 |
import org.eclipse.swt.widgets.Combo; |
|
12 |
import org.eclipse.swt.widgets.Composite; |
|
13 |
import org.eclipse.swt.widgets.Label; |
|
14 |
import org.txm.core.messages.TXMCoreMessages; |
|
15 |
import org.txm.rcp.messages.TXMUIMessages; |
|
16 |
import org.txm.searchengine.cqp.clientExceptions.CqiClientException; |
|
17 |
import org.txm.searchengine.cqp.corpus.CQPCorpus; |
|
18 |
import org.txm.searchengine.cqp.corpus.Partition; |
|
19 |
import org.txm.searchengine.cqp.corpus.StructuralUnit; |
|
20 |
import org.txm.searchengine.cqp.corpus.StructuralUnitProperty; |
|
21 |
import org.txm.utils.logger.Log; |
|
22 |
|
|
23 |
public class SimplePartitionPanel extends Composite { |
|
24 |
|
|
25 |
// For the "simple" tab |
|
26 |
/** The selected structural unit. */ |
|
27 |
private StructuralUnit selectedStructuralUnit; |
|
28 |
|
|
29 |
/** The selected structural unit property. */ |
|
30 |
private StructuralUnitProperty selectedStructuralUnitProperty; |
|
31 |
|
|
32 |
/** The structural units combo. */ |
|
33 |
private Combo structuralUnitsCombo; |
|
34 |
|
|
35 |
/** The structural units final. */ |
|
36 |
private List<StructuralUnit> structuralUnitsFinal; |
|
37 |
|
|
38 |
/** The property combo. */ |
|
39 |
private Combo propertyCombo; |
|
40 |
|
|
41 |
private CQPCorpus corpus; |
|
42 |
|
|
43 |
public SimplePartitionPanel(Composite parent, int style, CQPCorpus corpus) { |
|
44 |
super(parent, style); |
|
45 |
|
|
46 |
this.corpus = corpus; |
|
47 |
|
|
48 |
GridLayout layout = new GridLayout(2, false); |
|
49 |
this.setLayout(layout); |
|
50 |
|
|
51 |
// StructuralUnit |
|
52 |
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|
53 |
|
|
54 |
Label structureLabel = new Label(this, SWT.NONE); |
|
55 |
structureLabel.setText(TXMUIMessages.ampStructureColon); |
|
56 |
structureLabel.setLayoutData(new GridData(GridData.END, GridData.CENTER, false, false)); |
|
57 |
|
|
58 |
structuralUnitsCombo = new Combo(this, SWT.READ_ONLY); |
|
59 |
structuralUnitsCombo.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false)); |
|
60 |
|
|
61 |
List<StructuralUnit> structuralUnits = null; |
|
62 |
try { |
|
63 |
structuralUnits = corpus.getOrderedStructuralUnits(); |
|
64 |
} |
|
65 |
catch (CqiClientException e) { |
|
66 |
Log.severe(TXMCoreMessages.bind(TXMCoreMessages.error_errorP0, Log.toString(e))); |
|
67 |
} |
|
68 |
structuralUnitsFinal = new ArrayList<>(); |
|
69 |
for (StructuralUnit unit : structuralUnits) { |
|
70 |
if (unit.getName().equals("txmcorpus")) continue; // ignore txmcorpus structure //$NON-NLS-1$ |
|
71 |
|
|
72 |
if (unit.getOrderedProperties() != null && unit.getOrderedProperties().size() != 0) { |
|
73 |
/* |
|
74 |
* if ((unit.getName().equals("text") && |
|
75 |
* unit.getProperties().size() > 3)) //$NON-NLS-1$ { |
|
76 |
* structuralUnitsCombo.add(unit.getName()); |
|
77 |
* structuralUnitsFinal.add(unit); } else |
|
78 |
* if (!unit.getName().equals("text")) //$NON-NLS-1$ { |
|
79 |
*/ |
|
80 |
structuralUnitsCombo.add(unit.getName()); |
|
81 |
structuralUnitsFinal.add(unit); |
|
82 |
// } |
|
83 |
} |
|
84 |
} |
|
85 |
|
|
86 |
if (structuralUnitsCombo.getItemCount() == 0) { |
|
87 |
|
|
88 |
} |
|
89 |
else { |
|
90 |
structuralUnitsCombo.select(0); |
|
91 |
String[] items = structuralUnitsCombo.getItems(); |
|
92 |
for (int i = 0; i < items.length; i++) { |
|
93 |
if (items[i].equals("text")) { //$NON-NLS-1$ |
|
94 |
structuralUnitsCombo.select(i); |
|
95 |
break; |
|
96 |
} |
|
97 |
} |
|
98 |
selectedStructuralUnit = structuralUnitsFinal.get(0); |
|
99 |
} |
|
100 |
// combo.setSize (200, 200); |
|
101 |
|
|
102 |
// StructuralUnitProperty |
|
103 |
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|
104 |
|
|
105 |
Label propertyLabel = new Label(this, SWT.NONE); |
|
106 |
propertyLabel.setText(TXMUIMessages.ampPropertyColon); |
|
107 |
propertyLabel.setLayoutData(new GridData(GridData.END, GridData.CENTER, false, false)); |
|
108 |
|
|
109 |
propertyCombo = new Combo(this, SWT.READ_ONLY); |
|
110 |
propertyCombo.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false)); |
|
111 |
|
|
112 |
// combo.setSize (200, 200); |
|
113 |
structuralUnitsCombo.addSelectionListener(new SelectionListener() { |
|
114 |
|
|
115 |
@Override |
|
116 |
public void widgetDefaultSelected(SelectionEvent e) {} |
|
117 |
|
|
118 |
@Override |
|
119 |
public void widgetSelected(SelectionEvent event) { |
|
120 |
|
|
121 |
reloadProperties(); |
|
122 |
} |
|
123 |
}); |
|
124 |
|
|
125 |
for (StructuralUnitProperty property : structuralUnitsFinal.get(0).getOrderedProperties()) { |
|
126 |
if (!(structuralUnitsFinal.get(0).getName().equals("text") && //$NON-NLS-1$ |
|
127 |
(property.getName().equals("project") || property.getName().equals("base")))) //$NON-NLS-1$ //$NON-NLS-2$ |
|
128 |
propertyCombo.add(property.getName()); |
|
129 |
} |
|
130 |
propertyCombo.select(0); |
|
131 |
selectedStructuralUnitProperty = selectedStructuralUnit.getOrderedProperties().get(0); |
|
132 |
|
|
133 |
propertyCombo.addSelectionListener(new SelectionListener() { |
|
134 |
|
|
135 |
@Override |
|
136 |
public void widgetDefaultSelected(SelectionEvent e) {} |
|
137 |
|
|
138 |
@Override |
|
139 |
public void widgetSelected(SelectionEvent event) { |
|
140 |
|
|
141 |
selectedStructuralUnitProperty = selectedStructuralUnit.getOrderedProperties().get(propertyCombo.getSelectionIndex()); |
|
142 |
} |
|
143 |
}); |
|
144 |
|
|
145 |
reloadProperties(); |
|
146 |
} |
|
147 |
|
|
148 |
/** |
|
149 |
* Reload values. |
|
150 |
*/ |
|
151 |
protected void reloadValues() { |
|
152 |
|
|
153 |
List<StructuralUnitProperty> properties = null; |
|
154 |
selectedStructuralUnit = structuralUnitsFinal.get(structuralUnitsCombo.getSelectionIndex()); |
|
155 |
|
|
156 |
properties = selectedStructuralUnit.getOrderedProperties(); |
|
157 |
propertyCombo.removeAll(); |
|
158 |
for (StructuralUnitProperty property : properties) { |
|
159 |
/* |
|
160 |
* if (!(selectedStructuralUnit.getName().equals("text") && |
|
161 |
* //$NON-NLS-1$ (property.getName().equals("id") || //$NON-NLS-1$ |
|
162 |
* property.getName().equals("base") || //$NON-NLS-1$ |
|
163 |
* property.getName().equals("project")))) //$NON-NLS-1$ |
|
164 |
*/ |
|
165 |
if (selectedStructuralUnit.getName().equals("text") && //$NON-NLS-1$ |
|
166 |
(property.getName().equals("project") || property.getName().equals("base"))) continue; // ignore technical properties //$NON-NLS-1$ //$NON-NLS-2$ |
|
167 |
propertyCombo.add(property.getName()); |
|
168 |
} |
|
169 |
if (propertyCombo.getItemCount() > 0) { |
|
170 |
propertyCombo.select(0); |
|
171 |
String[] items = propertyCombo.getItems(); |
|
172 |
for (int i = 0; i < items.length; i++) { |
|
173 |
if (items[i].equals("id")) { //$NON-NLS-1$ |
|
174 |
propertyCombo.select(i); |
|
175 |
break; |
|
176 |
} |
|
177 |
} |
|
178 |
selectedStructuralUnitProperty = selectedStructuralUnit |
|
179 |
.getOrderedProperties().get(0); |
|
180 |
// this.getButton(IDialogConstants.OK_ID).setEnabled(true); |
|
181 |
} |
|
182 |
} |
|
183 |
|
|
184 |
/** |
|
185 |
* Reload properties. |
|
186 |
*/ |
|
187 |
protected void reloadProperties() { |
|
188 |
|
|
189 |
selectedStructuralUnit = structuralUnitsFinal.get(structuralUnitsCombo.getSelectionIndex()); |
|
190 |
List<StructuralUnitProperty> properties = null; |
|
191 |
selectedStructuralUnit = structuralUnitsFinal.get(structuralUnitsCombo.getSelectionIndex()); |
|
192 |
|
|
193 |
properties = selectedStructuralUnit.getOrderedProperties(); |
|
194 |
propertyCombo.removeAll(); |
|
195 |
for (StructuralUnitProperty property : properties) { |
|
196 |
/* |
|
197 |
* if (!(selectedStructuralUnit.getName().equals("text") && |
|
198 |
* //$NON-NLS-1$ (property.getName().equals("id") || //$NON-NLS-1$ |
|
199 |
* property.getName().equals("base") || //$NON-NLS-1$ |
|
200 |
* property.getName().equals("project")))) //$NON-NLS-1$ |
|
201 |
*/ |
|
202 |
if (selectedStructuralUnit.getName().equals("text") && //$NON-NLS-1$ |
|
203 |
(property.getName().equals("project") || property.getName().equals("base"))) continue; // ignore technical properties //$NON-NLS-1$ //$NON-NLS-2$ |
|
204 |
propertyCombo.add(property.getName()); |
|
205 |
} |
|
206 |
if (propertyCombo.getItemCount() > 0) { |
|
207 |
propertyCombo.select(0); |
|
208 |
String[] items = propertyCombo.getItems(); |
|
209 |
for (int i = 0; i < items.length; i++) { |
|
210 |
if (items[i].equals("id")) { //$NON-NLS-1$ |
|
211 |
propertyCombo.select(i); |
|
212 |
break; |
|
213 |
} |
|
214 |
} |
|
215 |
selectedStructuralUnitProperty = selectedStructuralUnit |
|
216 |
.getOrderedProperties().get(0); |
|
217 |
// this.getButton(IDialogConstants.OK_ID).setEnabled(true); |
|
218 |
} |
|
219 |
} |
|
220 |
|
|
221 |
/** |
|
222 |
* Gets the structural unit. |
|
223 |
* |
|
224 |
* @return the structural unit |
|
225 |
*/ |
|
226 |
public StructuralUnit getStructuralUnit() { |
|
227 |
|
|
228 |
return selectedStructuralUnit; |
|
229 |
} |
|
230 |
|
|
231 |
/** |
|
232 |
* Gets the structural unit property. |
|
233 |
* |
|
234 |
* @return the structural unit property |
|
235 |
*/ |
|
236 |
public StructuralUnitProperty getStructuralUnitProperty() { |
|
237 |
|
|
238 |
return selectedStructuralUnitProperty; |
|
239 |
} |
|
240 |
|
|
241 |
public Partition createPartition(String name) { |
|
242 |
|
|
243 |
Partition partition = null; |
|
244 |
|
|
245 |
// Simple mode |
|
246 |
|
|
247 |
StructuralUnit structuralUnit = this.structuralUnitsFinal.get(this.structuralUnitsCombo.getSelectionIndex()); |
|
248 |
StructuralUnitProperty property = structuralUnit.getProperty(this.propertyCombo.getText()); |
|
249 |
try { |
|
250 |
// auto-naming if needed |
|
251 |
if (name.isEmpty()) { |
|
252 |
name = property.asFullNameString(); |
|
253 |
} |
|
254 |
|
|
255 |
partition = new Partition(corpus); |
|
256 |
partition.setParameters(name, property, null); |
|
257 |
} |
|
258 |
catch (Exception e) { |
|
259 |
org.txm.utils.logger.Log.printStackTrace(e); |
|
260 |
return null; |
|
261 |
} |
|
262 |
|
|
263 |
return partition; |
|
264 |
} |
|
265 |
} |
|
0 | 266 |
Formats disponibles : Unified diff