clunit_prune 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #!/bin/sh
  2. ###########################################################################
  3. ## ##
  4. ## Language Technologies Institute ##
  5. ## Carnegie Mellon University ##
  6. ## Copyright (c) 2002-2010 ##
  7. ## All Rights Reserved. ##
  8. ## ##
  9. ## Permission is hereby granted, free of charge, to use and distribute ##
  10. ## this software and its documentation without restriction, including ##
  11. ## without limitation the rights to use, copy, modify, merge, publish, ##
  12. ## distribute, sublicense, and/or sell copies of this work, and to ##
  13. ## permit persons to whom this work is furnished to do so, subject to ##
  14. ## the following conditions: ##
  15. ## 1. The code must retain the above copyright notice, this list of ##
  16. ## conditions and the following disclaimer. ##
  17. ## 2. Any modifications must be clearly marked as such. ##
  18. ## 3. Original authors' names are not deleted. ##
  19. ## 4. The authors' names are not used to endorse or promote products ##
  20. ## derived from this software without specific prior written ##
  21. ## permission. ##
  22. ## ##
  23. ## CARNEGIE MELLON UNIVERSITY AND THE CONTRIBUTORS TO THIS WORK ##
  24. ## DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ##
  25. ## ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT ##
  26. ## SHALL CARNEGIE MELLON UNIVERSITY NOR THE CONTRIBUTORS BE LIABLE ##
  27. ## FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES ##
  28. ## WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN ##
  29. ## AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ##
  30. ## ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF ##
  31. ## THIS SOFTWARE. ##
  32. ## ##
  33. ###########################################################################
  34. ## ##
  35. ## Prune the clunits catalogue basic on usage ##
  36. ## ##
  37. ###########################################################################
  38. # Assume units_used.out contains the units used in by example text
  39. # Mark all these units (and all previous units to them) used
  40. UNIT_CATALOGUE=$1
  41. UNIT_TREES=$2
  42. UNITS_USED=$3
  43. # Prune the catalogue
  44. cat $UNIT_CATALOGUE |
  45. awk '{ if (past_header != 1)
  46. {
  47. print $0;
  48. if ($1 == "EST_Header_End")
  49. past_header = 1;
  50. }}' >${UNIT_CATALOGUE}.pruned
  51. ( cat $UNITS_USED ; echo end_used ;
  52. sed '1,/EST_Header_End/d' $UNIT_CATALOGUE ) |
  53. awk '{ if ($1 == "end_used" )
  54. {
  55. end_used = 1;
  56. }
  57. else if (end_used != 1)
  58. used[$1] = 1;
  59. else
  60. {
  61. if (last_entry == "")
  62. true;
  63. else if (used[$1] == 1)
  64. {
  65. print last_entry;
  66. }
  67. else if (used[last_unit] != 1)
  68. {
  69. printf("0_0 %s %s %s %s\n",last_2,last_3,last_4,last_5);
  70. }
  71. else
  72. {
  73. print last_entry;
  74. }
  75. last_entry = $0;
  76. last_unit = $1;
  77. last_2 = $2;
  78. last_3 = $3;
  79. last_4 = $4;
  80. last_5 = $5;
  81. }
  82. }' >>${UNIT_CATALOGUE}.pruned
  83. # Prune the trees
  84. cat $UNITS_USED |
  85. sed 's/_[0-9][0-9]*$/_&/;s/__/ /' |
  86. sort |
  87. awk '{if (l != $1)
  88. {
  89. if (NR > 1)
  90. printf(")\n");
  91. printf("( \"%s\" ",$1);
  92. }
  93. printf("%s ",$2);
  94. l = $1;
  95. }
  96. END {printf(")\n");}' >${UNITS_USED}.sorted
  97. $ESTDIR/../festival/bin/festival --heap 10000000 -b $FLITEDIR/tools/make_clunits.scm \
  98. '(clunits_prune "'$UNIT_TREES'" "'${UNITS_USED}.sorted'" "'${UNIT_TREES}.pruned'")'