Revision 479 tmp/org.txm.groovy.core/src/groovy/org/txm/importer/transcriber/pager.groovy

pager.groovy (revision 479)
44 44
 *  
45 45
 */
46 46
class pager {
47
	
47

  
48 48
	boolean SIMPLE_TOOLTIP = false; // show less properties in word tooltips
49 49
	String ENQ_HIGHLIGHT_ELEMENT = "b"
50
	
50

  
51 51
	List<String> NoSpaceBefore;
52 52

  
53 53
	/** The No space after. */
......
201 201
			return false;
202 202
		}
203 203
	}
204
	
204

  
205 205
	/** The events. */
206 206
	List<String> events = [];
207 207
	String previousEvent = "", nextEvent = "";
......
382 382
							if (overlapping) {
383 383
								writer.writeEmptyElement("br");
384 384
								writeSpeaker(parser.getAttributeValue(null,"speaker"), false)
385
								
385

  
386 386
								writer.writeEmptyElement("br");
387 387
								whos = spid.split(" ")
388 388
							}
......
391 391
						case "u":
392 392
							writer.writeCharacters("\n");
393 393
							this.currentTime = parser.getAttributeValue(null,"time");
394
						
394

  
395 395
							if (previousElem == "u" && writenLength == 0) { // if previous u had no words, it was a silence
396 396
								writer.writeStartElement("span");
397 397
								writer.writeAttribute("class", "event");
......
399 399
								writer.writeEndElement(); // span
400 400
								writer.writeEmptyElement("br");
401 401
							}
402
							
402

  
403 403
							String spk = parser.getAttributeValue(null, "spk")
404 404
							if (spk != null && spk != previousSPK) {
405 405
								endBoldIfNeeded()
......
464 464
									wordid = (parser.getAttributeValue(i));
465 465
									break;
466 466
								}
467

  
468
							wordcount++;
469
							if (wordcount >= wordmax) {
470
								shouldBreak = true;
471
							}
472

  
467 473
							if (firstWord) {
468 474
								indexes << wordid
469 475
								firstWord = false;
470 476
							}
471
							wordcount++;
472
							if (wordcount >= wordmax) {
473
								shouldBreak = true;
474
							}
477

  
475 478
							break;
476 479

  
477 480
						case "ana":
478
							
481

  
479 482
							String type = parser.getAttributeValue(null,"type").substring(1);
