Révision 3708

TXM/trunk/bundles/org.txm.treesearch.rcp/src/org/txm/treesearch/editor/TreeSearchEditor.java (revision 3708)
6 6
import java.util.HashMap;
7 7
import java.util.List;
8 8

  
9
import org.eclipse.e4.ui.workbench.modeling.EModelService;
9 10
import org.eclipse.swt.SWT;
10 11
import org.eclipse.swt.browser.Browser;
12
import org.eclipse.swt.events.MenuDetectEvent;
13
import org.eclipse.swt.events.MenuDetectListener;
11 14
import org.eclipse.swt.events.MouseEvent;
12 15
import org.eclipse.swt.events.MouseWheelListener;
13 16
import org.eclipse.swt.events.SelectionEvent;
14 17
import org.eclipse.swt.events.SelectionListener;
18
import org.eclipse.swt.graphics.Point;
15 19
import org.eclipse.swt.layout.GridData;
16 20
import org.eclipse.swt.layout.GridLayout;
17 21
import org.eclipse.swt.widgets.Button;
......
20 24
import org.eclipse.swt.widgets.Event;
21 25
import org.eclipse.swt.widgets.Label;
22 26
import org.eclipse.swt.widgets.Listener;
27
import org.eclipse.swt.widgets.Menu;
28
import org.eclipse.swt.widgets.MenuItem;
23 29
import org.eclipse.swt.widgets.Spinner;
24 30
import org.eclipse.ui.IEditorInput;
25 31
import org.eclipse.ui.IEditorSite;
......
129 135
					}
130 136
					updateFields = true;
131 137
				}
138
				
132 139
				if (updateFields) {
140
					
141
					TreeSearch currentTreeSearch = tsPerRepresentation.get(currentSelector.getEngine());
142
					
133 143
					queryArea.setQueryClass(currentSelector.getQueryClass());
134 144
					initializeFields();
135 145
					getEditorInput().setResult(tsPerRepresentation.get(currentSelector.getEngine()));
......
186 196
			@Override
187 197
			public void widgetSelected(SelectionEvent e) {
188 198
				
189
				try {
190
					String[] currentMatch = TreeSearchEditor.this.getResult().getTextAndWordIDSOfCurrentSentence();
191
					if (currentMatch == null || currentMatch.length != 2 || currentMatch[0] == null || currentMatch[1] == null) {
192
						return;
193
					}
194
					String textId = currentMatch[0];
195
					String wordId = currentMatch[1];
196
					
197
					SynopticEditionEditor editor = OpenEdition.openEdition(corpus, null, textId, null, wordId);
198
					int position = SynopticEditionPreferences.getInstance().getInt(SynopticEditionPreferences.BACKTOTEXT_POSITION);
199
					if (editor != null && position >= 0) {
200
						SWTEditorsUtils.addEditor(editor, TreeSearchEditor.this, position);
201
					}
202
				}
203
				catch (Exception e1) {
204
					// TODO Auto-generated catch block
205
					e1.printStackTrace();
206
				}
199
				readText();
207 200
			}
208 201
			
209 202
			@Override
......
375 368
			}
376 369
		});
377 370
		
371
//		svgPanel.addMenuDetectListener(new MenuDetectListener() {
372
//			
373
//			@Override
374
//			public void menuDetected(MenuDetectEvent e) {
375
//				
376
//				Menu menu = svgPanel.getMenu();
377
//				System.out.println(menu);
378
//				MenuItem editionItem = new MenuItem(menu, SWT.PUSH);
379
//				editionItem.setText("Read text");
380
//				editionItem.addSelectionListener(new SelectionListener() {
381
//					
382
//					@Override
383
//					public void widgetSelected(SelectionEvent e) {
384
//						readText();
385
//					}
386
//					
387
//					@Override
388
//					public void widgetDefaultSelected(SelectionEvent e) { }
389
//				});
390
//			}
391
//		});
392
	
393
		
378 394
		// this.getTopToolbar().setVisible(COMPUTING_PARAMETERS_GROUP_ID, true);
379 395
		initializeFields();
380 396
	}
381 397
	
398
	protected void readText() {
399
		try {
400
			String[] currentMatch = TreeSearchEditor.this.getResult().getTextAndWordIDSOfCurrentSentence();
401
			if (currentMatch == null || currentMatch.length != 2 || currentMatch[0] == null || currentMatch[1] == null) {
402
				return;
403
			}
404
			String textId = currentMatch[0];
405
			String wordId = currentMatch[1];
406
			
407
			SynopticEditionEditor editor = OpenEdition.openEdition(corpus, null, textId, null, wordId);
408
			int position = SynopticEditionPreferences.getInstance().getInt(SynopticEditionPreferences.BACKTOTEXT_POSITION);
409
			if (position == -2) {
410
				Point s = editor.getParent().getSize();
411
				if (s.x < s.y) {
412
					position = EModelService.ABOVE;
413
				} else {
414
					position = EModelService.RIGHT_OF;
415
				}
416
			}
417
			if (editor != null && position >= 0) {
418
				SWTEditorsUtils.addEditor(editor, TreeSearchEditor.this, position);
419
			}
420
		}
421
		catch (Exception e1) {
422
			// TODO Auto-generated catch block
423
			e1.printStackTrace();
424
		}
425
	}
426

  
382 427
	protected void initializeFields() {
383 428
		// String id = corpus.getID();
384 429
		
TXM/trunk/bundles/org.txm.treesearch.rcp/src/org/txm/treesearch/command/ComputeTreeSearch.java (revision 3708)
187 187
			}
188 188
		}
189 189
		else {
190
			
191 190
			Log.warning(Messages.bind(Messages.SelectionIsNotACorpusP0, obj));
192 191
			return null;
193 192
		}
