Révision 1075

tmp/org.txm.textsbalance.core/src/org/txm/textsbalance/core/functions/TextsBalance.java (revision 1075)
148 148
						QueryResult r = this.getCorpus().query(new CQLQuery("[_."+p.getFullName()+"=\""+value+"\"] expand to text"), "tmp", false);
149 149
						int t = 0;
150 150
						for (Match m : r.getMatches()) {
151
							t += m.getLength();
151
							t += m.size();
152 152
						}
153 153
						v = t;
154 154
						r.drop();
......
204 204
						if (!interUniq.containsKey(o)) {
205 205
							interUniq.put(o, 0);
206 206
						}
207
						int s = supLimits.get(inter.get(iMatch)).getLength();
207
						int s = supLimits.get(inter.get(iMatch)).size();
208 208
						interUniq.put(o, interUniq.get(o) + s);
209 209

  
210 210
					}
tmp/org.txm.index.core/src/org/txm/index/core/functions/Index.java (revision 1075)
49 49
import org.txm.index.core.functions.LineComparator.SortMode;
50 50
import org.txm.index.core.messages.IndexCoreMessages;
51 51
import org.txm.index.core.preferences.IndexPreferences;
52
import org.txm.searchengine.core.Query;
52 53
import org.txm.searchengine.cqp.CQPSearchEngine;
53 54
import org.txm.searchengine.cqp.ICqiClient;
54 55
import org.txm.searchengine.cqp.clientExceptions.CqiClientException;
......
132 133
	 * The CQP query.
133 134
	 */
134 135
	@Parameter(key=TBXPreferences.QUERY)
135
	protected CQLQuery pQuery;
136
	protected Query pQuery;
136 137
	
137 138
	/**
138 139
	 * The line index of the current index page.
......
786 787
	 *
787 788
	 * @return the query used
788 789
	 */