480 483
							if (SIMPLE_TOOLTIP) {
481 484
								if (type.contains("lemma") || type.contains("pos")) {
......
516 519

  
517 520
						case "div":
518 521
						//writer.writeCharacters("}");
519
							
522

  
520 523
							writer.writeEndElement(); // div
521 524
							writer.writeCharacters("\n");
522 525
							break;
523 526
						case "sp":
524
							//println "CLOSING: "+parser.getLocalName()
527
						//println "CLOSING: "+parser.getLocalName()
525 528
							endBoldIfNeeded()
526 529
							if (!spokenTurn) {
527 530
								writer.writeStartElement("span");
......
538 541
								writer.writeEmptyElement("pb");
539 542
								writer.writeAttribute("id", ""+nbBreak);
540 543
								writer.writeCharacters("\n");
541
								
544

  
542 545
								pages << new File(defaultDir, "${txtname}_${nbBreak}.html")
543 546
								indexes << wordid
544 547

  
......
548 551
							writer.writeCharacters("\n");
549 552
							break;
550 553
						case "u":
551
							//writer.writeEndElement() // span@class=u
552
							//writer.writeEmptyElement("br");
554
						//writer.writeEndElement() // span@class=u
555
						//writer.writeEmptyElement("br");
553 556
						//if (overlapping) writer.writeEndElement(); // b
554 557
							break;
555 558
						case "event":
......
580 583
							}
581 584
							interpvalue = interpvalue.replace("=, ","='', "); // add '' to empty interp value
582 585
							if (interpvalue.startsWith(", ")) interpvalue = interpvalue.substring(2)
583
//							println "** SPACE TEST"
584
//							println "NoSpaceBefore: "+NoSpaceBefore+" contains ? "+wordvalue
585
//							println "NoSpaceAfter: "+NoSpaceAfter+" contains ? "+lastword
586
//							println "wordvalue starts with '-' ? "+wordvalue
587
//							println "NoSpaceAfter: "+NoSpaceAfter+" contains endOfLastWord ? "+endOfLastWord
586
						//							println "** SPACE TEST"
587
						//							println "NoSpaceBefore: "+NoSpaceBefore+" contains ? "+wordvalue
588
						//							println "NoSpaceAfter: "+NoSpaceAfter+" contains ? "+lastword
589
						//							println "wordvalue starts with '-' ? "+wordvalue
590
						//							println "NoSpaceAfter: "+NoSpaceAfter+" contains endOfLastWord ? "+endOfLastWord
588 591
							if(NoSpaceBefore.contains(wordvalue) ||
589 592
							NoSpaceAfter.contains(lastword) ||
590 593
							wordvalue.startsWith("-") ||
591 594
							NoSpaceAfter.contains(endOfLastWord)) {
592
//								println " NO SPACE"
595
								//								println " NO SPACE"
593 596
							} else {
594
//								println " SPACE"
597
								//								println " SPACE"
595 598
								writer.writeCharacters(" ");
596 599
							}
597 600

  
......
623 626
							if (interpvalue.contains("rapp2")) {
624 627
								writer.writeCharacters(" » ");
625 628
							}
626
							
629

  
627 630
							lastword=wordvalue;
628 631
							break;
629 632
					}
630
					
633

  
631 634
					break;
632 635

  
633 636
				case XMLStreamConstants.CHARACTERS:
......
662 665
		//		println "words: "+indexes
663 666

  
664 667

  
665
				if (pages.size() > 1) {
666
					for (int i = 1 ; i < nbBreak ; i++) {
667
						ApplyXsl2 a = new ApplyXsl2(xslfile.getAbsolutePath());
668
						String[] params = ["pbval1", i,"pbval2", i+1];
669
		
670
						File resultfile = pages[i-1]
671
						//println "BBmilestones: "+i+" "+(i+1)+" in file "+resultfile
672
						//println "process $outfile -> $resultfile"
673
						a.process(outfile.getAbsolutePath(), resultfile.getAbsolutePath(), params);
674
					}
675
				} else {
676
					File page = pages[0]
677
					FileCopy.copy(outfile, page)
678
				}
668
		if (pages.size() > 1) {
669
			for (int i = 1 ; i < nbBreak ; i++) {
670
				ApplyXsl2 a = new ApplyXsl2(xslfile.getAbsolutePath());
671
				String[] params = ["pbval1", i,"pbval2", i+1];
672

  
673
				File resultfile = pages[i-1]
674
				//println "BBmilestones: "+i+" "+(i+1)+" in file "+resultfile
675
				//println "process $outfile -> $resultfile"
676
				a.process(outfile.getAbsolutePath(), resultfile.getAbsolutePath(), params);
677
			}
678
		} else {
679
			File page = pages[0]
680
			FileCopy.copy(outfile, page)
681
		}
679 682
	}
680 683

  
681 684
	private void writeCurrentTime()
......
687 690
	}
688 691

  
689 692
	private void writeSpeaker(String spk, boolean overlapping) {
690
		
693

  
691 694
		writer.writeStartElement("span");
692 695
		writer.writeAttribute("class", "spk");
693 696
		if(interviewers.contains(spk))
......
706 709
		else
707 710
			return desc;
708 711
	}
709
	
712

  
710 713
	boolean boldOpenned = false;
711 714
	private void startBoldIfNeeded() {
712 715
		if (bold) {
......
714 717
			boldOpenned = true;
715 718
		}
716 719
	}
717
	
720

  
718 721
	private endBoldIfNeeded() {
719 722
		if (boldOpenned) {
720
//			println "CLOSE BOLD"
723
			//			println "CLOSE BOLD"
721 724
			writer.writeEndElement(); // b
722 725
			boldOpenned = false;
723 726
		}

Also available in: Unified diff