TXM/trunk/bundles/org.txm.treesearch.rcp/src/org/txm/treesearch/command/SendToTreeSearch.java (revision 3708)
27 27
//
28 28
package org.txm.treesearch.command;
29 29

  
30
import java.io.IOException;
31 30
import java.util.List;
32 31

  
33 32
import org.eclipse.core.commands.ExecutionEvent;
34 33
import org.eclipse.core.commands.ExecutionException;
35
import org.eclipse.jface.text.TextSelection;
34
import org.eclipse.e4.ui.workbench.modeling.EModelService;
36 35
import org.eclipse.jface.viewers.ISelection;
37 36
import org.eclipse.jface.viewers.StructuredSelection;
37
import org.eclipse.swt.graphics.Point;
38 38
import org.eclipse.ui.handlers.HandlerUtil;
39
import org.eclipse.ui.part.EditorPart;
39 40
import org.txm.concordance.core.functions.Concordance;
40 41
import org.txm.concordance.core.functions.Line;
41 42
import org.txm.concordance.rcp.editors.ConcordanceEditor;
......
43 44
import org.txm.edition.rcp.editors.SynopticEditionEditor;
44 45
import org.txm.objects.Match;
45 46
import org.txm.rcp.editors.ITXMResultEditor;
47
import org.txm.rcp.editors.TXMEditor;
46 48
import org.txm.rcp.handlers.BaseAbstractHandler;
47 49
import org.txm.rcp.utils.SWTEditorsUtils;
48 50
import org.txm.searchengine.core.Selection;
49 51
import org.txm.searchengine.cqp.CQPSearchEngine;
50
import org.txm.searchengine.cqp.clientExceptions.CqiClientException;
51
import org.txm.searchengine.cqp.clientExceptions.UnexpectedAnswerException;
52 52
import org.txm.searchengine.cqp.corpus.CQPCorpus;
53 53
import org.txm.searchengine.cqp.corpus.WordProperty;
54 54
import org.txm.searchengine.cqp.corpus.query.CQLQuery;
55
import org.txm.searchengine.cqp.serverException.CqiServerError;
56 55
import org.txm.treesearch.editor.TreeSearchEditor;
57 56
import org.txm.treesearch.function.TreeSearch;
57
import org.txm.treesearch.preferences.TreeSearchPreferences;
58 58
import org.txm.treesearch.rcp.Messages;
59 59
import org.txm.utils.logger.Log;
60 60

  
......
113 113
		}
114 114
		
