Révision 3413

TXM/trunk/org.txm.groovy.core/src/groovy/org/txm/macro/transcription/AddSectionsFromTableV2Macro.groovy (revision 3413)
251 251
					// Cas 2 : on est arrivés à la section à considérer
252 252
					iSection = i
253 253
					// if section_start > turn_end OU |section_start - turn_end| < turn_threshold
254
					if (sections[i][0] > end || Math.abs(sections[i][0] - end) < turnsCutActivationThreashold) { // Section is before section
254
					if (sections[i][0] > end || Math.abs(sections[i][0] - end) < turnsCutActivationThreashold) { // Turn is before section
255 255
						// Cas 2.1 : la section est complètement après (modulo la marge) (et les suivantes le seront aussi)
256
						foundSection=null
257
						isTurnSynchronized=false
258
						cutCheck=false
256
						foundSection = null
257
						isTurnSynchronized = false
258
						cutCheck = false
259 259
					} else {
260 260
						// if |section_start - turn_start| > turn_threshold
261
						if (Math.abs(start - sections[i][0]) > turnsCutActivationThreashold) { // Section is before section
261
						if (Math.abs(start - sections[i][0]) > turnsCutActivationThreashold) { // Turn begins before section does
262 262
							// Cas 2.2 : la section commence significativement après le début du tour (le début est non synchronisé)
263
							foundSection=sections[i] // (c'est la première section rencontrée, mais elle sera pour le tour suivant)
264
							isTurnSynchronized=false
265
							cutCheck=true
263
							foundSection = sections[i] // (c'est la première section rencontrée, mais elle sera pour le tour suivant)
264
							isTurnSynchronized = false
265
							cutCheck = true
266 266
						} else {
267 267
							// Cas 2.3 : le début du tour est dans la section (on n'a pas besoin de chercher d'autres sections car si ce n'est pas la seule on coupera le tour et ce sera un autre tour).
268
							foundSection=sections[i]  // (c'est la section qui commence le tour, au moins)
269
							isTurnSynchronized=true
270
							cutCheck=true
268
							foundSection = sections[i]  // (c'est la section qui commence le tour, au moins)
269
							isTurnSynchronized = true
270
							cutCheck = true
271 271
						}
272 272
					}
273 273
					break; // stop searching and set iSection to accelerate next search
274 274
				}
275 275
			}
276 276
			
277
			// Etape 3 : positionne *le* tour dans *le* noeud (cf. ~ l.247-264 ?)
277
			// Etape 2 : positionne *le* tour dans *le* noeud
278 278
			// (on ne gère qu'un seul tour et un seul noeud à chaque itération de la boucle tour,
279 279
			// puisqu'on a retaillé le tour pour qu'il ne concerne pas plusieurs noeuds)
