Révision 2488

tmp/org.txm.progression.core/src/org/txm/progression/core/functions/Progression.java (revision 2488)
64 64

  
65 65
/**
66 66
 * Progression similar to the progression of Weblex software.
67
 *  
67
 * 
68 68
 * @author mdecorde
69 69
 * @author sjacquot
70 70
 */
71
public class Progression extends ChartResult	{
72

  
73

  
71
public class Progression extends ChartResult {
72
	
73
	
74 74
	/** The norep. */
75 75
	public static int norep = 1;
76

  
76
	
77 77
	/** The prefix r. */
78 78
	public static String prefixR = "Progression"; //$NON-NLS-1$
79

  
79
	
80 80
	public static final String DENSITY_CHART_TYPE = "density"; //$NON-NLS-1$
81

  
81
	
82 82
	/** The Xmin corpus. */
83 83
	protected int XminCorpus;
84

  
84
	
85 85
	/** The Xmax corpus. */
86 86
	protected int XmaxCorpus;
87

  
87
	
88 88
	/** The writer. */
89 89
	private BufferedWriter writer;
90

  
90
	
91 91
	/** List of token position in the text. */
92 92
	protected List<int[]> allPositions;
93

  
93
	
94 94
	/** The structurepositions. */
95 95
	protected int[] structurePositions;
96

  
96
	
97 97
	/** The structurenames. */
98 98
	protected String[] structureNames;
99

  
99
	
100 100
	/** graph boundaries. */
101 101
	protected int maxY;
102

  
102
	
103 103
	/** The max x. */
104 104
	protected int maxX;
105

  
106

  
105
	
106
	
107 107
	/** The bande. */
108 108
	protected float bande = 0.0f;
109

  
109
	
110 110
	/**
111 111
	 * set this to skip the QueryResult build step
112 112
	 */
113 113
	protected List<QueryResult> queryResults;
114

  
115

  
114
	
115
	
116 116
	/**
117 117
	 * Queries.
118 118
	 */
119
	@Parameter(key=TXMPreferences.QUERIES)
119
	@Parameter(key = TXMPreferences.QUERIES)
120 120
	protected List<CQLQuery> queries;
121

  
121
	
122 122
	/**
123 123
	 * Structural unit.
124 124
	 */
125
	@Parameter(key=TXMPreferences.STRUCTURAL_UNIT, type=Parameter.RENDERING)
125
	@Parameter(key = TXMPreferences.STRUCTURAL_UNIT, type = Parameter.RENDERING)
126 126
	protected StructuralUnit structuralUnit;
127

  
127
	
128 128
	/**
129 129
	 * Structural unit property.
130 130
	 */
131
	@Parameter(key=TXMPreferences.STRUCTURAL_UNIT_PROPERTY, type=Parameter.RENDERING)
131
	@Parameter(key = TXMPreferences.STRUCTURAL_UNIT_PROPERTY, type = Parameter.RENDERING)
132 132
	protected StructuralUnitProperty structuralUnitProperty;
133

  
133
	
134 134
	/**
135 135
	 * Repeats or not the same value when displaying the section markers.
136 136
	 */
137
	@Parameter(key=ProgressionPreferences.REPEAT_SAME_VALUES, type=Parameter.RENDERING)
137
	@Parameter(key = ProgressionPreferences.REPEAT_SAME_VALUES, type = Parameter.RENDERING)
138 138
	protected boolean repeatValues;
139

  
139
	
140 140
	/**
141 141
	 * Only used in Density mode.
142 142
	 */
143
	@Parameter(key=ProgressionPreferences.BANDE_MULTIPLIER)
143
	@Parameter(key = ProgressionPreferences.BANDE_MULTIPLIER)
144 144
	protected float bandeMultiplier;
145

  
145
	
146 146
	/**
147 147
	 * Regex to display only the property that match it.
148 148
	 */
149
	@Parameter(key=ProgressionPreferences.PROPERTY_REGEX, type=Parameter.RENDERING)
149
	@Parameter(key = ProgressionPreferences.PROPERTY_REGEX, type = Parameter.RENDERING)
150 150
	protected String propertyRegex;
151

  
152

  
151
	
152
	
153 153
	/**
154 154
	 * Creates a not computed progression
155
	 * 
155 156
	 * @param parent
156 157
	 */
157
	public Progression(CQPCorpus parent)	{
158
	public Progression(CQPCorpus parent) {
158 159
		this(null, parent);
159 160
	}
160

  
161
	
161 162
	/**
162 163
	 * Creates a not computed progression
164
	 * 
163 165
	 * @param parametersNodePath
164 166
	 */
165
	public Progression(String parametersNodePath)	{
167
	public Progression(String parametersNodePath) {
166 168
		super(parametersNodePath, null);
167 169
	}
168

  
170
	
169 171
	/**
170 172
	 * Creates a not computed progression.
173
	 * 
171 174
	 * @param parametersNodePath
172 175
	 * @param parent
173 176
	 */
......
176 179
		
177 180
		this.domainGridLinesVisible = false;
178 181
	}
179

  
180 182
	
181

  
183
	
184
	
182 185
	@Override
183 186
	public boolean loadParameters() {
184
		if(!this.getStringParameterValue(TXMPreferences.QUERIES).isEmpty())	{
187
		if (!this.getStringParameterValue(TXMPreferences.QUERIES).isEmpty()) {
185 188
			this.queries = CQLQuery.stringToQueries(this.getStringParameterValue(TXMPreferences.QUERIES));
186 189
		}
187

  
188
		if(!this.getStringParameterValue(TXMPreferences.STRUCTURAL_UNIT).isEmpty())	{
190
		
191
		if (!this.getStringParameterValue(TXMPreferences.STRUCTURAL_UNIT).isEmpty()) {
189 192
			try {
190 193
				this.structuralUnit = this.getCorpus().getStructuralUnit(this.getStringParameterValue(TXMPreferences.STRUCTURAL_UNIT));
191
				if(!this.getStringParameterValue(TXMPreferences.STRUCTURAL_UNIT_PROPERTY).isEmpty())	{
194
				if (!this.getStringParameterValue(TXMPreferences.STRUCTURAL_UNIT_PROPERTY).isEmpty()) {
192 195
					this.structuralUnitProperty = this.structuralUnit.getProperty(this.getStringParameterValue(TXMPreferences.STRUCTURAL_UNIT_PROPERTY));
193 196
				}
194 197
			}
......
197 200
				e.printStackTrace();
198 201
			}
199 202
		}
200

  
201

  
203
		
204
		
202 205
		// generate the chart type according to cumulative boolean preference
203
		if(!this.getBooleanParameterValue(ProgressionPreferences.CHART_CUMULATIVE))	{
206
		if (!this.getBooleanParameterValue(ProgressionPreferences.CHART_CUMULATIVE)) {
204 207
			this.chartType = Progression.DENSITY_CHART_TYPE;
205 208
		}
206

  
209
		
207 210
		return true;
208 211
	}
209

  
210

  
212
	
213
	
211 214
	@Override
212 215
	public boolean saveParameters() {
213

  
214
		if(this.queries != null && !this.queries.isEmpty())	{
216
		
217
		if (this.queries != null && !this.queries.isEmpty()) {
215 218
			this.saveParameter(TXMPreferences.QUERIES, CQLQuery.queriesToString(this.queries));
216 219
		}
217

  
218
		if(this.structuralUnit != null)	{
220
		
221
		if (this.structuralUnit != null) {
219 222
			this.saveParameter(TXMPreferences.STRUCTURAL_UNIT, this.structuralUnit.getName());
220 223
		}
221

  
222
		if(this.structuralUnitProperty != null)	{
224
		
225
		if (this.structuralUnitProperty != null) {
223 226
			this.saveParameter(TXMPreferences.STRUCTURAL_UNIT_PROPERTY, this.structuralUnitProperty.getName());
224 227
		}
225

  
228
		
226 229
		return true;
227 230
	}
228

  
231
	
229 232
	@Override
230 233
	public boolean canCompute() {
231

  
234
		
232 235
		// null or empty queries
233
		if (this.queries == null || this.queries.isEmpty())	{
236
		if (this.queries == null || this.queries.isEmpty()) {
234 237
			Log.fine("Progression.canCompute(): can not compute with no query."); //$NON-NLS-1$
235 238
			return false;
236 239
		}
237

  
240
		
238 241
		// wrong REGEX
239
		if (!this.propertyRegex.isEmpty())	{
242
		if (!this.propertyRegex.isEmpty()) {
240 243
			try {
241 244
				Pattern.compile(this.propertyRegex);
242 245
			}
......
246 249
				return false;
247 250
			}
248 251
		}
249

  
252
		
250 253
		return true;
251 254
	}
252

  
255
	
253 256
	@Override
254 257
	public boolean setParameters(TXMParameters parameters) {
255 258
		// TODO Auto-generated method stub
256 259
		System.err.println("Progression.setParameters(): not yet implemented."); //$NON-NLS-1$
257 260
		return true;
258 261
	}
259

  
260

  
261

  
262
	
263
	
264
	
262 265
	/**
263 266
	 * Sets the structural unit.
267
	 * 
264 268
	 * @param structuralUnit
265 269
	 */
266
	public void setStructuralUnit(StructuralUnit structuralUnit)	{
270
	public void setStructuralUnit(StructuralUnit structuralUnit) {
267 271
		this.structuralUnit = structuralUnit;
268 272
		this.setStructuralUnitProperty(null);
269 273
	}
270

  
274
	
271 275
	/**
272 276
	 * Sets the structural unit property.
277
	 * 
273 278
	 * @param structuralUnitProperty
274 279
	 */
275
	public void setStructuralUnitProperty(StructuralUnitProperty structuralUnitProperty)	{
280
	public void setStructuralUnitProperty(StructuralUnitProperty structuralUnitProperty) {
276 281
		this.structuralUnitProperty = structuralUnitProperty;
277 282
	}
278 283
	
279 284
	public void setQueryResults(List<QueryResult> queryResults) {
280 285
		this.queryResults = queryResults;
281 286
	}
282

  
287
	
283 288
	/**
284 289
	 * 
285 290
	 * @param queries
......
292 297
	 * @param bandeMultiplier
293 298
	 */
294 299
	// FIXME : SJ: all parameters related to rendering should be removed from this class and centralized in the charts engine system, eg. line width
295
	public void setParameters(List<CQLQuery> queries, 
296
			StructuralUnit structuralUnit, StructuralUnitProperty property, String propertyregex, 
297
			boolean doCumulative, int lineWidth, boolean repeatValues, float bandeMultiplier)	{
300
	public void setParameters(List<CQLQuery> queries,
301
			StructuralUnit structuralUnit, StructuralUnitProperty property, String propertyregex,
302
			boolean doCumulative, int lineWidth, boolean repeatValues, float bandeMultiplier) {
298 303
		this.queries = queries; // the query of the selection
299 304
		this.structuralUnit = structuralUnit;
300 305
		this.structuralUnitProperty = property;
301 306
		this.propertyRegex = propertyregex;
302 307
		this.repeatValues = repeatValues;
303 308
		this.bandeMultiplier = bandeMultiplier;
304

  
305
		for (int i = 0 ; i < DefaultTheme.monoWidths.length ; i++) {
309
		
310
		for (int i = 0; i < DefaultTheme.monoWidths.length; i++) {
306 311
			DefaultTheme.monoWidths[i] = lineWidth;
307 312
		}
308 313
	}
309

  
314
	
310 315
	/**
311 316
	 * Computes.
312 317
	 *
313 318
	 * @return true, if successful
314 319
	 * @throws CqiClientException the cqi client exception
315
	 * @throws CqiServerError 
316
	 * @throws IOException 
320
	 * @throws CqiServerError
321
	 * @throws IOException
317 322
	 */
323
	@Override
318 324
	protected boolean __compute() throws Exception {
319

  
325
		
320 326
		// Queries
321
		if(this.hasParameterChanged(ProgressionPreferences.QUERIES))	{
322
			this.allPositions = new ArrayList<int[]>();
327
		if (this.hasParameterChanged(ProgressionPreferences.QUERIES)) {
328
			this.allPositions = new ArrayList<>();
323 329
			this.structurePositions = new int[0];
324 330
			this.structureNames = new String[0];
325

  
331
			
326 332
			this.subTask("Processing queries...");
327 333
			if (!this.stepQueries()) {
328 334
				return true;
329 335
			}
330

  
331
			if (this.isCanceled())	{
336
			
337
			if (this.isCanceled()) {
332 338
				return false;
333 339
			}
334 340
			this.worked(10);
335 341
		}
336

  
342
		
337 343
		// Structural units
338 344
		this.subTask("Processing structural units...");
339
		if (!this.stepStructuralUnits())	{
345
		if (!this.stepStructuralUnits()) {
340 346
			return false;
341 347
		}
342 348
		this.worked(20);
343

  
344

  
349
		
350
		
345 351
		// Finalization steps
346
		if(this.hasParameterChanged(ProgressionPreferences.QUERIES))	{
352
		if (this.hasParameterChanged(ProgressionPreferences.QUERIES)) {
347 353
			this.subTask("Finalizing...");
348
			if (!stepFinalize())	{
354
			if (!stepFinalize()) {
349 355
				return false;
350 356
			}
351 357
			this.worked(20);
352 358
		}
353

  
359
		
354 360
		return true;
355 361
	}
356

  
362
	
357 363
	/**
358 364
	 * Test discontinuity of a corpus. If the corpus is a subcorpus then test if the start-end of matches make no hole
365
	 * 
359 366
	 * @param corpus
360 367
	 * @return
361 368
	 */
......
370 377
					previousMatch = m;
371 378
					continue;
372 379
				}
373

  
374
				if (m.getStart() == previousMatch.getEnd()+1) {
380
				
381
				if (m.getStart() == previousMatch.getEnd() + 1) {
375 382
					previousMatch = m;
376 383
					continue;
377 384
				}
......
382 389
		}
383 390
		return true;
384 391
	}
385

  
392
	
386 393
	/**
387 394
	 * compute using already resolved QueryResults
395
	 * 
388 396
	 * @param queryResults
389 397
	 * @return
390 398
	 * @throws CqiClientException
391 399
	 */
392 400
	public boolean stepQueries(List<QueryResult> queryResults) throws CqiClientException {
393 401
		if (queryResults.size() != queries.size()) return false;
394

  
402
		
395 403
		maxX = getCorpus().getSize();
396 404
		int npositions = 0;
397
		for (int iQuery = 0 ; iQuery < queries.size() ; iQuery++) {
405
		for (int iQuery = 0; iQuery < queries.size(); iQuery++) {
398 406
			QueryResult result = queryResults.get(iQuery);
399

  
407
			
400 408
			int nLines = result.getNMatch();
401 409
			if (maxY < nLines) {
402 410
				maxY = nLines;
403 411
			}
404

  
412
			
405 413
			List<Match> matches = null;
406 414
			if (nLines > 0) {
407 415
				matches = result.getMatches(0, nLines - 1); // get the indexes sequences of result's tokens
408 416
			}
409 417
			else {
410
				matches = new ArrayList<Match>();
418
				matches = new ArrayList<>();
411 419
			}
412
			//System.out.println("matches: "+matches);
420
			// System.out.println("matches: "+matches);
413 421
			int[] positions = new int[matches.size()];
414 422
			// System.out.println("nb positions "+matches.size());
415 423
			// if (matches.size() > 0)
......
422 430
		}
423 431
		return npositions > 0;
424 432
	}
425

  
433
	
426 434
	/**
427 435
	 * Step queries.
428 436
	 *
429 437
	 * @throws CqiClientException the cqi client exception
430 438
	 */
431
	public boolean stepQueries() throws CqiClientException	{
439
	public boolean stepQueries() throws CqiClientException {
432 440
		maxX = getCorpus().getSize();
433 441
		int npositions = 0;
434

  
435
		for (int iQuery = 0 ; iQuery < queries.size() ; iQuery++) {
442
		
443
		for (int iQuery = 0; iQuery < queries.size(); iQuery++) {
436 444
			QueryResult result = null;
437 445
			if (queryResults != null) {
438 446
				result = queryResults.get(iQuery);
439
			} else {
447
			}
448
			else {
440 449
				CQLQuery query = queries.get(iQuery);
441
				// System.out.println("query  "+query.getQueryString());
450
				// System.out.println("query "+query.getQueryString());
442 451
				result = getCorpus().query(query, query.getQueryString()
443 452
						.replace(" ", "_") + "_progression", true); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
444 453
			}
445 454
			int nLines = result.getNMatch();
446 455
			if (maxY < nLines)
447 456
				maxY = nLines;
448

  
457
			
449 458
			List<Match> matches = null;
450 459
			if (nLines > 0) {
451 460
				matches = result.getMatches(0, nLines - 1); // get the indexes
452 461
				// sequences of result's tokens
453
			} else {
454
				matches = new ArrayList<Match>();
455 462
			}
456
			//System.out.println("matches: "+matches);
463
			else {
464
				matches = new ArrayList<>();
465
			}
466
			// System.out.println("matches: "+matches);
457 467
			int[] positions = new int[matches.size()];
458 468
			// System.out.println("nb positions "+matches.size());
459 469
			// if (matches.size() > 0)
......
467 477
		}
468 478
		return npositions > 0;
469 479
	}
470

  
480
	
471 481
	/**
472 482
	 * Step structural units.
473 483
	 *
474 484
	 * @throws CqiClientException the cqi client exception
475
	 * @throws CqiServerError 
476
	 * @throws IOException 
485
	 * @throws CqiServerError
486
	 * @throws IOException
477 487
	 */
478
	public boolean stepStructuralUnits() throws CqiClientException, IOException, CqiServerError	{
488
	public boolean stepStructuralUnits() throws CqiClientException, IOException, CqiServerError {
479 489
		// structure query
480 490
		if (structuralUnit != null) {
481 491
			CQLQuery query = new CQLQuery("<" + structuralUnit.getName() + ">[]"); //$NON-NLS-1$ //$NON-NLS-2$
......
483 493
				if (!propertyRegex.isEmpty()) {
484 494
					query = new CQLQuery("<" + structuralUnitProperty.getFullName() + "=\"" + propertyRegex + "\">[]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
485 495
				}
486
				else	{
496
				else {
487 497
					query = new CQLQuery("<" + structuralUnitProperty.getFullName() + ">[]"); //$NON-NLS-1$ //$NON-NLS-2$
488 498
				}
489 499
			}
490

  
500
			
491 501
			// System.out.println("Struct: "+ structure+" property: "+property);
492 502
			// System.out.println(query.getQueryString());
493 503
			QueryResult result = getCorpus().query(query, query.getQueryString().replace(" ", "_") + "_progression", true); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
494 504
			int[] starts = result.getStarts();
495 505
			result.drop();
496 506
			int nLines = starts.length;
497

  
498
			//			List<Match> matches = new ArrayList<Match>();
499
			//			if (nLines > 0)
500
			//				matches = result.getMatches(0, nLines - 1); // get the indexes
507
			
508
			// List<Match> matches = new ArrayList<Match>();
509
			// if (nLines > 0)
510
			// matches = result.getMatches(0, nLines - 1); // get the indexes
501 511
			// sequences of result's tokens
502

  
512
			
503 513
			structurePositions = new int[nLines];
504 514
			structureNames = new String[nLines];
505

  
506

  
507

  
508
			Map<Property, List<String>> refValues = new HashMap<Property, List<String>>();
515
			
516
			
517
			
518
			Map<Property, List<String>> refValues = new HashMap<>();
509 519
			if (structuralUnitProperty != null) {
510 520
				List<String> values = CorpusManager.getCorpusManager().getCqiClient().getSingleData(structuralUnitProperty, starts);
511 521
				refValues.put(structuralUnitProperty, values);
512 522
			}
513

  
523
			
514 524
			int i = 0;
515 525
			String previousname = ""; //$NON-NLS-1$
516 526
			String currentname = ""; //$NON-NLS-1$
......
523 533
				else {
524 534
					currentname = structuralUnit.getName() + i;
525 535
				}
526

  
527
				//				if (repeatValues) {
536
				
537
				// if (repeatValues) {
528 538
				structureNames[i] = currentname;
529 539
				structurePositions[i] = m;
530
				//				}
531
				//				else {
532
				//					if (!previousname.equals(currentname)) {
533
				//						structureNames[i] = currentname;
534
				//						structurePositions[i] = m;
535
				//					}
536
				//				}
540
				// }
541
				// else {
542
				// if (!previousname.equals(currentname)) {
543
				// structureNames[i] = currentname;
544
				// structurePositions[i] = m;
545
				// }
546
				// }
537 547
				if (i == 0) {
538 548
					structurePositions[i] += 1;
539 549
				}
540

  
550
				
541 551
				if (m - previousposition < distmin) {
542 552
					distmin = m - previousposition;
543 553
				}
544

  
554
				
545 555
				previousname = currentname;
546 556
				previousposition = m;
547

  
557
				
548 558
				i++;
549

  
559
				
550 560
				this.worked(1);
551 561
			}
552 562
			this.bande = distmin * this.bandeMultiplier;
553 563
		}
554 564
		return true;
555 565
	}
556

  
566
	
557 567
	/**
558 568
	 * Step finalize.
559 569
	 *
560 570
	 * @throws CqiClientException the cqi client exception
561 571
	 */
562
	public boolean stepFinalize() throws CqiClientException	{
572
	public boolean stepFinalize() throws CqiClientException {
563 573
		if (getCorpus() instanceof Subcorpus) {
564 574
			List<Match> matches = ((Subcorpus) getCorpus()).getMatches();
565 575
			if (matches.size() == 0) {
566 576
				System.out.println(ProgressionCoreMessages.errorColonSubcorpusWithSize0);
567 577
				return false;
568 578
			}
569

  
579
			
570 580
			XminCorpus = matches.get(0).getStart();
571
			XmaxCorpus = matches.get(matches.size()-1).getEnd();
581
			XmaxCorpus = matches.get(matches.size() - 1).getEnd();
572 582
		}
573 583
		else {
574 584
			XminCorpus = 0;
575 585
			XmaxCorpus = getCorpus().getSize();
576 586
		}
577
		//System.out.println("min: "+XminCorpus+ "max: "+XmaxCorpus);
578

  
587
		// System.out.println("min: "+XminCorpus+ "max: "+XmaxCorpus);
588
		
579 589
		if (bande <= 0) {
580 590
			bande = ((XmaxCorpus - XminCorpus) / 100) * bandeMultiplier;
581 591
			if (bande == 0) {
......
584 594
		}
585 595
		return true;
586 596
	}
587

  
588

  
589

  
590

  
591

  
597
	
598
	
599
	
600
	
601
	
592 602
	/**
593 603
	 * Gets the max x.
594 604
	 *
......
597 607
	public int getMaxX() {
598 608
		return maxX;
599 609
	}
600

  
610
	
601 611
	/**
602 612
	 * Gets the max y.
603 613
	 *
......
606 616
	public int getMaxY() {
607 617
		return maxY;
608 618
	}
609

  
619
	
610 620
	/**
611 621
	 * Gets the corpus.
612 622
	 *
......
615 625
	public CQPCorpus getCorpus() {
616 626
		return (CQPCorpus) this.parent;
617 627
	}
618

  
628
	
619 629
	/**
620 630
	 * Gets the queries.
621 631
	 *
......
624 634
	public List<CQLQuery> getQueries() {
625 635
		return this.queries;
626 636
	}
627

  
637
	
628 638
	/**
629 639
	 * @return the allPositions
630 640
	 */
631 641
	public List<int[]> getAllPositions() {
632 642
		return allPositions;
633 643
	}
634

  
635

  
644
	
645
	
636 646
	/**
637 647
	 * Gets the positions counts.
638 648
	 *
639 649
	 * @return the positions counts
640 650
	 */
641 651
	public List<Integer> getPositionsCounts() {
642
		ArrayList<Integer> counts = new ArrayList<Integer>();
652
		ArrayList<Integer> counts = new ArrayList<>();
643 653
		for (int[] list : allPositions) {
644 654
			counts.add(list.length);
645 655
		}
646 656
		return counts;
647 657
	}
648

  
649

  
658
	
659
	
650 660
	/**
651 661
	 * Checks if is repeatvalues.
652 662
	 *
......
655 665
	public boolean isRepeatingValues() {
656 666
		return repeatValues;
657 667
	}
658

  
659

  
660

  
668
	
669
	
670
	
661 671
	@Override
662 672
	public void clean() {
663 673
		try {
......
671 681
			org.txm.utils.logger.Log.printStackTrace(e);
672 682
		}
673 683
	}
674

  
684
	
675 685
	@Override
676 686
	public boolean toTxt(File outfile, String encoding, String colseparator,
677 687
			String txtseparator) throws Exception {
678 688
		return toTxt(outfile, encoding);
679 689
	}
680

  
681

  
690
	
691
	
682 692
	/**
683 693
	 * 
684 694
	 * @param outfile
......
690 700
		// NK: writer declared as class attribute to perform a clean if the operation is interrupted
691 701
		tryAcquireSemaphore();
692 702
		this.writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outfile),
693
				encoding)); 
694
		for (int i = 0 ; i < queries.size() ; i++) {
695
			writer.write("* "+queries.get(i)+"\n"); //$NON-NLS-1$ //$NON-NLS-2$
703
				encoding));
704
		for (int i = 0; i < queries.size(); i++) {
705
			writer.write("* " + queries.get(i) + "\n"); //$NON-NLS-1$ //$NON-NLS-2$
696 706
			for (int p : allPositions.get(i)) {
697
				writer.write(""+p+"\n"); //$NON-NLS-1$ //$NON-NLS-2$
707
				writer.write("" + p + "\n"); //$NON-NLS-1$ //$NON-NLS-2$
698 708
			}
699 709
		}
700 710
		writer.close();
701 711
		releaseSemaphore();
702 712
		return true;
703 713
	}
704

  
705

  
714
	
715
	
706 716
	/**
707 717
	 * @return the structurePositions
708 718
	 */
709 719
	public int[] getStructurePositions() {
710 720
		return structurePositions;
711 721
	}
712

  
722
	
713 723
	/**
714 724
	 * @return the structureNames
715 725
	 */
716 726
	public String[] getStructureNames() {
717 727
		return structureNames;
718 728
	}
719

  
720

  
729
	
730
	
721 731
	/**
722 732
	 * @return the propertyRegex
723 733
	 */
724 734
	public String getPropertyRegex() {
725 735
		return propertyRegex;
726 736
	}
727

  
737
	
728 738
	/**
729 739
	 * @return the bande
730 740
	 */
731 741
	public float getBande() {
732 742
		return bande;
733 743
	}
734

  
744
	
735 745
	/**
736 746
	 * @return the xminCorpus
737 747
	 */
738 748
	public int getXminCorpus() {
739 749
		return XminCorpus;
740 750
	}
741

  
751
	
742 752
	/**
743 753
	 * @return the xmaxCorpus
744 754
	 */
745 755
	public int getXmaxCorpus() {
746 756
		return XmaxCorpus;
747 757
	}
748

  
749

  
758
	
759
	
750 760
	@Override
751 761
	public String[] getExportTXTExtensions() {
752
		return new String[]{"*.txt"};
762
		return new String[] { "*.txt" };
753 763
	}
754

  
755

  
764
	
765
	
756 766
	/**
757 767
	 * Computes and gets a query constructed from all the queries in alternative mode (with pipe |).
768
	 * 
758 769
	 * @return
759 770
	 */
760 771
	// FIXME: not used? even in synchronous editors (concordance and edition?)?
761
	public String getQueriesString()	{
762
		ArrayList<Integer> allQueriesIndexes = new ArrayList<Integer>(this.queries.size());
763
		for(int i = 0; i < this.queries.size(); i++) {
772
	public String getQueriesString() {
773
		ArrayList<Integer> allQueriesIndexes = new ArrayList<>(this.queries.size());
774
		for (int i = 0; i < this.queries.size(); i++) {
764 775
			allQueriesIndexes.add(i);
765 776
		}
766
		return this.getQueriesString(allQueriesIndexes) ;
777
		return this.getQueriesString(allQueriesIndexes);
767 778
	}
768

  
779
	
769 780
	/**
770 781
	 * Computes and gets a query constructed from all the queries specified by their index in alternative mode (with pipe |).
782
	 * 
771 783
	 * @param queriesIndexes
772 784
	 * @return
773 785
	 */
774
	public String getQueriesString(ArrayList<Integer> queriesIndexes)	{
775

  
786
	public String getQueriesString(ArrayList<Integer> queriesIndexes) {
787
		
776 788
		String query = "";
777

  
778
		for(int i = 0; i < this.queries.size(); i++) {
779
			if(queriesIndexes.contains(i))	{
789
		
790
		for (int i = 0; i < this.queries.size(); i++) {
791
			if (queriesIndexes.contains(i)) {
780 792
				String tmpQuery = this.queries.get(i).getQueryString();
781
				// Remove "[" and "]" only if it's a simple query as "[look]" 
782
				if(tmpQuery.startsWith("[") && !tmpQuery.contains("="))	{
793
				// Remove "[" and "]" only if it's a simple query as "[look]"
794
				if (tmpQuery.startsWith("[") && !tmpQuery.contains("=")) {
783 795
					int length = tmpQuery.length();
784
					if(tmpQuery.endsWith("]"))	{
796
					if (tmpQuery.endsWith("]")) {
785 797
						length--;
786 798
					}
787 799
					tmpQuery = tmpQuery.substring(1, length);
788 800
				}
789
				if(query.length() > 0)	{
801
				if (query.length() > 0) {
790 802
					query += " | ";
791 803
				}
792 804
				query += tmpQuery;
793 805
			}
794 806
		}
795

  
807
		
796 808
		return query;
797

  
809
		
798 810
	}
799

  
800

  
811
	
812
	
801 813
	@Override
802 814
	public String getDetails() {
803 815
		return this.getName();
804 816
	}
805

  
817
	
806 818
	@Override
807 819
	public String getName() {
808 820
		try {
809 821
			return this.parent.getSimpleName() + ": " + this.getSimpleName(); //$NON-NLS-1$
810 822
		}
811
		catch(Exception e) {
823
		catch (Exception e) {
812 824
		}
813 825
		return ""; //$NON-NLS-1$
814 826
	}
815

  
827
	
816 828
	@Override
817 829
	public String getSimpleName() {
818 830
		try {
819 831
			if (this.queries == null || this.queries.isEmpty()) {
820 832
				return getEmptyName();
821 833
			}
822
			String output  = StringUtils.join(this.queries, ","); //$NON-NLS-1$
834
			String output = StringUtils.join(this.queries, ","); //$NON-NLS-1$
823 835
			if (this.propertyRegex != null) {
824 836
				output += " " + this.propertyRegex; //$NON-NLS-1$
825 837
			}
......
829 841
		}
830 842
		return this.getEmptyName();
831 843
	}
832

  
833

  
844
	
845
	
834 846
	@Override
835 847
	public String getComputingStartMessage() {
836
		return TXMCoreMessages.bind(ProgressionCoreMessages.progressionOfP0InTheP1Corpus, this.queries.toString(), this.getCorpus().getName());
848
		return TXMCoreMessages.bind(ProgressionCoreMessages.progressionOfP0InTheP1Corpus, this.queries, this.getCorpus().getName());
837 849
	}
838

  
839

  
850
	
851
	
840 852
	@Override
841 853
	public String getComputingDoneMessage() {
842
		if (this.getAllPositions() == null || this.getAllPositions().isEmpty())	{
854
		if (this.getAllPositions() == null || this.getAllPositions().isEmpty()) {
843 855
			return TXMCoreMessages.common_noResults;
844 856
		}
845 857
		else {
......
850 862
			return TXMCoreMessages.bind(TXMCoreMessages.common_P0Positions, positions);
851 863
		}
852 864
	}
853

  
865
	
854 866
	/**
855 867
	 * @return the bandeMultiplier
856 868
	 */
857 869
	public float getBandeMultiplier() {
858 870
		return bandeMultiplier;
859 871
	}
860

  
872
	
861 873
	/**
862 874
	 * @param bandeMultiplier the bandeMultiplier to set
863 875
	 */
864 876
	public void setBandeMultiplier(float bandeMultiplier) {
865 877
		this.bandeMultiplier = bandeMultiplier;
866 878
	}
867

  
868

  
869

  
879
	
880
	
881
	
870 882
	/**
871 883
	 * @param repeatValues the repeatValues to set
872 884
	 */
873 885
	public void setRepeatValues(boolean repeatValues) {
874 886
		this.repeatValues = repeatValues;
875 887
	}
876

  
877

  
878

  
879

  
888
	
889
	
890
	
891
	
880 892
	/**
881 893
	 * @return the structuralUnit
882 894
	 */
883 895
	public StructuralUnit getStructuralUnit() {
884 896
		return structuralUnit;
885 897
	}
886

  
887

  
888

  
898
	
899
	
900
	
889 901
	/**
890 902
	 * @return the structuralUnitProperty
891 903
	 */
892 904
	public StructuralUnitProperty getStructuralUnitProperty() {
893 905
		return structuralUnitProperty;
894 906
	}
895

  
896

  
897

  
907
	
908
	
909
	
898 910
	/**
899 911
	 * @param queries the queries to set
900 912
	 */
901 913
	public void setQueries(List<CQLQuery> queries) {
902 914
		this.queries = queries;
903 915
	}
904

  
916
	
905 917
	@Override
906 918
	public String getResultType() {
907 919
		return ProgressionCoreMessages.RESULT_TYPE;
908 920
	}
909

  
910

  
911
}
921
	
922
	
923
}

Formats disponibles : Unified diff