115 115
		if (word_id != null) {
116
			WordProperty p_id = editor.getCorpus().getProperty("id");
116
			//WordProperty p_id = editor.getCorpus().getProperty("id");
117 117
			Selection sel = CQPSearchEngine.getEngine().query(editor.getCorpus(), new CQLQuery("[id=\""+word_id+"\" & _.text_id=\""+editor.getResult().getName()+"\"]"), "TMP", false);
118 118
			if (sel.getNMatch() > 0) {
119 119
				kp = sel.getMatches().get(0).getStart();
......
187 187
		
188 188
		try {
189 189
			boolean c = ts.compute();
190
			Selection sel = ts.getSelection();
191 190
			
192 191
//			System.out.println("KP="+kp);
193
			if (c &&  sel != null) {
194
				int i = 0;
195
				List<? extends Match> matches = ts.getSelection().getMatches();
196
				
197
				for (Match m : matches) {
198
					if (m.getStart() <= kp && kp <= m.getEnd()) {
199
//						System.out.println("set index "+(i+1));
200
						ts.setIndexAndSubIndex(i+1, 1);
201
						break;
192
			if (c) {
193
				Selection sel = ts.getSelection();
194
				if (sel != null) {
195
					int i = 0;
196
					List<? extends Match> matches = ts.getSelection().getMatches();
197
					
198
					for (Match m : matches) {
199
						if (m.getStart() <= kp && kp <= m.getEnd()) {
200
//							System.out.println("set index "+(i+1));
201
							ts.setIndexAndSubIndex(i+1, 1);
202
							break;
203
						}
204
						i++;
202 205
					}
203
					i++;
204 206
				}
205 207
			}
206 208
		}
207 209
		catch (Exception e) {
208
			// TODO Auto-generated catch block
209 210
			e.printStackTrace();
211
			return null;
210 212
		}
211 213
		
212 214
		if (leditor == null) {
213
			ITXMResultEditor<TXMResult> openedEditor = ComputeTreeSearch.openEditor(ts);
215
			
216
			TreeSearchEditor openedEditor = ComputeTreeSearch.openEditor(ts);
217
			
214 218
			if (openedEditor != null) {
215 219
				editor.addLinkedEditor(openedEditor);
220

  
221
				int position = TreeSearchPreferences.getInstance().getInt(TreeSearchPreferences.BACKTOTREE_POSITION);
222
				if (position == -2 && editor instanceof TXMEditor) {
223
					Point p = ((TXMEditor)editor).getParent().getSize();
224
					if (p.x < p.y) {
225
						position = EModelService.ABOVE;
226
					} else {
227
						position = EModelService.RIGHT_OF;
228
					}
229
				}
230
				if (editor != null && position >= 0 && editor instanceof EditorPart) {
231
					SWTEditorsUtils.addEditor((EditorPart)editor, openedEditor, position);
232
				}
216 233
			}
217 234
			return openedEditor;
218 235
		} else {
TXM/trunk/bundles/org.txm.treesearch.rcp/src/org/txm/treesearch/preferences/TreeSearchPreferencePage.java (revision 3708)
1 1
package org.txm.treesearch.preferences;
2 2

  
3
import org.eclipse.e4.ui.workbench.modeling.EModelService;
4
import org.eclipse.jface.preference.ComboFieldEditor;
3 5
import org.eclipse.jface.preference.StringFieldEditor;
4 6
import org.eclipse.ui.IWorkbench;
5 7
import org.txm.rcp.IImageKeys;
......
15 17
 */
16 18
public class TreeSearchPreferencePage extends TXMPreferencePage {
17 19

  
20
	private ComboFieldEditor backtotext_position;
21
	
18 22
	@Override
19 23
	public void createFieldEditors() {
20 24
		
21 25
		this.addField(new StringFieldEditor(TreeSearchPreferences.DEFAULT_VISUALISATION, Messages.DefaultSyntacticVisualisation, this.getFieldEditorParent()));
26
		
27
		String[][] values = {
28
				{"RATIO", "-2"},
29
				{"OVER", "-1"}, 
30
				{"ABOVE", ""+EModelService.ABOVE}, 
31
				{"BELOW", ""+EModelService.BELOW}, 
32
				{"LEFT_OF", ""+EModelService.LEFT_OF}, 
33
				{"RIGHT_OF", ""+EModelService.RIGHT_OF}};
34
		
35
		backtotext_position = new ComboFieldEditor(TreeSearchPreferences.BACKTOTREE_POSITION, "Linked editor position", values, getFieldEditorParent());
36
		addField(backtotext_position);
22 37
	}
23 38
	
24 39
	/*
TXM/trunk/bundles/org.txm.backtomedia.rcp/src/org/txm/backtomedia/commands/function/BackToMedia.java (revision 3708)
38 38
import org.eclipse.core.commands.ExecutionEvent;
39 39
import org.eclipse.core.commands.ExecutionException;
40 40
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
41
import org.eclipse.e4.ui.workbench.modeling.EModelService;
41 42
import org.eclipse.jface.viewers.IStructuredSelection;
42 43
import org.eclipse.jface.window.Window;
43 44
import org.eclipse.osgi.util.NLS;
45
import org.eclipse.swt.graphics.Point;
44 46
import org.eclipse.swt.widgets.Shell;
45 47
import org.eclipse.ui.IWorkbenchPart;
46 48
import org.eclipse.ui.handlers.HandlerUtil;
......
552 554
				
553 555
				// move the editor in the window
554 556
				int position = BackToMediaPreferences.getInstance().getInt(BackToMediaPreferences.BACKTOMEDIA_POSITION);
557
				if (position == -2) {
558
					Point s = editor.getParent().getSize();
559
					if (s.x < s.y) {
560
						position = EModelService.ABOVE;
561
					} else {
562
						position = EModelService.RIGHT_OF;
563
					}
564
				}
555 565
				if (editor != null && position >= 0) {
556 566
					SWTEditorsUtils.addEditor((EditorPart) editor, mediaPlayerEditor, position);
557 567
				}
TXM/trunk/bundles/org.txm.texts.rcp/src/org/txm/texts/rcp/TextsViewEditor.java (revision 3708)
3 3
import java.util.ArrayList;
4 4
import java.util.List;
5 5

  
6
import org.eclipse.e4.ui.workbench.modeling.EModelService;
6 7
import org.eclipse.jface.viewers.ColumnLabelProvider;
7 8
import org.eclipse.jface.viewers.DoubleClickEvent;
8 9
import org.eclipse.jface.viewers.IDoubleClickListener;
......
14 15
import org.eclipse.jface.viewers.Viewer;
15 16
import org.eclipse.swt.SWT;
16 17
import org.eclipse.swt.graphics.Image;
18
import org.eclipse.swt.graphics.Point;
17 19
import org.eclipse.swt.layout.GridData;
18 20
import org.eclipse.swt.layout.GridLayout;
19 21
import org.eclipse.swt.widgets.Label;
......
261 263
				if (o != null && o instanceof Text) {
262 264
					SynopticEditionEditor editor = OpenEdition.openEdition(getResult().getCorpus(), new String[] {getResult().getProject().getDefaultEditionName()}, ((Text)o).getName());
263 265
					int position = SynopticEditionPreferences.getInstance().getInt(SynopticEditionPreferences.BACKTOTEXT_POSITION);
266
					if (position == -2) {
267
						Point s = editor.getParent().getSize();
268
						if (s.x < s.y) {
269
							position = EModelService.ABOVE;
270
						} else {
271
							position = EModelService.RIGHT_OF;
272
						}
273
					}
264 274
					if (editor != null && position >= 0) {
265 275
						SWTEditorsUtils.addEditor(editor, TextsViewEditor.this, position);
266 276
					}
TXM/trunk/bundles/org.txm.tigersearch.rcp/src/org/txm/searchengine/ts/TIGERSearchEngine.java (revision 3708)
10 10
import java.nio.MappedByteBuffer;
11 11
import java.nio.channels.FileChannel;
12 12
import java.util.ArrayList;
13
import java.util.Arrays;
13 14
import java.util.HashMap;
14 15
import java.util.LinkedHashSet;
15 16
import java.util.List;
16 17

  
18
import org.apache.commons.lang.StringUtils;
17 19
import org.apache.log4j.BasicConfigurator;
18 20
import org.eclipse.core.runtime.IProgressMonitor;
19 21
import org.txm.core.results.TXMResult;
......
40 42
import org.txm.utils.io.IOUtils;
41 43
import org.txm.utils.logger.Log;
42 44

  
45
import ims.tiger.corpus.Feature;
46
import ims.tiger.corpus.Header;
43 47
import ims.tiger.corpus.Sentence;
44 48
import ims.tiger.corpus.T_Node;
45 49
import ims.tiger.index.reader.Index;
......
52 56
import ims.tiger.query.processor.CorpusQueryProcessor;
53 57

  
54 58
public class TIGERSearchEngine extends SearchEngine {
55
	
59

  
56 60
	public static final String NAME = "TIGER";
57
	
61

  
58 62
	HashMap<CorpusBuild, TSCorpus> corpora = null;
59
	
63

  
60 64
	public TSCorpus getTSCorpus(CorpusBuild corpus) {
61 65
		CorpusBuild root = corpus.getRootCorpusBuild();
62 66
		TSCorpus tscorpus = corpora.get(root);
63 67
		if (tscorpus != null) {
64 68
			return tscorpus;
65 69
		}
66
		
70

  
67 71
		File tigerDirectory = new File(root.getProjectDirectory(), "tiger");
68 72
		File configfile = new File(tigerDirectory, "tigersearch.logprop");
69 73
		if (!tigerDirectory.exists()) {
......
72 76
		if (!configfile.exists()) {
73 77
			return null;
74 78
		}
75
		
79

  
76 80
		TSCorpusManager manager = new TSCorpusManager(tigerDirectory, configfile);
77 81
		tscorpus = manager.getCorpus(root.getID());
78 82
		if (tscorpus != null) {
......
83 87
			return null;
84 88
		}
85 89
	}
86
	
90

  
87 91
	public TSCorpus removeTSCorpus(CorpusBuild corpus) {
88 92
		CorpusBuild root = corpus.getRootCorpusBuild();
89 93
		return corpora.remove(root);
90 94
	}
91
	
95

  
92 96
	@Override
93 97
	public boolean isRunning() {
94 98
		return true;
95 99
	}
96
	
100

  
97 101
	@Override
98 102
	public boolean initialize() throws Exception {
99 103
		return true;
100 104
	}
101
	
105

  
102 106
	/**
103 107
	 * 
104 108
	 * @param cqpCorpus the targeted CQPCorpus
......
114 118
		if (matches.size() == 0) {
115 119
			return new int[] { 0, 0 };
116 120
		}
117
		
121

  
118 122
		return getSentMinMax(cqpCorpus, matches.get(0).getStart(), matches.get(matches.size() - 1).getEnd());
119 123
	}
120
	
124

  
121 125
	/**
122 126
	 * 
123 127
	 * @param cqpCorpus the targeted CQPCorpus
......
143 147
		int sent_max = structs[structs.length - 1];
144 148
		return new int[] { sent_min, sent_max };
145 149
	}
146
	
150

  
147 151
	/**
148 152
	 * 
149 153
	 * @return true because TIGER queries are frequently multi lines
......
152 156
	public boolean hasMultiLineQueries() {
153 157
		return true;
154 158
	}
155
	
159

  
156 160
	@Override
157 161
	public boolean start(IProgressMonitor monitor) throws Exception {
158 162
		corpora = new HashMap<>();
159 163
		return true;
160 164
	}
161
	
165

  
162 166
	@Override
163 167
	public boolean stop() throws Exception {
164 168
		if (corpora != null) {
......
169 173
		}
170 174
		return true;
171 175
	}
172
	
176

  
173 177
	@Override
174 178
	public String getName() {
175 179
		return NAME;
176 180
	}
177
	
181

  
178 182
	@Override
179 183
	public Selection query(CorpusBuild corpus, IQuery query, String name, boolean saveQuery) throws Exception {
180
		
184

  
181 185
		TSCorpus tcorpus = this.getTSCorpus(corpus);
182 186
		TSResult result = null;
183 187
		if (corpus == corpus.getRootCorpusBuild() || !(corpus instanceof CQPCorpus)) { // root corpus or something not a CQPCorpus
......
200 204
			Log.finest("QUERYING sentences: " + sent_min + " -> " + sent_max);
201 205
			result = tcorpus.query(query.getQueryString().replace("\n", " "), sent_min, sent_max + 1, -1);
202 206
		}
203
		
207

  
204 208
		return fromTIGERMatchToSelection(tcorpus, result, query, corpus);
205 209
	}
206
	
210

  
207 211
	public static Selection fromTIGERMatchToSelection(TSCorpus tcorpus, TSResult result, IQuery query, CorpusBuild corpus) throws IndexException {
208
		
212

  
209 213
		MatchResult mresult = result.getMatchResult();
210 214
		int size = mresult.size();
211 215
		// System.out.println("size: "+size);
......
213 217
		if (size == 0 || subsize == 0) {
214 218
			return new EmptySelection(query);
215 219
		}
216
		
220

  
217 221
		Index index = tcorpus.getIndex();
218
		
222

  
219 223
		// compute sentence positions
220 224
		// TODO move it to TSCorpus
221 225
		int[] starts = tcorpus.getSentenceStartPositions();
222
		
226

  
223 227
		LinkedHashSet<TIGERMatch> tigerMatchesList = new LinkedHashSet<>();
224
		
228

  
225 229
		List<String> variables = java.util.Arrays.asList(mresult.getVariableNames());
226 230
		// System.out.println("Variables: "+variables+" iPivot="+variables.indexOf("pivot"));
227 231
		int iPivot = variables.indexOf("pivot");
228
		
232

  
229 233
		MappedByteBuffer offsetsMapped = tcorpus.getOffsetsMapped();
230 234
		// MappedByteBuffer offsetsMapped = tcorpus.getOffsetsMapped();
231
		
235

  
232 236
		boolean useSubMatches = TigerSearchTreePreferences.getInstance().getBoolean(TigerSearchTreePreferences.USESUBMATCHES);
233
		
237

  
234 238
		// System.out.println("submatchSize: "+subsize);
235 239
		for (int isentMatch = 0; isentMatch < size; isentMatch++) { // the matching sentences
236 240
			int sent = mresult.getSentenceNumberAt(isentMatch);
237 241
			// Sentence sentence = tcorpus.manager.getSentence(sent);
238
			
242

  
239 243
			// System.out.println(" sent: "+sent);
240 244
			int sent_submatch = mresult.getSentenceSubmatchSize(sent);
241
			
245

  
242 246
			// System.out.println(" sent submatch size: "+sent_submatch);
243 247
			for (int iSubMatch = 0; iSubMatch < sent_submatch; iSubMatch++) { // the matches in the sentence
244 248
				int[] match = mresult.getSentenceSubmatchAt(sent, iSubMatch);
245
				
249

  
246 250
				int sent_start = starts[sent];
247
				
251

  
248 252
				// System.out.println(" sent="+sent_start+ " matches="+Arrays.toString(match)+" ipivot="+iPivot);
249 253
				for (int i = 0; i < match.length; i++) {
250
					
254

  
251 255
					if (iPivot != -1 && i != iPivot) continue; // skip match that are not 'pivot'
252
					
256

  
253 257
					int left = sent_start + index.getLeftCorner(sent, match[i]);
254 258
					if (offsetsMapped != null) { // the TIGER token is not in the CQP corpus
255 259
						left += offsetsMapped.getInt(left * Integer.BYTES);
......
260 264
						right += offsetsMapped.getInt(right * Integer.BYTES);
261 265
					}
262 266
					// System.out.println(" M="+match[i]+" ("+left+", "+right+")");
263
					
267

  
264 268
					TIGERMatch tigerMatch = new TIGERMatch(left, right);
265
					
269

  
266 270
					// System.out.println(" ajusted="+(tigerMatch));
267 271
					tigerMatchesList.add(tigerMatch);
268
					
272

  
269 273
					if (!useSubMatches) { // use only the first submatch
270 274
						break;
271 275
					}
272 276
				}
273 277
			}
274 278
		}
275
		
279

  
276 280
		// intersect with corpus matches
277 281
		List<? extends Match> result2 = Match.intersect(corpus.getMatches(), new ArrayList<>(tigerMatchesList), true);
278
		
282

  
279 283
		return new TIGERSelection(query, result2);
280 284
	}
281
	
285

  
282 286
	@Override
283 287
	public Query newQuery() {
284 288
		return new TIGERQuery();
285 289
	}
286
	
290

  
287 291
	@Override
288 292
	public boolean hasIndexes(CorpusBuild corpus) {
289 293
		if (corpus == null) return false;
290
		
294

  
291 295
		// TODO implement a corpora of TIGER corpus
292 296
		CorpusBuild root = corpus.getRootCorpusBuild();
293 297
		File buildDirectory = new File(root.getProjectDirectory(), "tiger");
294 298
		return new File(buildDirectory, "tigersearch.logprop").exists() &&
295 299
				new File(buildDirectory, root.getID()).exists();
296 300
	}
297
	
301

  
298 302
	@Override
299 303
	public void notify(TXMResult r, String state) {
300
//		if (r instanceof MainCorpus && "clean".equals(state)) { // the CQP corpus has been deleted by the user
301
//			MainCorpus c = (MainCorpus) r;
302
//			File buildDirectory = new File(c.getProjectDirectory(), "tiger/" + c.getID());
303
//			if (buildDirectory.exists()) {
304
//				DeleteDir.deleteDirectory(buildDirectory);
305
//			}
306
//		}
307
//		else
304
		//		if (r instanceof MainCorpus && "clean".equals(state)) { // the CQP corpus has been deleted by the user
305
		//			MainCorpus c = (MainCorpus) r;
306
		//			File buildDirectory = new File(c.getProjectDirectory(), "tiger/" + c.getID());
307
		//			if (buildDirectory.exists()) {
308
		//				DeleteDir.deleteDirectory(buildDirectory);
309
		//			}
310
		//		}
311
		//		else
308 312
		if (r instanceof Project && "clean".equals(state)) {  // the Project has been deleted by the user
309 313
			Project c = (Project) r;
310 314
			File buildDirectory = new File(c.getProjectDirectory(), "tiger");
......
313 317
			}
314 318
		}
315 319
	}
316
	
320

  
317 321
	@Override
318 322
	public String getValueForProperty(Match match, SearchEngineProperty property) {
319 323
		// TODO Auto-generated method stub
320 324
		return null;
321 325
	}
322
	
326

  
323 327
	@Override
324 328
	public List<String> getValuesForProperty(Match match, SearchEngineProperty property) {
325 329
		// TODO Auto-generated method stub
326 330
		return null;
327 331
	}
328
	
332

  
329 333
	/**
330 334
	 * 
331 335
	 * @param sourceDirectory must contain the main.xml file
......
335 339
	 * @throws UnsupportedEncodingException 
336 340
	 */
337 341
	public static boolean buildTIGERCorpus(File sourceDirectory, File binaryDirectory, String corpusName) throws UnsupportedEncodingException, FileNotFoundException {
338
		
342

  
339 343
		File tigerDir = new File(binaryDirectory, "tiger");
340 344
		tigerDir.mkdir();
341
		
345

  
342 346
		File logprop = new File(tigerDir, "tigersearch.logprop");
343
		
347

  
344 348
		PrintWriter writer = IOUtils.getWriter(logprop, "UTF-8");
345 349
		writer.println("# Default log configuration of the TIGERSearch suite"+"\n"+
346 350
				"log4j.rootLogger=SEVERE,Logfile"+"\n"+
......
351 355
				"log4j.appender.Logfile.MaxBackupIndex=1"+"\n"+
352 356
				"log4j.appender.Logfile.layout=org.apache.log4j.PatternLayout"+"\n"+
353 357
				"log4j.appender.Logfile.layout.ConversionPattern=%5r %-5p [%t] %c{2} - %m%n");
354
		
358

  
355 359
		BasicConfigurator.configure();
356
		
360

  
357 361
		String driverFilename = TigerSearchPreferences.getInstance().getString(TigerSearchPreferences.DRIVER_FILENAME);
358
		
362

  
359 363
		File master = new File(sourceDirectory, driverFilename);
360 364
		if (!master.exists()) {
361 365
			File[] xmlFiles = sourceDirectory.listFiles(new FileFilter() {
362
						public boolean accept(File file) {
363
							if (file.isDirectory()) return false;
364
							if (file.isHidden()) return false;
365
							String filename = file.getName();
366
							if (filename.equals("import.xml")) return false;
367
							if (!filename.endsWith(".xml")) return false;
368
							
369
							return true;
370
						}
371
					});
372
			
366
				public boolean accept(File file) {
367
					if (file.isDirectory()) return false;
368
					if (file.isHidden()) return false;
369
					String filename = file.getName();
370
					if (filename.equals("import.xml")) return false;
371
					if (!filename.endsWith(".xml")) return false;
372

  
373
					return true;
374
				}
375
			});
376

  
373 377
			if (xmlFiles == null) {
374 378
				System.out.println("No master file found in: "+sourceDirectory);
375 379
				return false;
......
381 385
		tigerBinDir.mkdir();
382 386
		try {
383 387
			IndexBuilderErrorHandler handler = new SimpleErrorHandler(tigerBinDir.getAbsolutePath()) {
384
						public void setMessage(String message) { }
385
						public void setNumberOfSentences(int number) { }
386
						public void setProgressBar(int value) { }
387
					};
388
				public void setMessage(String message) { }
389
				public void setNumberOfSentences(int number) { }
390
				public void setProgressBar(int value) { }
391
			};
388 392
			XMLIndexing indexing = new XMLIndexing(corpusName, uri, tigerBinDir.getAbsolutePath(), handler, false);
389 393
			indexing.startIndexing();
390 394
			File logs = new File(tigerBinDir, "indexing.log");
......
400 404
		}
401 405
		return true;
402 406
	}
403
	
404 407

  
408

  
405 409
	public static int writeOffsetDataFiles(MainCorpus corpus, String wordIdAttribute, File tigerCorpusDirectory, File tigerDirectory, File tigerCorpusExistingDirectory) throws IndexException, QueryIndexException, UnexpectedAnswerException, IOException, CqiServerError, CqiClientException {
406
		
410

  
407 411
		// TXM corpus files
408 412
		File configfile = new File(tigerDirectory, "tigersearch.logprop");
409
		
413

  
410 414
		TSCorpusManager manager = new TSCorpusManager(tigerCorpusDirectory.getParentFile(), configfile);
411 415
		TSCorpus tcorpus = manager.getCorpus(tigerCorpusDirectory.getName());
412 416
		InternalCorpusQueryManagerLocal2 tigermanager = tcorpus.manager;
413 417
		CorpusQueryProcessor processor = tigermanager.getQueryProcessor();
414 418
		AbstractCqiClient CQI = CQPSearchEngine.getCqiClient();
415
		
419

  
416 420
		Index index = processor.getIndex();
417 421
		int size = 0;
418 422
		for (int nr = 0; nr < index.getNumberOfGraphs(); nr++) {
419 423
			size += index.getNumberOfTNodes(nr);
420 424
		}
421
		
425

  
422 426
		if (size == 0) {
423 427
			Log.warning("No word found in the TIGERSearch corpus: " + tigerCorpusDirectory + ". Aborting.");
424 428
			return 0;
425 429
		}
426
		
430

  
427 431
		Log.info("Importing " + size + " word annotations...");
428
		
432

  
429 433
		// compute start position of sentences
430 434
		int[] starts = new int[index.getNumberOfGraphs()];
431 435
		for (int i = 0; i < index.getNumberOfGraphs(); i++) {
......
434 438
				starts[i] += index.getNumberOfTNodes(i - 1) + starts[i - 1];
435 439
			}
436 440
		}
437
		
441

  
438 442
		File offsetsFile = new File(tigerCorpusExistingDirectory, "offsets.data");
439 443
		RandomAccessFile offsetsRAFile = new RandomAccessFile(offsetsFile, "rw");
440 444
		FileChannel offsetsFileChannel = offsetsRAFile.getChannel();
441 445
		MappedByteBuffer offsetsMapped = offsetsFileChannel.map(FileChannel.MapMode.READ_WRITE, 0, size * Integer.BYTES);
442 446
		// out.putInt(positions[i])
443
		
447

  
444 448
		File presencesFile = new File(tigerCorpusExistingDirectory, "presences.data");
445 449
		RandomAccessFile presencesRAFile = new RandomAccessFile(presencesFile, "rw");
446 450
		FileChannel presencesFileChannel = presencesRAFile.getChannel();
447 451
		MappedByteBuffer presencesMapped = presencesFileChannel.map(FileChannel.MapMode.READ_WRITE, 0, size);
448
		
452

  
449 453
		int numberOfWordsAnnotated = 0;
450
		
454

  
451 455
		// for each sentence
452 456
		ConsoleProgressBar cpb = new ConsoleProgressBar(index.getNumberOfGraphs());
453 457
		for (int nr = 0; nr < index.getNumberOfGraphs(); nr++) {
454 458
			cpb.tick();
455 459
			int sent_size = index.getNumberOfTNodes(nr);
456 460
			Sentence sent = tcorpus.manager.getSentence(nr);
457
			
461

  
458 462
			String[] ids = new String[sent_size];
459 463
			int[] tigerPositions = new int[sent_size];
460 464
			for (int t = 0; t < sent_size; t++) {
461 465
				T_Node terminal = (T_Node) sent.getTerminalAt(t);
462 466
				ids[t] = terminal.getFeature(wordIdAttribute);
463
				
467

  
464 468
				// try fixing ID
465 469
				if (ids[t].startsWith("w")) {
466 470
					if (!ids[t].startsWith("w_")) {
......
473 477
				tigerPositions[t] = starts[nr] + t;
474 478
				// System.out.println("T id="+terminal.getID());
475 479
			}
476
			
480

  
477 481
			int[] ids_idx = CQI.str2Id(corpus.getProperty("id").getQualifiedName(), ids);
478 482
			Integer[] cqpPositions = new Integer[sent_size];
479 483
			Integer[] offsets = new Integer[sent_size];
......
489 493
					Log.warning("Could not find word for id=" + ids[t]);
490 494
					cqpPositions[t] = null;
491 495
				}
492
				
496

  
493 497
				if (cqpPositions[t] != null) {
494 498
					offsets[t] = cqpPositions[t] - tigerPositions[t];
495 499
				}
......
502 506
			// System.out.println("tiger positions="+Arrays.toString(tigerPositions));
503 507
			// System.out.println("cqp positions="+Arrays.toString(cqpPositions));
504 508
			// System.out.println("offsets="+Arrays.toString(offsets));
505
			
509

  
506 510
			// writing data to offset and presences files
507 511
			for (int t = 0; t < sent_size; t++) {
508
				
512

  
509 513
				if (offsets[t] != null) {
510 514
					numberOfWordsAnnotated++;
511 515
					presencesMapped.put((byte) 1);
......
518 522
			}
519 523
		}
520 524
		cpb.done();
521
		
525

  
522 526
		offsetsFileChannel.close();
523 527
		offsetsRAFile.close();
524 528
		presencesFileChannel.close();
525 529
		presencesRAFile.close();
526
		
530

  
527 531
		return numberOfWordsAnnotated;
528 532
	}
533

  
534
	public String hasAdditionalDetailsForResult(TXMResult result) {
535
		if (result instanceof CQPCorpus) {
536
			return hasIndexes((CQPCorpus)result)?"Syntax":null;
537
		}
538
		return null;
539
	}
540

  
541
	public String getAdditionalDetailsForResult(TXMResult result) {
542
		if (result instanceof CQPCorpus) {
543
			TSCorpus tscorpus = this.getTSCorpus((CQPCorpus)result);
544
			Index index = tscorpus.getIndex();
545
			Header header = tscorpus.getHeader();
546
			StringBuilder buffer = new StringBuilder();
547
			buffer.append("<h3>TIGERSearch informations</h3>\n");
548
			buffer.append("<h4>Commons</h4>\n");
549
			buffer.append("<p>Name: "+header.getCorpus_Name()+"</p>\n");
550
			buffer.append("<p>Id: "+header.getCorpus_ID()+"</p>\n");
551
			buffer.append("<p>Date: "+header.getCorpus_Date()+"</p>\n");
552
			buffer.append("<p>Format: "+header.getCorpus_Format()+"</p>\n");
553
			buffer.append("<p>History: "+header.getCorpus_History()+"</p>\n");
554
			buffer.append("<h4>Statiticss</h4>\n");
555
			buffer.append("<p>Edges: "+header.getNumberOfEdges()+"</p>\n");
556
			buffer.append("<p>Sentences: "+header.getNumberOfSentences()+"</p>\n");
557
			buffer.append("<p>NT Nodes: "+header.getNumberOfNTNodes()+"</p>\n");
558
			buffer.append("<p>T Nodes: "+header.getNumberOfTNodes()+"</p>\n");
559
			buffer.append("<h4>Terminals</h4>\n");
560
			//buffer.append("<p>"+header.getAllTerminalFeatures()+"</p>\n");
561
			buffer.append("<p>"+header.getAllTerminalFeaturesSize()+" "+StringUtils.join(header.getAllTFeatureNames(), ", ")+"</p>\n");
562
			if (header.getAllTFeatureNames().size() > 0) {
563
				buffer.append("<ul>\n");
564
				for (Object name : header.getAllTFeatureNames()) {
565
					Feature f = header.getTFeature(name.toString());
566
					buffer.append("<li>"+f.getName());
567
					List desc = f.getDescriptions();
568
					List vals = f.getItems();
569
					if (f.getItems().size() > 0) {
570
						buffer.append(":");
571
						for (int i = 0 ; i < vals.size() ; i++) {
572
							if (i > 0) buffer.append(",");
573
							buffer.append(" ("+vals.get(i)+": "+desc.get(i)+")");
574
						}
575
					} else { // not defined
576
						try {
577
							LinkedHashSet<String> values = new LinkedHashSet<String>();
578
							for (int p = 0 ; p < 20 ; p++) {
579
								values.add(index.getTFeatureValueAt(name.toString(), p));
580
							}
581
							if (values.size() > 0) {
582
								buffer.append(": "+StringUtils.join(values, ", "));
583
							}
584
						} catch (IndexException e) {
585
							// TODO Auto-generated catch block
586
							e.printStackTrace();
587
						}
588
					}
589
					buffer.append("</li>\n");
590
				}
591
				buffer.append("</ul>\n");
592
			}
593

  
594
			buffer.append("<h4>Non-Terminals</h4>\n");
595
			//buffer.append("<p>"+header.getAllNonterminalFeatures()+"</p>\n");
596
			buffer.append("<p>"+header.getAllNonterminalFeaturesSize()+" "+StringUtils.join(header.getAllNTFeatureNames(), ", ")+"</p>\n");
597
			if (header.getAllNTFeatureNames().size() > 0) {
598
				buffer.append("<ul>\n");
599
				for (Object name : header.getAllNTFeatureNames()) {
600
					Feature f = header.getNTFeature(name.toString());
601
					buffer.append("<li>"+f.getName());
602
					List desc = f.getDescriptions();
603
					List vals = f.getItems();
604
					if (f.getItems().size() > 0) {
605
						buffer.append(":");
606
						for (int i = 0 ; i < vals.size() ; i++) {
607
							if (i > 0) buffer.append(",");
608
							if (vals.get(i).equals(desc.get(i))) {
609
								buffer.append(" "+vals.get(i));
610
							} else {
611
								buffer.append(" "+vals.get(i)+" ("+desc.get(i)+")");
612
							}
613
						}
614
					}
615
					buffer.append("</li>\n");
616
				}
617
				buffer.append("</ul>\n");
618
			}
619

  
620
			return buffer.toString();
621
		}
622
		return null;
623
	}
529 624
}
TXM/trunk/bundles/org.txm.tigersearch.rcp/src/org/txm/function/tigersearch/TIGERSearch.java (revision 3708)
3 3
import java.io.File;
4 4
import java.io.IOException;
5 5
import java.nio.MappedByteBuffer;
6
import java.util.ArrayList;
7
import java.util.Arrays;
8 6
import java.util.List;
9 7

  
10 8
import org.apache.commons.lang.StringUtils;
......
17 15
import org.txm.searchengine.cqp.corpus.WordProperty;
18 16
import org.txm.searchengine.ts.TIGERQuery;
19 17
import org.txm.searchengine.ts.TIGERSearchEngine;
20
import org.txm.searchengine.ts.TIGERSelection;
21 18
import org.txm.searchengine.ts.TSCorpus;
22 19
import org.txm.searchengine.ts.TSCorpusManager;
23 20
import org.txm.searchengine.ts.TSMatch;
......
25 22
import org.txm.tigersearch.rcp.Messages;
26 23
import org.txm.treesearch.function.TreeSearch;
27 24
import org.txm.treesearch.function.TreeSearchSelector;
28
import org.txm.treesearch.preferences.TreeSearchPreferences;
29 25
import org.txm.utils.TXMProgressMonitor;
30 26
import org.txm.utils.logger.Log;
31 27

  
......
55 51
		
56 52
		this.corpus = getParent();
57 53
		
58
		String id = corpus.getRootCorpusBuild().getName();
54
		String id = corpus.getRootCorpusBuild().getID();
59 55
		
60 56
		File tsRegistryDirectory = new File(corpus.getProjectDirectory(), "tiger"); //$NON-NLS-1$
61 57
		File configfile = new File(tsRegistryDirectory, "tigersearch.logprop"); //$NON-NLS-1$
TXM/trunk/bundles/org.txm.tigersearch.rcp/src/org/txm/function/tigersearch/TIGERTreeSearchSelector.java (revision 3708)
4 4
import org.txm.searchengine.core.SearchEnginesManager;
5 5
import org.txm.searchengine.cqp.corpus.CQPCorpus;
6 6
import org.txm.searchengine.ts.TIGERQuery;
7
import org.txm.searchengine.ts.TIGERSearchEngine;
8 7
import org.txm.treesearch.function.TreeSearch;
9 8
import org.txm.treesearch.function.TreeSearchSelector;
10 9

  
11

  
12 10
public class TIGERTreeSearchSelector extends TreeSearchSelector {
13 11
	
14 12
	public static String TIGER = "TIGER"; //$NON-NLS-1$
TXM/trunk/bundles/org.txm.edition.rcp/src/org/txm/edition/rcp/preferences/SynopticEditionPreferencePage.java (revision 3708)
34 34
		addField(fast_highlight);
35 35
		
36 36
		String[][] values = {
37
				{"RATIO", "-2"}, 
37 38
				{"OVER", "-1"}, 
38 39
				{"ABOVE", ""+EModelService.ABOVE}, 
39 40
				{"BELOW", ""+EModelService.BELOW}, 
40 41
				{"LEFT_OF", ""+EModelService.LEFT_OF}, 
41 42
				{"RIGHT_OF", ""+EModelService.RIGHT_OF}};
42 43
		
43
		backtotext_position = new ComboFieldEditor(SynopticEditionPreferences.BACKTOTEXT_POSITION, "new editor position", values, getFieldEditorParent());
44
		backtotext_position = new ComboFieldEditor(SynopticEditionPreferences.BACKTOTEXT_POSITION, "Linked editor position", values, getFieldEditorParent());
44 45
		addField(backtotext_position);
45 46
	}
46 47
	
TXM/trunk/bundles/org.txm.edition.rcp/src/org/txm/edition/rcp/editors/RGBA.java (revision 3708)
1 1
package org.txm.edition.rcp.editors;
2 2

  
3
import java.awt.Color;
4

  
3 5
public class RGBA {
4 6
	public int r=0, g=0, b=0;
5 7
	public float a = 1f;
8
	
6 9
	public RGBA(int r, int g, int b) {
7 10
		this.r =r;this.g=g; this.b =b;
8 11
	}
9
	public RGBA(String rgb) {
10
		String[] split = rgb.split(","); //$NON-NLS-1$
11
		try{this.r =Integer.parseInt(split[0]);}catch(Exception e){}
12
		try{this.g =Integer.parseInt(split[1]);}catch(Exception e){}
13
		try{this.b =Integer.parseInt(split[2]);}catch(Exception e){}
12
	
13
	public RGBA(int r, int g, int b, float a) {
14
		this.r =r;this.g=g; this.b =b;this.a =a;
14 15
	}
16
	
17
	public RGBA(String rgbOrrgba) {
18
		if (rgbOrrgba.startsWith("#")) {
19
			
20
			Color c = HexToColor(rgbOrrgba);
21
			
22
			this.r = c.getRed();
23
			this.g = c.getGreen();
24
			this.b = c.getBlue();
25
			this.a = c.getAlpha();
26
		} else {
27
			String[] split = rgbOrrgba.split(","); //$NON-NLS-1$
28
			try{this.r =Integer.parseInt(split[0]);}catch(Exception e){}
29
			try{this.g =Integer.parseInt(split[1]);}catch(Exception e){}
30
			try{this.b =Integer.parseInt(split[2]);}catch(Exception e){}
31
			try{this.a =Float.parseFloat(split[3]);}catch(Exception e){}
32
		}
33
	}
34
	
15 35
	public RGBA(String rgb, float a) {
16 36
		String[] split = rgb.split(","); //$NON-NLS-1$
17 37
		try{this.r =Integer.parseInt(split[0]);}catch(Exception e){}
......
19 39
		try{this.b =Integer.parseInt(split[2]);}catch(Exception e){}
20 40
		this.a = a;
21 41
	}
22
	public RGBA(int r, int g, int b, float a) {
23
		this.r =r;this.g=g; this.b =b;this.a =a;
42
	
43
	/**
44
	 * Converts a hex string to a color. If it can't be converted null is returned.
45
	 * @param hex (i.e. #CCCCCCFF or CCCCCC)
46
	 * @return Color
47
	 */
48
	public static Color HexToColor(String hex) 
49
	{
50
	    hex = hex.replace("#", "");
51
	    switch (hex.length()) {
52
	        case 6:
53
	            return new Color(
54
	            Integer.valueOf(hex.substring(0, 2), 16),
55
	            Integer.valueOf(hex.substring(2, 4), 16),
56
	            Integer.valueOf(hex.substring(4, 6), 16));
57
	        case 8:
58
	            return new Color(
59
	            Integer.valueOf(hex.substring(0, 2), 16),
60
	            Integer.valueOf(hex.substring(2, 4), 16),
61
	            Integer.valueOf(hex.substring(4, 6), 16),
62
	            Integer.valueOf(hex.substring(6, 8), 16));
63
	    }
64
	    return null;
24 65
	}
25

  
26
	public String toString() {return "{"+r+", "+g+","+b+", "+a+"}";} //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
66
	
67
	public String toString() {return ""+r+","+g+","+b+","+a+"f";} //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
27 68
}
TXM/trunk/bundles/org.txm.edition.rcp/src/org/txm/edition/rcp/editors/SynopticEditionEditor.java (revision 3708)
514 514
				// public void widgetDefaultSelected(SelectionEvent e) { }
515 515
				// });
516 516
				if (!text_text.isDisposed()) {
517
					Cursor cursor = new Cursor(text_text.getDisplay(), SWT.CURSOR_SIZENS);
517
					Cursor cursor = text_text.getDisplay().getSystemCursor(SWT.CURSOR_SIZENS);
518 518
					text_text.setCursor(cursor);
519 519
				}
520 520
			}
TXM/trunk/bundles/org.txm.edition.rcp/src/org/txm/edition/rcp/handlers/BackToText.java (revision 3708)
37 37
import org.apache.commons.lang.StringUtils;
38 38
import org.eclipse.core.commands.ExecutionEvent;
39 39
import org.eclipse.core.commands.ExecutionException;
40
import org.eclipse.e4.ui.workbench.modeling.EModelService;
40 41
import org.eclipse.osgi.util.NLS;
42
import org.eclipse.swt.graphics.Point;
41 43
import org.eclipse.ui.IEditorPart;
42 44
import org.eclipse.ui.IWorkbenchPage;
43 45
import org.eclipse.ui.IWorkbenchWindow;
......
287 289
				editor.addLinkedEditor(attachedBrowserEditor);
288 290
				
289 291
				int position = SynopticEditionPreferences.getInstance().getInt(SynopticEditionPreferences.BACKTOTEXT_POSITION);
292
				if (position == -2) {
293
					Point s = editor.getParent().getSize();
294
					if (s.x < s.y) {
295
						position = EModelService.ABOVE;
296
					} else {
297
						position = EModelService.RIGHT_OF;
298
					}
299
				}
290 300
				if (editor != null && position >= 0) {
291 301
					SWTEditorsUtils.addEditor(editor, attachedBrowserEditor, position);
292 302
				}

Formats disponibles : Unified diff