789
	public CQLQuery getQuery() {
790
	public Query getQuery() {
790 791
		return pQuery;
791 792
	}
792 793

  
......
859 860
	 * @throws CqiServerError 
860 861
	 * @throws IOException 
861 862
	 */
862
	protected boolean scanCorpus(Corpus corpus) throws CqiClientException, IOException, CqiServerError {
863
	protected boolean scanCorpus(Corpus corpus) throws Exception {
863 864
		// get the cqp result of the query
864 865

  
865 866
		//long time = System.currentTimeMillis();
866
		QueryResult result = corpus.query(pQuery, "index", true); //$NON-NLS-1$
867
		QueryResult result = null;
868
		if (pQuery instanceof CQLQuery) {
869
			result = corpus.query((CQLQuery)pQuery, "index", true); //$NON-NLS-1$
870
		} else {
871
			pQuery.getSearchEngine().query(corpus, pQuery, "index", true); //$NON-NLS-1$
872
		}
867 873
		boolean isTargetUsed = CQPSearchEngine.getCqiClient().subCorpusHasField(result.getQualifiedCqpId(), ICqiClient.CQI_CONST_FIELD_TARGET);
868 874
		int nbresults = result.getNMatch();
869 875
		this.nTotalTokens += nbresults; // get number of tokens
tmp/org.txm.searchengine.cqp.core/src/org/txm/searchengine/cqp/core/functions/preview/Preview.java (revision 1075)
39 39
		boolean ok = false;
40 40
		List<Match> matches = corpus.getMatches();
41 41
		for (Match m : matches) {
42
			if (m.getLength() >= n) {
42
			if (m.size() >= n) {
43 43
				ok = true;
44 44
			}
45 45
		}
......
52 52
		
53 53
		Match firstOkMatch = matches.get(0);
54 54
		for (Match m : matches) {
55
			if (m.getLength() >= n) {
55
			if (m.size() >= n) {
56 56
				Collection<? extends Integer> positions = m.getRange();
57 57
				
58 58
			}
tmp/org.txm.searchengine.cqp.core/src/org/txm/searchengine/cqp/corpus/query/CQLQuery.java (revision 1075)
34 34

  
35 35
import org.txm.core.preferences.TXMPreferences;
36 36
import org.txm.searchengine.core.Query;
37
import org.txm.searchengine.core.SearchEngine;
38
import org.txm.searchengine.core.SearchEnginesManager;
39
import org.txm.searchengine.cqp.CQPSearchEngine;
37 40

  
38 41
/**
39 42
 * Implements a CQL query. Use fixQuery to use query sugar.
......
383 386
		String test = "^$sdf<>sdf|\\sdf\"{(sdf)}?+sdf*."; //$NON-NLS-1$
384 387
		System.out.println(CQLQuery.addBackSlash(test));
385 388
	}
389

  
390
	@Override
391
	public SearchEngine getSearchEngine() {
392
		return SearchEnginesManager.getCQPSearchEngine();
393
	}
394

  
395
	@Override
396
	public Query setQuery(String rawQuery) {
397
		this.queryString = rawQuery;
398
		return this;
399
	}
400

  
401
	@Override
402
	public Query fixQuery() {
403
		this.queryString = fixQuery(this.queryString);
404
		return this;
405
	}
386 406
}
tmp/org.txm.searchengine.cqp.core/src/org/txm/searchengine/cqp/corpus/query/Match.java (revision 1075)
29 29

  
30 30
import java.util.ArrayList;
31 31
import java.util.Arrays;
32
import java.util.Collection;
33 32
import java.util.List;
34 33

  
35
import org.apache.commons.lang.math.IntRange;
36 34
import org.txm.searchengine.cqp.AbstractCqiClient;
37 35
import org.txm.searchengine.cqp.clientExceptions.CqiClientException;
38 36
import org.txm.searchengine.cqp.corpus.CorpusManager;
......
44 42
 * 
45 43
 * @author jmague, mdecorde
46 44
 */
47
public class Match implements Comparable<Match> {
45
public class Match extends org.txm.searchengine.core.Match {
48 46

  
49 47
	/** The start. */
50 48
	private int start;
......
103 101
	public int getEnd() {
104 102
		return end;
105 103
	}
106
	
107
	public boolean contains(Match m) {
108
		return (this.start <= m.start && m.end <= this.end);
109
	}
110 104

  
111 105
//	/**
112 106
//	 * Gets the query result.
......
207 201

  
208 202
	}
209 203

  
210
	/* (non-Javadoc)
211
	 * @see java.lang.Comparable#compareTo(java.lang.Object)
212
	 */
213
	@Override
214
	public int compareTo(Match m) {
215

  
216
		if (m == null)
217
			return -1;
218
		if (this.start < m.start)
219
			return -1;
220
		else if (this.start > m.start)
221
			return 1;
222
		else if (this.end < m.end)
223
			return -1;
224
		else
225
			return 1;
226

  
227
	}
228

  
229
	/* (non-Javadoc)
230
	 * @see java.lang.Object#toString()
231
	 */
232
	@Override
233
	public String toString() {
234
		return "<" + start + ", " + end + ">"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
235
	}
236

  
237 204
	/**
238 205
	 * Gets the ids.
239 206
	 *
......
261 228
		}
262 229
	}
263 230

  
264
	/**
265
	 * Size.
266
	 *
267
	 * @return the int
268
	 */
269
	public int size() {
270
		return end - start + 1;
271
	}
272
	
273
	public int getLength() {
274
		return (end - start);
275
	}
276

  
277
	public List<Integer> getRange() {
278
		List<Integer> ret = new ArrayList<Integer>(size());
279
		for (int i = start ; i <= end; i++) ret.add(i);
280
		return ret;
281
	}
282

  
283 231
	public void setEnd(int p) {
284 232
		this.end = p;
285 233
	}
......
287 235
	public void setStart(int p) {
288 236
		this.start = p;
289 237
	}
238

  
239
	@Override
240
	public void setTarget(int p) {
241
		this.target = p;
242
	}
290 243
}
tmp/org.txm.searchengine.cqp.core/src/org/txm/searchengine/cqp/corpus/QueryResult.java (revision 1075)
32 32
import java.util.List;
33 33

  
34 34
import org.txm.core.messages.TXMCoreMessages;
35
import org.txm.searchengine.core.Selection;
35 36
import org.txm.searchengine.cqp.AbstractCqiClient;
36 37
import org.txm.searchengine.cqp.NetCqiClient;
37 38
import org.txm.searchengine.cqp.clientExceptions.CqiClientException;
......
46 47
 * 
47 48
 * @author jmague
48 49
 */
49
public class QueryResult implements CqpObject {
50
public class QueryResult extends Selection implements CqpObject {
50 51

  
51 52
	/** The cqp id. */
52 53
	protected String cqpId;
tmp/org.txm.searchengine.cqp.core/src/org/txm/searchengine/cqp/CQPSearchEngine.java (revision 1075)
15 15
import org.txm.core.preferences.TXMPreferences;
16 16
import org.txm.importer.cwb.PatchCwbRegistry;
17 17
import org.txm.libs.cqp.CQPLibPreferences;
18
import org.txm.objects.CorpusBuild;
18 19
import org.txm.objects.Project;
20
import org.txm.searchengine.core.EmptySelection;
21
import org.txm.searchengine.core.Query;
19 22
import org.txm.searchengine.core.SearchEngine;
23
import org.txm.searchengine.core.Selection;
24
import org.txm.searchengine.cqp.clientExceptions.CqiClientException;
25
import org.txm.searchengine.cqp.clientExceptions.InvalidCqpIdException;
20 26
import org.txm.searchengine.cqp.clientExceptions.ServerNotFoundException;
27
import org.txm.searchengine.cqp.corpus.CQPCorpus;
28
import org.txm.searchengine.cqp.corpus.Corpus;
21 29
import org.txm.searchengine.cqp.corpus.CorpusManager;
22 30
import org.txm.searchengine.cqp.corpus.MainCorpus;
31
import org.txm.searchengine.cqp.corpus.query.CQLQuery;
23 32
import org.txm.utils.OSDetector;
24 33
import org.txm.utils.Sh;
25 34
import org.txm.utils.logger.Log;
......
415 424
	public boolean isRunning() {
416 425
		return state;
417 426
	}
427

  
428
	@Override
429
	public Selection query(CorpusBuild corpus, Query query, String name, boolean saveQuery) throws CqiClientException {
430
		if (query instanceof CQLQuery && corpus instanceof Corpus) {
431
			return ((Corpus)corpus).query((CQLQuery)query, name, saveQuery);
432
		} else {
433
			return new EmptySelection(query); 
434
		}
435
	}
436

  
437
	@Override
438
	public Query newQuery() {
439
		return new CQLQuery("");
440
	}
441

  
442
	@Override
443
	public boolean hasIndexes(CorpusBuild corpus) {
444
		try {
445
			return CorpusManager.getCorpusManager().getCorpus(corpus.getName()) != null;
446
		} catch (Exception e) {
447
			e.printStackTrace();
448
			return false;
449
		}
450
	}
418 451
}
tmp/org.txm.libs.office/.classpath (revision 1075)
9 9
	<classpathentry exported="true" kind="lib" path="lib/commons-logging-1.2.jar"/>
10 10
	<classpathentry exported="true" kind="lib" path="lib/commons-validator-1.5.0.jar"/>
11 11
	<classpathentry exported="true" kind="lib" path="lib/java-rdfa-0.4.2.jar"/>
12
	<classpathentry exported="true" kind="lib" path="lib/jena-core-2.11.2.jar"/>
12
	<classpathentry exported="true" kind="lib" path="lib/jena-core-2.11.2.jar" sourcepath="/home/mdecorde/.m2/repository/org/apache/jena/jena-core/2.11.2/jena-core-2.11.2-sources.jar"/>
13 13
	<classpathentry exported="true" kind="lib" path="lib/jena-iri-1.0.2.jar"/>
14 14
	<classpathentry exported="true" kind="lib" path="lib/junit-3.8.1.jar"/>
15 15
	<classpathentry exported="true" kind="lib" path="lib/log4j-1.2.17.jar"/>
tmp/org.txm.index.rcp/src/org/txm/index/rcp/editors/IndexEditor.java (revision 1075)
62 62
import org.txm.rcp.editors.listeners.ComputeSelectionListener;
63 63
import org.txm.rcp.messages.TXMUIMessages;
64 64
import org.txm.rcp.swt.GLComposite;
65
import org.txm.rcp.swt.widget.AssistedChoiceQueryWidget;
65 66
import org.txm.rcp.swt.widget.AssistedQueryWidget;
66 67
import org.txm.rcp.swt.widget.NavigationWidget;
67 68
import org.txm.rcp.swt.widget.PropertiesSelector;
68 69
import org.txm.rcp.views.QueriesView;
70
import org.txm.searchengine.core.Query;
69 71
import org.txm.searchengine.cqp.clientExceptions.CqiClientException;
70 72
import org.txm.searchengine.cqp.corpus.Corpus;
71 73
import org.txm.searchengine.cqp.corpus.Property;
......
123 125
	/** The title. */
124 126
	String title;
125 127

  
126
	
127
	
128 128
	/** The query widget. */
129 129
	@Parameter(key=TXMPreferences.QUERY)
130
	protected AssistedQueryWidget queryWidget;
130
	protected AssistedChoiceQueryWidget queryWidget;
131 131

  
132 132
	/** The Fmin spinner. */
133 133
	@Parameter(key=TXMPreferences.F_MIN)
......
200 200
		queryLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, true));
201 201

  
202 202
		// [ (v)]
203
		queryWidget = new AssistedQueryWidget(getMainParametersComposite(), SWT.DROP_DOWN,	index.getCorpus());
203
		queryWidget = new AssistedChoiceQueryWidget(getMainParametersComposite(), SWT.DROP_DOWN,	index.getCorpus());
204 204
		GridData layoutData = new GridData(GridData.VERTICAL_ALIGN_CENTER);
205 205
		layoutData.horizontalAlignment = GridData.FILL;
206 206
		layoutData.grabExcessHorizontalSpace = true;
......
623 623
		this.queryWidget.setText(query);
624 624
	}
625 625

  
626
	public CQLQuery getQuery() {
626
	public Query getQuery() {
627 627
		return queryWidget.getQuery();
628 628
	}
629 629
}
tmp/org.txm.core/src/java/org/txm/objects/Project.java (revision 1075)
46 46
import javax.xml.transform.stream.StreamResult;
47 47

  
48 48
import org.eclipse.core.runtime.IProgressMonitor;
49
import org.txm.Toolbox;
50
import org.txm.core.engines.EngineType;
49 51
import org.txm.core.messages.TXMCoreMessages;
50 52
import org.txm.core.results.TXMResult;
51 53
import org.txm.utils.logger.Log;
tmp/org.txm.core/src/java/org/txm/core/engines/ImportEngines.java (revision 1075)
1
package org.txm.core.engines;
2

  
3
public class ImportEngines extends EnginesManager<ImportEngine>{
4

  
5
	@Override
6
	public boolean fetchEngines() {
7
		return this.fetchEngines(ImportEngine.EXTENSION_POINT_ID);
8
	}
9

  
10
	@Override
11
	public EngineType getEnginesType() {
12
		return EngineType.IMPORT;
13
	}
14
	
15
	// commons import modules
16
	
17
	public ImportEngine getTXTEngine() {
18
		return this.getEngine("txt");
19
	}
20
	
21
	public ImportEngine getXTZEngine() {
22
		return this.getEngine("xtz");
23
	}
24
	
25
	public ImportEngine getXMLEngine() {
26
		return this.getEngine("xmlw");
27
	}
28
		
29
	public ImportEngine getTranscriberEngine() {
30
		return this.getEngine("transcriber");
31
	}
32
}
0 33

  
tmp/org.txm.core/src/java/org/txm/core/engines/EngineType.java (revision 1075)
16 16
	SCRIPT("scripts"),
17 17
	ANNOTATION("annotations"),
18 18
	TAL("tal"),
19
	OTHER("others engines");
19
	OTHER("others engines"), IMPORT("import");
20 20

  
21 21
	/**
22 22
	 * Description.
tmp/org.txm.core/src/java/org/txm/core/engines/ImportEngine.java (revision 1075)
1
package org.txm.core.engines;
2

  
3
import org.eclipse.core.runtime.IProgressMonitor;
4
import org.txm.objects.Project;
5

  
6
public abstract class ImportEngine implements Engine {
7

  
8
	public static final String EXTENSION_POINT_ID = ImportEngine.class.getCanonicalName();
9
	
10
	@Override
11
	public abstract String getName();
12
	
13
	/**
14
	 * Regenerate all project results
15
	 *  
16
	 * @param project
17
	 * @param monitor
18
	 * @return
19
	 */
20
	public abstract boolean build(Project project, IProgressMonitor monitor);
21

  
22
}
0 23

  
tmp/org.txm.core/schema/org.txm.core.engines.ImportEngine.exsd (revision 1075)
1
<?xml version='1.0' encoding='UTF-8'?>
2
<!-- Schema file written by PDE -->
3
<schema targetNamespace="org.txm.core" xmlns="http://www.w3.org/2001/XMLSchema">
4
<annotation>
5
      <appinfo>
6
         <meta.schema plugin="org.txm.core" id="org.txm.core.engines.ImportEngine" name="org.txm.core.engines.ImportEngine"/>
7
      </appinfo>
8
      <documentation>
9
         [Enter description of this extension point.]
10
      </documentation>
11
   </annotation>
12

  
13
   <element name="extension">
14
      <annotation>
15
         <appinfo>
16
            <meta.element />
17
         </appinfo>
18
      </annotation>
19
      <complexType>
20
         <choice minOccurs="1" maxOccurs="unbounded">
21
            <element ref="ImportEngine"/>
22
         </choice>
23
         <attribute name="point" type="string" use="required">
24
            <annotation>
25
               <documentation>
26
                  
27
               </documentation>
28
            </annotation>
29
         </attribute>
30
         <attribute name="id" type="string">
31
            <annotation>
32
               <documentation>
33
                  
34
               </documentation>
35
            </annotation>
36
         </attribute>
37
         <attribute name="name" type="string">
38
            <annotation>
39
               <documentation>
40
                  
41
               </documentation>
42
               <appinfo>
43
                  <meta.attribute translatable="true"/>
44
               </appinfo>
45
            </annotation>
46
         </attribute>
47
      </complexType>
48
   </element>
49

  
50
   <element name="ImportEngine">
51
      <complexType>
52
         <attribute name="class" type="string" use="required">
53
            <annotation>
54
               <documentation>
55
                  
56
               </documentation>
57
               <appinfo>
58
                  <meta.attribute kind="java" basedOn="org.txm.core.engines.ImportEngine:"/>
59
               </appinfo>
60
            </annotation>
61
         </attribute>
62
         <attribute name="name" type="string" use="required">
63
            <annotation>
64
               <documentation>
65
                  
66
               </documentation>
67
            </annotation>
68
         </attribute>
69
      </complexType>
70
   </element>
71

  
72
   <annotation>
73
      <appinfo>
74
         <meta.section type="since"/>
75
      </appinfo>
76
      <documentation>
77
         [Enter the first release in which this extension point appears.]
78
      </documentation>
79
   </annotation>
80

  
81
   <annotation>
82
      <appinfo>
83
         <meta.section type="examples"/>
84
      </appinfo>
85
      <documentation>
86
         [Enter extension point usage example here.]
87
      </documentation>
88
   </annotation>
89

  
90
   <annotation>
91
      <appinfo>
92
         <meta.section type="apiinfo"/>
93
      </appinfo>
94
      <documentation>
95
         [Enter API information here.]
96
      </documentation>
97
   </annotation>
98

  
99
   <annotation>
100
      <appinfo>
101
         <meta.section type="implementation"/>
102
      </appinfo>
103
      <documentation>
104
         [Enter information about supplied implementation of this extension point.]
105
      </documentation>
106
   </annotation>
107

  
108

  
109
</schema>
0 110

  
tmp/org.txm.searchengine.core/src/org/txm/searchengine/core/EmptySelection.java (revision 1075)
1
package org.txm.searchengine.core;
2

  
3
import java.util.ArrayList;
4
import java.util.List;
5

  
6
public class EmptySelection extends Selection {
7
	
8
	private static final List<? extends Match> EMPTY = new ArrayList<Match>();
9
	protected Query query;
10
	
11
	public EmptySelection(Query query) {
12
		this.query = query;
13
	}
14

  
15
	public List<? extends Match> getMatches() {
16
		return EMPTY;
17
	}
18
	
19
	public List<? extends Match> getMatches(int from, int to) {
20
		return EMPTY;
21
	}
22
	
23
	public int getNMatch() {
24
		return 0;
25
	}
26
	
27
	public Query getQuery() {
28
		return query;
29
	}
30
}
0 31

  
tmp/org.txm.searchengine.core/src/org/txm/searchengine/core/Query.java (revision 1075)
11 11
	public String getQueryString();
12 12
	
13 13
	public boolean isEmpty();
14

  
15
	/**
16
	 * 
17
	 * @return the Query SearchEngine that can resolve the query
18
	 */
19
	public SearchEngine getSearchEngine();
20

  
21
	/**
22
	 * update the query
23
	 * 
24
	 * @param rawQuery
25
	 * @return this
26
	 */
27
	public Query setQuery(String rawQuery);
14 28
	
29
	/**
30
	 * fix the query using sugar syntax rules
31
	 * @return this
32
	 */
33
	public Query fixQuery();
34
	
15 35
}
tmp/org.txm.searchengine.core/src/org/txm/searchengine/core/Selection.java (revision 1075)
1
package org.txm.searchengine.core;
2

  
3
import java.util.List;
4

  
5
public abstract class Selection {
6
	
7

  
8

  
9
	public abstract List<? extends Match> getMatches() throws Exception;
10
	
11
	public abstract List<? extends Match> getMatches(int from, int to) throws Exception;
12
	
13
	public abstract int getNMatch() throws Exception;
14
	
15
	public abstract Query getQuery();
16
}
0 17

  
tmp/org.txm.searchengine.core/src/org/txm/searchengine/core/SearchEnginesManager.java (revision 1075)
1 1
package org.txm.searchengine.core;
2 2

  
3
import java.util.ArrayList;
4
import java.util.List;
5

  
3 6
import org.txm.Toolbox;
4 7
import org.txm.core.engines.EngineType;
5 8
import org.txm.core.engines.EnginesManager;
9
import org.txm.objects.CorpusBuild;
6 10

  
7 11
/**
8 12
 * Search engines manager.
......
38 42
		return EngineType.SEARCH;
39 43
	}
40 44

  
45
	public static List<SearchEngine> getAvailableEngines(CorpusBuild corpus) {
46
		List<SearchEngine> availables = new ArrayList<SearchEngine>();
47
		SearchEnginesManager em = (SearchEnginesManager) Toolbox.getEngineManager(EngineType.SEARCH);
48
		for (String name : em.getEngines().keySet()) {
49
			SearchEngine engine = em.getEngine(name);
50
			if (engine.hasIndexes(corpus)) {
51
				availables.add(engine);
52
			}
53
		}
54
		return availables;
55
	}
41 56
}
tmp/org.txm.searchengine.core/src/org/txm/searchengine/core/SearchEngine.java (revision 1075)
1 1
package org.txm.searchengine.core;
2 2

  
3 3
import org.txm.core.engines.Engine;
4
import org.txm.objects.CorpusBuild;
4 5

  
5 6
// FIXME: useless class
6 7
public abstract class SearchEngine implements Engine {
......
9 10

  
10 11
	@Override
11 12
	public abstract String getName();
13
	
14
	public abstract Selection query(CorpusBuild corpus, Query query, String name, boolean saveQuery) throws Exception;
15
	
16
	public abstract Query newQuery();
17

  
18
	/**
19
	 * 
20
	 * @param corpus
21
	 * @return true if the Engine can query the corpus
22
	 */
23
	public abstract boolean hasIndexes(CorpusBuild corpus);
12 24
}
tmp/org.txm.searchengine.core/src/org/txm/searchengine/core/corpus/CorpusSearchException.java (revision 1075)
1
package org.txm.searchengine.core.corpus;
2

  
3
public class CorpusSearchException extends Exception {
4

  
5
	/**
6
	 * 
7
	 */
8
	private static final long serialVersionUID = 3518861723206508596L;
9

  
10
	public CorpusSearchException(String message) {
11
		super(message);
12
	}
13

  
14
	public CorpusSearchException(String message, Throwable cause) {
15
		super(message, cause);
16
	}
17
}
0 18

  
tmp/org.txm.searchengine.core/src/org/txm/searchengine/core/Match.java (revision 1075)
1
package org.txm.searchengine.core;
2

  
3
import java.util.ArrayList;
4
import java.util.List;
5

  
6
public abstract class Match implements Comparable<Match> {
7
	public abstract int getStart();
8
	public abstract int getEnd();
9
	public abstract int getTarget();
10
	
11
	public boolean contains(Match m) {
12
		return (this.getStart() <= m.getStart() && m.getEnd() <= this.getEnd());
13
	}
14
	
15
	/* (non-Javadoc)
16
	 * @see java.lang.Comparable#compareTo(java.lang.Object)
17
	 */
18
	@Override
19
	public int compareTo(Match m) {
20

  
21
		if (m == null)
22
			return -1;
23
		if (this.getStart() < m.getStart())
24
			return -1;
25
		else if (this.getStart() > m.getStart())
26
			return 1;
27
		else if (this.getEnd() < m.getEnd())
28
			return -1;
29
		else
30
			return 1;
31

  
32
	}
33

  
34
	/* (non-Javadoc)
35
	 * @see java.lang.Object#toString()
36
	 */
37
	@Override
38
	public String toString() {
39
		return "<" + this.getStart() + ", " + this.getEnd() + ">"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
40
	}
41
	
42
	/**
43
	 * Size.
44
	 *
45
	 * @return the int
46
	 */
47
	public int size() {
48
		return getEnd() - getStart() + 1;
49
	}
50
	
51
	public List<Integer> getRange() {
52
		List<Integer> ret = new ArrayList<Integer>(size());
53
		for (int i = getStart() ; i <= getEnd(); i++) ret.add(i);
54
		return ret;
55
	}
56

  
57
	public abstract void setEnd(int p);
58

  
59
	public abstract void setStart(int p);
60
	
61
	public abstract void setTarget(int p);
62
}
0 63

  
tmp/org.txm.progression.rcp/src/org/txm/progression/rcp/editors/ProgressionEditor.java (revision 1075)
43 43
import org.txm.rcp.swt.widget.structures.StructuralUnitPropertiesComboViewer;
44 44
import org.txm.rcp.swt.widget.structures.StructuralUnitsComboViewer;
45 45
import org.txm.rcp.swt.widget.structures.StructuralUnitsCombosGroup;
46
import org.txm.searchengine.core.Query;
46 47
import org.txm.searchengine.cqp.corpus.query.CQLQuery;
47 48
import org.txm.utils.io.IOUtils;
48 49
import org.txm.utils.logger.Log;
......
95 96
	 * Queries.
96 97
	 */
97 98
	@Parameter(key=ProgressionPreferences.QUERIES)
98
	protected List<CQLQuery> queryList;
99
	protected List<Query> queryList;
99 100

  
100 101
	/**
101 102
	 * Structural unit.
......
520 521
			assistedQueryWidget.setText(query);
521 522
		}
522 523

  
523
		public CQLQuery getQuery() {
524
		public Query getQuery() {
524 525
			return assistedQueryWidget.getQuery();
525 526
		}
526 527

  
......
599 600

  
600 601
		 // initialize query fields
601 602
		if (queryWidgets.size() == 0 && queryList != null) {
602
			for (CQLQuery q : queryList) {
603
			for (Query q : queryList) {
603 604
				addFocusQueryField(q.getQueryString()); 
604 605
			}
605 606
		}
......
614 615
	public void updateResultFromEditor() {
615 616

  
616 617
		// create query list from widget
617
		queryList = new ArrayList<CQLQuery>();
618
		queryList = new ArrayList<Query>();
618 619
		for (QueryField wid : queryWidgets) {
619 620
			if (!wid.getQuery().isEmpty()) {
620 621
				queryList.add(wid.getQuery());
tmp/org.txm.rcp/src/main/java/org/txm/rcp/editors/TXMEditor.java (revision 1075)
64 64
import org.txm.rcp.handlers.BaseAbstractHandler;
65 65
import org.txm.rcp.messages.TXMUIMessages;
66 66
import org.txm.rcp.swt.GLComposite;
67
import org.txm.rcp.swt.widget.AssistedChoiceQueryWidget;
67 68
import org.txm.rcp.swt.widget.AssistedQueryWidget;
68 69
import org.txm.rcp.swt.widget.FloatSpinner;
69 70
import org.txm.rcp.swt.widget.NewNavigationWidget;
......
73 74
import org.txm.rcp.utils.SWTEditorsUtils;
74 75
import org.txm.rcp.views.corpora.CorporaView;
75 76
import org.txm.rcp.views.debug.TXMResultDebugView;
77
import org.txm.searchengine.core.Query;
76 78
import org.txm.searchengine.cqp.ReferencePattern;
77 79
import org.txm.searchengine.cqp.corpus.Property;
78 80
import org.txm.searchengine.cqp.corpus.query.CQLQuery;
......
885 887
						((AssistedQueryWidget)object).setText(((CQLQuery)value).getQueryString());
886 888
					}
887 889
				}
890
				else if(object instanceof AssistedChoiceQueryWidget)	{
891
					if(!((Query)value).getQueryString().isEmpty())	{
892
						((QueryWidget)object).setText(((Query)value).getQueryString());
893
					}
894
				}
895
				else if(object instanceof AssistedQueryWidget)	{
896
					if(!((CQLQuery)value).getQueryString().isEmpty())	{
897
						((QueryWidget)object).setText(((CQLQuery)value).getQueryString());
898
					}
899
				}
888 900
				else if(object instanceof QueryWidget)	{
889 901
					if(!((CQLQuery)value).getQueryString().isEmpty())	{
890 902
						((QueryWidget)object).setText(((CQLQuery)value).getQueryString());
......
987 999
				else if(object instanceof NewNavigationWidget)	{
988 1000
					value = ((NewNavigationWidget)object).getCurrentPosition(); 
989 1001
				}
1002
				else if(object instanceof AssistedChoiceQueryWidget)	{
1003
					value = ((AssistedChoiceQueryWidget)object).getQuery();
1004
				}
990 1005
				else if(object instanceof AssistedQueryWidget)	{
991 1006
					value = ((AssistedQueryWidget)object).getQuery();
992 1007
				}
tmp/org.txm.rcp/src/main/java/org/txm/rcp/swt/widget/QueryWidget.java (revision 1075)
32 32

  
33 33
import org.eclipse.swt.widgets.Combo;
34 34
import org.eclipse.swt.widgets.Composite;
35
import org.txm.searchengine.cqp.corpus.query.CQLQuery;
35
import org.txm.searchengine.core.Query;
36
import org.txm.searchengine.core.SearchEngine;
37
import org.txm.searchengine.core.SearchEnginesManager;
38
import org.txm.searchengine.cqp.corpus.Corpus;
36 39

  
37 40
// TODO: Auto-generated Javadoc
38 41
/**
......
45 48
 */
46 49
public class QueryWidget extends Combo {
47 50

  
51
	SearchEngine se;
52
	
48 53
	/** The history. */
49 54
	private static Deque<String> history = new LinkedList<String>();
50 55

  
......
54 59
	 * @param parent the parent
55 60
	 * @param style the style
56 61
	 */
57
	public QueryWidget(Composite parent, int style) {
62
	public QueryWidget(Composite parent, int style, SearchEngine se) {
58 63
		super(parent, style);
64
		this.se = se;
59 65
		this.setItems(history.toArray(new String[history.size()]));
60 66
	}
67
	
68
	public QueryWidget(Composite composite, int style) {
69
		this(composite, style, SearchEnginesManager.getCQPSearchEngine());
70
	}
61 71

  
72
	public void setSearchEngine(SearchEngine se) {
73
		this.se = se;
74
	}
75

  
62 76
	/**
63 77
	 * Gets the CQP query string inferred from the user input.
64 78
	 *
......
72 86
		else {
73 87
			rawQuery = this.getItem(this.getSelectionIndex());
74 88
		}
75
		return CQLQuery.fixQuery(rawQuery);
89
		return se.newQuery().setQuery(rawQuery).fixQuery().getQueryString();
76 90
	}
77 91

  
78 92
	/**
......
116 130
	 *
117 131
	 * @return the query
118 132
	 */
119
	public CQLQuery getQuery() {
120
		if(!this.getQueryString().isEmpty())	{
121
			return new CQLQuery(this.getQueryString());	
122
		}
123
		else	{
133
	public Query getQuery() {
134
		if (!this.getQueryString().isEmpty())	{
135
			return se.newQuery().setQuery(this.getQueryString());	
136
		} else {
124 137
			return null;
125 138
		}
126 139
	};
tmp/org.txm.rcp/src/main/java/org/txm/rcp/swt/widget/AssistedQueryWidget.java (revision 1075)
33 33
import org.eclipse.swt.events.SelectionEvent;
34 34
import org.eclipse.swt.events.SelectionListener;
35 35
import org.eclipse.swt.layout.GridData;
36
import org.eclipse.swt.layout.GridLayout;
37 36
import org.eclipse.swt.widgets.Button;
38 37
import org.eclipse.swt.widgets.Composite;
39 38
import org.txm.rcp.IImageKeys;
40 39
import org.txm.rcp.messages.TXMUIMessages;
41 40
import org.txm.rcp.swt.GLComposite;
42 41
import org.txm.rcp.swt.dialog.QueryAssistDialog;
42
import org.txm.searchengine.core.Query;
43
import org.txm.searchengine.core.SearchEngine;
44
import org.txm.searchengine.core.SearchEnginesManager;
43 45
import org.txm.searchengine.cqp.corpus.Corpus;
44
import org.txm.searchengine.cqp.corpus.query.CQLQuery;
45 46
// TODO: Auto-generated Javadoc
46 47
/**
47 48
 * the QueryWidget plus the button to open the QueryAssisDialog @ author
......
49 50
 */
50 51
public class AssistedQueryWidget extends Composite {
51 52
	
53
	protected SearchEngine se;
54
	
52 55
	/** The magicstick button: opens the QueryAssist dialog. */
53 56
	protected Button magicstick;
54 57
	
......
64 67
	 * @param style the style
65 68
	 * @param corpus the corpus
66 69
	 */
67
	public AssistedQueryWidget(Composite parent, int style, final Corpus corpus) {
70
	public AssistedQueryWidget(Composite parent, int style, final Corpus corpus, SearchEngine se) {
68 71
		super(parent, SWT.NONE);
69 72
		this.setLayout(GLComposite.createDefaultLayout(2));
70 73

  
74
		this.se = se;
75
		
71 76
		magicstick = new Button(this, SWT.PUSH);
72 77
		magicstick.setLayoutData(new GridData(GridData.FILL, GridData.CENTER,
73 78
				false, false));
......
86 91
			public void widgetDefaultSelected(SelectionEvent e) { }
87 92
		});
88 93

  
89
		querywidget = new QueryWidget(this, style);
94
		querywidget = new QueryWidget(this, style, se);
90 95
		querywidget.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));
91 96
	}
92 97
	
98
	public AssistedQueryWidget(Composite parent, int style, Corpus corpus) {
99
		this(parent, style, corpus, SearchEnginesManager.getCQPSearchEngine());
100
	}
101

  
93 102
	public boolean setFocus() {
94 103
		return this.querywidget.setFocus();
95 104
	}
......
158 167
		querywidget.setText(query);
159 168
	}
160 169

  
161
	public CQLQuery getQuery() {
170
	public Query getQuery() {
162 171
		return this.querywidget.getQuery();
163 172
	}
164 173
}
tmp/org.txm.rcp/src/main/java/org/txm/rcp/swt/widget/parameters/QueryField.java (revision 1075)
7 7
import org.eclipse.swt.widgets.Label;
8 8
import org.kohsuke.args4j.NamedOptionDef;
9 9
import org.txm.rcp.swt.widget.QueryWidget;
10
import org.txm.searchengine.core.Query;
10 11
import org.txm.searchengine.cqp.corpus.query.CQLQuery;
11 12

  
12 13
public class QueryField extends ParameterField {
......
30 31
		resetToDefault();
31 32
	}
32 33

  
33
	public CQLQuery getWidgetValue() {
34
	public Query getWidgetValue() {
34 35
		return w.getQuery();
35 36
	}
36 37

  
tmp/org.txm.rcp/src/main/java/org/txm/rcp/swt/widget/AssistedChoiceQueryWidget.java (revision 1075)
1
// Copyright © 2010-2013 ENS de Lyon.
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;
29

  
30
import java.util.List;
31

  
32
import org.eclipse.jface.viewers.ComboViewer;
33
import org.eclipse.jface.viewers.IBaseLabelProvider;
34
import org.eclipse.jface.viewers.ILabelProviderListener;
35
import org.eclipse.jface.viewers.ISelection;
36
import org.eclipse.jface.viewers.ISelectionChangedListener;
37
import org.eclipse.jface.viewers.LabelProvider;
38
import org.eclipse.jface.viewers.SelectionChangedEvent;
39
import org.eclipse.jface.viewers.StructuredSelection;
40
import org.eclipse.jface.window.Window;
41
import org.eclipse.swt.SWT;
42
import org.eclipse.swt.events.KeyListener;
43
import org.eclipse.swt.events.SelectionEvent;
44
import org.eclipse.swt.events.SelectionListener;
45
import org.eclipse.swt.layout.GridData;
46
import org.eclipse.swt.widgets.Button;
47
import org.eclipse.swt.widgets.Combo;
48
import org.eclipse.swt.widgets.Composite;
49
import org.txm.rcp.IImageKeys;
50
import org.txm.rcp.messages.TXMUIMessages;
51
import org.txm.rcp.swt.GLComposite;
52
import org.txm.rcp.swt.dialog.QueryAssistDialog;
53
import org.txm.rcp.swt.provider.ListContentProvider;
54
import org.txm.rcp.swt.provider.SimpleLabelProvider;
55
import org.txm.searchengine.core.Query;
56
import org.txm.searchengine.core.SearchEngine;
57
import org.txm.searchengine.core.SearchEnginesManager;
58
import org.txm.searchengine.cqp.corpus.Corpus;
59
import org.txm.searchengine.cqp.corpus.query.CQLQuery;
60

  
61
/**
62
 * the QueryWidget 
63
 * 	+ the button to open the QueryAssisDialog
64
 *  + Engine selector 
65
 * 
66
 * @author mdecorde.
67
 */
68
public class AssistedChoiceQueryWidget extends Composite {
69

  
70
	/** The magicstick button: opens the QueryAssist dialog. */
71
	protected Button magicstick;
72

  
73
	/** The querywidget. */
74
	protected QueryWidget querywidget;
75

  
76
	private QueryAssistDialog d;
77

  
78
	/**
79
	 * Instantiates a new assisted query widget.
80
	 *
81
	 * @param parent the parent
82
	 * @param style the style
83
	 * @param corpus the corpus
84
	 */
85
	public AssistedChoiceQueryWidget(Composite parent, int style, final Corpus corpus) {
86
		super(parent, SWT.NONE);
87
		this.setLayout(GLComposite.createDefaultLayout(3));
88

  
89
		List<SearchEngine> engines = SearchEnginesManager.getAvailableEngines(corpus);
90

  
91
		//if (engines.size() > 1) {
92
			ComboViewer combo = new ComboViewer(this);
93
			Combo ccombo = combo.getCombo();
94
			combo.setContentProvider(new ListContentProvider());
95
			ccombo.setLayoutData(new GridData(GridData.FILL, GridData.CENTER,
96
					false, false));
97
			combo.setLabelProvider(new LabelProvider() {
98
				@Override
99
				public String getText(Object element) {
100
					return ((SearchEngine)element).getName();
101
				}
102
			});
103
			combo.setInput(engines);
104
			ccombo.select(0);
105
			combo.addSelectionChangedListener(new ISelectionChangedListener() {
106
				
107
				@Override
108
				public void selectionChanged(SelectionChangedEvent event) {
109
					ISelection isel = event.getSelection();
110
					StructuredSelection sel = (StructuredSelection)isel;
111
					Object o = sel.getFirstElement();
112
					SearchEngine se = (SearchEngine)o;
113
					querywidget.setSearchEngine(se);
114
				}
115
			});
116
		//}
117

  
118
		magicstick = new Button(this, SWT.PUSH);
119
		magicstick.setLayoutData(new GridData(GridData.FILL, GridData.CENTER,
120
				false, false));
121
		magicstick.setImage(IImageKeys.getImage(IImageKeys.ACTION_ASSISTQUERY));
122
		magicstick.setToolTipText(TXMUIMessages.AssistedQueryWidget_0);
123
		magicstick.addSelectionListener(new SelectionListener() {
124
			@Override
125
			public void widgetSelected(SelectionEvent e) {
126
				d = new QueryAssistDialog(e.display.getActiveShell(), corpus);
127
				if (d.open() == Window.OK) {
128
					querywidget.setText(d.getQuery());
129
				}
130
			}
131

  
132
			@Override
133
			public void widgetDefaultSelected(SelectionEvent e) { }
134
		});
135

  
136
		for (SearchEngine engine : engines) {
137
			querywidget = new QueryWidget(this, style, engine);
138
			querywidget.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));
139
			break; // set the first engine as default engine
140
		}
141
	}
142

  
143
	public boolean setFocus() {
144
		return this.querywidget.setFocus();
145
	}
146

  
147
	/* (non-Javadoc)
148
	 * @see org.eclipse.swt.widgets.Control#addKeyListener(org.eclipse.swt.events.KeyListener)
149
	 */
150
	@Override
151
	public void addKeyListener(KeyListener listener) {
152
		if (querywidget != null)
153
			this.querywidget.addKeyListener(listener);
154
	}
155

  
156
	/**
157
	 * Gets the query string.
158
	 *
159
	 * @return the query string
160
	 */
161
	public String getQueryString() {
162
		return querywidget.getQueryString();
163
	}
164

  
165
	/**
166
	 * Gets the query string.
167
	 *
168
	 * @return the query string
169
	 */
170
	public String getRawString() {
171
		return querywidget.getText();
172
	}
173

  
174
	/**
175
	 * Memorize.
176
	 */
177
	public void memorize() {
178
		querywidget.memorize();
179
	}
180

  
181
	/**
182
	 * Memorize.
183
	 *
184
	 * @param query the query
185
	 */
186
	public void memorize(String query) {
187
		querywidget.memorize(query);
188
	}
189

  
190
	/**
191
	 * Clears the query test.
192
	 */
193
	public void clearQuery()	{
194
		this.querywidget.setText(""); //$NON-NLS-1$
195
	}
196

  
197
	/**
198
	 * Sets the text.
199
	 *
200
	 * @param query the new text
201
	 */
202
	public void setText(String query) {
203

  
204
		//		if(query.isEmpty())	{
205
		//			query = ""; //$NON-NLS-1$
206
		//		}
207

  
208
		querywidget.setText(query);
209
	}
210

  
211
	public Query getQuery() {
212
		return this.querywidget.getQuery();
213
	}
214
}
0 215

  

Formats disponibles : Unified diff