Revision 1924

tmp/org.txm.annotation.kr.core/src/org/txm/annotation/kr/core/storage/temporary/TemporaryAnnotationManager.java (revision 1924)
312 312
		int i = 0;
313 313

  
314 314
		for (Match match : matches) {
315
			int start,end;
316
			if (match.getTarget() >= 0) {
317
				start = end = match.getTarget();
318
			} else {
319
				start = match.getStart();
320
				end = match.getEnd();
321
			}
322
				
315 323
			if (i==0) {
316 324
				if (overlap) {
317
					queryPos+= " ( ("+overlapString(match.getStart(), match.getEnd(), 0)+")" 
318
							+ " OR ("+overlapString(match.getStart(), match.getEnd(), 1)+") ";
325
					queryPos+= " ( ("+overlapString(start, end, 0)+")" 
326
							+ " OR ("+overlapString(start, end, 1)+") ";
319 327
					//String overlapBesides = "annot.PK.endpos < "+match.getStart()+" OR annot.PK.startpos > "+match.getEnd()+"";
320 328
					//queryPos += " AND NOT ( "+overlapBesides+" ) ) ";
321
					queryPos += " OR ( annot.PK.startpos <= "+match.getStart()+ " AND "+match.getEnd()+" <= annot.PK.endpos ) )";
329
					queryPos += " OR ( annot.PK.startpos <= "+start+ " AND "+end+" <= annot.PK.endpos ) )";
322 330
				} else {
323
					queryPos+= " (annot.PK.startpos = "+match.getStart()+" AND annot.PK.endpos = "+match.getEnd()+")";
331
					queryPos+= " (annot.PK.startpos = "+start+" AND annot.PK.endpos = "+end+")";
324 332
				}
325 333
			} else {
326 334
				if (overlap) {
327
					queryPos+= " OR ( ("+overlapString(match.getStart(), match.getEnd(), 0)+")" 
328
							+ " OR ("+overlapString(match.getStart(), match.getEnd(), 1)+") ";
335
					queryPos+= " OR ( ("+overlapString(start, end, 0)+")" 
336
							+ " OR ("+overlapString(start, end, 1)+") ";
329 337
					//String overlapBesides = "annot.PK.endpos < "+match.getStart()+" OR annot.PK.startpos > "+match.getEnd()+"";
330 338
					//queryPos += " AND NOT ( "+overlapBesides+" ) ) ";
331
					queryPos += " OR ( annot.PK.startpos <= "+match.getStart()+ " AND "+match.getEnd()+" <= annot.PK.endpos ) )";
339
					queryPos += " OR ( annot.PK.startpos <= "+start+ " AND "+end+" <= annot.PK.endpos ) )";
332 340
				} else {
333
					queryPos+= " OR (annot.PK.startpos = "+match.getStart()+" AND annot.PK.endpos = "+match.getEnd()+")";
341
					queryPos+= " OR (annot.PK.startpos = "+start+" AND annot.PK.endpos = "+end+")";
334 342
				}
335 343
			}
336 344
			++i;
......
376 384
		int nMatch = matches.size();
377 385
		int nAnnotations = annotations.size();
378 386

  
387
		Match match = null;
388
		Annotation annotation = null;
379 389
		while (iMatch < nMatch && iAnnotation < nAnnotations) {
390
			match = matches.get(iMatch);
391
			int start,end;
392
			if (match.getTarget() >= 0) {
393
				start = end = match.getTarget();
394
			} else {
395
				start = match.getStart();
396
				end = match.getEnd();
397
			}
398
			
399
			annotation = annotations.get(iAnnotation);
400
			int astart = annotation.getStart(), aend = annotation.getEnd();
401
			
380 402
			if (overlap) {
381
				if (matches.get(iMatch).getEnd() < annotations.get(iAnnotation).getStart()) {
403
				if (end < astart) {
382 404
					iMatch++;
383 405
					annotsList.add(null); // nothing for this match
384
				} else if (annotations.get(iAnnotation).getEnd() < matches.get(iMatch).getStart()) {
406
				} else if (aend < start) {
385 407
					iAnnotation++;
386 408
				} else {
387
					annotsList.add(annotations.get(iAnnotation));
409
					annotsList.add(annotation);
388 410
					iMatch++;
389 411
				}
390 412
			} else {
391
				if (matches.get(iMatch).getEnd() < annotations.get(iAnnotation).getStart()) {
413
				if (end < astart) {
392 414
					iMatch++;
393 415
					annotsList.add(null); // nothing for this match
394
				} else if (annotations.get(iAnnotation).getEnd() < matches.get(iMatch).getStart()) {
416
				} else if (aend < start) {
395 417
					iAnnotation++;
396
				} else if (annotations.get(iAnnotation).getStart() == matches.get(iMatch).getStart() && 
397
						annotations.get(iAnnotation).getEnd() == matches.get(iMatch).getEnd()) {
398
					annotsList.add(annotations.get(iAnnotation));
418
				} else if (astart == start && 
419
						aend == end) {
420
					annotsList.add(annotation);
399 421
					iMatch++;
400 422
					iAnnotation++;
401 423
				} else {
tmp/org.txm.annotation.kr.core/src/org/txm/annotation/kr/core/AnnotationManager.java (revision 1924)
128 128
	public boolean deleteAnnotations(AnnotationType type, List<Match> matches, IProgressMonitor job) throws Exception {
129 129
		try {
130 130
			tempManager.getEntityManager().getTransaction().begin();
131
			for (Match m : matches) {
131
			for (Match match : matches) {
132
				
133
				int start, end;
134
				if (match.getTarget() >= 0) {
135
					start = end = match.getTarget();
136
				} else {
137
					start = match.getStart();
138
					end = match.getEnd();
139
					if (type.getEffect().equals(AnnotationEffect.TOKEN)) {
140
						end = start;
141
					}
142
				}
143
				
132 144
				if (job != null && job.isCanceled()) {
133 145
					System.out.println("Delete annotation canceled.");
134 146
					return false;
135 147
				}
136 148
				
137
				String value = cqpManager.getCQPAnnotationValue(m.getStart(), m.getEnd(), type);
149
				String value = cqpManager.getCQPAnnotationValue(start, end, type);
138 150

  
139 151
				if (value != null) {
140
					tempManager.createAnnotationNoCommit(type, new TypedValue("#del", "#del", type.getId()),  m.getStart(), m.getEnd());
152
					tempManager.createAnnotationNoCommit(type, new TypedValue("#del", "#del", type.getId()),  start, end);
141 153
				} else {
142
					tempManager.deleteAnnotationNoCommit(type, m.getStart(), m.getEnd());
154
					tempManager.deleteAnnotationNoCommit(type, start, end);
143 155
				}
144 156
			}
145 157
			dirty = true;
......
228 240
		for (Match match : matches) {
229 241
			allAnnotationsThatCollides.put(match, new ArrayList<Annotation>());
230 242
			
243
			int start, end;
244
			if (match.getTarget() >= 0) {
245
				start = end = match.getTarget();
246
			} else {
247
				start = match.getStart();
248
				end = match.getEnd();
249
			}
250
			
231 251
			if (job != null && job.isCanceled()) { // check if user canceled the job
232 252
				System.out.println("Affect annotation canceled.");
233 253
				return null;
......
242 262
						Annotation a = cqpAnnotations.get(i);
243 263

  
244 264
						// exact match + exact type
245
						if (a.getType().equals(annotSelectedType.getId()) && a.getStart() == match.getStart() && a.getEnd() == match.getEnd()) {
265
						if (a.getType().equals(annotSelectedType.getId()) && a.getStart() == start && a.getEnd() == end) {
246 266
							cqpAnnotations.remove(i);
247 267
							i--;
248 268
						} else if (!a.getType().equals(annotSelectedType.getId()) && (// different type and inner or outer wrap
249
								(a.getStart() <= match.getStart() && match.getEnd() <= a.getEnd()) ||
250
								(match.getStart() <= a.getStart() && a.getEnd() <= match.getEnd())
269
								(a.getStart() <= start && end <= a.getEnd()) ||
270
								(start <= a.getStart() && a.getEnd() <= end)
251 271
								)) {
252 272
							cqpAnnotations.remove(i);
253 273
							i--;
......
263 283
					continue; // don't create annotation, process next match
264 284
				} else { // test with temporary annotation manager 
265 285
					List<Annotation> tempAnnotations = null;
266
					if (match.getTarget() >= 0) { // the @ operator has been used, annotate only the @position
267
						tempAnnotations = tempManager.createAnnotationNoCommit(annotSelectedType, annotSelectedTypedValue, match.getTarget(), match.getTarget());
268
					} else {
269 286
						if (annotSelectedType.getEffect() == AnnotationEffect.TOKEN) { // only annotate the first word
270
							tempAnnotations = tempManager.createAnnotationNoCommit(annotSelectedType, annotSelectedTypedValue, match.getStart(), match.getStart());
287
							tempAnnotations = tempManager.createAnnotationNoCommit(annotSelectedType, annotSelectedTypedValue, start, start);
271 288
						} else {
272
							tempAnnotations = tempManager.createAnnotationNoCommit(annotSelectedType, annotSelectedTypedValue, match.getStart(), match.getEnd());
289
							tempAnnotations = tempManager.createAnnotationNoCommit(annotSelectedType, annotSelectedTypedValue, start, end);
273 290
						}
274
					}
275 291
					if (tempAnnotations.size() > 0)
276 292
						allAnnotationsThatCollides.get(match).addAll(tempAnnotations);
277 293
				}
tmp/org.txm.annotation.kr.core/src/org/txm/annotation/kr/core/CQPAnnotationManager.java (revision 1924)
204 204
		
205 205
		int positions[] = new int[matches.size()];
206 206
		int i = 0;
207
		for (Match m : matches) positions[i++] = m.getStart();
207
		for (Match m : matches) {
208
			if (m.getTarget() >= 0) {
209
				positions[i++] = m.getTarget();
210
			} else {
211
				positions[i++] = m.getStart();
212
			}
213
		}
208 214
		
209 215
		String[] strs = cqi.cpos2Str(prop.getQualifiedName(), positions);
210 216
		
......
252 258
		if (overlap) {
253 259
			for (iMatch = 0 ; iStruct < Nstruct && iMatch < Nmatches; ) {
254 260
				Match m = matches.get(iMatch);
255

  
256
				if(smatch[1] < m.getStart()) { // next struct
261
				int start,end;
262
				if (m.getTarget() >= 0) {
263
					start = end = m.getTarget();
264
				} else {
265
					start = m.getStart();
266
					end = m.getEnd();
267
				}
268
				if(smatch[1] < start) { // next struct
257 269
					iStruct++;
258 270
					if (iStruct < Nstruct)
259 271
						smatch = CQPSearchEngine.getCqiClient().struc2Cpos(sup.getQualifiedName(), iStruct);
260 272
					//System.out.println(" NEXT STRUCT TEST WITH "+smatch[0]+"-"+smatch[1]);
261
				} else if (m.getEnd() < smatch[0]) { // next match
273
				} else if (end < smatch[0]) { // next match
262 274
					values.add(null);
263 275
					annotationsStartEnd.add(null);
264 276
					iMatch++;
......
276 288
		} else { // strict matches
277 289
			for (iMatch = 0 ; iStruct < Nstruct && iMatch < Nmatches; ) {
278 290
				Match m = matches.get(iMatch);
279
				if (smatch[0] == m.getStart() && smatch[1] == m.getEnd()) {
291
				int start,end;
292
				if (m.getTarget() >= 0) {
293
					start = end = m.getTarget();
294
				} else {
295
					start = m.getStart();
296
					end = m.getEnd();
297
				}
298
				
299
				if (smatch[0] == start && smatch[1] == end) {
280 300
					values.add(iStruct);
281 301
					annotationsStartEnd.add(smatch);
282 302
					iMatch++;
283 303
					iStruct++;
284 304
					if (iStruct < Nstruct)
285 305
						smatch = CQPSearchEngine.getCqiClient().struc2Cpos(sup.getQualifiedName(), iStruct);
286
				} else if(smatch[1] < m.getStart()) { // next struct
306
				} else if(smatch[1] < start) { // next struct
287 307
					iStruct++;
288 308
					if (iStruct < Nstruct)
289 309
						smatch = CQPSearchEngine.getCqiClient().struc2Cpos(sup.getQualifiedName(), iStruct);
290
				} else if (m.getEnd() < smatch[0]) { // next match
310
				} else if (end < smatch[0]) { // next match
291 311
					values.add(null);
292 312
					annotationsStartEnd.add(null);
293 313
					iMatch++;
tmp/org.txm.annotation.kr.rcp/src/org/txm/annotation/kr/rcp/concordance/WordAnnotationToolbar.java (revision 1924)
110 110
	protected Label equalLabel;
111 111
	protected Text annotationValuesText;
112 112
	protected Button affectAnnotationButton;
113
	protected Button deleteAnnotationButton;
113 114
	private Button affectAllAnnotationButton;
114 115

  
115 116
	protected KnowledgeRepository currentKnowledgeRepository = null;
......
147 148
		if (getSelectedAnnotationType() != null) {
148 149
			annotationValuesText.setEnabled(true);
149 150
			affectAnnotationButton.setEnabled(true);
151
			deleteAnnotationButton.setEnabled(true);
150 152
		} else {
151 153
			annotationValuesText.setEnabled(false);
152 154
			affectAnnotationButton.setEnabled(false);
155
			deleteAnnotationButton.setEnabled(false);
153 156
		}
154 157
	}
155 158

  
......
266 269
			}
267 270
		});
268 271
	}
272
	
273
	protected void deleteAnnotationValues(ISelection selection) {
269 274

  
275
		final IStructuredSelection lineSelection = (IStructuredSelection) selection;
276
		List<Line> lines = lineSelection.toList();
277
		ArrayList<Match> matches = new ArrayList<Match>();
278
		for (Line l : lines) {
279
			matches.add(l.getMatch());
280
		}
281

  
282
		deleteAnnotationValues(matches);
283
	}
284
	
285
	protected void deleteAnnotationValues(final List<Match> matches) {
286
		final AnnotationType type = getSelectedAnnotationType();
287

  
288
		JobHandler job = new JobHandler(KRAnnotationUIMessages.annotatingConcordanceSelection, true) {
289
			@Override
290
			protected IStatus run(IProgressMonitor monitor) {
291
				this.runInit(monitor);
292
				try {
293
					deleteAnnotationValues(matches, type, this);
294
				} catch(Exception e) {
295
					Log.severe(NLS.bind(KRAnnotationUIMessages.errorWhileAnnotatingConcordanceSelectionColonP0, e));
296
					Log.printStackTrace(e);
297
					return Status.CANCEL_STATUS;
298
				} catch(ThreadDeath td) {
299
					System.out.println(KRAnnotationUIMessages.annotationCanceledByUser);
300
					return Status.CANCEL_STATUS;
301
				}
302

  
303
				return Status.OK_STATUS;
304
			}
305
		};
306
		job.startJob(true);
307
	}
308

  
270 309
	protected void deleteAnnotationValues(List<Match> matches, AnnotationType type, JobHandler job) {
271 310

  
272 311
		if (matches.size() == 0) {
......
544 583
			@Override
545 584
			public void widgetDefaultSelected(SelectionEvent e) { }
546 585
		});
586
		
587
		deleteAnnotationButton = new Button(annotationArea, SWT.PUSH);
588
		deleteAnnotationButton.setText(KRAnnotationUIMessages.delete);
589
		deleteAnnotationButton.setToolTipText(KRAnnotationUIMessages.delete);
590
		deleteAnnotationButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
591
		deleteAnnotationButton.addSelectionListener(new SelectionListener() {
592
			@Override
593
			public void widgetSelected(SelectionEvent e) {
594
				affectAnnotationToSelection(editor.getLineTableViewer().getSelection());
595
			}
547 596

  
597
			@Override
598
			public void widgetDefaultSelected(SelectionEvent e) { }
599
		});
600

  
548 601
		affectAllAnnotationButton = new Button(annotationArea, SWT.PUSH);
549 602
		affectAllAnnotationButton.setText(KRAnnotationUIMessages.all);
550 603
		affectAllAnnotationButton.setToolTipText(KRAnnotationUIMessages.proceedToAnnotation);

Also available in: Unified diff