Révision 3729
TXM/trunk/bundles/org.txm.rcp/src/main/java/org/txm/rcp/views/cmdparameters/TXMResultParametersView.java (revision 3729) | ||
---|---|---|
281 | 281 |
c = sp; |
282 | 282 |
} |
283 | 283 |
else if (clazz.equals(IQuery.class)) { |
284 |
final QueryWidget qw = new QueryWidget(panel, SWT.NONE); |
|
284 |
final QueryWidget qw = new QueryWidget(panel, SWT.NONE, null, null);
|
|
285 | 285 |
if (value != null) { |
286 | 286 |
qw.setText(((IQuery) value).getQueryString()); |
287 | 287 |
} |
TXM/trunk/bundles/org.txm.rcp/src/main/java/org/txm/rcp/actions/CreateSubcorpusDialog.java (revision 3729) | ||
---|---|---|
196 | 196 |
advancedPartLabel.setText(TXMUIMessages.ampQuery); |
197 | 197 |
advancedPartLabel.setLayoutData(new GridData(GridData.END, GridData.CENTER, false, false)); |
198 | 198 |
|
199 |
queryText = new QueryWidget(compositeForAdvanced, SWT.DROP_DOWN); |
|
199 |
queryText = new QueryWidget(compositeForAdvanced, SWT.DROP_DOWN, corpus.getProject(), null);
|
|
200 | 200 |
queryText.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false)); |
201 | 201 |
GridData gridData = new GridData(GridData.FILL, GridData.CENTER, true, false); |
202 | 202 |
gridData.widthHint = convertHeightInCharsToPixels(20); |
TXM/trunk/bundles/org.txm.rcp/src/main/java/org/txm/rcp/actions/CreatePartitionDialog.java (revision 3729) | ||
---|---|---|
524 | 524 |
partNames.add(advancedPartLabel); |
525 | 525 |
|
526 | 526 |
final QueryWidget queryText; |
527 |
queryText = new QueryWidget(compositeForAdvanced, SWT.DROP_DOWN); |
|
528 |
queryText.setLayoutData(new GridData(GridData.FILL, GridData.FILL, |
|
529 |
true, false)); |
|
530 |
GridData gridData = new GridData(GridData.FILL, GridData.FILL, true, |
|
531 |
false); |
|
527 |
queryText = new QueryWidget(compositeForAdvanced, SWT.DROP_DOWN, corpus.getProject(), null); |
|
528 |
queryText.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false)); |
|
529 |
GridData gridData = new GridData(GridData.FILL, GridData.FILL, true, false); |
|
532 | 530 |
// gridData.widthHint = convertHeightInCharsToPixels(20); |
533 | 531 |
queryText.setLayoutData(gridData); |
534 | 532 |
queries.add(queryText); |
TXM/trunk/bundles/org.txm.rcp/src/main/java/org/txm/rcp/preferences/UserPreferencePage.java (revision 3729) | ||
---|---|---|
30 | 30 |
import org.eclipse.jface.preference.BooleanFieldEditor; |
31 | 31 |
import org.eclipse.jface.preference.IntegerFieldEditor; |
32 | 32 |
import org.txm.core.preferences.TBXPreferences; |
33 |
import org.txm.objects.Project; |
|
34 |
import org.txm.objects.Workspace; |
|
33 | 35 |
import org.txm.rcp.messages.TXMUIMessages; |
36 |
import org.txm.searchengine.core.QueryHistory; |
|
34 | 37 |
|
35 | 38 |
/** |
36 | 39 |
* User preferences page. |
... | ... | |
69 | 72 |
.getFieldEditorParent())); |
70 | 73 |
|
71 | 74 |
this.addField(new IntegerFieldEditor(RCPPreferences.MAX_NUMBER_OF_COLUMNS, "The maximum number of columns shown in tables", this.getFieldEditorParent())); |
75 |
|
|
76 |
this.addField(new IntegerFieldEditor(TBXPreferences.QUERY_HISTORY_SIZE, "The maximum number of query stored in the query history", this.getFieldEditorParent())); |
|
72 | 77 |
} |
78 |
|
|
79 |
@Override |
|
80 |
public boolean performOk() { |
|
81 |
boolean ret = super.performOk(); |
|
82 |
if (ret) { |
|
83 |
|
|
84 |
int MAX = TBXPreferences.getInstance().getInt(TBXPreferences.QUERY_HISTORY_SIZE); |
|
85 |
for (Project p : Workspace.getInstance().getProjects()) { |
|
86 |
QueryHistory h = p.getFirstChild(QueryHistory.class); |
|
87 |
if (h != null) { |
|
88 |
h.reduceSize(MAX); |
|
89 |
} |
|
90 |
} |
|
91 |
} |
|
92 |
|
|
93 |
return ret; |
|
94 |
} |
|
73 | 95 |
} |
TXM/trunk/bundles/org.txm.rcp/src/main/java/org/txm/rcp/swt/widget/NamedAssistedQueryWidget.java (revision 3729) | ||
---|---|---|
45 | 45 |
import org.txm.searchengine.cqp.corpus.CQPCorpus; |
46 | 46 |
|
47 | 47 |
|
48 |
// TODO: Auto-generated Javadoc |
|
49 | 48 |
/** |
50 | 49 |
* the QueryWidget plus the button to open the QueryAssisDialog @ author |
51 | 50 |
* mdecorde. |
... | ... | |
88 | 87 |
magicstick.addSelectionListener(new SelectionListener() { |
89 | 88 |
@Override |
90 | 89 |
public void widgetSelected(SelectionEvent e) { |
91 |
QueryAssistDialog d = new QueryAssistDialog(e.display |
|
92 |
.getActiveShell(), corpus); |
|
90 |
QueryAssistDialog d = new QueryAssistDialog(e.display.getActiveShell(), corpus); |
|
93 | 91 |
// System.out.println(d); |
94 | 92 |
if (d.open() == Window.OK) { |
95 | 93 |
querywidget.setText(d.getQuery()); |
... | ... | |
102 | 100 |
} |
103 | 101 |
}); |
104 | 102 |
|
105 |
querywidget = new QueryWidget(this, style); |
|
103 |
querywidget = new QueryWidget(this, style, corpus.getProject(), null);
|
|
106 | 104 |
querywidget.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, true)); |
107 | 105 |
} |
108 | 106 |
|
TXM/trunk/bundles/org.txm.rcp/src/main/java/org/txm/rcp/swt/widget/parameters/QueryField.java (revision 3729) | ||
---|---|---|
25 | 25 |
gd.widthHint = 100; |
26 | 26 |
l.setLayoutData(gd); |
27 | 27 |
|
28 |
w = new QueryWidget(this, SWT.BORDER); |
|
28 |
w = new QueryWidget(this, SWT.BORDER, null, null);
|
|
29 | 29 |
w.setLayoutData(new GridData(SWT.FILL, SWT.LEFT, true, false)); |
30 | 30 |
resetToDefault(); |
31 | 31 |
} |
TXM/trunk/bundles/org.txm.rcp/src/main/java/org/txm/rcp/swt/widget/AssistedChoiceQueryWidget.java (revision 3729) | ||
---|---|---|
173 | 173 |
|
174 | 174 |
setMagicEnabled("CQP".equals(initialEngine.getName())); //$NON-NLS-1$ |
175 | 175 |
|
176 |
querywidget = new QueryWidget(this, style, initialEngine); |
|
176 |
querywidget = new QueryWidget(this, style, corpus.getProject(), initialEngine);
|
|
177 | 177 |
querywidget.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false)); |
178 | 178 |
} |
179 | 179 |
|
TXM/trunk/bundles/org.txm.rcp/src/main/java/org/txm/rcp/swt/widget/QueryWidget.java (revision 3729) | ||
---|---|---|
27 | 27 |
// |
28 | 28 |
package org.txm.rcp.swt.widget; |
29 | 29 |
|
30 |
import java.util.ArrayList; |
|
30 | 31 |
import java.util.Deque; |
31 | 32 |
import java.util.LinkedList; |
32 | 33 |
|
33 | 34 |
import org.eclipse.swt.widgets.Combo; |
34 | 35 |
import org.eclipse.swt.widgets.Composite; |
36 |
import org.txm.objects.Project; |
|
35 | 37 |
import org.txm.searchengine.core.IQuery; |
38 |
import org.txm.searchengine.core.Query; |
|
39 |
import org.txm.searchengine.core.QueryHistory; |
|
36 | 40 |
import org.txm.searchengine.core.SearchEngine; |
37 | 41 |
import org.txm.searchengine.core.SearchEnginesManager; |
42 |
import org.txm.searchengine.cqp.CQPSearchEngine; |
|
38 | 43 |
|
39 | 44 |
// TODO: Auto-generated Javadoc |
40 | 45 |
/** |
... | ... | |
46 | 51 |
* |
47 | 52 |
*/ |
48 | 53 |
public class QueryWidget extends Combo { |
49 |
|
|
54 |
|
|
50 | 55 |
SearchEngine se; |
51 |
|
|
56 |
Project project; |
|
57 |
private QueryHistory h; |
|
58 |
|
|
52 | 59 |
/** The history. */ |
53 | 60 |
private static Deque<String> history = new LinkedList<>(); |
54 |
|
|
61 |
|
|
55 | 62 |
/** |
56 | 63 |
* Instantiates a new query widget. |
57 | 64 |
* |
58 | 65 |
* @param parent the parent |
59 |
* @param style the style |
|
66 |
* @param style the style
|
|
60 | 67 |
*/ |
61 |
public QueryWidget(Composite parent, int style, SearchEngine se) { |
|
68 |
public QueryWidget(Composite parent, int style, Project project, SearchEngine se) { |
|
69 |
|
|
62 | 70 |
super(parent, style); |
63 | 71 |
this.se = se; |
64 |
this.setItems(history.toArray(new String[history.size()])); |
|
72 |
this.project = project; |
|
73 |
|
|
74 |
loadHistory(); |
|
65 | 75 |
} |
66 | 76 |
|
67 |
public QueryWidget(Composite composite, int style) { |
|
68 |
this(composite, style, SearchEnginesManager.getCQPSearchEngine()); |
|
77 |
public void loadHistory() { |
|
78 |
|
|
79 |
h = null; |
|
80 |
|
|
81 |
// if (this.project != null) { |
|
82 |
// h = this.project.getFirstChild(QueryHistory.class); |
|
83 |
// |
|
84 |
// if (h == null) { |
|
85 |
// h = new QueryHistory(project); |
|
86 |
// } |
|
87 |
// } |
|
88 |
// |
|
89 |
// try { // load history from queries.txt file |
|
90 |
// h.compute(false); |
|
91 |
// } catch (InterruptedException e) { |
|
92 |
// // TODO Auto-generated catch block |
|
93 |
// e.printStackTrace(); |
|
94 |
// } |
|
95 |
|
|
96 |
setHistoryItems(); |
|
69 | 97 |
} |
70 | 98 |
|
99 |
private void setHistoryItems() { |
|
100 |
|
|
101 |
if (this.h != null) { |
|
102 |
|
|
103 |
ArrayList<? extends Query> queries = null; |
|
104 |
if (se != null) { // get onlny the queries of the current searchengine |
|
105 |
queries = h.getQueries(se.newQuery().getClass()); |
|
106 |
} else { // get all queries |
|
107 |
queries = h.getQueries(); |
|
108 |
} |
|
109 |
|
|
110 |
String[] strings = new String[queries.size()]; |
|
111 |
for (int i = 0; i < queries.size(); i++) { |
|
112 |
strings[i] = queries.get(queries.size() - i - 1).getQueryString(); |
|
113 |
} |
|
114 |
this.setItems(strings); |
|
115 |
} else { // get the general query history |
|
116 |
this.setItems(history.toArray(new String[history.size()])); |
|
117 |
} |
|
118 |
} |
|
119 |
|
|
120 |
// public QueryWidget(Composite composite, int style) { |
|
121 |
// this(composite, style, SearchEnginesManager.getCQPSearchEngine()); |
|
122 |
// } |
|
123 |
|
|
71 | 124 |
/** |
72 | 125 |
* Set the SearchEngine to use with query |
126 |
* |
|
73 | 127 |
* @param se |
74 | 128 |
*/ |
75 | 129 |
public void setSearchEngine(SearchEngine se) { |
130 |
|
|
131 |
if (this.se == se) return; |
|
132 |
|
|
76 | 133 |
this.se = se; |
77 |
// if (se.newQuery().canBeMultiLine()) { |
|
78 |
// Object l = this.getLayoutData(); // cannot change the widget style -> maybe use a ComboViewer OR recreate a widget (so the setSearchEngine must be moved) |
|
79 |
// if (l instanceof GridData) { |
|
80 |
// GridData gd = (GridData)l; |
|
81 |
// gd.minimumHeight = this.getSize().y * 2; |
|
82 |
// } |
|
83 |
// this.layout(); |
|
84 |
// } else { |
|
85 |
// Object l = this.getLayoutData(); // cannot change the widget style -> maybe use a ComboViewer OR recreate a widget (so the setSearchEngine must be moved) |
|
86 |
// if (l instanceof GridData) { |
|
87 |
// GridData gd = (GridData)l; |
|
88 |
// gd.minimumHeight = this.getSize().y / 2; |
|
89 |
// } |
|
90 |
// this.layout(); |
|
91 |
// } |
|
134 |
|
|
135 |
loadHistory(); |
|
136 |
// if (se.newQuery().canBeMultiLine()) { |
|
137 |
// Object l = this.getLayoutData(); // cannot change the widget style -> maybe |
|
138 |
// use a ComboViewer OR recreate a widget (so the setSearchEngine must be moved) |
|
139 |
// if (l instanceof GridData) { |
|
140 |
// GridData gd = (GridData)l; |
|
141 |
// gd.minimumHeight = this.getSize().y * 2; |
|
142 |
// } |
|
143 |
// this.layout(); |
|
144 |
// } else { |
|
145 |
// Object l = this.getLayoutData(); // cannot change the widget style -> maybe |
|
146 |
// use a ComboViewer OR recreate a widget (so the setSearchEngine must be moved) |
|
147 |
// if (l instanceof GridData) { |
|
148 |
// GridData gd = (GridData)l; |
|
149 |
// gd.minimumHeight = this.getSize().y / 2; |
|
150 |
// } |
|
151 |
// this.layout(); |
|
152 |
// } |
|
92 | 153 |
} |
93 |
|
|
94 |
|
|
154 |
|
|
95 | 155 |
public SearchEngine getSearchEngine() { |
96 | 156 |
return this.se; |
97 | 157 |
} |
98 |
|
|
158 |
|
|
99 | 159 |
/** |
100 | 160 |
* Gets the CQP query string inferred from the user input. |
101 | 161 |
* |
... | ... | |
105 | 165 |
String rawQuery; |
106 | 166 |
if (getSelectionIndex() < 0) { |
107 | 167 |
rawQuery = getText(); |
108 |
} |
|
109 |
else { |
|
168 |
} else { |
|
110 | 169 |
rawQuery = this.getItem(this.getSelectionIndex()); |
111 | 170 |
} |
112 | 171 |
return se.newQuery().setQuery(rawQuery).getQueryString(); |
113 | 172 |
} |
114 |
|
|
173 |
|
|
115 | 174 |
/** |
116 | 175 |
* Memorize. |
117 | 176 |
*/ |
118 | 177 |
public void memorize() { |
178 |
|
|
119 | 179 |
String inputString; |
120 | 180 |
if (getSelectionIndex() == -1) { |
121 | 181 |
inputString = getText(); |
122 |
} |
|
123 |
else { |
|
182 |
} else { |
|
124 | 183 |
inputString = getItems()[getSelectionIndex()]; |
125 | 184 |
} |
126 |
history.remove(inputString); |
|
127 |
history.addFirst(inputString); |
|
128 |
this.setItems(history.toArray(new String[history.size()])); |
|
185 |
|
|
186 |
if (inputString == null || inputString.length() == 0) return; |
|
187 |
|
|
188 |
if (h != null && se != null && project != null) { |
|
189 |
Query q = se.newQuery(); |
|
190 |
q.setQuery(inputString); |
|
191 |
h.addQuery(q); |
|
192 |
} else { |
|
193 |
history.remove(inputString); |
|
194 |
history.addFirst(inputString); |
|
195 |
} |
|
196 |
|
|
197 |
setHistoryItems(); |
|
129 | 198 |
this.setText(this.getItem(0)); |
130 | 199 |
} |
131 |
|
|
200 |
|
|
132 | 201 |
/** |
133 | 202 |
* Memorize. |
134 | 203 |
* |
135 | 204 |
* @param query the query to memorize |
136 | 205 |
*/ |
137 | 206 |
public void memorize(String query) { |
207 |
|
|
138 | 208 |
String inputString = query; |
139 | 209 |
this.setText(query); |
140 | 210 |
history.remove(inputString); |
141 | 211 |
history.addFirst(inputString); |
142 | 212 |
this.setItems(history.toArray(new String[history.size()])); |
143 | 213 |
this.setText(this.getItem(0)); |
214 |
|
|
215 |
if (h != null && se != null && project != null) { |
|
216 |
Query q = se.newQuery(); |
|
217 |
q.setQuery(inputString); |
|
218 |
h.addQuery(q); |
|
219 |
} |
|
144 | 220 |
} |
145 |
|
|
221 |
|
|
146 | 222 |
/* |
147 | 223 |
* (non-Javadoc) |
224 |
* |
|
148 | 225 |
* @see org.eclipse.swt.widgets.Combo#checkSubclass() |
149 | 226 |
*/ |
150 | 227 |
@Override |
151 | 228 |
protected void checkSubclass() { |
152 |
|
|
229 |
|
|
153 | 230 |
} |
154 |
|
|
231 |
|
|
155 | 232 |
/** |
156 | 233 |
* Gets the query. |
157 | 234 |
* |
158 |
* @return the query |
|
235 |
* @return the query or null if no query is set
|
|
159 | 236 |
*/ |
160 | 237 |
public IQuery getQuery() { |
161 |
if (!this.getQueryString().isEmpty()) { |
|
238 |
|
|
239 |
if (this.getQueryString().isEmpty()) { |
|
240 |
return null; |
|
241 |
} |
|
242 |
|
|
243 |
if (se != null) { |
|
162 | 244 |
return se.newQuery().setQuery(this.getQueryString()); |
245 |
} else { |
|
246 |
Query q = new Query(); |
|
247 |
q.setQuery(this.getQueryString()); |
|
248 |
return q; |
|
163 | 249 |
} |
164 |
else { |
|
165 |
return null; |
|
166 |
} |
|
167 | 250 |
} |
168 | 251 |
} |
TXM/trunk/bundles/org.txm.rcp/src/main/java/org/txm/rcp/swt/widget/AssistedQueryWidget.java (revision 3729) | ||
---|---|---|
101 | 101 |
public void widgetDefaultSelected(SelectionEvent e) {} |
102 | 102 |
}); |
103 | 103 |
|
104 |
querywidget = new QueryWidget(this, style, se); |
|
104 |
querywidget = new QueryWidget(this, style, corpus.getProject(), se);
|
|
105 | 105 |
querywidget.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false)); |
106 | 106 |
} |
107 | 107 |
|
TXM/trunk/bundles/org.txm.core/src/java/org/txm/core/preferences/TBXPreferences.java (revision 3729) | ||
---|---|---|
174 | 174 |
|
175 | 175 |
public static final String CLIPBOARD_IMPORT_ASK_LANG = "clipboard_import_ask_lang"; |
176 | 176 |
|
177 |
public static final String QUERY_HISTORY_SIZE = "query_history_size"; |
|
178 |
|
|
177 | 179 |
/** |
178 | 180 |
* Gets the instance. |
179 | 181 |
* |
... | ... | |
236 | 238 |
preferences.put(RAWFILESSITE, "https://gitlab.huma-num.fr/txm/txm-software/-/raw/master/files/"); |
237 | 239 |
preferences.put(FILESSITE, "https://txm.gitpages.huma-num.fr/textometrie/files/"); |
238 | 240 |
|
241 |
preferences.putInt(TBXPreferences.QUERY_HISTORY_SIZE, 100); |
|
239 | 242 |
} |
240 | 243 |
} |
TXM/trunk/bundles/org.txm.core/src/java/org/txm/core/results/TXMResult.java (revision 3729) | ||
---|---|---|
1607 | 1607 |
* @param clazz |
1608 | 1608 |
* @return the first child if exists otherwise null |
1609 | 1609 |
*/ |
1610 |
public <T extends TXMResult> TXMResult getFirstChild(Class<T> clazz) {
|
|
1610 |
public <T extends TXMResult> T getFirstChild(Class<T> clazz) { |
|
1611 | 1611 |
List<T> children = this.getChildren(clazz, false); |
1612 | 1612 |
try { |
1613 | 1613 |
return children.get(0); |
TXM/trunk/bundles/org.txm.core/src/java/org/txm/objects/SavedQuery.java (revision 3729) | ||
---|---|---|
55 | 55 |
import org.w3c.dom.Element; |
56 | 56 |
import org.w3c.dom.NodeList; |
57 | 57 |
|
58 |
// TODO: Auto-generated Javadoc |
|
59 | 58 |
/** |
60 | 59 |
* contains a query and examples of results @ author mdecorde. |
61 | 60 |
*/ |
... | ... | |
100 | 99 |
} |
101 | 100 |
|
102 | 101 |
protected boolean setParameters(Element pElement) { |
102 |
|
|
103 | 103 |
this.setUserName(pElement.getAttribute("name")); //$NON-NLS-1$ |
104 | 104 |
this.pValue = pElement.getAttribute("value"); //$NON-NLS-1$ |
105 | 105 |
this.examples = new ArrayList<>(); |
TXM/trunk/bundles/org.txm.groovy.core/src/groovy/org/txm/macro/annotation/SampleWordsMacro.groovy (revision 3729) | ||
---|---|---|
1 |
// Copyright © 2021 ENS Lyon |
|
2 |
// Licensed under the terms of the GNU General Public License version 3 (http://www.gnu.org/licenses/gpl-3.0.html) |
|
3 |
// @author mdecorde |
|
4 |
// @author sheiden |
|
5 |
|
|
6 |
package org.txm.macro.annotation |
|
7 |
|
|
8 |
// STANDARD DECLARATIONS |
|
9 |
import org.txm.rcpapplication.swt.widget.parameters.* |
|
10 |
import org.txm.searchengine.cqp.corpus.* |
|
11 |
import org.txm.xml.DOMIdentityHook |
|
12 |
import org.txm.xml.LocalNameHookActivator |
|
13 |
import org.txm.xml.XMLProcessor |
|
14 |
import org.txm.objects.* |
|
15 |
import org.txm.rcp.utils.JobHandler |
|
16 |
import org.txm.rcp.views.corpora.CorporaView |
|
17 |
import org.eclipse.core.runtime.Status |
|
18 |
import org.txm.annotation.kr.core.KRAnnotationEngine |
|
19 |
import org.txm.annotation.kr.core.repository.* |
|
20 |
import org.txm.annotation.kr.rcp.commands.SaveAnnotations |
|
21 |
import org.txm.annotation.kr.rcp.concordance.WordAnnotationToolbar |
|
22 |
import org.txm.importer.StaxIdentityParser |
|
23 |
|
|
24 |
def scriptName = this.class.getSimpleName() |
|
25 |
|
|
26 |
if (!(corpusViewSelection instanceof MainCorpus)) { |
|
27 |
println "** $scriptName: please select a Corpus in the Corpus view." |
|
28 |
return 0 |
|
29 |
} |
|
30 |
|
|
31 |
MainCorpus mcorpus = corpusViewSelection |
|
32 |
Project project = mcorpus.getProject() |
|
33 |
File txmDir = new File(project.getProjectDirectory(), "txm/"+mcorpus.getName()) |
|
34 |
|
|
35 |
@Field @Option(name="nWordsPerText", usage="the number of words per text", widget="Integer", required=true, def="") |
|
36 |
File nWordsPerText |
|
37 |
|
|
38 |
|
|
39 |
@Field @Option(name="debug", usage="Afficher les messages de debug", widget="Boolean", required=true, def="false") |
|
40 |
def debug |
|
41 |
|
|
42 |
// Open the parameters input dialog box |
|
43 |
if (!ParametersDialog.open(this)) return |
|
44 |
|
|
45 |
if (!outputDirectory.exists()) { |
|
46 |
println "Error: output directory not found: "+outputDirectory |
|
47 |
return false |
|
48 |
} |
|
49 |
|
|
50 |
values_to_ignore_regex = /$values_to_ignore_regex/ |
|
51 |
|
|
52 |
project.compute(); |
|
53 |
|
|
54 |
for (Text text : project.getChildren(Text.class)) { |
|
55 |
println "Text: "+text |
|
56 |
|
|
57 |
File orig = text.getXMLTXMFile() |
|
58 |
if ((orig == null) || !orig.exists()) { |
|
59 |
println "** Error: no XML-TXM file found for "+text |
|
60 |
return // next ! |
|
61 |
} |
|
62 |
|
|
63 |
File result = new File(outputDirectory, orig.getName()) |
|
64 |
|
|
65 |
if (false && result.lastModified() > orig.lastModified()) { |
|
66 |
println "Skipping $text: result file is more recent: $result" |
|
67 |
continue // next ! |
|
68 |
} |
|
69 |
|
|
70 |
XMLProcessor xp = new XMLProcessor(orig); |
|
71 |
LocalNameHookActivator activator = new LocalNameHookActivator("w") |
|
72 |
|
|
73 |
nWords = 0 |
|
74 |
new DOMIdentityHook("word", activator, xp) { |
|
75 |
@Override |
|
76 |
public void processDom() { |
|
77 |
//println dom |
|
78 |
use(groovy.xml.dom.DOMCategory) { |
|
79 |
nWords++ |
|
80 |
if (nWords > nWordsPerText) { |
|
81 |
dom = null |
|
82 |
} |
|
83 |
} |
|
84 |
} |
|
85 |
} |
|
86 |
xp.process(result) |
|
87 |
|
|
88 |
if (nWords == 0) { |
|
89 |
println "Removing empty <text>: $text: $result" |
|
90 |
result.delete() |
|
91 |
} |
|
92 |
} |
|
93 |
|
|
94 |
println "Done: update the corpus using the 'Corpus > Update' main menu to see the modifications in commnds." |
TXM/trunk/bundles/org.txm.searchengine.core/src/org/txm/searchengine/core/Query.java (revision 3729) | ||
---|---|---|
263 | 263 |
} |
264 | 264 |
return str.toString(); |
265 | 265 |
} |
266 |
|
|
267 |
@Override |
|
268 |
public int compareTo(IQuery o) { |
|
269 |
|
|
270 |
int c = this.getSearchEngine().getName().compareTo(o.getSearchEngine().getName()); |
|
271 |
|
|
272 |
if (c == 0) { |
|
273 |
c = this.queryString.compareTo(o.getQueryString()); |
|
274 |
} |
|
275 |
|
|
276 |
if (c == 0) { |
|
277 |
c = this.getName().compareTo(o.getName()); |
|
278 |
} |
|
279 |
|
|
280 |
return c; |
|
281 |
} |
|
266 | 282 |
} |
TXM/trunk/bundles/org.txm.searchengine.core/src/org/txm/searchengine/core/QueryHistory.java (revision 3729) | ||
---|---|---|
1 |
package org.txm.searchengine.core; |
|
2 |
|
|
3 |
import java.io.BufferedReader; |
|
4 |
import java.io.File; |
|
5 |
import java.io.PrintWriter; |
|
6 |
import java.util.ArrayList; |
|
7 |
import java.util.LinkedHashSet; |
|
8 |
|
|
9 |
import org.txm.core.preferences.TBXPreferences; |
|
10 |
import org.txm.core.results.TXMParameters; |
|
11 |
import org.txm.core.results.TXMResult; |
|
12 |
import org.txm.objects.Project; |
|
13 |
import org.txm.utils.TXMProgressMonitor; |
|
14 |
import org.txm.utils.io.IOUtils; |
|
15 |
|
|
16 |
public class QueryHistory extends TXMResult { |
|
17 |
|
|
18 |
LinkedHashSet<IQuery> queries = new LinkedHashSet<IQuery>(); // first is the older and last is the newer |
|
19 |
|
|
20 |
public QueryHistory(String parametersNodePath, TXMResult parent) { |
|
21 |
super(parametersNodePath, parent); |
|
22 |
} |
|
23 |
|
|
24 |
public QueryHistory(Project corpus) { |
|
25 |
super(null, corpus); |
|
26 |
} |
|
27 |
|
|
28 |
@Override |
|
29 |
public boolean saveParameters() throws Exception { |
|
30 |
|
|
31 |
return true; |
|
32 |
} |
|
33 |
|
|
34 |
@Override |
|
35 |
public boolean isVisible() { |
|
36 |
|
|
37 |
return true; |
|
38 |
} |
|
39 |
|
|
40 |
@Override |
|
41 |
public boolean loadParameters() throws Exception { |
|
42 |
|
|
43 |
return true; |
|
44 |
} |
|
45 |
|
|
46 |
@Override |
|
47 |
public boolean setParameters(TXMParameters parameters) throws Exception { |
|
48 |
|
|
49 |
return true; |
|
50 |
} |
|
51 |
|
|
52 |
@Override |
|
53 |
public String getName() { |
|
54 |
|
|
55 |
return "Query History"; |
|
56 |
} |
|
57 |
|
|
58 |
@Override |
|
59 |
public String getSimpleName() { |
|
60 |
|
|
61 |
return "Query History"; |
|
62 |
} |
|
63 |
|
|
64 |
@Override |
|
65 |
public String getDetails() { |
|
66 |
|
|
67 |
return "Query history of "+queries.size(); |
|
68 |
} |
|
69 |
|
|
70 |
@Override |
|
71 |
public void clean() { |
|
72 |
|
|
73 |
} |
|
74 |
|
|
75 |
@Override |
|
76 |
public boolean canCompute() throws Exception { |
|
77 |
|
|
78 |
return true; |
|
79 |
} |
|
80 |
|
|
81 |
public Project getParent() { |
|
82 |
return (Project) super.getParent(); |
|
83 |
} |
|
84 |
|
|
85 |
@Override |
|
86 |
protected boolean _compute(TXMProgressMonitor monitor) throws Exception { |
|
87 |
queries.clear(); |
|
88 |
|
|
89 |
File logFile = new File(this.getParent().getProjectDirectory(), "queries.txt"); |
|
90 |
int MAX = TBXPreferences.getInstance().getInt(TBXPreferences.QUERY_HISTORY_SIZE); |
|
91 |
|
|
92 |
BufferedReader reader = IOUtils.getReader(logFile); |
|
93 |
String line = reader.readLine(); |
|
94 |
while (line != null) { |
|
95 |
line = line.trim(); |
|
96 |
if (line.length() > 0 && !line.startsWith("#")) { |
|
97 |
IQuery q = Query.stringToQuery(line); |
|
98 |
queries.add(q); |
|
99 |
} |
|
100 |
|
|
101 |
if (queries.size() > MAX) break; |
|
102 |
line = reader.readLine(); |
|
103 |
} |
|
104 |
reader.close(); |
|
105 |
|
|
106 |
return true; |
|
107 |
} |
|
108 |
|
|
109 |
@SuppressWarnings("unchecked") |
|
110 |
public <Q extends IQuery> ArrayList<Q> getQueries(Class<Q> clazz) { |
|
111 |
ArrayList<Q> ret = new ArrayList<Q>(); |
|
112 |
for (IQuery q : queries) { |
|
113 |
if (clazz == null || q.getClass().isInstance(clazz) || q.getClass().isAssignableFrom(clazz)) { |
|
114 |
ret.add((Q) q); |
|
115 |
} |
|
116 |
} |
|
117 |
return ret; |
|
118 |
|
|
119 |
} |
|
120 |
|
|
121 |
public void addQuery(IQuery query) { |
|
122 |
|
|
123 |
int MAX = TBXPreferences.getInstance().getInt(TBXPreferences.QUERY_HISTORY_SIZE); |
|
124 |
reduceSize(MAX - 1); // ensure history size limit |
|
125 |
queries.add(query); |
|
126 |
} |
|
127 |
|
|
128 |
public void reduceSize(int MAX) { |
|
129 |
|
|
130 |
while (queries.size() > MAX && queries.size() > 0) { |
|
131 |
for (IQuery q : queries) { |
|
132 |
queries.remove(q); |
|
133 |
break; // remove 1 query |
|
134 |
} |
|
135 |
} |
|
136 |
} |
|
137 |
|
|
138 |
@Override |
|
139 |
protected boolean _toTxt(File outfile, String encoding, String colseparator, String txtseparator) throws Exception { |
|
140 |
|
|
141 |
PrintWriter writer = IOUtils.getWriter(outfile, encoding); |
|
142 |
for (IQuery q : queries) { |
|
143 |
writer.println(q); |
|
144 |
} |
|
145 |
writer.close(); |
|
146 |
|
|
147 |
return true; |
|
148 |
} |
|
149 |
|
|
150 |
@Override |
|
151 |
public String getResultType() { |
|
152 |
|
|
153 |
return "History"; |
|
154 |
} |
|
155 |
|
|
156 |
public ArrayList<Query> getQueries() { |
|
157 |
return getQueries(Query.class); |
|
158 |
} |
|
159 |
|
|
160 |
} |
|
0 | 161 |
TXM/trunk/bundles/org.txm.searchengine.core/src/org/txm/searchengine/core/IQuery.java (revision 3729) | ||
---|---|---|
8 | 8 |
* @author mdecorde |
9 | 9 |
* |
10 | 10 |
*/ |
11 |
public interface IQuery { |
|
11 |
public interface IQuery extends Comparable<IQuery>{
|
|
12 | 12 |
|
13 | 13 |
public String getQueryString(); |
14 | 14 |
|
Formats disponibles : Unified diff