Debian Codegraph @

tools/clunit_prune

raw
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
39 # Assume units_used.out contains the units used in by example text
40 # Mark all these units (and all previous units to them) used
41
42 UNIT_CATALOGUE=$1
43 UNIT_TREES=$2
44 UNITS_USED=$3
45
46 # Prune the catalogue
47 cat $UNIT_CATALOGUE |
48 awk '{ if (past_header != 1)
49 {
50 print $0;
51 if ($1 == "EST_Header_End")
52 past_header = 1;
53 }}' >${UNIT_CATALOGUE}.pruned
54 ( cat $UNITS_USED ; echo end_used ;
55 sed '1,/EST_Header_End/d' $UNIT_CATALOGUE ) |
56 awk '{ if ($1 == "end_used" )
57 {
58 end_used = 1;
59 }
60 else if (end_used != 1)
61 used[$1] = 1;
62 else
63 {
64 if (last_entry == "")
65 true;
66 else if (used[$1] == 1)
67 {
68 print last_entry;
69 }
70 else if (used[last_unit] != 1)
71 {
72 printf("0_0 %s %s %s %s\n",last_2,last_3,last_4,last_5);
73 }
74 else
75 {
76 print last_entry;
77 }
78 last_entry = $0;
79 last_unit = $1;
80 last_2 = $2;
81 last_3 = $3;
82 last_4 = $4;
83 last_5 = $5;
84 }
85 }' >>${UNIT_CATALOGUE}.pruned
86
87 # Prune the trees
88 cat $UNITS_USED |
89 sed 's/_[0-9][0-9]*$/_&/;s/__/ /' |
90 sort |
91 awk '{if (l != $1)
92 {
93 if (NR > 1)
94 printf(")\n");
95 printf("( \"%s\" ",$1);
96 }
97 printf("%s ",$2);
98 l = $1;
99 }
100 END {printf(")\n");}' >${UNITS_USED}.sorted
101
102 $ESTDIR/../festival/bin/festival --heap 10000000 -b $FLITEDIR/tools/make_clunits.scm \
103 '(clunits_prune "'$UNIT_TREES'" "'${UNITS_USED}.sorted'" "'${UNIT_TREES}.pruned'")'
104