Blame view
tools/sctk-2.4.10/src/utf_filt/utf_filt.pl
59.1 KB
8dcb6dfcb first commit |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 |
#!/usr/bin/perl -w ######################################################## # File: utf_filt_v55.pl # # History: # # Version 1-24 Debugging versions non release # # Version 25 Released 8/14/98 # This version converts the output of a nsgmls to various formats. # These formats include: # 1) stm without NE tags for ASR processing, # 2) stm with NE tags for NE processing # 3) ctm with NE tags for NE processing (word time is obtained # from averaging number of words in a turn), # 4) ctm with NE tags for NE processing (word time is obtained # from word time tag). # Several issues are still unresolved in this version: # 1) period in Ms. # 2) turn end time is marked when music ends not when speaker # stops talking # # Version 26 # Added stm_sm_u format # Fixed usage statement and change <format> values to be more # readable # # Version 27 # Added the nsgmls conversion to be done internally so that # the input to the filter is the sgml transcript not the output # of the nsgmls program # sgml --> filter ---> output in specified format # # Version 28 # Added the -o flag to indicate if overlap is to be processed # or ignored # Added the -e option for user to specify the dtd file to be used # # Version 29 # Accomondated the latest version of dtd. Attributes of the old # episode tag is divided between a utf tag and episode tag # # Version 30 # Modified usage statement. Inproved command line interface. # Corrected the output NE tags to include double quotes. # # Version 31-32 # Fixed the warning messaged generated on implied data elements # in turns and section. # Added handlers for 'conversation' and 'b_aside'/'e_aside' # Modified the routine to parenthize words so that sgml tags are handled # # Version 33-34 # Added the CTM output format # Modified the tokenization of stm2ctm to be more robust. # # Version 35 # modified the IECTM output format to make a single token out of # all named entity tags so that sclite doesn't divide them # # Version 36 # Added the option -k to keep the text in the excluded text regions # (rather than 'IGNORE_TIME_...' # Modified the way IECTMs are made when the -w tag is not used in # that overlap tags with times are used to divide turns so that # the inferred word times next to overlapped regions are correct. # Version 37 # Fixed the handling if possessive acronyms. The pattern match was # case sensitive # # Version 38 # Modified the way overlaps are diagnosed so that identical numbers # are tolerated. # Changed the sex label for inter_segment_gaps to be blank. # Removed the child designation for a possoble label # Fixed the contraction parser to handle upper case letters, and use # either => or = in the eform rule # # Version 39 # Incorporated changes from Aaron Douthat that handled back-to-back NE tags. # # Version 40 # Fixed an interaction with acronyms and contractions. # ASR and PUNCTUATION tags now function as WORD separators. # # Version 41 # Fixed handling of optionally deletable text in the ctm output. # - all opt-del tags are removed, thus making them normal lexical items # # Version 42 # Fixed how fragments are handled if they are ne tagged # # Version 43 # Fixed the interaction between netags and the -w switch # # Version 44 # Fixed a problem with a local scoping bug that showed up with the # newest version of perl. # # Version 45 # Added the sex designation "unknown" the the LUR labels # # Version 46 # Added code to usure the asr attribute stack orders the start and # end times appropriately. It's clear that codes needs rewritten. It # was done before JGF knew about hash of hashes # # Version 47 # Added -c flag to disable focus conditions # # Version 48 # Fixed the unknown gender tag to match for the lur conditions. # # Version 49 # Corrected the handling of the process_overlap flag # # Fixed a problem in ie_split(). The [^\\s<>] expressiuon should # not have been escaped for new versions of perl. # # Version 50 # 1. Fixed a problem with splitting uncleare tokens. There was never a space put between them. # 2. Fixed problem with plural ancronyms # 3. Fixed problem with unclear spoken letters. # 4. Fixed problem with pre-token fragments (-ord) # # Version 51 # Fixed problem with reading UTF-8 character # Use Getopt::Long instead of getopt # # Version 52 # Added the option to not expand contractions # # Version 53 # Added code to warn IF there are non-posessive contractions that are not annotated. # # Version 54 # Added code to not translate non-lexemes to %hesitation. # Added code to not translate non-lexemes to %hesitation. # # Version 55 # Don't lowercase the speaker and channel of a turn # # Version 56 # Added support for onsgmls # ######################################################## ######################################################## # constant definitions ######################################################## # fields for items in a stm turn # $FILENAME_KEY = "FILENAME"; $NUM_CHAN_KEY = "NUM_CHAN"; $SPEAKER_KEY = "SPEAKER"; $SPKRTYPE_KEY = "SPKRTYPE"; $TURN_STIME_KEY = "STARTTIME"; $TURN_ETIME_KEY = "ENDTIME"; $TURN_CHANNEL_KEY = "CHANNEL"; $FOCUS_COND_KEY = "FOCUS_COND"; $TEXT_KEY = "TEXT"; $SECTION_STIME_KEY = "SECTION_STARTTIME"; $SECTION_ETIME_KEY = "SECTION_ENDTIME"; $SECTION_TYPE_KEY = "SECTION_TYPE"; $SECTION_ID_KEY = "SECTION_ID"; # fields for determining the focus condition # $DIALECT_KEY = "DIALECT"; $MODE_KEY = "MODE"; $FIDELITY_KEY = "FIDELITY"; $MUSIC_KEY = "MUSIC"; $SPEECH_KEY = "SPEECH"; $OTHER_KEY = "OTHER"; $LEVEL_KEY = "LEVEL"; # noise and fidelity levels # $HIGH = "high"; $LOW = "low"; $ON = "on"; $OFF = "off"; # modes # $PLANNED = "planned"; $SPONTANEOUS = "spontaneous"; # dialect types # $NATIVE = "native"; #$NONNATIVE = "nonnative"; # constant strings in lower case. Must convert to lower case before # comparison # $IGNORE_TIME_SEGMENT_IN_SCORING = "ignore_time_segment_in_scoring"; $EXCLUDED_REGION = "excluded_region"; $INTER_SEGMENT_GAP = "inter_segment_gap"; $UNKNOWN = "unk"; # misc. constants # $OVERLAP = 1; $NO_OVERLAP = -2; $THRESHOLD = 1; # output format # $STM = "STM"; $IESTM = "IESTM"; $IECTM = "IECTM"; $CTM = "CTM"; $IESM = "IESM"; $SM = "SM"; # debug level # $DEBUG_NONE = 0; $DEBUG_BRIEF = 1; $DEBUG_DETAIL = 2; #$DEBUG_FULL = 4; # define usage statement # $USAGE = " $0 [-wkph] -f <format> -e <dtd_file> -i <input file> -o <output file> ". "Desc: This script reformats an input UTF transcript file to various formats ". " The script uses the SGML DTD, and nsgmls to read the <input_file> and write ". " the file reformatted to <format> into <output_file> ". " ". "Required arguments: ". " -f <format> indicates the format of the output ". " where <format> can be one of the following: ". " IESTM: stm format with IE tags ". " STM: stm format for ASR--default ". " CTM: ctm format ". " IECTM: ctm format with IE tags ". " IESM: Story marked STM format with IE tags ". " SM: Story marked STM format for ASR ". " -e <dtd file> is the dtd file ". " -i <input file> is the sgml transcript ". " -o <output file> is the output of this script ". "Optional Arguments ". " -d <debug level> prints out debug information ". " -c flag to disable focus condition tagging ". " -h flag to display this message ". " -k flag to keep text within excluded regions in the output stream. only ". " This option valid only if -p is specified ". " -p flag to process overlap instead of ignoring it ". " -w flag to use word time tag instead of average word duration for CTM format ". " -t do not translate contractions to their expanded form ". " -n do not delete acousticnoise and nonspeech events. Do not translate nonlexemes ". " to the %hesitation symbol ". " -s 'prog' set the SGML parsing program name to 'prog'". " "; @TextAttribs = ('ACOUSTICNOISE', 'NONSPEECH', 'ACRONYM', 'NONLEXEME', 'MISPRONOUNCED', 'MISSPELLING', 'PNAME', 'IDIOSYNCRATIC'); @NE_beg_tags = ('B_ENAMEX', 'B_TIMEX', 'B_NUMEX'); @NE_end_tags = ('E_ENAMEX', 'E_TIMEX', 'E_NUMEX'); @ASR_beg_tags = ('B_FOREIGN', 'B_UNCLEAR', 'B_OVERLAP', 'B_NOSCORE', 'B_ASIDE'); @ASR_end_tags = ('E_FOREIGN', 'E_UNCLEAR', 'E_OVERLAP', 'E_NOSCORE', 'E_ASIDE'); @PUNCT_tags = ('PERIOD', 'QMARK', 'COMMA'); # generate regular expressions once for speed # $TextAttribs_re = join("|",@TextAttribs); $NE_beg_tags_re = join("|",@NE_beg_tags); $NE_end_tags_re = join("|",@NE_end_tags); $ASR_beg_tags_re = join("|",@ASR_beg_tags); $ASR_end_tags_re = join("|",@ASR_end_tags); $PUNCT_tags_re = join("|",@PUNCT_tags); ######################################################## # global variables ######################################################## $conformance = 0; $incomment = 0; %attr_stack = (); %ne_attr_stack = (); %asr_attr_stack = (); %bkgrnd_attr_stack = (); %wtime_attr_stack = (); @sorted_section_stack = (); @section_stack = (); %section_attr = (); %turn_attr = (); @turn_stack = (); %turn_elems = (); @text_elem = (); $text = ""; $text_flag = 0; $filename = ""; $music_level = $OFF; # default $speech_level = $OFF; # default $other_level = $OFF; # default $num_chan = 1; # default $in_turn = 0; # 0 not in the middle of a turn, 1 otherwise $kept_turn = 1; # 0 turn is not kept, 1 otherwise $format = $STM; # default $use_wtag = 0; # flag to use average word duration $process_overlap = 0; # flag to ignore overlap $input = ""; $output = ""; $dtd_file = "/home1/le/su_98/dtd/utf-1.0.dtd"; $debug_level = $DEBUG_NONE; # default no debugging info $display_help = 0; # default no display of help file $focus_condition_enabled = 1; # maek dat with focus conditions $inter_segment_gap_enabled = 1; #enable/disable marking inter-segment gaps $DBoff = ""; $keep_exclude_text = 0; $translateContractions = 1; $translateNonlexemes = 1; $deleteNonspeech = 1; $deleteAcousticnoise = 1; $NSGMLS = "nsgmls"; ######################################################## # include extended perl libraries ######################################################## # use the SGMLS class # use SGMLS; ######################################################## # main program ######################################################## #require "getopts.pl"; #&Getopts('pwkchd:f:e:i:o:'); use Getopt::Long; my $ret = GetOptions ("p", "w", "k", "c", "h", "d:i", "f=s", "e=s", "i=s", "o=s", "t", "n", "s=s"); $use_wtag = $opt_w if (defined($opt_w)); $process_overlap = $opt_p if (defined($opt_p)); $display_help = $opt_h if (defined($opt_h)); $output = $opt_o if (defined($opt_o)); $debug_level = $opt_d if (defined($opt_d)); $focus_condition_enabled = (! $opt_c) if (defined($opt_c)); $translateContractions = (!$opt_t) if (defined($opt_t)); if (defined($opt_n)){ $translateNonlexemes = (!$opt_n); $deleteNonspeech = (!$opt_n); $deleteAcousticnoise = (!$opt_n); } if (defined($opt_k)){ $keep_exclude_text = $opt_k; die "${USAGE}Error: option -k only valid with option -p" if (!defined($opt_p)); } if (defined($opt_f)){ ($format = $opt_f) =~ tr/a-z/A-Z/; die "${USAGE}Error: Unknown format '$format'" if ($format !~ /^(IESTM|STM|IECTM|CTM|IESM|SM)$/); } if (defined($opt_e)){ die "Error: DTD file '$opt_e' is not a readable file" if (! -r $opt_e); $dtd_file = $opt_e; } if (defined($opt_i)){ die "Error: Input file '$opt_i' is not a readable file" if (! -r $opt_i); $input = $opt_i; } $NSGMLS = $opt_s if (defined($opt_s)); # check command line arguments # die "${USAGE}Error: Output format required" if (!defined($opt_f)); die "${USAGE}Error: Output file required" if (!defined($opt_o)); die "${USAGE}Error: Input UTF file required" if (!defined($opt_i)); die "${USAGE}Error: SGML DTD file required" if (!defined($opt_e)); die ("$USAGE") if ($display_help) ; die ("ERROR: use -w only with IECTM format ") if ($use_wtag == 1 && $format !~ /^($CTM|$IECTM)$/); # open files # open(IN, "cat $dtd_file $input | $NSGMLS |") or die("Unable to open nsgmls parsed data $input"); binmode IN; open (OUT, ">$output") or die ("Unable to open $output for writing "); binmode OUT; # allocate an object of SGMLS class # $this_parse = new SGMLS(IN); while ($this_event = $this_parse->next_event) { local $type = $this_event->type; local $data = $this_event->data; print "${DBoff}Main-WHILE \$text='$text' \@text_elem = '".join(" ",@text_elem)."' " if ($debug_level > $DEBUG_DETAIL) ; SWITCH: { $type eq 'start_element' && do { if ($debug_level > $DEBUG_BRIEF) { print "${DBoff}start ".$data->name." "; ${DBoff} .= " "; } if ($data->name eq "UTF"){ &proc_beg_utf($data); } elsif ($data->name eq "BN_EPISODE_TRANS"){ &proc_beg_episode($data); } elsif ($data->name eq "CONVERSATION_TRANS"){ &proc_beg_converse($data); } elsif ($data->name eq "SECTION"){ &proc_beg_section($data); } elsif ($data->name eq "TURN"){ &proc_beg_turn($data); } elsif ($data->name eq "SEPARATOR"){ &proc_beg_separator($data); } elsif ($data->name eq "WTIME"){ &proc_beg_wtime($data); } elsif ($data->name eq "TIME"){ ; ## ignore for now } elsif ($data->name eq "COMMENT"){ $incomment = 1; } elsif ($data->name eq "BACKGROUND"){ &proc_beg_bkgrnd($data); } elsif ($data->name eq "CONTRACTION"){ &proc_beg_cont($data); } elsif ($data->name eq "FRAGMENT"){ &proc_beg_frag($data); } elsif ($data->name eq "HYPHEN"){ &proc_beg_hyphen($data); } elsif ($data->name =~ /($PUNCT_tags_re)/){ ### Pre-check, ASR tags ARE word separators &proc_beg_separator("") if ($text ne ""); } elsif ($data->name =~ /($TextAttribs_re)/){ &proc_beg_TextAttrib($1); } elsif ($data->name =~ /($NE_beg_tags_re)/){ &proc_beg_NE_tag($1,$data); } elsif ($data->name =~ /($NE_end_tags_re)/){ &proc_end_NE_tag($1,$data); } elsif ($data->name =~ /($ASR_beg_tags_re)/){ &proc_beg_ASR_tag($1,$data); } elsif ($data->name =~ /($ASR_end_tags_re)/){ &proc_end_ASR_tag($1,$data); } else { die "undefined start tag ".$data->name; } last SWITCH; }; $type eq 'end_element' && do { if ($debug_level > $DEBUG_BRIEF) { ${DBoff} =~ s/..$//; print "${DBoff}end ".$data->name." "; } if ($data->name eq "UTF"){ &proc_end_utf($data); } elsif ($data->name eq "BN_EPISODE_TRANS"){ &proc_end_episode(); } elsif ($data->name eq "CONVERSATION_TRANS"){ &proc_end_converse(); } elsif ($data->name eq "SECTION"){ &proc_end_section(); } elsif ($data->name eq "TURN"){ &proc_end_turn(); } elsif ($data->name eq "SEPARATOR"){ ; ## ignore for now } elsif ($data->name eq "WTIME"){ ; ## ignore for now } elsif ($data->name eq "TIME"){ ; ## ignore for now } elsif ($data->name eq "COMMENT"){ $incomment = 0; } elsif ($data->name eq "BACKGROUND"){ if ($debug_level > $DEBUG_DETAIL){ print "${DBoff} After BKG music=$bkgrnd_attr_stack{$MUSIC_KEY} ". "speech=$bkgrnd_attr_stack{$SPEECH_KEY} ". "other=$bkgrnd_attr_stack{$OTHER_KEY} " } ; ## ignore for now } elsif ($data->name eq "CONTRACTION"){ ; ## ignore for now } elsif ($data->name eq "FRAGMENT"){ ; ## ignore for now } elsif ($data->name eq "HYPHEN"){ ; ## ignore for now } elsif ($data->name =~ /($PUNCT_tags_re)/){ ; ## ignore for now } elsif ($data->name =~ /($TextAttribs_re)/){ ; ## ignore for now } elsif ($data->name =~ /($NE_beg_tags_re)/){ ; ## ignore for now } elsif ($data->name =~ /($NE_end_tags_re)/){ ; ## ignore for now } elsif ($data->name =~ /($ASR_beg_tags_re)/){ ; ## ignore for now } elsif ($data->name =~ /($ASR_end_tags_re)/){ ; ## ignore for now } else { die "undefined end tag ".$data->name; } last SWITCH; }; $type eq 'cdata' && do { print "${DBoff} CDATA ".$data." " if ($debug_level > $DEBUG_BRIEF); if ($incomment){ ; #### Skipping Comment } else { &proc_cdata($data); } last SWITCH; }; $type eq 're' && do { if ($incomment){ ; } last SWITCH; }; $type eq 'conforming' && do { $conformance = 1; last SWITCH; }; die "Undefined event occurred '$type' in file"; } } if ($conformance == 0) { die("Transcript file '$input' does not conform to DTD '$dtd_file'"); } # close input and output files # close (IN); close (OUT); # exit normally # exit 0; ######################################################## # subroutines ######################################################## sub proc_beg_utf{ local($data) = @_; local($key); for $key ($data->attribute_names) { if ($debug_level > $DEBUG_DETAIL) { print "${DBoff}Attribute: $key=" . (($data->attribute($key)->is_implied) ? "" : $data->attribute($key)->value) . " "; } # extract the filename for one of the fields in an stm turn # if ($key eq "AUDIO_FILENAME") { $filename = $data->attribute($key)->value; $filename =~ s/(\S+)\.\S+/$1/; # if value of FILENAME key is UNK, use the input filename # if (lc($filename) eq $UNKNOWN) { $filename = $input; } } } # initialize background conditions # $bkgrnd_attr_stack{$MUSIC_KEY} = $OFF; $bkgrnd_attr_stack{$SPEECH_KEY} = $OFF; $bkgrnd_attr_stack{$OTHER_KEY} = $OFF; $bkgrnd_attr_stack{$TURN_STIME_KEY} = 0; $music_level = $OFF; $speech_level = $OFF; $other_level = $OFF; # reset a variable that holds all the turns (of all the sections) # in an episode # @section_stack = (); } sub proc_end_utf{ if ($debug_level > $DEBUG_BRIEF) { print "${DBoff}End of Utf ----------- "; } # sort the turn by start time # @sorted_section_stack = sort proc_bystarttime @section_stack; # eliminate turns whose text field is empty # # &proc_del_turn(*sorted_section_stack); # fill in the gap between turns # &proc_fill_gap(*sorted_section_stack) if ($inter_segment_gap_enabled); # print the content of the stack # &proc_print_stack(OUT, $format, *sorted_section_stack); } sub proc_beg_episode{ local($data) = @_; local($key); for $key ($data->attribute_names) { if ($debug_level > $DEBUG_DETAIL) { print "${DBoff}Attribute: $key=" . $data->attribute($key)->value . " "; } } } sub proc_end_episode{ ; } sub proc_beg_section{ local($data) = @_; local $key; local $temp_key; %section_attr = (); for $key ($data->attribute_names) { if ($debug_level > $DEBUG_DETAIL) { print "${DBoff}Attribute: $key=" . (($data->attribute($key)->is_implied) ? "" : $data->attribute($key)->value) . " "; } # add the "SECTION_" in front of the original key to differentiate # key in a turn # $temp_key = "SECTION_" . $key; $section_attr{$temp_key} = ($data->attribute($key)->is_implied) ? "" : $data->attribute($key)->value; } # reset a variable that holds all the turns in a section # @turn_stack = (); } sub proc_end_section{ local %tmp_turn = (); # eliminate turns whose text field is empty # &proc_del_turn(*turn_stack); # check for overlap and zap it # if ($process_overlap) { &proc_elim_overlap(*turn_stack); } # save all the turns in a section in another variable # for ($i = 0; $i <= $#turn_stack; $i++) { %tmp_turn = (); for $key (keys %{$turn_stack[$i]}) { $tmp_turn{$key} = $turn_stack[$i]{$key}; } push @section_stack, { % tmp_turn }; } } sub proc_beg_converse{ local($data) = @_; local($key); ### Disable focus conditions $focus_condition_enabled = 0; $inter_segment_gap_enabled = 0; %section_attr = (); for $key ($data->attribute_names) { if ($debug_level > $DEBUG_DETAIL) { print "${DBoff}Attribute: $key=" . (($data->attribute($key)->is_implied) ? "" : $data->attribute($key)->value) . " "; } # add the "CONVERSATION_" in front of the original key to differentiate # key in a turn # $temp_key = "CONVERSATION_" . $key; $section_attr{$temp_key} = ($data->attribute($key)->is_implied) ? "" : $data->attribute($key)->value; } # reset a variable that holds all the turns in a section # @turn_stack = (); } sub proc_end_converse{ local %tmp_turn = (); # check for overlap and zap it # if ($process_overlap) { &proc_elim_overlap(*turn_stack); } # save all the turns in a section in another variable # for ($i = 0; $i <= $#turn_stack; $i++) { %tmp_turn = (); for $key (keys %{$turn_stack[$i]}) { $tmp_turn{$key} = $turn_stack[$i]{$key}; } push @section_stack, { % tmp_turn }; } } sub proc_beg_turn{ local($data) = @_; local ($key); for $key ($data->attribute_names) { if (! $data->attribute($key)->is_implied){ if ($debug_level > $DEBUG_DETAIL) { print "${DBoff}Attribute: $key=" . (($data->attribute($key)->is_implied) ? "" : $data->attribute($key)->value) . " "; } } else { if ($key eq "CHANNEL") { $num_chan = 1; } } } # reset all the variables that hold info for a turn # %turn_attr = (); %turn_elems = (); @text_elem = (); # keep the attributes of a turn # foreach $key (keys %section_attr) { $turn_elems{$key} = $section_attr{$key}; } foreach $key($data->attribute_names){ $turn_attr{$key} = ($data->attribute($key)->is_implied) ? "" : lc($data->attribute($key)->value); $turn_elems{$key} = $turn_attr{$key}; } $turn_elems{$FILENAME_KEY} = $filename; $turn_elems{$TURN_CHANNEL_KEY} = "1" if ($turn_elems{$TURN_CHANNEL_KEY} eq ""); $turn_attr{$TURN_CHANNEL_KEY} = "1" if ($turn_attr{$TURN_CHANNEL_KEY} eq ""); $turn_elems{$NUM_CHAN_KEY} = ($turn_elems{$TURN_CHANNEL_KEY} eq "") ? $num_chan : $turn_elems{$TURN_CHANNEL_KEY}; ### Ignore children for lur report if ($turn_elems{$SPKRTYPE_KEY} =~ /child/i){ $turn_elems{$SPKRTYPE_KEY} = ""; $turn_attr{$SPKRTYPE_KEY} = ""; } $turn_elems{$FOCUS_COND_KEY} = &proc_get_focus_cond( $turn_attr{$DIALECT_KEY}, $turn_attr{$FIDELITY_KEY}, $turn_attr{$MODE_KEY}, $bkgrnd_attr_stack{$MUSIC_KEY}, $bkgrnd_attr_stack{$SPEECH_KEY}, $bkgrnd_attr_stack{$OTHER_KEY}); $turn_elems{$TEXT_KEY} = ""; # we are in a middle of a turn # $in_turn = 1; # keep the turn unless otherwise # $kept_turn = 1; } sub proc_end_turn{ local $i; $turn_elems{$TEXT_KEY} = ""; # if cdata is preceded by the separator tag then we can put a space # after it, else do not but a space after. However, an acronym # is an exception to this rule. No separator precedes cdata but # we must put a space after each acronym. # For example, B. B. C.'s not B.B.C.'s. So if we put a space after # each acronym then when we get to 's the space after C. will show. # There is no way we can tell when the last acronym is read as we do # not do any lookahead but process each event as it is encountered. # So we output B.B.C.'s and go back and postprocess it to be B. B. C.'s # &proc_preproc_text (*text_elem); for ($i = 0; $i <= $#text_elem; $i++) { $turn_elems{$TEXT_KEY} .= $text_elem[$i] . " "; } if ($kept_turn) { push @turn_stack, { %turn_elems }; } # we are not in a turn # $in_turn = 0; } sub proc_beg_separator{ local($data) = @_; local $kept_text = 1; if ($text eq "") { $kept_text = 0; } if ($debug_level > $DEBUG_DETAIL) { print "${DBoff} ( "; } # Look for un-annotated contractions if ($translateContractions && ! defined($attr_stack{"CONTRACTION"})){ print "Warning: Possible non-annotated contraction \"$text\" " if ($text =~ /\w'\w+/ && $text !~ /\w's$/); } for $key(keys %attr_stack){ if ($debug_level > $DEBUG_DETAIL) { print "$key=".$attr_stack{$key} . " "; } # do not keep nonspeech # if ($key eq "NONSPEECH") { if ($deleteNonspeech){ $kept_text = 0; } else { $text = "{".$text; } } elsif ($key eq "ACOUSTICNOISE") { if ($deleteAcousticnoise){ $kept_text = 0; } else { $text = "\[".$text; } } # output (%hesitation) for nonlexeme # elsif ($key eq "NONLEXEME") { if ($translateNonlexemes){ ### This perserves any named entity tag appended to a hesitation $text =~ s/^[^<>]+/(%hesitation)/; $text =~ s/[^<>\(\)]+$/(%hesitation)/; } else { $text = "%".$text; } } # change contraction to full word # elsif ($key eq "CONTRACTION") { if ($translateContractions){ local $tmp_str = $attr_stack{$key}; $tmp_str =~ s/\s//g; $tmp_str =~ s/\S+=(\[.*)/$1/g; $tmp_str =~ s/\]\[/\] \[/g; local @tmp_data1 = split (/\s+/, $tmp_str); local $word; local $tag; local $val; foreach $word (@tmp_data1) { $word =~ s/\[(\S+)=>*(.*)\]/$1 $2/g; ($tag, $val) = split (/\s/, $word); $text =~ s/(.*)$tag(\.?)(.*)/$1 $val$2 $3/i; } $text =~ s/\s$//; } } } if ($debug_level > $DEBUG_DETAIL) { print "NE: "; foreach $key(sort(keys %ne_attr_stack)){ print "$key=".$ne_attr_stack{$key}." "; } print "ASR: "; foreach $key(sort(keys %asr_attr_stack)){ print "$key=".$asr_attr_stack{$key}." "; } print "BG: "; foreach $key(sort(keys %bkgrnd_attr_stack)){ print "$key=".$bkgrnd_attr_stack{$key}. " "; } print "\$text=$text kept_text=$kept_text) "; } if ($kept_text) { if ($parenthesize_text) { # check if there is a () around the word(s) already. # If so, take () off, split if multiple words, and put () # around each word. # if ($text =~ /\(([^\)]*)\)/) { $text = $1; } ### JGF: parenthisis fix local $newtext = ""; local $jword = ""; foreach $jword(ie_split ($text)){ $jword =~ s/^([^<> ]+)$/($1)/; $newtext .= " ".$jword; } $text = $newtext; } if ($use_wtag) { push (@text_elem, "STIME=$wtime_attr_stack{$TURN_STIME_KEY}"); push (@text_elem, "ETIME=$wtime_attr_stack{$TURN_ETIME_KEY}"); } push (@text_elem, $text); } # reset the text within separator tag # $text = ""; # reset attribute stack # %attr_stack = (); # reset wtime attribute stack # %wtime_attr_stack = (); print "${DBoff} final text arr '".join(" ",@text_elem)."' " if ($debug_level > $DEBUG_DETAIL); } sub proc_beg_wtime{ local($data) = @_; local ($key); foreach $key($data->attribute_names){ if (! $data->attribute($key)->is_implied){ $wtime_attr_stack{$key} = $data->attribute($key)->value; if ($debug_level > $DEBUG_DETAIL) { print "$key = $wtime_attr_stack{$key} "; } } } if ($debug_level > $DEBUG_DETAIL) { print " "; } } sub proc_beg_TextAttrib{ local($attrib) = @_; if ($debug_level > $DEBUG_BRIEF) { print " $attrib "; } # reset the attribute stack # $attr_stack{$attrib} = ""; } sub proc_cdata{ local($data) = @_; local($key); # add the text # $text .= $data; $text_flag = 1; for $key(keys %attr_stack){ # add ".@" after each letter of an acronym. Will convert @ to blank # later # if ($key eq "ACRONYM") { delete $attr_stack{$key}; # can't seem to make this work # # if ($text =~ /(.+)('ve|'s|'re|'m|n't|'ll|'d)/) { # $text =~ s/(.+)('ve|'s|'re|'m|n't|'ll|'d)/$1\.('ve|'s|'re|'m|n't|'ll|'d)/; # } # else { # $text .= ".@"; # } if ($text =~ /(.+)'s/i) { $text =~ s/(.+)('s)/$1\.$2/i; } elsif ($text =~ /(.+)s/i) { $text =~ s/(.+)(s)/$1\.$2/i; } else { $text .= ".@"; } } elsif ($key eq "FRAGMENT"){ $text = "(-$text)"; } } } sub proc_beg_frag{ local($data) = @_; local($newtext) = ""; &proc_beg_TextAttrib($data->name); foreach $word(ie_split($text)) { $newtext .= ($word =~ /^<.*>$/) ? $word : "($word-)"; } $text = $newtext; } sub proc_beg_hyphen{ local($data) = @_; # substitute hyphen for space. However, it's the same doing nothing # and treat the next cdata as a new word # if ($text !~ /\s$/) { $text .= " "; } $text =~ s:(<[^/<>]+>)\s+$:$1:; } sub proc_beg_NE_tag{ local($tag,$data) = @_; local($norm_tag) = $tag; $norm_tag =~ s/B_//; $ne_attr_stack{$norm_tag} = "<$norm_tag"; foreach $key($data->attribute_names){ if (! $data->attribute($key)->is_implied){ $ne_attr_stack{$norm_tag} .= " $key=\"".$data->attribute($key)->value."\""; } } $ne_attr_stack{$norm_tag} .= ">"; if ($format eq $IESTM || $format eq $IECTM || $format eq $IESM) { if ($text ne "" && $text !~ /\s$/){ $text .= " "; } $text .= $ne_attr_stack{$norm_tag}; } } sub proc_end_NE_tag{ local($tag,$data) = @_; local($norm_tag) = $tag; $norm_tag =~ s/E_//; delete $ne_attr_stack{$norm_tag}; if ($format eq $IESTM || $format eq $IECTM || $format eq $IESM) { if ($text =~ /\s$/){ $text =~ s/\s+$// ; $text .= "\<\/$norm_tag\> "; } else { $text .= "\<\/$norm_tag\>"; } } } sub proc_beg_ASR_tag{ local($tag,$data) = @_; local($norm_tag) = $tag; ### Pre-check, ASR tags ARE word separators &proc_beg_separator("") if ($text ne ""); $norm_tag =~ s/B_//; $asr_attr_stack{$norm_tag} = "<$norm_tag"; foreach $key($data->attribute_names){ next if ($key eq "STARTTIME" || $key eq "ENDTIME"); $asr_attr_stack{$norm_tag} .= " $key=" . ((! $data->attribute($key)->is_implied) ? $data->attribute($key)->value : "" ); } foreach $key($data->attribute_names){ next unless ($key eq "STARTTIME"); $asr_attr_stack{$norm_tag} .= " $key=" . ((! $data->attribute($key)->is_implied) ? $data->attribute($key)->value : "" ); } foreach $key($data->attribute_names){ next unless ($key eq "ENDTIME"); $asr_attr_stack{$norm_tag} .= " $key=" . ((! $data->attribute($key)->is_implied) ? $data->attribute($key)->value : "" ); } $asr_attr_stack{$norm_tag} .= ">"; # print "${DBoff} ASR stack $asr_attr_stack{$norm_tag} " # process overlap if flagged # # if ($process_overlap) { if (1) { # if overlap or noscore, divide each into individual turn and # eliminate later # if (($norm_tag eq "OVERLAP" && $process_overlap) || $norm_tag eq "NOSCORE" ){ local $starttime_tag; local $starttime; local $endtime_tag; local $endtime; if ($asr_attr_stack{$norm_tag} =~ /(STARTTIME)=(\S+)\s*(ENDTIME)=(\S+)\>/) { $starttime_tag = $1; $starttime = $2; $endtime_tag = $3; $endtime = $4; } else { die "Unable to process '$norm_tag' tags w/o times" } if ($turn_elems{$starttime_tag} != $starttime) { $turn_elems{$endtime_tag} = $starttime; $turn_elems{$TEXT_KEY} = ""; # see note in proc_end_turn routine # &proc_preproc_text (*text_elem); for ($i = 0; $i <= $#text_elem; $i++) { $turn_elems{$TEXT_KEY} .= $text_elem[$i] . " "; } push @turn_stack, { %turn_elems }; } %turn_elems = (); @text_elem = (); # copy prev attribute over # for $key (keys %section_attr) { $turn_elems{$key} = $section_attr{$key}; } for $key (keys %turn_attr) { $turn_elems{$key} = $turn_attr{$key}; } $turn_elems{$starttime_tag} = $starttime; $turn_elems{$endtime_tag} = $endtime; $turn_elems{$FILENAME_KEY} = $filename; $turn_elems{$NUM_CHAN_KEY} = $num_chan; $turn_elems{$FOCUS_COND_KEY} = &proc_get_focus_cond( $turn_attr{$DIALECT_KEY}, $turn_attr{$FIDELITY_KEY}, $turn_attr{$MODE_KEY}, $bkgrnd_attr_stack{$MUSIC_KEY}, $bkgrnd_attr_stack{$SPEECH_KEY}, $bkgrnd_attr_stack{$OTHER_KEY}); $turn_elems{$TEXT_KEY} = ""; } } elsif ($format eq $IECTM && (!$use_wtag) && ($norm_tag eq "OVERLAP" || $norm_tag eq "NOSCORE") && $#text_elem >= 0) { ### divide the turn here so that the inferred word time work out if ($asr_attr_stack{$norm_tag} =~ /(STARTTIME)=(\S+)\s*(ENDTIME)=(\S+)\>/) { $starttime_tag = $1; $starttime = $2; $endtime_tag = $3; $endtime = $4; #### flush the residual data $turn_elems{$endtime_tag} = $starttime; &proc_preproc_text (*text_elem); $turn_elems{$TEXT_KEY} .= join(" ",@text_elem) . " "; push @turn_stack, { %turn_elems }; # copy prev attribute over # for $key (keys %section_attr) { $turn_elems{$key} = $section_attr{$key}; } for $key (keys %turn_attr) { $turn_elems{$key} = $turn_attr{$key}; } $turn_elems{$starttime_tag} = $starttime; $turn_elems{$endtime_tag} = $endtime; $turn_elems{$FILENAME_KEY} = $filename; $turn_elems{$NUM_CHAN_KEY} = $num_chan; $turn_elems{$FOCUS_COND_KEY} = &proc_get_focus_cond( $turn_attr{$DIALECT_KEY}, $turn_attr{$FIDELITY_KEY}, $turn_attr{$MODE_KEY}, $bkgrnd_attr_stack{$MUSIC_KEY}, $bkgrnd_attr_stack{$SPEECH_KEY}, $bkgrnd_attr_stack{$OTHER_KEY}); $turn_elems{$TEXT_KEY} = ""; @text_elem = (); } } if ($norm_tag eq "FOREIGN" || $norm_tag eq "UNCLEAR") { $parenthesize_text = 1; } &dump_turn_stack() if ($debug_level > $DEBUG_DETAIL) ; } sub proc_end_ASR_tag{ local($tag,$data) = @_; local($norm_tag) = $tag; $norm_tag =~ s/E_//; ### Pre-check, ASR tags ARE word separators &proc_beg_separator("") if ($text ne ""); # print STDERR "==== text arr '".join(" ",@text_elem)."' "; # if ($process_overlap) { if (1) { if (($norm_tag eq "OVERLAP" && $process_overlap) || $norm_tag eq "NOSCORE") { $turn_elems{$SPEAKER_KEY} = $EXCLUDED_REGION; $turn_elems{$SPKRTYPE_KEY} = $UNKNOWN; $turn_elems{$FOCUS_COND_KEY} = ""; if ($keep_exclude_text){ $turn_elems{$TEXT_KEY} = join(" ",@text_elem)." "; } else { $turn_elems{$TEXT_KEY} = $IGNORE_TIME_SEGMENT_IN_SCORING; } push @turn_stack, { %turn_elems }; %turn_elems = (); @text_elem = (); # copy prev attribute over # for $key (keys %section_attr) { $turn_elems{$key} = $section_attr{$key}; } for $key (keys %turn_attr) { $turn_elems{$key} = $turn_attr{$key}; } if ($asr_attr_stack{$norm_tag} =~ /(STARTTIME)=(\S+)\s*(ENDTIME)=(\S+)\>/) { $starttime_tag = $1; $starttime = $2; $endtime_tag = $3; $endtime = $4; } if ($turn_elems{$endtime_tag} != $endtime) { $turn_elems{$starttime_tag} = $endtime; $turn_elems{$FILENAME_KEY} = $filename; $turn_elems{$NUM_CHAN_KEY} = $num_chan; $turn_elems{$FOCUS_COND_KEY} = &proc_get_focus_cond( $turn_attr{$DIALECT_KEY}, $turn_attr{$FIDELITY_KEY}, $turn_attr{$MODE_KEY}, $bkgrnd_attr_stack{$MUSIC_KEY}, $bkgrnd_attr_stack{$SPEECH_KEY}, $bkgrnd_attr_stack{$OTHER_KEY}); $turn_elems{$TEXT_KEY} = ""; } else { $kept_turn = 0; } } } elsif ($format eq $IECTM && (!$use_wtag) && ($norm_tag eq "OVERLAP" || $norm_tag eq "NOSCORE") && $#text_elem >= 0) { ### divide the turn here so that the inferred word time work out if ($asr_attr_stack{$norm_tag} =~ /(STARTTIME)=(\S+)\s*(ENDTIME)=(\S+)\>/) { $starttime_tag = $1; $starttime = $2; $endtime_tag = $3; $endtime = $4; #### flush the residual data $turn_elems{$endtime_tag} = $endtime; &proc_preproc_text (*text_elem); $turn_elems{$TEXT_KEY} .= join(" ",@text_elem) . " "; push @turn_stack, { %turn_elems }; # copy prev attribute over # for $key (keys %section_attr) { $turn_elems{$key} = $section_attr{$key}; } for $key (keys %turn_attr) { $turn_elems{$key} = $turn_attr{$key}; } $turn_elems{$starttime_tag} = $endtime; $turn_elems{$endtime_tag} = $turn_attr{$endtime_tag}; $turn_elems{$FILENAME_KEY} = $filename; $turn_elems{$NUM_CHAN_KEY} = $num_chan; $turn_elems{$FOCUS_COND_KEY} = &proc_get_focus_cond( $turn_attr{$DIALECT_KEY}, $turn_attr{$FIDELITY_KEY}, $turn_attr{$MODE_KEY}, $bkgrnd_attr_stack{$MUSIC_KEY}, $bkgrnd_attr_stack{$SPEECH_KEY}, $bkgrnd_attr_stack{$OTHER_KEY}); $turn_elems{$TEXT_KEY} = ""; @text_elem = (); } } # parenthesize the text if foreign or unclear # if ($norm_tag eq "FOREIGN" || $norm_tag eq "UNCLEAR") { $parenthesize_text = 0; } delete $asr_attr_stack{$norm_tag}; # print "==== exit text arr '".join(" ",@text_elem)."' "; &dump_turn_stack() if ($debug_level > $DEBUG_DETAIL) ; } sub dump_turn_stack{ my $ji; my $jkey; #### Turn stack for ($ji=0; $ji<=$#turn_stack; $ji++){ print "Turn $ji "; foreach $jkey(sort(keys %{ $turn_stack[$ji] } )){ print " $jkey=$turn_stack[$ji]{$jkey} "; } } } sub proc_beg_cont{ local($data) = @_; $attr_stack{$data->name} = ""; foreach $key($data->attribute_names){ if (! $data->attribute($key)->is_implied){ $attr_stack{$data->name} .= "$key=" . $data->attribute($key)->value . " "; } } } sub proc_beg_bkgrnd{ local($data) = @_; my $cur_focus_cond; ### my $x1; print "Begin_bkgnd: "; foreach $x1(sort(keys %turn_elems)){print " $x1 -> '$turn_elems{$x1}' "; } } # get the current focus condition. The reason is that sometimes # the level of noise changing from high->low or low->high is not # enough to split the turn. When they do split the turn (high/low->off # or off->high/low) the focus condition is still the # condition before high->low or low->high changes. We need to get the # focus condition after the high->low and vice versa changes but before # the high/low->off and vice versa changes # if ($debug_level > $DEBUG_DETAIL){ print "${DBoff} Before BKG music=$bkgrnd_attr_stack{$MUSIC_KEY} ". "speech=$bkgrnd_attr_stack{$SPEECH_KEY} ". "other=$bkgrnd_attr_stack{$OTHER_KEY} " } if ($in_turn) { $cur_focus_cond = &proc_get_focus_cond( $turn_attr{$DIALECT_KEY}, $turn_attr{$FIDELITY_KEY}, $turn_attr{$MODE_KEY}, $bkgrnd_attr_stack{$MUSIC_KEY}, $bkgrnd_attr_stack{$SPEECH_KEY}, $bkgrnd_attr_stack{$OTHER_KEY}); } ### I believe this is BAD, it should be ... #local $mlevel = $music_level; #local $slevel = $speech_level; #local $olevel = $other_level; local $mlevel = ($bkgrnd_attr_stack{$MUSIC_KEY} eq "off") ? "off" : "on"; local $slevel = ($bkgrnd_attr_stack{$SPEECH_KEY} eq "off") ? "off" : "on"; local $olevel = ($bkgrnd_attr_stack{$OTHER_KEY} eq "off") ? "off" : "on"; #### local $bkgrnd_prev_stime = $bkgrnd_attr_stack{$TURN_STIME_KEY}; foreach $key($data->attribute_names){ if (! $data->attribute($key)->is_implied){ if (lc($data->attribute($key)->value) eq "music") { $bkgrnd_attr_stack{$MUSIC_KEY} = lc($data->attribute($LEVEL_KEY)->value); if ($bkgrnd_attr_stack{$MUSIC_KEY} eq $HIGH || $bkgrnd_attr_stack{$MUSIC_KEY} eq $LOW) { $mlevel = $ON; } else { $mlevel = $OFF; } } elsif (lc($data->attribute($key)->value) eq "speech") { $bkgrnd_attr_stack{$SPEECH_KEY} = lc($data->attribute($LEVEL_KEY)->value); if ($bkgrnd_attr_stack{$SPEECH_KEY} eq $HIGH || $bkgrnd_attr_stack{$SPEECH_KEY} eq $LOW) { $slevel = $ON; } else { $slevel = $OFF; } } elsif (lc($data->attribute($key)->value) eq "other") { $bkgrnd_attr_stack{$OTHER_KEY} = lc($data->attribute($LEVEL_KEY)->value); if ($bkgrnd_attr_stack{$OTHER_KEY} eq $HIGH || $bkgrnd_attr_stack{$OTHER_KEY} eq $LOW) { $olevel = $ON; } else { $olevel = $OFF; } } elsif ($key eq $TURN_STIME_KEY) { $bkgrnd_attr_stack{$TURN_STIME_KEY} = $data->attribute($key)->value; } } } if ($in_turn) { if ($debug_level > $DEBUG_DETAIL){ print " ??? should i Dividing Turn "; print " if ($music_level ne $mlevel || $speech_level ne $slevel ||". " $other_level ne $olevel || (!$text_flag &&". " ($bkgrnd_attr_stack{$TURN_STIME_KEY} - ". "$turn_elems{$TURN_ETIME_KEY} > $THRESHOLD))) "; } if ($music_level ne $mlevel || $speech_level ne $slevel || $other_level ne $olevel || (!$text_flag && ($bkgrnd_attr_stack{$TURN_STIME_KEY} - $turn_elems{$TURN_ETIME_KEY} > $THRESHOLD))) { print " Dividing Turn " if ($debug_level > $DEBUG_DETAIL); local $starttime = $turn_elems{$TURN_ETIME_KEY}; if ($text_flag == 0) { $turn_elems{$TURN_ETIME_KEY} = $bkgrnd_prev_stime; } else { $turn_elems{$TURN_ETIME_KEY} = $bkgrnd_attr_stack{$TURN_STIME_KEY}; } local $i; $turn_elems{$FOCUS_COND_KEY} = $cur_focus_cond; $turn_elems{$TEXT_KEY} = ""; # see note in proc_end_turn routine # &proc_preproc_text (*text_elem); for ($i = 0; $i <= $#text_elem; $i++) { $turn_elems{$TEXT_KEY} .= $text_elem[$i] . " "; } push @turn_stack, { %turn_elems }; ### { my $x1; print "About to push: "; foreach $x1(sort(keys %turn_elems)){print " $x1 -> '$turn_elems{$x1}' "; } } %turn_elems = (); @text_elem = (); # copy prev attribute over # for $key (keys %section_attr) { $turn_elems{$key} = $section_attr{$key}; } for $key (keys %turn_attr) { $turn_elems{$key} = $turn_attr{$key}; } $turn_elems{$TURN_STIME_KEY} = $bkgrnd_attr_stack{$TURN_STIME_KEY}; $turn_elems{$TURN_ETIME_KEY} = $starttime; $turn_elems{$FILENAME_KEY} = $filename; $turn_elems{$NUM_CHAN_KEY} = $num_chan; $turn_elems{$FOCUS_COND_KEY} = &proc_get_focus_cond( $turn_attr{$DIALECT_KEY}, $turn_attr{$FIDELITY_KEY}, $turn_attr{$MODE_KEY}, $bkgrnd_attr_stack{$MUSIC_KEY}, $bkgrnd_attr_stack{$SPEECH_KEY}, $bkgrnd_attr_stack{$OTHER_KEY}); } } $music_level = $mlevel; $speech_level = $slevel; $other_level = $olevel; $text_flag = 0; } # determine if two segments, i and j, are overlapping. # two segments can be of the situations below: # # i ############### #1 j ########## no overlapped # j #### #2 j ############ overlap begin j end i # j ################ #3 j ######################## j # j ############################## j #4 j ######### i # j ############### i #5 j ################### j #6 j ####### i # j ########### i #7 j ############### overlap begin i end j #8 j ##### no overlapped # # return : an array of 3 items # no overlap or overlap, begin time, and end time # sub proc_is_overlap{ local ($btime_i, $etime_i, $chan_i, $btime_j, $etime_j, $chan_j) = @_; # print "($btime_i, $etime_i, $chan_i, $btime_j, $etime_j, $chan_j) "; local @return_val = (); # Initial case # if ($chan_i ne $chan_j) { push(@return_val, $NO_OVERLAP); push(@return_val, 0); push(@return_val, 0); return (@return_val); } # case 1 # if ($btime_i eq $etime_j || ($btime_i - $etime_j) > -0.0001) { push(@return_val, $NO_OVERLAP); push(@return_val, 0); push(@return_val, 0); return (@return_val); } # case 8 # elsif ($btime_j eq $etime_i || ($btime_j - $etime_i) > -0.0001) { push(@return_val, $NO_OVERLAP); push(@return_val, 0); push(@return_val, 0); return (@return_val); } # case 2,3,4,5,6,7 # else { # case 2,3 # if ($btime_j < $btime_i) { # case 2 # if ($etime_j < $etime_i) { push(@return_val, $OVERLAP); push(@return_val, $btime_j); push(@return_val, $etime_i); return (@return_val); } # case 3 # else { push(@return_val, $OVERLAP); push(@return_val, $btime_j); push(@return_val, $etime_j); return (@return_val); } } # case 4,5,6,7 # else { # case 4,5 # if ($btime_j == $btime_i) { # case 4 # if ($etime_j < $etime_i) { push(@return_val, $OVERLAP); push(@return_val, $btime_i); push(@return_val, $etime_i); return (@return_val); } # case 5 # else { push(@return_val, $OVERLAP); push(@return_val, $btime_j); push(@return_val, $etime_j); return (@return_val); } } # case 6,7 # else { # case 6 # if ($etime_j <= $etime_i) { push(@return_val, $OVERLAP); push(@return_val, $btime_i); push(@return_val, $etime_i); return (@return_val); } # case 7 # else { push(@return_val, $OVERLAP); push(@return_val, $btime_i); push(@return_val, $etime_j); return (@return_val); } } } } } sub proc_elim_overlap{ local(*stack) = @_; local $i; local $j; local @status = (); # find the maximum overlap if any # for ($i = 0; $i < $#stack; $i++) { for ($j = $i+1; $j <= $#stack && $stack[$j]{$TURN_STIME_KEY}-5 < $stack[$i]{$TURN_ETIME_KEY}; $j++) { @status = &proc_is_overlap($stack[$i]{$TURN_STIME_KEY}, $stack[$i]{$TURN_ETIME_KEY}, $stack[$i]{$TURN_CHANNEL_KEY}, $stack[$j]{$TURN_STIME_KEY}, $stack[$j]{$TURN_ETIME_KEY}, $stack[$j]{$TURN_CHANNEL_KEY}); if ($status[0] != $NO_OVERLAP) { if ($debug_level > $DEBUG_DETAIL) { print "${DBoff} Found Overlapped turns "; print "${DBoff} ".join(" ",%{ $stack[$i] })." "; print "${DBoff} ".join(" ",%{ $stack[$j] })." "; } ### Convert $i to an exclude tag $stack[$i]{$SPEAKER_KEY} = $EXCLUDED_REGION; $stack[$i]{$SPKRTYPE_KEY} = $UNKNOWN; $stack[$i]{$TURN_STIME_KEY} = &MIN($stack[$i]{$TURN_STIME_KEY}, $stack[$j]{$TURN_STIME_KEY}); $stack[$i]{$TURN_ETIME_KEY} = &MAX($stack[$i]{$TURN_ETIME_KEY}, $stack[$j]{$TURN_ETIME_KEY}); $stack[$i]{$FOCUS_COND_KEY} = ""; if ($keep_exclude_text) { $stack[$i]{$TEXT_KEY} .= " - $stack[$j]{$TEXT_KEY}"; } else { $stack[$i]{$TEXT_KEY} = $IGNORE_TIME_SEGMENT_IN_SCORING; } ### Delete Stack element $j splice(@stack,$j,1); ### Decriment $j to reflect the deletion $j--; } } } } sub write_stm_header{ local ($fp) = @_; local $cat = 0; print $fp ";; CATEGORY \"$cat\" \"\" \"\" "; print $fp ";; LABEL \"O\" \"Overall\" \"Overall\" "; print $fp ";; "; $cat ++; if ($focus_condition_enabled) { print $fp ";; CATEGORY \"$cat\" \"Hub4 Focus Conditions\" \"\" "; print $fp ";; LABEL \"F0\" \"Baseline//Broadcast//Speech\" \"\" "; print $fp ";; LABEL \"F1\" \"Spontaneous//Broadcast//Speech\" \"\" "; print $fp ";; LABEL \"F2\" \"Speech Over//Telephone//Channels\" \"\" "; print $fp ";; LABEL \"F3\" \"Speech in the//Presence of//Background Music\" \"\" "; print $fp ";; LABEL \"F4\" \"Speech Under//Degraded//Acoustic Conditions\" \"\" "; print $fp ";; LABEL \"F5\" \"Speech from//Non-Native//Speakers\" \"\" "; print $fp ";; LABEL \"FX\" \"All other speech\" \"\" "; $cat ++; } print $fp ";; CATEGORY \"$cat\" \"Speaker Sex\" \"\" "; print $fp ";; LABEL \"female\" \"Female\" \"\" "; print $fp ";; LABEL \"male\" \"Male\" \"\" "; print $fp ";; LABEL \"child\" \"Child\" \"\" "; print $fp ";; LABEL \"$UNKNOWN\" \"Unknown\" \"\" "; $cat++; } sub proc_print_stack{ local($fp, $format, *stack) = @_; local $i; if ($format eq $IESTM || $format eq $STM) { &write_stm_header($fp); &proc_print_stm($fp, *stack); } elsif ($format eq $IESM || $format eq $SM) { &proc_print_stm_sm_u($fp, *stack); } # do some post processing to get ctm format # elsif ($format eq $IECTM || $format eq $CTM) { if ($use_wtag) { &proc_stm2ctm_wspec ($fp, *stack); } else { &proc_stm2ctm_wavg ($fp, *stack); } } } sub proc_get_focus_cond{ local($dialect, $fidelity, $mode, $music_lvl, $speech_lvl, $other_lvl) = @_; local $focus_cond = ""; # determine focus condition from dialect, fidelity, mode, and background # attributes # # F0, F1, F2, F3, F4, FX # if ($dialect eq "$NATIVE") { # F0, F1, F3, F4, FX # if ($fidelity eq $HIGH) { # F0, F1, FX # if ($music_lvl eq $OFF && $speech_lvl eq $OFF && $other_lvl eq $OFF) { # F0 # if ($mode eq "$PLANNED") { $focus_cond = "f0"; } # F1 # elsif ($mode eq "$SPONTANEOUS") { $focus_cond = "f1"; } # FX # else { $focus_cond = "fx"; } } # F3 # elsif ($music_lvl ne $OFF && $speech_lvl eq $OFF && $other_lvl eq $OFF) { $focus_cond = "f3"; } # F4 # elsif ($music_lvl eq $OFF && ($speech_lvl ne $OFF || $other_lvl ne $OFF)) { $focus_cond = "f4"; } # FX # else { $focus_cond = "fx"; } } # F2, FX # else { # F2 # if ($music_lvl eq $OFF && $speech_lvl eq $OFF && $other_lvl eq $OFF) { $focus_cond = "f2"; } # FX # else { $focus_cond = "fx"; } } } # F5, FX # else { # F5, FX # if ($fidelity eq $HIGH) { # F5 # if ($music_lvl eq $OFF && $speech_lvl eq $OFF && $other_lvl eq $OFF) { if ($mode eq "$PLANNED") { $focus_cond = "f5"; } # FX # else { $focus_cond = "fx"; } } else { $focus_cond = "fx"; } } # FX # else { $focus_cond = "fx"; } } die "Error: Focus condition not assigned" if ($focus_cond eq ""); return ($focus_cond); } sub proc_fill_gap{ local(*stack) = @_; local $i = 0; local $key; local %tmp_turn = (); while ($i < $#stack) { %tmp_turn = (); # there's a gap # if ($stack[$i+1]{$TURN_STIME_KEY} - $stack[$i]{$TURN_ETIME_KEY} > $THRESHOLD) { $tmp_turn{$SECTION_STIME_KEY} = -1; $tmp_turn{$SECTION_ETIME_KEY} = -1; $tmp_turn{$SECTION_TYPE_KEY} = $UNKNOWN; $tmp_turn{$SECTION_ID_KEY} = $UNKNOWN; $tmp_turn{$FILENAME_KEY} = $filename; $tmp_turn{$NUM_CHAN_KEY} = $num_chan; $tmp_turn{$SPEAKER_KEY} = $INTER_SEGMENT_GAP; $tmp_turn{$SPKRTYPE_KEY} = ""; $tmp_turn{$FOCUS_COND_KEY} = "fx"; $tmp_turn{$TURN_CHANNEL_KEY} = $stack[$i]{$TURN_CHANNEL_KEY}; $tmp_turn{$TURN_STIME_KEY} = $stack[$i]{$TURN_ETIME_KEY}; $tmp_turn{$TURN_ETIME_KEY} = $stack[$i+1]{$TURN_STIME_KEY}; $tmp_turn{$TEXT_KEY} = ""; splice @stack, $i+1, 0, { % tmp_turn }; } $i++; } } sub proc_bystarttime { %ah = %{ $a }; %bh = %{ $b }; if ($ah{$TURN_CHANNEL_KEY} ne $bh{$TURN_CHANNEL_KEY}){ $ah{$TURN_CHANNEL_KEY} cmp $bh{$TURN_CHANNEL_KEY}; } else { $ah{$TURN_STIME_KEY} <=> $bh{$TURN_STIME_KEY}; } } sub proc_preproc_text{ local(*stack) = @_; local $i; local $j; print "---- before preprec_text '".join("^",@stack)."' " if ($debug_level > $DEBUG_DETAIL) ; for ($i = 0; $i <= $#stack; $i++) { $stack[$i] =~ s/\.@(['< ])/.$1/g; # $stack[$i] =~ s/\.@([^@])/.+$1/g; $stack[$i] =~ s/@\)/)/g; $stack[$i] =~ s/@/ /g; } print "---- after preprec_text '".join("^",@stack)."' " if ($debug_level > $DEBUG_DETAIL) ; } sub proc_del_turn{ local(*stack) = @_; local $i = 0; # kill turns whose text field is empty # while ($i <= $#stack) { if ($stack[$i]{$TEXT_KEY} =~ /^\s*$/) { splice @stack, $i, 1; } else { $i++; } } } sub proc_dump_stack { local (*stack) = @_; my ($k); for ($i = 0; $i <= $#stack; $i++) { print "----------------------------------------------------- "; foreach $k(sort(keys %{ $stack[$i] })){ print "Stack $i: $k -> '$stack[$i]{$k}' "; } } } sub proc_print_stm { local ($fp, *stack) = @_; # proc_dump_stack(*stack); for ($i = 0; $i <= $#stack; $i++) { print $fp "$stack[$i]{$FILENAME_KEY} "; print $fp "$stack[$i]{$TURN_CHANNEL_KEY} "; print $fp "$stack[$i]{$SPEAKER_KEY} "; printf $fp ("%.6f ", $stack[$i]{$TURN_STIME_KEY}); printf $fp ("%.6f ", $stack[$i]{$TURN_ETIME_KEY}); print $fp "<o"; if ($focus_condition_enabled) { print $fp ",$stack[$i]{$FOCUS_COND_KEY}"; } print $fp ",$stack[$i]{$SPKRTYPE_KEY}"; print $fp "> "; print $fp "$stack[$i]{$TEXT_KEY} "; } } sub proc_print_stm_sm_u { local ($fp, *stack) = @_; local $prev_stime = -1; local $prev_etime = -1; local $temp_focus_cond = ""; for ($i = 0; $i <= $#stack; $i++) { if (($stack[$i]{$SECTION_STIME_KEY} != $prev_stime) && ($stack[$i]{$SECTION_ETIME_KEY} != $prev_etime) && ($stack[$i]{$SECTION_STIME_KEY} != -1)) { if ($i != 0) { print $fp "</Section> "; } printf $fp ("<Section Type=%s S_time=%.6f E_time=%.6f id=%s> ", $stack[$i]{$SECTION_TYPE_KEY}, $stack[$i]{$SECTION_STIME_KEY}, $stack[$i]{$SECTION_ETIME_KEY}, $stack[$i]{$SECTION_ID_KEY}); $prev_stime = $stack[$i]{$SECTION_STIME_KEY}; $prev_etime = $stack[$i]{$SECTION_ETIME_KEY}; } print $fp "$stack[$i]{$FILENAME_KEY} "; print $fp "$stack[$i]{$TURN_CHANNEL_KEY} "; print $fp "$stack[$i]{$SPEAKER_KEY} "; printf $fp ("%.6f ", $stack[$i]{$TURN_STIME_KEY}); printf $fp ("%.6f ", $stack[$i]{$TURN_ETIME_KEY}); $temp_focus_cond = "<o"; if ($focus_condition_enabled) { $temp_focus_cond .= ",".$stack[$i]{$FOCUS_COND_KEY}; } $temp_focus_cond .= ",$stack[$i]{$SPKRTYPE_KEY}"; $temp_focus_cond .= ">"; print $fp "$temp_focus_cond "; print $fp "$stack[$i]{$TEXT_KEY} "; } print $fp "</Section> "; } sub proc_stm2ctm_wavg{ local ($fp, *stack) = @_; local $i; local $j; local $stime; local $duration; local @num_words = (); local $tmp_str = ""; for ($i = 0; $i <= $#stack; $i++) { if (($stack[$i]{$TEXT_KEY} ne $IGNORE_TIME_SEGMENT_IN_SCORING) && ($stack[$i]{$SPEAKER_KEY} ne $INTER_SEGMENT_GAP)) { $stime = $stack[$i]{$TURN_STIME_KEY}; @num_words = (); ### Delete optionally deletable words!!!! # ($newtext = $stack[$i]{$TEXT_KEY}) =~ s/\([^\(\)]*\)//g; ### Convert optionally deletable words to normal words ($newtext = $stack[$i]{$TEXT_KEY}) =~ s/[\(\)]//g; foreach $word(ie_split($newtext)) { if ($word !~ /^\s*$/){ push(@num_words,$word) if ($word !~ /^(-\S+|\S+-)$/); } } ### splice back together # for ($j=0; $j<$#num_words; $j++){ # if ($num_words[$j] =~ /<(ENAMEX|TIMEX|NUMEX)/i){ # if ($num_words[$j] !~ /<\/(ENAMEX|TIMEX|NUMEX)>/i){ # $num_words[$j] .= "#".splice(@num_words,$j+1,1); # $j--; # } # } # } # ALD FIX # for ($j=0; $j<$#num_words; $j++){ # if ($num_words[$j] =~ /<(ENAMEX|TIMEX|NUMEX)/i){ # $num_words[$j] .= splice(@num_words,$j+1,1); # } elsif ($num_words[$j] =~ /<\/(ENAMEX|TIMEX|NUMEX)>/i){ # $num_words[$j-1] .= splice(@num_words,$j,1); # $j--; # } # } for ($j=0; $j<$#num_words; $j++){ if ($num_words[$j] =~ /^<(ENAMEX|TIMEX|NUMEX)[^<>]*>$/i){ $num_words[$j] .= splice(@num_words,$j+1,1); } elsif ($num_words[$j] =~ /^<\/(ENAMEX|TIMEX|NUMEX)[^<>]*>$/i){ $num_words[$j-1] .= splice(@num_words,$j,1); $j--; } } print "${DBoff} stm2ctm wavg: ~".join("~",@num_words)."~ " if ($debug_level > $DEBUG_DETAIL) ; # ### $num_words = $#num_words + 1; if ($#num_words < 0) { print "Warning: number of words is zero "; next; } $duration = ($stack[$i]{$TURN_ETIME_KEY} - $stack[$i]{$TURN_STIME_KEY})/($#num_words+1); for ($j = 0; $j <= $#num_words; $j++) { if ($num_words[$j] =~ /\(\S+\)/) { next; } # elsif ($num_words[$j] =~ /<ENAMEX|<TIMEX|<NUMEX\s*$/) { # $tmp_str = "$num_words[$j] "; # } else { print $fp "$stack[$i]{$FILENAME_KEY} "; print $fp "$stack[$i]{$NUM_CHAN_KEY} "; printf $fp ("%.6f ", $stime); printf $fp ("%.6f ", $duration); $tmp_str .= $num_words[$j]; print $fp "$tmp_str "; $tmp_str = ""; } $stime = $stime + $duration; } } } } sub proc_stm2ctm_wspec{ local ($fp, *stack) = @_; local $i; local $j; local @num_words = (); for ($i = 0; $i <= $#stack; $i++) { if ($stack[$i]{$TEXT_KEY} ne $IGNORE_TIME_SEGMENT_IN_SCORING) { @num_words = (); @num_words = split(/STIME=/, $stack[$i]{$TEXT_KEY}); print "${DBoff} stm2ctm wspec: ~".join("~",@num_words)."~ " if ($debug_level > $DEBUG_DETAIL) ; for ($j = 0; $j <= $#num_words; $j++) { ### Remove all optionally deletable markers $num_words[$j] =~ s/[\(\)]//g; $num_words[$j] =~ s/ETIME=//g; if ($num_words[$j] =~ /(\d+\.\d+)\s+(\d+\.\d+)\s+\(\S+\)$/) { next; } elsif ($num_words[$j] =~ /(\d+\.\d+)\s+(\d+\.\d+)\s+(\S+)(<[^<>]+>)/) { print $fp "$stack[$i]{$FILENAME_KEY} "; print $fp "$stack[$i]{$NUM_CHAN_KEY} "; printf $fp ("%.6f %.6f %s ", $1, $2-$1, $3.$4); } elsif ($num_words[$j] =~ /(\d+\.\d+)\s+(\d+\.\d+)\s+(<[^<>]+>\S+<[^<>]+>)/) { print $fp "$stack[$i]{$FILENAME_KEY} "; print $fp "$stack[$i]{$NUM_CHAN_KEY} "; printf $fp ("%.6f %.6f %s ", $1, $2-$1, $3); } elsif ($num_words[$j] =~ /(\d+\.\d+)\s+(\d+\.\d+)\s+(<[^<>]+>)(\S+)/) { print $fp "$stack[$i]{$FILENAME_KEY} "; print $fp "$stack[$i]{$NUM_CHAN_KEY} "; printf $fp ("%.6f %.6f %s ", $1, $2-$1, $3.$4); } elsif ($num_words[$j] =~ /(\d+\.\d+)\s+(\d+\.\d+)\s+(.+$)/) { print $fp "$stack[$i]{$FILENAME_KEY} "; print $fp "$stack[$i]{$NUM_CHAN_KEY} "; printf $fp ("%.6f %.6f %s ", $1, $2-$1, $3); } } } } } sub MAX{ local(@a) = @_; local($max) = -99e9; while ($#a >= 0){ $max = $a[0] if ($max < $a[0]); splice(@a,0,1); } $max; } sub MIN{ local(@a) = @_; local($min) = 99e9; while ($#a >= 0){ # print " $a[0] "; $min = $a[0] if ($min > $a[0]); splice(@a,0,1); } $min; } #### tokenize a text stream by whitespace while respecting sgml tags sub ie_split{ local($text) = @_; local(@a) = (); local($i); # ALD FIX # @a = split(/(\s+|">|<\/)/,$text); # for ($i=0; $i<=$#a; $i++){ # if ($a[$i] =~ /^[^<]*<[^>]*$/){ # $a[$i] .= splice(@a,$i+1,1); # $i--; # } # } # " # tag regexp my $t = "<(?:(?:\\\"[^\\\"]*\\\")|[^<>])*>"; # cdata regexp my $d = '[^ <>]+'; @a = ($text =~ m( $t | $d(?:$t$d)+ | $d )xiog ); @a; } |