File: | modules/Text/xxml.cc |
Location: | line 125, column 5 |
Description: | Value stored to 'utt' is never read |
1 | /*************************************************************************/ |
2 | /* */ |
3 | /* Centre for Speech Technology Research */ |
4 | /* University of Edinburgh, UK */ |
5 | /* Copyright (c) 1996,1997 */ |
6 | /* All Rights Reserved. */ |
7 | /* */ |
8 | /* Permission is hereby granted, free of charge, to use and distribute */ |
9 | /* this software and its documentation without restriction, including */ |
10 | /* without limitation the rights to use, copy, modify, merge, publish, */ |
11 | /* distribute, sublicense, and/or sell copies of this work, and to */ |
12 | /* permit persons to whom this work is furnished to do so, subject to */ |
13 | /* the following conditions: */ |
14 | /* 1. The code must retain the above copyright notice, this list of */ |
15 | /* conditions and the following disclaimer. */ |
16 | /* 2. Any modifications must be clearly marked as such. */ |
17 | /* 3. Original authors' names are not deleted. */ |
18 | /* 4. The authors' names are not used to endorse or promote products */ |
19 | /* derived from this software without specific prior written */ |
20 | /* permission. */ |
21 | /* */ |
22 | /* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */ |
23 | /* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */ |
24 | /* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */ |
25 | /* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */ |
26 | /* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */ |
27 | /* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */ |
28 | /* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */ |
29 | /* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */ |
30 | /* THIS SOFTWARE. */ |
31 | /* */ |
32 | /*************************************************************************/ |
33 | /* Author : Alan W Black */ |
34 | /* Date : August 1997 */ |
35 | /*-----------------------------------------------------------------------*/ |
36 | /* */ |
37 | /* There are just too many different versions of sgml-based mark up */ |
38 | /* and none of them are stable so this is allows arbitrary */ |
39 | /* of tags to Lisp functions so any of them can be implemented in Lisp */ |
40 | /* That is people can worry about the actual content later and do not */ |
41 | /* need to change the C++ */ |
42 | /* */ |
43 | /* Of course once I give you this functionality you'll just want more */ |
44 | /* */ |
45 | /*=======================================================================*/ |
46 | #include "EST_unix.h" |
47 | #include "festival.h" |
48 | #include "text.h" |
49 | #include "lexicon.h" |
50 | |
51 | using namespace std; |
52 | |
53 | static LISP xxml_get_attribute(const EST_String &remainder); |
54 | static char *xxml_process_line(const char *line); |
55 | static void tts_xxml_token(EST_Item *t); |
56 | static void tts_xxml_utt(LISP lutt); |
57 | |
58 | static LISP xxml_word_features = NIL((struct obj *) 0); |
59 | static LISP xxml_token_hooks = NIL((struct obj *) 0); |
60 | |
61 | void tts_file_xxml(LISP filename) |
62 | { |
63 | // For stml ssml rsml and jsml etc |
64 | // filename contains *output* from something like nsgml |
65 | EST_String inname = get_c_string(filename); |
66 | EST_String line, type, remainder; |
67 | EST_TokenStream ts; |
68 | LISP atts, element_defs; |
69 | LISP utt = NIL((struct obj *) 0); // for cummulation of tokens |
70 | |
71 | if (ts.open(inname) == -1) |
72 | { |
73 | cerr << "xxml: unable to open output from SGML parser" << endl; |
74 | festival_error()(errjmp_ok ? longjmp(*est_errjmp,1) : festival_tidy_up(),exit (-1)); |
75 | } |
76 | ts.set_WhiteSpaceChars(" \t\r\n"); |
77 | ts.set_SingleCharSymbols(""); |
78 | ts.set_PunctuationSymbols(""); |
79 | ts.set_PrePunctuationSymbols(""); |
80 | |
81 | element_defs = siod_get_lval("xxml_elements",NULL__null); |
82 | atts = NIL((struct obj *) 0); |
83 | |
84 | if (ts.peek() != get_c_string(car(car(element_defs)))) |
85 | { |
86 | cerr << "xxml parse error: " << get_c_string(filename) << |
87 | " Expected " << get_c_string(car(car(element_defs))) |
88 | << " but found " << ts.peek() << endl; |
89 | festival_error()(errjmp_ok ? longjmp(*est_errjmp,1) : festival_tidy_up(),exit (-1)); |
90 | } |
91 | while (ts.peek() != get_c_string(car(car(cdr(element_defs))))) |
92 | { |
93 | if (ts.eof()) |
94 | { |
95 | cerr << "xxml parse error: unexpected end of file \n"; |
96 | festival_error()(errjmp_ok ? longjmp(*est_errjmp,1) : festival_tidy_up(),exit (-1)); |
97 | } |
98 | line = (EST_String)ts.get_upto_eoln(); |
99 | type = line.at(0,1); |
100 | remainder = line.after(0); |
101 | if (type == "-") |
102 | { // Segments into utterances as it goes along |
103 | utt = xxml_get_tokens(remainder, |
104 | siod_get_lval("xxml_word_features",NULL__null), |
105 | utt); |
106 | } |
107 | else if (type == "A") // general attribute |
108 | { |
109 | atts = cons(xxml_get_attribute(remainder),atts); |
110 | } |
111 | else if ((type == "(") || (type == ")")) |
112 | { |
113 | utt = xxml_call_element_function(type+remainder,atts, |
114 | element_defs,utt); |
115 | atts = NIL((struct obj *) 0); |
116 | } |
117 | else |
118 | { |
119 | cerr << "xxml parse error: unexpected token found " |
120 | << line << endl; |
121 | festival_error()(errjmp_ok ? longjmp(*est_errjmp,1) : festival_tidy_up(),exit (-1)); |
122 | } |
123 | } |
124 | // Last call (should synthesize trailing tokens |
125 | utt = xxml_call_element_function(ts.get().string(),atts,element_defs,utt); |
Value stored to 'utt' is never read | |
126 | |
127 | ts.close(); |
128 | } |
129 | |
130 | LISP xxml_call_element_function(const EST_String &element, |
131 | LISP atts, LISP elements, LISP utt) |
132 | { |
133 | // Form the call to the defined element function, with the attributes |
134 | // and the utterance, returns the utterance |
135 | LISP def,l; |
136 | |
137 | def = siod_assoc_str(element,elements); |
138 | |
139 | if (def != NIL((struct obj *) 0)) |
140 | { |
141 | // You get two arguments, ATTLIST and UTTERANCE |
142 | l = cons( |
143 | make_param_lisp("ATTLIST", |
144 | cons(rintern("quote"),cons(atts,NIL((struct obj *) 0)))), |
145 | cons( |
146 | make_param_lisp("UTT", |
147 | cons(rintern("quote"),cons(utt,NIL((struct obj *) 0)))), |
148 | NIL((struct obj *) 0))); |
149 | return leval(cons(rintern("let"), |
150 | cons(l,cdr(cdr(def)))),NIL((struct obj *) 0)); |
151 | } |
152 | else // no definition to do nothing |
153 | return utt; |
154 | } |
155 | |
156 | static LISP xxml_get_attribute(const EST_String &remainder) |
157 | { |
158 | EST_TokenStream ts; |
159 | LISP tokens=NIL((struct obj *) 0),att=NIL((struct obj *) 0); |
160 | EST_String name; |
161 | EST_Token t; |
162 | |
163 | ts.open_string(remainder); |
164 | name = (EST_String)ts.get(); |
165 | if ((t=ts.get()) == "IMPLIED") |
166 | att = cons(rintern(name),cons(NIL((struct obj *) 0),NIL((struct obj *) 0))); |
167 | else if (t == "TOKEN") |
168 | { |
169 | EST_Token v = ts.get(); |
170 | att = cons(rintern(name),cons(cons(rintern(v.string()),NIL((struct obj *) 0)),NIL((struct obj *) 0))); |
171 | } |
172 | else if (t == "CDATA") |
173 | { |
174 | while (!ts.eof()) |
175 | tokens = cons(rintern(ts.get().string()),tokens); |
176 | att = cons(rintern(name),cons(reverse(tokens),NIL((struct obj *) 0))); |
177 | } |
178 | else |
179 | { |
180 | cerr << "XXML: unknow attribute type " << remainder << endl; |
181 | festival_error()(errjmp_ok ? longjmp(*est_errjmp,1) : festival_tidy_up(),exit (-1)); |
182 | } |
183 | |
184 | ts.close(); |
185 | return att; |
186 | } |
187 | |
188 | static char *xxml_process_line(const char *line) |
189 | { |
190 | // STML (sgml) data line have a number of special escape characters |
191 | // this undoes them, namely "\\n" to "\n" |
192 | char *procline = walloc(char,strlen(line)+1)((char *)safe_walloc(sizeof(char)*(strlen(line)+1))); |
193 | int i,j; |
194 | |
195 | for (i=j=0; line[i] != '\0'; j++,i++) |
196 | { |
197 | if (line[i] == '\\') |
198 | { |
199 | i++; |
200 | if (line[i] == 'n') |
201 | procline[j] = '\n'; |
202 | else if (line[i] == '\\') |
203 | procline[j] = '\\'; |
204 | else if ((line[i] == '0') || // its an octal number |
205 | (line[i] == '1')) |
206 | { |
207 | int k,oct = 0; |
208 | for (k=0; k < 3; k++,i++) |
209 | oct = (oct*8)+(line[i]-'0'); |
210 | procline[j] = oct; |
211 | i--; |
212 | } |
213 | else |
214 | { |
215 | procline[j] = line[i]; // no change |
216 | i--; |
217 | } |
218 | } |
219 | else |
220 | procline[j] = line[i]; // no change |
221 | } |
222 | procline[j] = '\0'; |
223 | return procline; |
224 | } |
225 | |
226 | static void tts_xxml_token(EST_Item *t) |
227 | { |
228 | // Add xxml_word features to t |
229 | LISP a; |
230 | |
231 | for (a=xxml_word_features; a != NIL((struct obj *) 0); a=cdr(a)) |
232 | if ((car(cdr(car(a))) != NIL((struct obj *) 0)) && |
233 | (!streq("NAME",get_c_string(car(car(a))))(strcmp("NAME",get_c_string(car(car(a))))==0))) |
234 | { |
235 | if (cdr(cdr(car(a))) == NIL((struct obj *) 0)) |
236 | t->set(get_c_string(car(car(a))), |
237 | get_c_string(car(cdr(car(a))))); |
238 | else |
239 | { |
240 | // Its more complex than a single atom so save the list |
241 | t->set(get_c_string(car(car(a))), |
242 | siod_sprint(car(cdr(car(a))))); |
243 | } |
244 | } |
245 | |
246 | apply_hooks(xxml_token_hooks,siod(t)); |
247 | } |
248 | |
249 | LISP xxml_get_tokens(const EST_String &line,LISP feats,LISP utt) |
250 | { |
251 | // Read from here until end of line collects all the tokens |
252 | // Note tokens are in reverse order until they are made into an |
253 | // utterance |
254 | EST_TokenStream ls; |
255 | EST_Token t; |
256 | LISP eou_tree; |
257 | char *processed_line; |
258 | processed_line = xxml_process_line(line); |
259 | ls.open_string(processed_line); |
260 | ls.set_SingleCharSymbols( |
261 | get_c_string(siod_get_lval("token.singlecharsymbols", |
262 | "token.singlecharsymbols unset"))); |
263 | ls.set_PunctuationSymbols( |
264 | get_c_string(siod_get_lval("token.punctuation", |
265 | "token.punctuation unset"))); |
266 | ls.set_PrePunctuationSymbols( |
267 | get_c_string(siod_get_lval("token.prepunctuation", |
268 | "token.prepunctuation unset"))); |
269 | ls.set_WhiteSpaceChars( |
270 | get_c_string(siod_get_lval("token.whitespace", |
271 | "token.whitespace unset"))); |
272 | |
273 | eou_tree = siod_get_lval("eou_tree","No end of utterance tree set"); |
274 | |
275 | xxml_word_features = feats; |
276 | xxml_token_hooks = siod_get_lval("xxml_token_hooks",NULL__null); |
277 | |
278 | // Segment and synth as much as appropriate |
279 | utt = tts_chunk_stream(ls,tts_xxml_token,tts_xxml_utt,eou_tree,utt); |
280 | |
281 | return utt; |
282 | } |
283 | |
284 | static void tts_xxml_utt(LISP lutt) |
285 | { |
286 | // Build and utterance with these tokens and apply xxml synth function |
287 | |
288 | if ((lutt == NIL((struct obj *) 0)) || |
289 | (get_c_utt(lutt)(utterance(lutt))->relation("Token")->length() == 0)) |
290 | return; // in this case do nothing. |
291 | |
292 | leval(cons(rintern("xxml_synth"), |
293 | cons(quote(lutt),NIL((struct obj *) 0))),NIL((struct obj *) 0)); |
294 | } |
295 |