#!/usr/bin/perl use locale; # ag2praat.pl # (c) Lauri Carlson 2002 while(<>) { # AGSet PROLOG START # print "!$_"; last if (/MetadataElement/); } while(<>) { # CDATA if (/xmax[^0-9]*([0-9]+)/) { $XMAX = $1/10; s/$1/sprintf "%f",$XMAX/e; } s/\<\!\[CDATA\[//g; s/\]\]\>//g; print; last if (/item \[\]:/); } LOOP: $item = $min = $max = $xmin = $xmax = 0; while(<>) { # AG PROLOG # print "!$_"; last if (//); } while(<>) { # CDATA if (/xmax[^0-9]*([0-9]+)/) { $XMAX = $1/10; s/$1/sprintf "%f",$XMAX/e; } s/\<\!\[CDATA\[//g; s/\]\]\>//g; last if (/\/Metadata/); print; } while(<>) { # Annotations # print "!at: $. $_"; SWITCH: for ($_) { /Annotation type="(.*)" start="A([0-9.]+)" end="A([0-9.]+)">/ && do { $start = $2; $end=$3; $item++; }; // && do { s///; while (!/<\/Feature>/) { s/\n/ /; $text .= $_; $_ = <>; } s/<\/Feature>//; chomp; $text .= $_; if ($start =~ /\./) { # real $xmin = $start; $xmax = $end; } else { # ordinal if ($tab{$end}) { $xmin = $tab{$start}; $xmax = $tab{$end}; } else { $xmin = $xmax; $xmax += length($text); $tab{$end} = $xmax; } } # print "!start,end,min,max,xmin,xmax:$start,$end,$min,$max,$xmin,$xmax\n"; # if ($max < $xmin || $item == 1 && $start > 0) { # fill gaps # printf " intervals [%d]:\ # xmin = %f\ # xmax = %f\ #", $item++, $max/10, $xmin/10; # print " text = \"\"\n"; # } printf " intervals [$item]:\ xmin = %f\ xmax = %f\ ", $xmin/10, $xmax/10; if ($text !~ /^".*"$/) { $text = "\"$text\""; } print " text = $text\n"; $min = $xmin; $max = $xmax; $text = ""; last; }; } # print "!$_"; last if (/AG/); } goto LOOP;