Debian Codegraph @

lang/cmu_indic_lang/cmu_indic_lang.c

raw
1 /*************************************************************************/
2 /* */
3 /* Language Technologies Institute */
4 /* Carnegie Mellon University */
5 /* Copyright (c) 2013 */
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 /* CARNEGIE MELLON UNIVERSITY 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 CARNEGIE MELLON UNIVERSITY 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 /* */
34 /* indic language support */
35 /* */
36 /*************************************************************************/
37 #include "flite.h"
38 #include "cst_val.h"
39 #include "cst_voice.h"
40 #include "cst_lexicon.h"
41 #include "cst_ffeatures.h"
42 #include "cmu_indic_lang.h"
43 #include "cst_tokenstream.h"
44
45 /* ./bin/compile_regexes cst_rx_eng_digits_only "^[0-9,]+$" */
46 static const unsigned char cst_rx_eng_digits_only_rxprog[] = {
47 156, 6, 0, 27, 1, 0, 3, 11, 0, 18, 4, 0, 0, 48, 49, 50,
48 51, 52, 53, 54, 55, 56, 57, 44, 0, 2, 0, 3, 0, 0, 0,
49 };
50 static const cst_regex cst_rx_eng_digits_only_rx = {
51 0, 1, NULL, 0, 31,
52 (char *)cst_rx_eng_digits_only_rxprog
53 };
54 const cst_regex * const cst_rx_eng_digits_only = &cst_rx_eng_digits_only_rx;
55
56 /* ./bin/compile_regexes cst_rx_not_indic "^[0-9a-zA-Z/:_'-,]+$" */
57 static const unsigned char cst_rx_not_indic_rxprog[] = {
58 156, 6, 0, 87, 1, 0, 3, 11, 0, 78, 4, 0, 0, 48, 49, 50,
59 51, 52, 53, 54, 55, 56, 57, 97, 98, 99, 100, 101, 102, 103, 104, 105,
60 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121,
61 122, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
62 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 47, 58, 95, 39, 40,
63 41, 42, 43, 44, 0, 2, 0, 3, 0, 0, 0,
64 };
65 static const cst_regex cst_rx_not_indic_rx = {
66 0, 1, NULL, 0, 91,
67 (char *)cst_rx_not_indic_rxprog
68 };
69 const cst_regex * const cst_rx_not_indic = &cst_rx_not_indic_rx;
70
71 /* ./bin/compile_regexes cst_rx_indic_eng_number "^[1-9][0-9],\\([0-9][0-9],\\)*[0-9][0-9][0-9]$" */
72 static const unsigned char cst_rx_indic_eng_number_rxprog[] = {
73 156, 6, 0, 137, 1, 0, 3, 4, 0, 13, 49, 50, 51, 52, 53, 54,
74 55, 56, 57, 0, 4, 0, 14, 48, 49, 50, 51, 52, 53, 54, 55, 56,
75 57, 0, 8, 0, 5, 44, 0, 6, 0, 48, 21, 0, 3, 6, 0, 36,
76 4, 0, 14, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 0, 4, 0,
77 14, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 0, 8, 0, 5, 44,
78 0, 31, 0, 3, 7, 0, 45, 6, 0, 3, 9, 0, 3, 4, 0, 14,
79 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 0, 4, 0, 14, 48, 49,
80 50, 51, 52, 53, 54, 55, 56, 57, 0, 4, 0, 14, 48, 49, 50, 51,
81 52, 53, 54, 55, 56, 57, 0, 2, 0, 3, 0, 0, 0,
82 };
83 static const cst_regex cst_rx_indic_eng_number_rx = {
84 0, 1, NULL, 0, 141,
85 (char *)cst_rx_indic_eng_number_rxprog
86 };
87 const cst_regex * const cst_rx_indic_eng_number = &cst_rx_indic_eng_number_rx;
88
89 cst_val *us_tokentowords(cst_item *token);
90
91 /* Note that's an ascii | not the devangari one */
92 const cst_string * const indic_postpunctuationsymbols = "\"'`.,:;!?(){}[]|";
93
94 static cst_val *cmu_indic_tokentowords_one(cst_item *token, const char *name);
95 cst_val *cmu_indic_tokentowords(cst_item *token) {
96 return cmu_indic_tokentowords_one(token, item_feat_string(token, "name"));
97 }
98
99 /* Indic numbers. This deals with all (quantity) numbers found in any Indic */
100 /* language no matter what script they are written in. We use the Indic_Nums */
101 /* table to convert the strings of digits (points and commas) into lists of */
102 /* words for those scripts' language. Thus Telugu digits get converted to */
103 /* Telugu words (even if the voice is a Hindi voice). */
104 /* We assume use lakh and crore examples when there is commas to identify */
105 /* thus 10,34,123 (in English digits) will be expanded to 10 lakh, thirty */
106 /* four thousand one hundred (and) twenty three */
107
108 /* We do English too, so I can debug it, and so lakh and crore are right */
109 #include "indic_eng_num_table.h"
110 #include "indic_hin_num_table.h"
111 #include "indic_guj_num_table.h"
112 #include "indic_kan_num_table.h"
113 #include "indic_mar_num_table.h"
114 #include "indic_san_num_table.h"
115 #include "indic_tel_num_table.h"
116 #include "indic_tam_num_table.h"
117 #include "indic_pan_num_table.h"
118
119
120 int ts_utf8_sequence_length(char c0);
121 // inline int utf8_sequence_length(char c0)
122 // {
123 // Get the expected length of UTF8 sequence given its most
124 // significant byte
125 // return (( 0xE5000000 >> (( c0 >> 3 ) & 0x1E )) & 3 ) + 1;
126 // }
127
128
129 int ts_utf8_sequence_length(char c0);
130 // inline int utf8_sequence_length(char c0)
131 // {
132 // Get the expected length of UTF8 sequence given its most
133 // significant byte
134 // return (( 0xE5000000 >> (( c0 >> 3 ) & 0x1E )) & 3 ) + 1;
135 // }
136
137
138 int indic_digit_to_offset(const char *ind_digit)
139 {
140 /* This functions returns int value of a single digit in Indic/English scripts.
141 Also, it returns -1 if the character isn't a digit */
142
143 int output=-1;
144 int i;
145 int offset=-1;
146
147 i = cst_utf8_ord_string(ind_digit);
148
149 if ((i >= 0x0030) && (i <= 0x0039)) /*ASCII*/
150 offset = 0x0030;
151 if ((i >= 0x0966) && (i <= 0x096F)) /*Devanagari*/
152 offset = 0x0966;
153 if ((i >= 0x09E6) && (i <= 0x09EF)) /*Bengali*/
154 offset = 0x09E6;
155 if ((i >= 0x0A66) && (i <= 0x0A6F)) /*Gurmukhi*/
156 offset = 0x0A66;
157 if ((i >= 0x0AE6) && (i <= 0x0AEF)) /*Gujarati*/
158 offset = 0x0AE6;
159 if ((i >= 0x0B66) && (i <= 0x0B6F)) /*Oriya*/
160 offset = 0x0B66;
161 if ((i >= 0x0BE6) && (i <= 0x0BEF)) /*Tamil*/
162 offset = 0x0BE6;
163 if ((i >= 0x0C66) && (i <= 0x0C6F)) /*Telugu*/
164 offset = 0x0C66;
165 if ((i >= 0x0CE6) && (i <= 0x0CEF)) /*Kannada*/
166 offset = 0x0CE6;
167 if ((i >= 0x0D66) && (i <= 0x0D6F)) /*Malayalam*/
168 offset = 0x0D66;
169
170 if (offset == -1)
171 {
172 /* Not a digit */
173 return -1;
174 }
175
176 output = i - offset;
177
178 return output;
179 }
180
181 static cst_val *indic_number_digit(const char *digit,const indic_num_table *t)
182 {
183 int i;
184
185 if ((digit == NULL) || (t == NULL))
186 return NULL;
187
188 i = indic_digit_to_offset(digit);
189
190 if (i == -1)
191 {
192 printf("Error in getting int from digit %s\n", digit);
193 return NULL;
194 }
195
196 /* The ith array index corresponds to the exact single digit number*/
197 return cons_val(string_val(num_table_digit(t,i,1)),NULL);
198 }
199
200 static cst_val *indic_number_two_digit(const char *digit1,
201 const char *digit2,
202 const indic_num_table *t)
203 {
204 int i,j;
205 cst_val *r = NULL;
206
207 if ((digit1 == NULL) || (digit2 == NULL) || (t == NULL))
208 return NULL;
209
210 i = indic_digit_to_offset(digit1);
211
212 j = indic_digit_to_offset(digit2);
213
214 if (i == -1)
215 {
216 printf("Error in getting int from digit %s\n", digit1);
217 return NULL;
218 }
219
220 if (j == -1)
221 {
222 printf("Error in getting int from digit %s\n", digit2);
223 return NULL;
224 }
225
226 if (i == 0)
227 {
228 printf("Single digit erroneously processed as double digit %s\n", digit2);
229 return cons_val(string_val(num_table_digit(t,i,1)),NULL);
230 }
231
232
233 /*10*(i-1)+j given correct two digit index*/
234 if (num_table_two_digit(t,10*(i-1)+j,3) != NULL)
235 r = cons_val(string_val(num_table_two_digit(t,10*(i-1)+j,3)),r);
236 if (num_table_two_digit(t,10*(i-1)+j,2) != NULL)
237 r = cons_val(string_val(num_table_two_digit(t,10*(i-1)+j,2)),r);
238
239 return r;
240 }
241
242 static cst_val *indic_number_lang(const indic_num_table *num_table)
243 {
244 return string_val(num_table->lang);
245 }
246 static cst_val *indic_number_hundred(const indic_num_table *num_table)
247 {
248 return string_val(num_table->hundred);
249 }
250 static cst_val *indic_number_thousand(const indic_num_table *num_table)
251 {
252 return string_val(num_table->thousand);
253 }
254 static cst_val *indic_number_lakh(const indic_num_table *num_table)
255 {
256 return string_val(num_table->lakh);
257 }
258 static cst_val *indic_number_crore(const indic_num_table *num_table)
259 {
260 return string_val(num_table->crore);
261 }
262
263 cst_val *indic_number(const cst_val *number,
264 const indic_num_table *num_table)
265 {
266 cst_val *r = NULL;
267 /* so its a number in some script (we actually don't care which script) */
268
269 #if 0
270 printf("awb_debug enter indic num ");
271 val_print(stdout,number); printf("\n");
272 #endif
273
274
275 if (number == NULL)
276 r = NULL;
277 /* If zero is the penultimate digit */
278 else if ((indic_digit_to_offset(val_string(val_car(number))) == 0) &&
279 (val_length(number) == 2))
280 {
281 /* If the last digit is non-zero */
282 if (indic_digit_to_offset(val_string(val_car(val_cdr(number)))) != 0)
283 {
284 r = indic_number_digit(val_string(val_car(val_cdr(number))),num_table);
285 }
286 else
287 {
288 /* So it doesn't say zero in the end*/
289 }
290 }
291 /* If the current digit is a 0 and there is a next digit */
292 else if ((indic_digit_to_offset(val_string(val_car(number))) == 0) &&
293 (val_cdr(number) != NULL))
294
295 {
296 r = indic_number(val_cdr(number),num_table);
297 }
298 else if (val_length(number) == 1)
299 {
300 r = indic_number_digit(val_string(val_car(number)),num_table);
301 }
302 else if (val_length(number) == 2)
303 {
304 r = indic_number_two_digit(val_string(val_car(number)),
305 val_string(val_car(val_cdr(number))),
306 num_table);
307 }
308 else if (val_length(number) == 3)
309 {
310 if ((!cst_streq(val_string(indic_number_lang(num_table)),"mar")) ||
311 indic_digit_to_offset(val_string(val_car(val_cdr(number)))) ||
312 indic_digit_to_offset(val_string(val_car(val_cdr(val_cdr(number))))))
313 r = val_append(indic_number_digit(val_string(val_car(number)),num_table),
314 cons_val(indic_number_hundred(num_table),
315 indic_number(val_cdr(number),num_table)));
316 else
317 r = val_append(indic_number_digit(val_string(val_car(number)),num_table),
318 cons_val(string_val("शंभर"), indic_number(val_cdr(number),num_table)));
319 }
320 else if (val_length(number) == 4)
321 {
322 r = val_append(indic_number_digit(val_string(val_car(number)),num_table),
323 cons_val(indic_number_thousand(num_table),
324 indic_number(val_cdr(number),num_table)));
325 }
326 else if (val_length(number) == 5)
327 {
328 r = val_append(indic_number_two_digit(val_string(val_car(number)),
329 val_string(val_car(val_cdr(number))),
330 num_table),
331 cons_val(indic_number_thousand(num_table),
332 indic_number(val_cdr(val_cdr(number)),num_table)));
333 }
334 else if (val_length(number) == 6)
335 {
336 r = val_append(indic_number_digit(val_string(val_car(number)),num_table),
337 cons_val(indic_number_lakh(num_table),
338 indic_number(val_cdr(number),num_table)));
339 }
340 else if (val_length(number) == 7)
341 {
342 r = val_append(indic_number_two_digit(val_string(val_car(number)),
343 val_string(val_car(val_cdr(number))),
344 num_table),
345 cons_val(indic_number_lakh(num_table),
346 indic_number(val_cdr(val_cdr(number)),num_table)));
347 }
348 else if (val_length(number) == 8)
349 {
350 r = val_append(indic_number_digit(val_string(val_car(number)),num_table),
351 cons_val(indic_number_crore(num_table),
352 indic_number(val_cdr(number),num_table)));
353 }
354 else if (val_length(number) == 9)
355 {
356 r = val_append(indic_number_two_digit(val_string(val_car(number)),
357 val_string(val_car(val_cdr(number))),
358 num_table),
359 cons_val(indic_number_crore(num_table),
360 indic_number(val_cdr(val_cdr(number)),num_table)));
361 }
362
363 #if 0
364 printf("awb_debug end of indic num ");
365 val_print(stdout,r); printf("\n");
366 #endif
367
368 return r;
369 }
370
371 cst_val *indic_number_indiv(const cst_val *number,
372 const indic_num_table *num_table)
373 {
374 cst_val *r = NULL;
375 /* Exapnd this as a string of digits (not an actual quantity) */
376
377 if (number == NULL)
378 r = NULL;
379 else
380 {
381 r = val_append(indic_number_digit(val_string(val_car(number)),num_table),
382 indic_number_indiv(val_cdr(number),num_table));
383 }
384
385 return r;
386 }
387
388 #if 0
389 static int indic_nump_old(const char *number)
390 {
391 /* True if all (unicode) characters are in num_table's digit table */
392 /* or is a comma or dot */
393 cst_val *p;
394 const cst_val *q;
395 int i;
396 int flag = TRUE;
397 int fflag;
398
399 p = cst_utf8_explode(number);
400 for (q=p; q && (flag==TRUE); q=val_cdr(q))
401 {
402 fflag = FALSE;
403 for (i=0; i<10; i++)
404 {
405 if (indic_digit_to_offset(val_string(val_car(q))) != -1)
406 {
407 fflag = TRUE;
408 break;
409 }
410 }
411 if ((cst_streq(val_string(val_car(q)),",")) ||
412 /* English zeros sometimes occur */
413 (cst_streq(val_string(val_car(q)),"0")))
414 fflag = TRUE;
415 flag = fflag;
416 }
417 delete_val(p); p = NULL;
418
419 return flag;
420
421 }
422 #endif
423
424
425 static int indic_nump(const char *number)
426 {
427 /* Check if non-empty string */
428 if (!number[0])
429 return FALSE;
430
431 /* Catch lone commas */
432 if (number[0] == ',')
433 return indic_nump(&number[1]);
434
435
436 /* Returns 2 if all characters are numbers or commas */
437 /* Returns 1 if it starts with a number */
438 cst_val *p;
439 const cst_val *q;
440 int flag = TRUE;
441 int fflag;
442 int ffflag = FALSE; /* Switches to TRUE at first digit found */
443
444 p = cst_utf8_explode(number);
445 for (q=p; q && (flag==TRUE); q=val_cdr(q))
446 {
447 fflag = FALSE;
448 if (indic_digit_to_offset(val_string(val_car(q))) != -1)
449 {
450 fflag = TRUE;
451 ffflag = TRUE;
452 }
453
454 else if (cst_streq(val_string(val_car(q)),","))
455 fflag = TRUE;
456 flag = fflag;
457 }
458 delete_val(p); p = NULL;
459
460 return flag+ffflag;
461
462 }
463
464 static int indic_hyphenated(const char *number)
465 {
466 /* Returns positive if first character is , - / and is followed by a */
467 /* number */
468 int flag = 0;
469 if ((number[0] == '-') || (number[0] == '/') || (number[0] == '.'))
470 flag = indic_nump(&number[1]);
471 return flag;
472 }
473
474 static int indic_text_splitable(const char *s,int i,int len1)
475 {
476 /* Returns true only if this and next chars are not both digits */
477 /* or both non-digits */
478
479 char *ccc, *ddd; /* Store this character and the next character */
480 int len2; /* Length of next character */
481
482 int flag;
483
484 ccc = cst_strdup(&s[i]);
485 ddd = cst_strdup(&s[i+len1]);
486
487 len2 = ts_utf8_sequence_length(ddd[0]);
488
489 ccc[len1] = '\0';
490 ddd[len2] = '\0';
491
492 /* Makeshift NOR */
493 flag = (indic_digit_to_offset(ccc) == -1)? !(indic_digit_to_offset(ddd) == -1):
494 (indic_digit_to_offset(ddd) == -1);
495
496 cst_free(ccc);
497 cst_free(ddd);
498
499 return flag;
500 }
501
502
503
504
505 static cst_val *indic_num_normalize(const char *number,
506 const indic_num_table *num_table)
507 {
508 /* Remove , */
509 cst_val *p, *np;
510 const cst_val *q;
511
512 p = cst_utf8_explode(number);
513 np = NULL;
514 for (q=p; q; q=val_cdr(q))
515 {
516 if (!cst_streq(val_string(val_car(q)),","))
517 np = cons_val(string_val(val_string(val_car(q))),np);
518 }
519 delete_val(p);
520 return val_reverse(np);
521 }
522
523 static cst_val *cmu_indic_tokentowords_one(cst_item *token, const char *name)
524 {
525 /* Return list of words that expand token/name */
526 cst_val *r, *p;
527 const indic_num_table *num_table;
528 const char *variant;
529 cst_utterance *utt;
530
531 /* printf("awb_debug token_name %s name %s\n",item_name(token),name); */
532 r = NULL;
533
534 if (item_feat_present(token,"phones"))
535 return cons_val(string_val(name),NULL);
536
537 #if 0
538 if (item_feat_present(token,"nsw"))
539 nsw = item_feat_string(token,"nsw");
540
541 utt = item_utt(token);
542 lex = val_lexicon(feat_val(utt->features,"lexicon"));
543 #endif
544 utt = item_utt(token);
545 variant = get_param_string(utt->features, "variant", "none");
546 if (cst_streq(variant,"hin"))
547 num_table = &hin_num_table;
548 else if (cst_streq(variant,"guj"))
549 num_table = &guj_num_table;
550 else if (cst_streq(variant,"kan"))
551 num_table = &kan_num_table;
552 else if (cst_streq(variant,"mar"))
553 num_table = &mar_num_table;
554 else if (cst_streq(variant,"nep"))
555 num_table = &hin_num_table;
556 else if (cst_streq(variant, "pan"))
557 num_table = &pan_num_table;
558 else if (cst_streq(variant, "san"))
559 num_table = &san_num_table;
560 else if (cst_streq(variant,"tam"))
561 num_table = &tam_num_table;
562 else if (cst_streq(variant,"tel"))
563 num_table = &tel_num_table;
564 else
565 num_table = &eng_num_table;
566
567 /* This matches *English* numbers of the form 99,99,999 that require lakh
568 or crore expansion -- otherwise they'll be dropped back to the English
569 front end */
570 if (cst_regex_match(cst_rx_indic_eng_number,name))
571 {
572 /* remove commas */
573 p = indic_num_normalize(name,num_table);
574 if (val_length(p) <= 9)
575 /* Long strings of digits are read as strings of digits */
576 r = indic_number(p, num_table);
577 else
578 r = indic_number_indiv(p,num_table);
579 delete_val(p);
580 }
581 else if (indic_nump(name))
582
583 { /* Its script specific digits (commas/dots) */
584 if (indic_nump(name) == 2)
585 { /* All characters are digits */
586 // printf("nump is 2\n");
587 p = indic_num_normalize(name,num_table);
588 if (val_length(p) <= 9)
589 r = indic_number(p, num_table);
590 else
591 r = indic_number_indiv(p,num_table);
592 delete_val(p);
593 }
594 else if (indic_nump(name) == 1)
595 { /* Some characters are digits */
596 int len = 1;
597 int i = 0;
598 char c0;
599 char *aaa;
600 char *bbb;
601 while(name[i] != '\0')
602 {
603 /* Iterate over UTF-8 string */
604 c0 = name[i];
605 len = ts_utf8_sequence_length(c0);
606 /* Check if char after this is comma */
607 if (name[i+len] == ',')
608 {
609 /* Skip commas */
610 i += len;
611 c0 = name[i];
612 len = ts_utf8_sequence_length(c0);
613 i += len;
614 continue;
615 }
616 /* Find where character type switches to or from digits */
617 if(indic_text_splitable(name, i, len))
618 break;
619 i +=len;
620 }
621 aaa = cst_strdup(name);
622 aaa[i+len] = '\0';
623 bbb = cst_strdup(&name[i+len]);
624 r = val_append(cmu_indic_tokentowords_one(token, aaa),
625 cmu_indic_tokentowords_one(token, bbb));
626 cst_free(aaa);
627 cst_free(bbb);
628 }
629 }
630 else if (indic_hyphenated(name))
631 { /* For numbers seeparated by - / , */
632 char *aaa;
633 aaa = cst_strdup(&name[1]);
634 r = cmu_indic_tokentowords_one(token, aaa);
635 cst_free(aaa);
636 }
637
638 else if (cst_regex_match(cst_rx_not_indic,name))
639 /* Do English analysis on non-unicode tokens */
640 r = us_tokentowords(token);
641 else if (cst_strlen(name) > 0)
642 r = cons_val(string_val(name),0);
643 else
644 r = NULL;
645
646 return r;
647 }
648
649 int indic_utt_break(cst_tokenstream *ts,
650 const char *token,
651 cst_relation *tokens)
652 {
653 const char *postpunct = item_feat_string(relation_tail(tokens), "punc");
654 const char *ltoken = item_name(relation_tail(tokens));
655
656 if (cst_strchr(ts->whitespace,'\n') != cst_strrchr(ts->whitespace,'\n'))
657 /* contains two new lines */
658 return TRUE;
659 else if ((cst_strlen(ltoken) >= 3) &&
660 (cst_streq(&ltoken[cst_strlen(ltoken)-3],"।"))) /* devanagari '|' */
661 return TRUE;
662 else if (strchr(postpunct,':') ||
663 strchr(postpunct,'?') ||
664 strchr(postpunct,'|') || /* if ascii '|' gets used as dvngr '|' */
665 strchr(postpunct,'!'))
666 return TRUE;
667 else if (strchr(postpunct,'.'))
668 return TRUE;
669 else
670 return FALSE;
671 }
672
673 DEF_STATIC_CONST_VAL_STRING(val_string_zero,"0");
674 DEF_STATIC_CONST_VAL_STRING(val_string_one,"1");
675
676 const cst_val *is_english(const cst_item *p)
677 {
678 if (p && cst_regex_match(cst_rx_not_indic,
679 flite_ffeature_string(p,"name")))
680 return (cst_val *)&val_string_one;
681 else
682 return (cst_val *)&val_string_zero;
683 }
684
685 void cmu_indic_lang_init(cst_voice *v)
686 {
687 /* Set indic language stuff */
688 feat_set_string(v->features,"language","cmu_indic_lang");
689
690 /* utterance break function */
691 feat_set(v->features,"utt_break",breakfunc_val(&indic_utt_break));
692
693 /* Phoneset -- need to get this from voice */
694 feat_set(v->features,"phoneset",phoneset_val(&cmu_indic_phoneset));
695 feat_set_string(v->features,"silence",cmu_indic_phoneset.silence);
696
697 /* Get information from voice and add to lexicon */
698
699 /* Text analyser -- whitespace defaults */
700 feat_set_string(v->features,"text_whitespace",
701 cst_ts_default_whitespacesymbols);
702 feat_set_string(v->features,"text_prepunctuation",
703 cst_ts_default_prepunctuationsymbols);
704 /* We can't put multi-byte characters in these classes so we can't */
705 /* add devanagari end of sentence '|' here, but would like to -- */
706 /* But we do add ascii '|' to it as it sometimes gets used the same way */
707 feat_set_string(v->features,"text_postpunctuation",
708 indic_postpunctuationsymbols);
709 feat_set_string(v->features,"text_singlecharsymbols",
710 cst_ts_default_singlecharsymbols);
711
712 /* Tokenization tokenization function */
713 feat_set(v->features,"tokentowords_func",itemfunc_val(&cmu_indic_tokentowords));
714 /* Pos tagger (gpos)/induced pos */
715
716 /* Phrasing */
717 feat_set(v->features,"phrasing_cart",cart_val(&cmu_indic_phrasing_cart));
718
719 /* Intonation, Duration and F0 -- part of cg */
720 feat_set_string(v->features,"no_intonation_accent_model","1");
721
722 /* Default ffunctions (required) */
723 basic_ff_register(v->ffunctions);
724
725 /* Indic specific features */
726 ff_register(v->ffunctions, "lisp_is_english", is_english);
727
728 return;
729 }