280
			if (foundSection != null) {  // on complète ou on ajoute une div.
280
			if (foundSection != null) { // on complète ou on ajoute une div.
281 281
				
282 282
				if (foundSection != currentSection || currentSection == null) {
283 283
					if (currentNode != null && currentNode.@synchronized == "false") {
......
288 288
					currentSection = foundSection
289 289
					currentNode = new Node(trsEpisode, "Section", currentSection[2])
290 290
				}
291
			} else {  // on complète ou on ajoute un noeud (div) non synchronisé.
292
				
293
				currentNode = new Node(trsEpisode, "Section", ["type":"Sujet non synchronisé", "startTime":sections[iSection][0], "endTime":sections[iSection][1], "synchronized":"false"] )
294
				currentSection = null;
291
			} else { // on complète ou on ajoute un noeud (div) non synchronisé.
292
				if (currentSection != null || currentNode == null) { // create a new unsynchronized section if there is no opened synchronized section or no un-synchronized section
293
				    currentNode = new Node(trsEpisode, "Section", ["type":"Sujet non synchronisé", "startTime":sections[iSection][0], "endTime":sections[iSection][1], "synchronized":"false"] )
294
				    currentSection = null;
295
                }
295 296
			}
296 297
			
297
			// Etape 2 : on coupe le tour s'il y a besoin (cf. ~l.267-315 ?)
298
			if (cutCheck) {
298
			// Etape 3 : on coupe le tour s'il y a besoin
299
			if (cutCheck && fixTurnsLimits) {
299 300
				if (isTurnSynchronized) {
300
					cutTurn(true) // iSection++ quand on coupe
301
					cutTurn(true) // iSection++  et test avec le **end** de la section quand on coupe
301 302
				} else {
302 303
					if (foundSection != null) {
303
						cutTurn(false)
304
						cutTurn(false) // test avec le **start** de la section quand on coupe
304 305
					}
305 306
				}
306 307
			}
307 308
			
308
	
309
			
310 309
			trsSection.remove(turn)
311 310
			currentNode.append(turn)
312 311
		}
......
329 328
	Log.printStackTrace(e)
330 329
}
331 330

  
332
def cutTurn(def incrementISection) {
331
def cutTurn(def testWithSectionEndTime) {
333 332
	def children = turn.children()
334 333
	Node newTurnKaNode = null;//new Node(trsEpisode, "Turn", currentSection[2])
335 334
	
......
352 351
			if ("w".equals(c.name())) {
353 352
				def start2 = Float.parseFloat(c.@startTime)
354 353
				def end2 = Float.parseFloat(c.@endTime)
354
                    
355
                boolean test = null
356
                if (testWithSectionEndTime) {
357
                   test = start2 > endSection
358
                } else {
359
                   test = start2 >= startSection
360
                }
355 361
				
356
				if (start2 > endSection && Math.abs(start2 - endSection) > turnsCutActivationThreashold) {
362
				if (test) { // && Math.abs(start2 - endSection) > turnsCutActivationThreashold // no more needed
357 363
					if (debug) println "cut with a w at ($start2, $end2) for section ("+startSection+", "+endSection+")"
358 364
					newTurnKaNode = new Node(trsSection, "Turn", ["startTime":""+start2, "endTime":""+turn.@endTime, "speaker":turn.@speaker])
365
                    new Node(newTurnKaNode, "Sync", ["time":""+start2]) // TRS
359 366
					turns.add(iTurn, newTurnKaNode)
360 367
					iTurn--
361 368
					if (debug) newTurnKaNode.@created = "yes"
......
364 371
					newTurnKaNode.append(c)
365 372
					
366 373
					if (debug) c.@moved="yes"
367
					if (incrementISection) iSection++
374
					if (testWithSectionEndTime) iSection++
368 375
					iChildren--
369 376
				}
370 377
			} else if ("Sync".equals(c.name())) {
371 378
				def start2 = c.@time
372 379
				if (start2 instanceof String) start2 = Float.parseFloat(c.@time)
373 380
				def end2 = start2
381
                    
382
                boolean test = null
383
                if (testWithSectionEndTime) {
384
                   test = start2 > endSection
385
                } else {
386
                   test = start2 >= startSection
387
                }
374 388
				
375
				if (start2 > endSection && Math.abs(start2 - endSection) > turnsCutActivationThreashold) {
389
				if (test) { //  && Math.abs(start2 - endSection) > turnsCutActivationThreashold
376 390
					if (debug) println "cut with a Sync at ($start2, $end2) for section ("+startSection+", "+endSection+")"
377 391
					newTurnKaNode = new Node(trsSection, "Turn", ["startTime":""+start2, "endTime":""+turn.@endTime, "speaker":turn.@speaker])
378 392
					turns.add(iTurn, newTurnKaNode)
......
381 395
					turn.@endTime = ""+start2;
382 396
					turn.remove(c)
383 397
					if (debug) c.@moved="yes"
384
					if (incrementISection) iSection++
398
					if (testWithSectionEndTime) iSection++
385 399
					newTurnKaNode.append(c)
386 400
					iChildren--
387 401
				}

Formats disponibles : Unified diff