| 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 |
#include "cst_hrg.h" |
| 85 |
#include "cst_phoneset.h" |
| 86 |
#include "cst_regex.h" |
| 87 |
|
| 88 |
static const cst_val *word_break(const cst_item *word); |
| 89 |
static const cst_val *word_punc(const cst_item *word); |
| 90 |
static const cst_val *word_numsyls(const cst_item *word); |
| 91 |
static const cst_val *ssyl_in(const cst_item *syl); |
| 92 |
static const cst_val *syl_in(const cst_item *syl); |
| 93 |
static const cst_val *syl_out(const cst_item *syl); |
| 94 |
static const cst_val *syl_break(const cst_item *syl); |
| 95 |
static const cst_val *syl_codasize(const cst_item *syl); |
| 96 |
static const cst_val *syl_onsetsize(const cst_item *syl); |
| 97 |
#ifdef FLITE_PLUS_HTS_ENGINE |
| 98 |
const cst_val *accented(const cst_item *p); |
| 99 |
#else |
| 100 |
static const cst_val *accented(const cst_item *p); |
| 101 |
#endif |
| 102 |
|
| 103 |
DEF_STATIC_CONST_VAL_STRING(val_string_onset,"onset"); |
| 104 |
DEF_STATIC_CONST_VAL_STRING(val_string_coda,"coda"); |
| 105 |
DEF_STATIC_CONST_VAL_STRING(val_string_initial,"initial"); |
| 106 |
DEF_STATIC_CONST_VAL_STRING(val_string_single,"single"); |
| 107 |
DEF_STATIC_CONST_VAL_STRING(val_string_final,"final"); |
| 108 |
DEF_STATIC_CONST_VAL_STRING(val_string_mid,"mid"); |
| 109 |
DEF_STATIC_CONST_VAL_STRING(val_string_empty,""); |
| 110 |
|
| 111 |
const cst_val *ph_vc(const cst_item *p) |
| 112 |
{ |
| 113 |
return phone_feature(item_phoneset(p),item_name(p),"vc"); |
| 114 |
} |
| 115 |
const cst_val *ph_vlng(const cst_item *p) |
| 116 |
{ |
| 117 |
return phone_feature(item_phoneset(p),item_name(p),"vlng"); |
| 118 |
} |
| 119 |
const cst_val *ph_vheight(const cst_item *p) |
| 120 |
{ |
| 121 |
return phone_feature(item_phoneset(p),item_name(p),"vheight"); |
| 122 |
} |
| 123 |
const cst_val *ph_vrnd(const cst_item *p) |
| 124 |
{ |
| 125 |
return phone_feature(item_phoneset(p),item_name(p),"vrnd"); |
| 126 |
} |
| 127 |
const cst_val *ph_vfront(const cst_item *p) |
| 128 |
{ |
| 129 |
return phone_feature(item_phoneset(p),item_name(p),"vfront"); |
| 130 |
} |
| 131 |
const cst_val *ph_ctype(const cst_item *p) |
| 132 |
{ |
| 133 |
return phone_feature(item_phoneset(p),item_name(p),"ctype"); |
| 134 |
} |
| 135 |
const cst_val *ph_cplace(const cst_item *p) |
| 136 |
{ |
| 137 |
return phone_feature(item_phoneset(p),item_name(p),"cplace"); |
| 138 |
} |
| 139 |
const cst_val *ph_cvox(const cst_item *p) |
| 140 |
{ |
| 141 |
return phone_feature(item_phoneset(p),item_name(p),"cvox"); |
| 142 |
} |
| 143 |
|
| 144 |
const cst_val *cg_duration(const cst_item *p) |
| 145 |
{ |
| 146 |
|
| 147 |
|
| 148 |
if (!p) |
| 149 |
return float_val(0.0); |
| 150 |
else if (!item_prev(p)) |
| 151 |
return item_feat(p,"end"); |
| 152 |
else |
| 153 |
return float_val(item_feat_float(p,"end") |
| 154 |
- item_feat_float(item_prev(p),"end")); |
| 155 |
} |
| 156 |
|
| 157 |
DEF_STATIC_CONST_VAL_STRING(val_string_pos_b,"b"); |
| 158 |
DEF_STATIC_CONST_VAL_STRING(val_string_pos_m,"m"); |
| 159 |
DEF_STATIC_CONST_VAL_STRING(val_string_pos_e,"e"); |
| 160 |
|
| 161 |
const cst_val *cg_state_pos(const cst_item *p) |
| 162 |
{ |
| 163 |
const char *name; |
| 164 |
name = item_feat_string(p,"name"); |
| 165 |
if (!cst_streq(name,ffeature_string(p,"p.name"))) |
| 166 |
return (cst_val *)&val_string_pos_b; |
| 167 |
if (cst_streq(name,ffeature_string(p,"n.name"))) |
| 168 |
return (cst_val *)&val_string_pos_m; |
| 169 |
else |
| 170 |
return (cst_val *)&val_string_pos_e; |
| 171 |
} |
| 172 |
|
| 173 |
const cst_val *cg_state_place(const cst_item *p) |
| 174 |
{ |
| 175 |
float start, end; |
| 176 |
int this; |
| 177 |
start = (float)ffeature_int(p,"R:mcep_link.parent.daughter1.frame_number"); |
| 178 |
end = (float)ffeature_int(p,"R:mcep_link.parent.daughtern.frame_number"); |
| 179 |
this = item_feat_int(p,"frame_number"); |
| 180 |
if ((end-start) == 0.0) |
| 181 |
return float_val(0.0); |
| 182 |
else |
| 183 |
return float_val((this-start)/(end-start)); |
| 184 |
} |
| 185 |
|
| 186 |
const cst_val *cg_state_index(const cst_item *p) |
| 187 |
{ |
| 188 |
float start; |
| 189 |
int this; |
| 190 |
start = (float)ffeature_int(p,"R:mcep_link.parent.daughter1.frame_number"); |
| 191 |
this = item_feat_int(p,"frame_number"); |
| 192 |
return float_val(this-start); |
| 193 |
} |
| 194 |
|
| 195 |
const cst_val *cg_state_rindex(const cst_item *p) |
| 196 |
{ |
| 197 |
float end; |
| 198 |
int this; |
| 199 |
end = (float)ffeature_int(p,"R:mcep_link.parent.daughtern.frame_number"); |
| 200 |
this = item_feat_int(p,"frame_number"); |
| 201 |
return float_val(end-this); |
| 202 |
} |
| 203 |
|
| 204 |
const cst_val *cg_phone_place(const cst_item *p) |
| 205 |
{ |
| 206 |
float start, end; |
| 207 |
int this; |
| 208 |
start = (float)ffeature_int(p,"R:mcep_link.parent.R:segstate.parent.daughter1.R:mcep_link.daughter1.frame_number"); |
| 209 |
end = (float)ffeature_int(p,"R:mcep_link.parent.R:segstate.parent.daughtern.R:mcep_link.daughtern.frame_number"); |
| 210 |
this = item_feat_int(p,"frame_number"); |
| 211 |
if ((end-start) == 0.0) |
| 212 |
return float_val(0.0); |
| 213 |
else |
| 214 |
return float_val((this-start)/(end-start)); |
| 215 |
} |
| 216 |
|
| 217 |
const cst_val *cg_phone_index(const cst_item *p) |
| 218 |
{ |
| 219 |
float start; |
| 220 |
int this; |
| 221 |
start = (float)ffeature_int(p,"R:mcep_link.parent.R:segstate.parent.daughter1.R:mcep_link.daughter1.frame_number"); |
| 222 |
this = item_feat_int(p,"frame_number"); |
| 223 |
return float_val(this-start); |
| 224 |
} |
| 225 |
|
| 226 |
const cst_val *cg_phone_rindex(const cst_item *p) |
| 227 |
{ |
| 228 |
float end; |
| 229 |
int this; |
| 230 |
end = (float)ffeature_int(p,"R:mcep_link.parent.R:segstate.parent.daughtern.R:mcep_link.daughtern.frame_number"); |
| 231 |
this = item_feat_int(p,"frame_number"); |
| 232 |
return float_val(end-this); |
| 233 |
} |
| 234 |
|
| 235 |
const cst_val *cg_is_pau(const cst_item *p) |
| 236 |
{ |
| 237 |
if (p && cst_streq("pau",item_feat_string(p,"name"))) |
| 238 |
return VAL_INT_1; |
| 239 |
else |
| 240 |
return VAL_INT_0; |
| 241 |
} |
| 242 |
|
| 243 |
const cst_val *cg_find_phrase_number(const cst_item *p) |
| 244 |
{ |
| 245 |
const cst_item *v; |
| 246 |
int x = 0; |
| 247 |
|
| 248 |
for (v=item_prev(p); v; v=item_prev(v)) |
| 249 |
x++; |
| 250 |
|
| 251 |
return val_int_n(x); |
| 252 |
} |
| 253 |
|
| 254 |
const cst_val *cg_position_in_phrasep(const cst_item *p) |
| 255 |
{ |
| 256 |
float pstart, pend, phrasenumber; |
| 257 |
float x; |
| 258 |
#define CG_FRAME_SHIFT 0.005 |
| 259 |
|
| 260 |
pstart = ffeature_float(p,"R:mcep_link.parent.R:segstate.parent.R:SylStructure.parent.parent.R:Phrase.parent.daughter1.R:SylStructure.daughter1.daughter1.R:Segment.p.end"); |
| 261 |
pend = ffeature_float(p,"R:mcep_link.parent.R:segstate.parent.R:SylStructure.parent.parent.R:Phrase.parent.daughtern.R:SylStructure.daughtern.daughtern.R:Segment.end"); |
| 262 |
phrasenumber = ffeature_float(p,"R:mcep_link.parent.R:segstate.parent.R:SylStructure.parent.parent.R:Phrase.parent.lisp_cg_find_phrase_number"); |
| 263 |
if ((pend - pstart) == 0.0) |
| 264 |
return float_val(-1.0); |
| 265 |
else |
| 266 |
{ |
| 267 |
x = phrasenumber + |
| 268 |
((CG_FRAME_SHIFT*item_feat_float(p,"frame_number"))-pstart) / |
| 269 |
(pend - pstart); |
| 270 |
return float_val(x); |
| 271 |
} |
| 272 |
} |
| 273 |
|
| 274 |
#ifdef FLITE_PLUS_HTS_ENGINE |
| 275 |
const cst_val *accented(const cst_item *syl) |
| 276 |
#else |
| 277 |
static const cst_val *accented(const cst_item *syl) |
| 278 |
#endif |
| 279 |
{ |
| 280 |
if ((item_feat_present(syl,"accent")) || |
| 281 |
(item_feat_present(syl,"endtone"))) |
| 282 |
return VAL_STRING_1; |
| 283 |
else |
| 284 |
return VAL_STRING_0; |
| 285 |
} |
| 286 |
|
| 287 |
static const cst_val *seg_coda_ctype(const cst_item *seg, const char *ctype) |
| 288 |
{ |
| 289 |
const cst_item *s; |
| 290 |
const cst_phoneset *ps = item_phoneset(seg); |
| 291 |
|
| 292 |
for (s=item_last_daughter(item_parent(item_as(seg,"SylStructure"))); |
| 293 |
s; |
| 294 |
s=item_prev(s)) |
| 295 |
{ |
| 296 |
if (cst_streq("+",phone_feature_string(ps,item_feat_string(s,"name"), |
| 297 |
"vc"))) |
| 298 |
return VAL_STRING_0; |
| 299 |
if (cst_streq(ctype,phone_feature_string(ps,item_feat_string(s,"name"), |
| 300 |
"ctype"))) |
| 301 |
return VAL_STRING_1; |
| 302 |
} |
| 303 |
|
| 304 |
return VAL_STRING_0; |
| 305 |
} |
| 306 |
|
| 307 |
static const cst_val *seg_onset_ctype(const cst_item *seg, const char *ctype) |
| 308 |
{ |
| 309 |
const cst_item *s; |
| 310 |
const cst_phoneset *ps = item_phoneset(seg); |
| 311 |
|
| 312 |
for (s=item_daughter(item_parent(item_as(seg,"SylStructure"))); |
| 313 |
s; |
| 314 |
s=item_next(s)) |
| 315 |
{ |
| 316 |
if (cst_streq("+",phone_feature_string(ps,item_feat_string(s,"name"), |
| 317 |
"vc"))) |
| 318 |
return VAL_STRING_0; |
| 319 |
if (cst_streq(ctype,phone_feature_string(ps,item_feat_string(s,"name"), |
| 320 |
"ctype"))) |
| 321 |
return VAL_STRING_1; |
| 322 |
} |
| 323 |
|
| 324 |
return VAL_STRING_0; |
| 325 |
} |
| 326 |
|
| 327 |
static const cst_val *seg_coda_fric(const cst_item *seg) |
| 328 |
{ |
| 329 |
return seg_coda_ctype(seg,"f"); |
| 330 |
} |
| 331 |
|
| 332 |
static const cst_val *seg_onset_fric(const cst_item *seg) |
| 333 |
{ |
| 334 |
return seg_onset_ctype(seg,"f"); |
| 335 |
} |
| 336 |
|
| 337 |
static const cst_val *seg_coda_stop(const cst_item *seg) |
| 338 |
{ |
| 339 |
return seg_coda_ctype(seg,"s"); |
| 340 |
} |
| 341 |
|
| 342 |
static const cst_val *seg_onset_stop(const cst_item *seg) |
| 343 |
{ |
| 344 |
return seg_onset_ctype(seg,"s"); |
| 345 |
} |
| 346 |
|
| 347 |
static const cst_val *seg_coda_nasal(const cst_item *seg) |
| 348 |
{ |
| 349 |
return seg_coda_ctype(seg,"n"); |
| 350 |
} |
| 351 |
|
| 352 |
static const cst_val *seg_onset_nasal(const cst_item *seg) |
| 353 |
{ |
| 354 |
return seg_onset_ctype(seg,"n"); |
| 355 |
} |
| 356 |
|
| 357 |
static const cst_val *seg_coda_glide(const cst_item *seg) |
| 358 |
{ |
| 359 |
if (seg_coda_ctype(seg,"r") == VAL_STRING_0) |
| 360 |
return seg_coda_ctype(seg,"l"); |
| 361 |
return VAL_STRING_1; |
| 362 |
} |
| 363 |
|
| 364 |
static const cst_val *seg_onset_glide(const cst_item *seg) |
| 365 |
{ |
| 366 |
if (seg_onset_ctype(seg,"r") == VAL_STRING_0) |
| 367 |
return seg_onset_ctype(seg,"l"); |
| 368 |
return VAL_STRING_1; |
| 369 |
} |
| 370 |
|
| 371 |
static const cst_val *seg_onsetcoda(const cst_item *seg) |
| 372 |
{ |
| 373 |
const cst_item *s; |
| 374 |
const cst_phoneset *ps = item_phoneset(seg); |
| 375 |
|
| 376 |
if (!seg) return VAL_STRING_0; |
| 377 |
for (s=item_next(item_as(seg,"SylStructure")); |
| 378 |
s; |
| 379 |
s=item_next(s)) |
| 380 |
{ |
| 381 |
if (cst_streq("+",phone_feature_string(ps,item_feat_string(s,"name"), |
| 382 |
"vc"))) |
| 383 |
return (cst_val *)&val_string_onset; |
| 384 |
} |
| 385 |
return (cst_val *)&val_string_coda; |
| 386 |
} |
| 387 |
|
| 388 |
static const cst_val *pos_in_syl(const cst_item *seg) |
| 389 |
{ |
| 390 |
const cst_item *s; |
| 391 |
int c; |
| 392 |
|
| 393 |
for (c=-1,s=item_as(seg,"SylStructure"); |
| 394 |
s; |
| 395 |
s=item_prev(s),c++); |
| 396 |
|
| 397 |
return val_string_n(c); |
| 398 |
} |
| 399 |
|
| 400 |
static const cst_val *position_type(const cst_item *syl) |
| 401 |
{ |
| 402 |
const cst_item *s = item_as(syl,"SylStructure"); |
| 403 |
|
| 404 |
if (s == 0) |
| 405 |
return (cst_val *)&val_string_single; |
| 406 |
else if (item_next(s) == 0) |
| 407 |
{ |
| 408 |
if (item_prev(s) == 0) |
| 409 |
return (cst_val *)&val_string_single; |
| 410 |
else |
| 411 |
return (cst_val *)&val_string_final; |
| 412 |
} |
| 413 |
else if (item_prev(s) == 0) |
| 414 |
return (cst_val *)&val_string_initial; |
| 415 |
else |
| 416 |
return (cst_val *)&val_string_mid; |
| 417 |
} |
| 418 |
|
| 419 |
static const cst_val *sub_phrases(const cst_item *syl) |
| 420 |
{ |
| 421 |
const cst_item *s; |
| 422 |
int c; |
| 423 |
|
| 424 |
for (c=0,s=path_to_item(syl,"R:SylStructure.parent.R:Phrase.parent.p"); |
| 425 |
s && (c < CST_CONST_INT_MAX); |
| 426 |
s=item_prev(s),c++); |
| 427 |
|
| 428 |
return val_string_n(c); |
| 429 |
} |
| 430 |
|
| 431 |
static const cst_val *last_accent(const cst_item *syl) |
| 432 |
{ |
| 433 |
const cst_item *s; |
| 434 |
int c; |
| 435 |
|
| 436 |
for (c=0,s=item_as(syl,"Syllable"); |
| 437 |
s && (c < CST_CONST_INT_MAX); |
| 438 |
s=item_prev(s),c++) |
| 439 |
{ |
| 440 |
if (val_int(accented(s))) |
| 441 |
return val_string_n(c); |
| 442 |
} |
| 443 |
|
| 444 |
return val_string_n(c); |
| 445 |
} |
| 446 |
|
| 447 |
static const cst_val *next_accent(const cst_item *syl) |
| 448 |
{ |
| 449 |
const cst_item *s; |
| 450 |
int c; |
| 451 |
|
| 452 |
s=item_as(syl,"Syllable"); |
| 453 |
if (s) |
| 454 |
s = item_next(s); |
| 455 |
else |
| 456 |
return val_string_n(0); |
| 457 |
for (c=0; |
| 458 |
s && (c < CST_CONST_INT_MAX); |
| 459 |
s=item_next(s),c++) |
| 460 |
{ |
| 461 |
if (val_int(accented(s))) |
| 462 |
return val_string_n(c); |
| 463 |
} |
| 464 |
|
| 465 |
return val_string_n(c); |
| 466 |
} |
| 467 |
|
| 468 |
static const cst_val *syl_final(const cst_item *seg) |
| 469 |
{ |
| 470 |
const cst_item *s = item_as(seg,"SylStructure"); |
| 471 |
|
| 472 |
if (!s || (item_next(s) == NULL)) |
| 473 |
return VAL_STRING_1; |
| 474 |
else |
| 475 |
return VAL_STRING_0; |
| 476 |
} |
| 477 |
|
| 478 |
static const cst_val *word_punc(const cst_item *word) |
| 479 |
{ |
| 480 |
cst_item *ww; |
| 481 |
const cst_val *v; |
| 482 |
|
| 483 |
ww = item_as(word,"Token"); |
| 484 |
|
| 485 |
if ((ww != NULL) && (item_next(ww) != 0)) |
| 486 |
v = (cst_val *) &val_string_empty; |
| 487 |
else |
| 488 |
v = ffeature(item_parent(ww),"punc"); |
| 489 |
|
| 490 |
|
| 491 |
|
| 492 |
|
| 493 |
|
| 494 |
return v; |
| 495 |
|
| 496 |
} |
| 497 |
|
| 498 |
static const cst_val *word_break(const cst_item *word) |
| 499 |
{ |
| 500 |
cst_item *ww,*pp; |
| 501 |
const char *pname; |
| 502 |
|
| 503 |
ww = item_as(word,"Phrase"); |
| 504 |
|
| 505 |
if ((ww == NULL) || (item_next(ww) != 0)) |
| 506 |
return VAL_STRING_1; |
| 507 |
else |
| 508 |
{ |
| 509 |
pp = item_parent(ww); |
| 510 |
pname = val_string(item_feat(pp,"name")); |
| 511 |
if (cst_streq("BB",pname)) |
| 512 |
return VAL_STRING_4; |
| 513 |
else if (cst_streq("B",pname)) |
| 514 |
return VAL_STRING_3; |
| 515 |
else |
| 516 |
return VAL_STRING_1; |
| 517 |
} |
| 518 |
} |
| 519 |
|
| 520 |
static const cst_val *word_numsyls(const cst_item *word) |
| 521 |
{ |
| 522 |
cst_item *d; |
| 523 |
int c; |
| 524 |
|
| 525 |
for (c=0,d=item_daughter(item_as(word,"SylStructure")); |
| 526 |
d; |
| 527 |
d=item_next(d),c++); |
| 528 |
|
| 529 |
return val_int_n(c); |
| 530 |
} |
| 531 |
|
| 532 |
static const cst_val *ssyl_in(const cst_item *syl) |
| 533 |
{ |
| 534 |
|
| 535 |
const cst_item *ss,*p,*fs; |
| 536 |
int c; |
| 537 |
|
| 538 |
ss = item_as(syl,"Syllable"); |
| 539 |
|
| 540 |
fs = path_to_item(syl,"R:SylStructure.parent.R:Phrase.parent.daughter.R:SylStructure.daughter"); |
| 541 |
|
| 542 |
|
| 543 |
|
| 544 |
for (c=0, p=item_prev(ss); |
| 545 |
p && (!item_equal(p,fs)) && (c < CST_CONST_INT_MAX); |
| 546 |
p=item_prev(p)) |
| 547 |
{ |
| 548 |
if (cst_streq("1",item_feat_string(p,"stress"))) |
| 549 |
c++; |
| 550 |
} |
| 551 |
|
| 552 |
return val_string_n(c); |
| 553 |
} |
| 554 |
|
| 555 |
static const cst_val *ssyl_out(const cst_item *syl) |
| 556 |
{ |
| 557 |
|
| 558 |
const cst_item *ss,*p,*fs; |
| 559 |
int c; |
| 560 |
|
| 561 |
ss = item_as(syl,"Syllable"); |
| 562 |
|
| 563 |
fs = path_to_item(syl,"R:SylStructure.parent.R:Phrase.parent.daughtern.R:SylStructure.daughtern"); |
| 564 |
|
| 565 |
for (c=0, p=item_next(ss); |
| 566 |
p && (c < CST_CONST_INT_MAX); |
| 567 |
p=item_next(p)) |
| 568 |
{ |
| 569 |
if (cst_streq("1",item_feat_string(p,"stress"))) |
| 570 |
c++; |
| 571 |
if (item_equal(p,fs)) |
| 572 |
break; |
| 573 |
} |
| 574 |
|
| 575 |
return val_string_n(c); |
| 576 |
} |
| 577 |
|
| 578 |
static const cst_val *syl_in(const cst_item *syl) |
| 579 |
{ |
| 580 |
|
| 581 |
const cst_item *ss,*p,*fs; |
| 582 |
int c; |
| 583 |
|
| 584 |
ss = item_as(syl,"Syllable"); |
| 585 |
|
| 586 |
fs = path_to_item(syl,"R:SylStructure.parent.R:Phrase.parent.daughter.R:SylStructure.daughter"); |
| 587 |
|
| 588 |
for (c=0, p=ss; |
| 589 |
p && (c < CST_CONST_INT_MAX); |
| 590 |
p=item_prev(p),c++) |
| 591 |
if (item_equal(p,fs)) |
| 592 |
break; |
| 593 |
return val_string_n(c); |
| 594 |
} |
| 595 |
|
| 596 |
static const cst_val *syl_out(const cst_item *syl) |
| 597 |
{ |
| 598 |
|
| 599 |
cst_item *ss,*p; |
| 600 |
const cst_item *fs; |
| 601 |
int c; |
| 602 |
|
| 603 |
ss = item_as(syl,"Syllable"); |
| 604 |
|
| 605 |
fs = path_to_item(syl,"R:SylStructure.parent.R:Phrase.parent.daughtern.R:SylStructure.daughtern"); |
| 606 |
|
| 607 |
for (c=0, p=ss; |
| 608 |
p && (c < CST_CONST_INT_MAX); |
| 609 |
p=item_next(p),c++) |
| 610 |
if (item_equal(p,fs)) |
| 611 |
break; |
| 612 |
return val_string_n(c); |
| 613 |
} |
| 614 |
|
| 615 |
static const cst_val *syl_break(const cst_item *syl) |
| 616 |
{ |
| 617 |
|
| 618 |
cst_item *ss; |
| 619 |
|
| 620 |
ss = item_as(syl,"SylStructure"); |
| 621 |
|
| 622 |
if (ss == NULL) |
| 623 |
return VAL_STRING_1; |
| 624 |
else if (item_next(ss) != NULL) |
| 625 |
return VAL_STRING_0; |
| 626 |
else if (item_parent(ss) == NULL) |
| 627 |
return VAL_STRING_1; |
| 628 |
else |
| 629 |
return word_break(item_parent(ss)); |
| 630 |
} |
| 631 |
|
| 632 |
static const cst_val *cg_break(const cst_item *syl) |
| 633 |
{ |
| 634 |
|
| 635 |
|
| 636 |
cst_item *ss; |
| 637 |
|
| 638 |
ss = item_as(syl,"SylStructure"); |
| 639 |
|
| 640 |
if (ss == NULL) |
| 641 |
return VAL_INT_0; |
| 642 |
else if (item_next(ss) != NULL) |
| 643 |
return VAL_INT_0; |
| 644 |
else if (path_to_item(ss,"R:SylStructure.parent.R:Word.n") == NULL) |
| 645 |
return VAL_INT_4; |
| 646 |
else if (path_to_item(ss,"R:SylStructure.parent.R:Phrase.n") == NULL) |
| 647 |
return VAL_INT_3; |
| 648 |
else |
| 649 |
return VAL_INT_1; |
| 650 |
} |
| 651 |
|
| 652 |
static const cst_val *syl_codasize(const cst_item *syl) |
| 653 |
{ |
| 654 |
cst_item *d; |
| 655 |
int c; |
| 656 |
|
| 657 |
for (c=1,d=item_last_daughter(item_as(syl,"SylStructure")); |
| 658 |
d; |
| 659 |
d=item_prev(d),c++) |
| 660 |
{ |
| 661 |
if (cst_streq("+",val_string(ph_vc(d)))) |
| 662 |
break; |
| 663 |
} |
| 664 |
|
| 665 |
return val_string_n(c); |
| 666 |
} |
| 667 |
|
| 668 |
static const cst_val *syl_onsetsize(const cst_item *syl) |
| 669 |
{ |
| 670 |
cst_item *d; |
| 671 |
int c; |
| 672 |
|
| 673 |
for (c=0,d=item_daughter(item_as(syl,"SylStructure")); |
| 674 |
d; |
| 675 |
d=item_next(d),c++) |
| 676 |
{ |
| 677 |
if (cst_streq("+",val_string(ph_vc(d)))) |
| 678 |
break; |
| 679 |
} |
| 680 |
|
| 681 |
return val_string_n(c); |
| 682 |
} |
| 683 |
|
| 684 |
static const cst_val *asyl_in(const cst_item *syl) |
| 685 |
{ |
| 686 |
|
| 687 |
const cst_item *ss,*p,*fs; |
| 688 |
int c; |
| 689 |
|
| 690 |
ss = item_as(syl,"Syllable"); |
| 691 |
|
| 692 |
fs = path_to_item(syl,"R:SylStructure.parent.R:Phrase.parent.daughter.R:SylStructure.daughter"); |
| 693 |
|
| 694 |
for (c=0, p=ss; |
| 695 |
p && (c < CST_CONST_INT_MAX); |
| 696 |
p=item_prev(p)) |
| 697 |
{ |
| 698 |
if (val_int(accented(p)) == 1) |
| 699 |
c++; |
| 700 |
if (item_equal(p,fs)) |
| 701 |
break; |
| 702 |
} |
| 703 |
|
| 704 |
return val_string_n(c); |
| 705 |
} |
| 706 |
|
| 707 |
static const cst_val *asyl_out(const cst_item *syl) |
| 708 |
{ |
| 709 |
|
| 710 |
cst_item *ss,*p; |
| 711 |
const cst_item *fs; |
| 712 |
int c; |
| 713 |
|
| 714 |
ss = item_as(syl,"Syllable"); |
| 715 |
|
| 716 |
fs = path_to_item(syl,"R:SylStructure.parent.R:Phrase.parent.daughtern.R:SylStructure.daughtern"); |
| 717 |
|
| 718 |
for (c=0, p=ss; |
| 719 |
p && (c < CST_CONST_INT_MAX); |
| 720 |
p=item_next(p)) |
| 721 |
{ |
| 722 |
if (val_int(accented(p)) == 1) |
| 723 |
c++; |
| 724 |
if (item_equal(p,fs)) |
| 725 |
break; |
| 726 |
} |
| 727 |
return val_string_n(c); |
| 728 |
} |
| 729 |
|
| 730 |
static const cst_val *segment_duration(const cst_item *seg) |
| 731 |
{ |
| 732 |
const cst_item *s = item_as(seg,"Segment"); |
| 733 |
|
| 734 |
if (!s) |
| 735 |
return VAL_STRING_0; |
| 736 |
else if (item_prev(s) == NULL) |
| 737 |
return item_feat(s,"end"); |
| 738 |
else |
| 739 |
|
| 740 |
|
| 741 |
|
| 742 |
return float_val(item_feat_float(s,"end") |
| 743 |
- item_feat_float(item_prev(s),"end")); |
| 744 |
} |
| 745 |
|
| 746 |
|
| 747 |
void basic_ff_register(cst_features *ffunctions) |
| 748 |
{ |
| 749 |
ff_register(ffunctions, "ph_vc",ph_vc); |
| 750 |
ff_register(ffunctions, "ph_vlng",ph_vlng); |
| 751 |
ff_register(ffunctions, "ph_vheight",ph_vheight); |
| 752 |
ff_register(ffunctions, "ph_vfront",ph_vfront); |
| 753 |
ff_register(ffunctions, "ph_vrnd",ph_vrnd); |
| 754 |
ff_register(ffunctions, "ph_ctype",ph_ctype); |
| 755 |
ff_register(ffunctions, "ph_cplace",ph_cplace); |
| 756 |
ff_register(ffunctions, "ph_cvox",ph_cvox); |
| 757 |
|
| 758 |
ff_register(ffunctions, "lisp_cg_duration", cg_duration); |
| 759 |
ff_register(ffunctions, "lisp_cg_state_pos", cg_state_pos); |
| 760 |
ff_register(ffunctions, "lisp_cg_state_place", cg_state_place); |
| 761 |
ff_register(ffunctions, "lisp_cg_state_index", cg_state_index); |
| 762 |
ff_register(ffunctions, "lisp_cg_state_rindex", cg_state_rindex); |
| 763 |
ff_register(ffunctions, "lisp_cg_phone_place", cg_phone_place); |
| 764 |
ff_register(ffunctions, "lisp_cg_phone_index", cg_phone_index); |
| 765 |
ff_register(ffunctions, "lisp_cg_phone_rindex", cg_phone_rindex); |
| 766 |
|
| 767 |
ff_register(ffunctions, "lisp_cg_position_in_phrasep", cg_position_in_phrasep); |
| 768 |
ff_register(ffunctions, "lisp_cg_find_phrase_number", cg_find_phrase_number); |
| 769 |
ff_register(ffunctions, "lisp_is_pau", cg_is_pau); |
| 770 |
|
| 771 |
ff_register(ffunctions, "word_numsyls",word_numsyls); |
| 772 |
ff_register(ffunctions, "word_break",word_break); |
| 773 |
ff_register(ffunctions, "word_punc",word_punc); |
| 774 |
ff_register(ffunctions, "ssyl_in",ssyl_in); |
| 775 |
ff_register(ffunctions, "ssyl_out",ssyl_out); |
| 776 |
ff_register(ffunctions, "syl_in",syl_in); |
| 777 |
ff_register(ffunctions, "syl_out",syl_out); |
| 778 |
ff_register(ffunctions, "syl_break",syl_break); |
| 779 |
ff_register(ffunctions, "lisp_cg_break",cg_break); |
| 780 |
ff_register(ffunctions, "old_syl_break",syl_break); |
| 781 |
ff_register(ffunctions, "syl_onsetsize",syl_onsetsize); |
| 782 |
ff_register(ffunctions, "syl_codasize",syl_codasize); |
| 783 |
ff_register(ffunctions, "accented",accented); |
| 784 |
ff_register(ffunctions, "asyl_in",asyl_in); |
| 785 |
ff_register(ffunctions, "asyl_out",asyl_out); |
| 786 |
ff_register(ffunctions, "lisp_coda_fric",seg_coda_fric); |
| 787 |
ff_register(ffunctions, "lisp_onset_fric",seg_onset_fric); |
| 788 |
ff_register(ffunctions, "lisp_coda_stop",seg_coda_stop); |
| 789 |
ff_register(ffunctions, "lisp_onset_stop",seg_onset_stop); |
| 790 |
ff_register(ffunctions, "lisp_coda_nasal",seg_coda_nasal); |
| 791 |
ff_register(ffunctions, "lisp_onset_nasal",seg_onset_nasal); |
| 792 |
ff_register(ffunctions, "lisp_coda_glide",seg_coda_glide); |
| 793 |
ff_register(ffunctions, "lisp_onset_glide",seg_onset_glide); |
| 794 |
ff_register(ffunctions, "seg_onsetcoda",seg_onsetcoda); |
| 795 |
ff_register(ffunctions, "pos_in_syl",pos_in_syl); |
| 796 |
ff_register(ffunctions, "position_type",position_type); |
| 797 |
ff_register(ffunctions, "sub_phrases",sub_phrases); |
| 798 |
ff_register(ffunctions, "last_accent",last_accent); |
| 799 |
ff_register(ffunctions, "next_accent",next_accent); |
| 800 |
ff_register(ffunctions, "syl_final",syl_final); |
| 801 |
ff_register(ffunctions, "segment_duration",segment_duration); |
| 802 |
|
| 803 |
} |