/*************************************************************************//* *//* Language Technologies Institute *//* Carnegie Mellon University *//* Copyright (c) 2007 *//* All Rights Reserved. *//* *//* Permission is hereby granted, free of charge, to use and distribute *//* this software and its documentation without restriction, including *//* without limitation the rights to use, copy, modify, merge, publish, *//* distribute, sublicense, and/or sell copies of this work, and to *//* permit persons to whom this work is furnished to do so, subject to *//* the following conditions: *//* 1. The code must retain the above copyright notice, this list of *//* conditions and the following disclaimer. *//* 2. Any modifications must be clearly marked as such. *//* 3. Original authors' names are not deleted. *//* 4. The authors' names are not used to endorse or promote products *//* derived from this software without specific prior written *//* permission. *//* *//* CARNEGIE MELLON UNIVERSITY AND THE CONTRIBUTORS TO THIS WORK *//* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING *//* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT *//* SHALL CARNEGIE MELLON UNIVERSITY NOR THE CONTRIBUTORS BE LIABLE *//* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES *//* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN *//* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, *//* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF *//* THIS SOFTWARE. *//* *//*************************************************************************//* Author: Alan W Black (awb@cs.cmu.edu) *//* Date: November 2007 *//*************************************************************************//* *//* Some language independent features *//* */ #include "cst_hrg.h"#include "cst_phoneset.h"#include "cst_regex.h" static const cst_val *word_break(const cst_item *word);static const cst_val *word_punc(const cst_item *word);static const cst_val *word_numsyls(const cst_item *word);static const cst_val *ssyl_in(const cst_item *syl);static const cst_val *syl_in(const cst_item *syl);static const cst_val *syl_out(const cst_item *syl);static const cst_val *syl_break(const cst_item *syl);static const cst_val *syl_codasize(const cst_item *syl);static const cst_val *syl_onsetsize(const cst_item *syl);static const cst_val *accented(const cst_item *p); DEF_STATIC_CONST_VAL_STRING(val_string_onset,"onset");DEF_STATIC_CONST_VAL_STRING(val_string_coda,"coda");DEF_STATIC_CONST_VAL_STRING(val_string_initial,"initial");DEF_STATIC_CONST_VAL_STRING(val_string_single,"single");DEF_STATIC_CONST_VAL_STRING(val_string_final,"final");DEF_STATIC_CONST_VAL_STRING(val_string_mid,"mid");DEF_STATIC_CONST_VAL_STRING(val_string_empty,""); const cst_val *ph_vc(const cst_item *p){ return phone_feature(item_phoneset(p),item_name(p),"vc");}const cst_val *ph_vlng(const cst_item *p){ return phone_feature(item_phoneset(p),item_name(p),"vlng");}const cst_val *ph_vheight(const cst_item *p){ return phone_feature(item_phoneset(p),item_name(p),"vheight");}const cst_val *ph_vrnd(const cst_item *p){ return phone_feature(item_phoneset(p),item_name(p),"vrnd");}const cst_val *ph_vfront(const cst_item *p){ return phone_feature(item_phoneset(p),item_name(p),"vfront");}const cst_val *ph_ctype(const cst_item *p){ return phone_feature(item_phoneset(p),item_name(p),"ctype");}const cst_val *ph_cplace(const cst_item *p){ return phone_feature(item_phoneset(p),item_name(p),"cplace");}const cst_val *ph_cvox(const cst_item *p){ return phone_feature(item_phoneset(p),item_name(p),"cvox");} const cst_val *cg_duration(const cst_item *p){ /* Note this constructs float vals, these will be freed when the */ /* cart cache is freed, so this should only be used in carts */ if (!p) return float_val(0.0); else if (!item_prev(p)) return item_feat(p,"end"); else return float_val(item_feat_float(p,"end") - item_feat_float(item_prev(p),"end"));} DEF_STATIC_CONST_VAL_STRING(val_string_pos_b,"b");DEF_STATIC_CONST_VAL_STRING(val_string_pos_m,"m");DEF_STATIC_CONST_VAL_STRING(val_string_pos_e,"e"); const cst_val *cg_state_pos(const cst_item *p){ const char *name; name = item_feat_string(p,"name"); if (!cst_streq(name,ffeature_string(p,"p.name"))) return (cst_val *)&val_string_pos_b; if (cst_streq(name,ffeature_string(p,"n.name"))) return (cst_val *)&val_string_pos_m; else return (cst_val *)&val_string_pos_e;} const cst_val *cg_state_place(const cst_item *p){ float start, end; int thisone; start = (float)ffeature_int(p,"R:mcep_link.parent.daughter1.frame_number"); end = (float)ffeature_int(p,"R:mcep_link.parent.daughtern.frame_number"); thisone = item_feat_int(p,"frame_number"); if ((end-start) == 0.0) return float_val(0.0); else return float_val((thisone-start)/(end-start));} const cst_val *cg_state_index(const cst_item *p){ float start; int thisone; start = (float)ffeature_int(p,"R:mcep_link.parent.daughter1.frame_number"); thisone = item_feat_int(p,"frame_number"); return float_val(thisone-start);} const cst_val *cg_state_rindex(const cst_item *p){ float end; int thisone; end = (float)ffeature_int(p,"R:mcep_link.parent.daughtern.frame_number"); thisone = item_feat_int(p,"frame_number"); return float_val(end-thisone);} const cst_val *cg_phone_place(const cst_item *p){ float start, end; int thisone; start = (float)ffeature_int(p,"R:mcep_link.parent.R:segstate.parent.daughter1.R:mcep_link.daughter1.frame_number"); end = (float)ffeature_int(p,"R:mcep_link.parent.R:segstate.parent.daughtern.R:mcep_link.daughtern.frame_number"); thisone = item_feat_int(p,"frame_number"); if ((end-start) == 0.0) return float_val(0.0); else return float_val((thisone-start)/(end-start));} const cst_val *cg_phone_index(const cst_item *p){ float start; int thisone; start = (float)ffeature_int(p,"R:mcep_link.parent.R:segstate.parent.daughter1.R:mcep_link.daughter1.frame_number"); thisone = item_feat_int(p,"frame_number"); return float_val(thisone-start);} const cst_val *cg_phone_rindex(const cst_item *p){ float end; int thisone; end = (float)ffeature_int(p,"R:mcep_link.parent.R:segstate.parent.daughtern.R:mcep_link.daughtern.frame_number"); thisone = item_feat_int(p,"frame_number"); return float_val(end-thisone);} const cst_val *cg_is_pau(const cst_item *p){ if (p && cst_streq("pau",item_feat_string(p,"name"))) return &val_int_1; else return &val_int_0;} const cst_val *cg_find_phrase_number(const cst_item *p){ const cst_item *v; int x = 0; for (v=item_prev(p); v; v=item_prev(v)) x++; return val_int_n(x);} const cst_val *cg_position_in_phrasep(const cst_item *p){ float pstart, pend, phrasenumber; float x; #define CG_FRAME_SHIFT 0.005 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"); 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"); phrasenumber = ffeature_float(p,"R:mcep_link.parent.R:segstate.parent.R:SylStructure.parent.parent.R:Phrase.parent.lisp_cg_find_phrase_number"); if ((pend - pstart) == 0.0) return float_val(-1.0); else { x = phrasenumber + ((CG_FRAME_SHIFT*item_feat_float(p,"frame_number"))-pstart) / (pend - pstart); return float_val(x); }} const cst_val *cg_position_in_phrase(const cst_item *p){ float pstart, pend; float x; #define CG_FRAME_SHIFT 0.005 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"); 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"); if ((pend - pstart) == 0.0) return float_val(-1.0); else { x = 0 + ((CG_FRAME_SHIFT*item_feat_float(p,"frame_number"))-pstart) / (pend - pstart); return float_val(x); }} const cst_val *cg_position_in_sentence(const cst_item *p){ float sstart, send; float x; #define CG_FRAME_SHIFT 0.005 sstart = ffeature_float(p,"R:mcep_link.parent.R:segstate.parent.R:SylStructure.parent.parent.R:Word.first.R:SylStructure.daughter1.daughter1.R:Segment.p.end"); send = ffeature_float(p,"R:mcep_link.parent.R:segstate.parent.R:SylStructure.parent.parent.R:Word.last.R:SylStructure.daughtern.daughtern.R:Segment.end"); if ((send - sstart) == 0.0) return float_val(-1.0); else { x = ((CG_FRAME_SHIFT*item_feat_float(p,"frame_number"))-sstart) / (send - sstart); return float_val(x); }} /* Spam specific features, but may be useful for others */const cst_val *pos_in_word(const cst_item *p){ const cst_item *s; int i=0; p=item_as(p,"Syllable"); s=item_as(path_to_item(p,"R:SylStructure.parent.daughter1"),"Syllable"); for (;s && !item_equal(p,s);s=item_next(s),i++){} return val_string_n(i);} const cst_val *syllable_duration(const cst_item *p){ return float_val(ffeature_float(p,"R:SylStructure.daughtern.R:Segment.end") - ffeature_float(p,"R:SylStructure.daughter1.R:Segment.p.end"));} const cst_val *syl_vowel(const cst_item *p){ const cst_item *s,*ls; s=item_as(path_to_item(p,"R:SylStructure.daughter1"),"Segment"); ls=item_as(path_to_item(p,"R:SylStructure.daughtern"),"Segment"); for(;s && !item_equal(s,ls);s=item_next(s)) { if (cst_streq("+",val_string(ph_vc(s)))) { return string_val(item_name(s)); } } if (cst_streq("+",val_string(ph_vc(s)))) { return string_val(item_name(s)); } return (cst_val *) NULL;} const cst_val *syl_numphones(const cst_item *p){ int i; const cst_item *s,*ls; s=item_as(path_to_item(p,"R:SylStructure.daughter1"),"Segment"); ls=item_as(path_to_item(p,"R:SylStructure.daughtern"),"Segment"); for(i=1;s && !item_equal(s,ls);s=item_next(s)){i++;} return val_string_n(i);} const cst_val *pos_in_phrase(const cst_item *p){ const cst_item *s; int i=0; p=item_as(p,"Word"); s=item_as(path_to_item(p,"R:SylStructure.R:Phrase.parent.daughter1"),"Word"); for (;s && !item_equal(p,s);s=item_next(s),i++){} return val_string_n(i);} const cst_val *cg_syl_ratio(const cst_item *p){ return float_val (( 1 + ffeature_float(p,"syl_in"))/(1 + ffeature_float(p,"syl_in") + ffeature_float(p,"syl_out")));} const cst_val *cg_phrase_ratio(const cst_item *p){ const cst_item *lp=p; while(item_next(lp)){lp=item_next(lp);} return float_val ((1 + ffeature_float(p,"lisp_cg_find_phrase_number"))/(1 + ffeature_float(lp,"lisp_cg_find_phrase_number")));} const cst_val *cg_syls_in_phrase(const cst_item *p){ cst_item *s=item_as(item_daughter(p),"Word"); return float_val(1 + ffeature_float(s,"R:SylStructure.daughter1.R:Syllable.syl_out"));} static const cst_val *accented(const cst_item *syl){ if ((item_feat_present(syl,"accent")) || (item_feat_present(syl,"endtone"))) return VAL_STRING_1; else return VAL_STRING_0;} static const cst_val *seg_coda_ctype(const cst_item *seg, const char *ctype){ const cst_item *s; const cst_phoneset *ps = item_phoneset(seg); for (s=item_last_daughter(item_parent(item_as(seg,"SylStructure"))); s; s=item_prev(s)) { if (cst_streq("+",phone_feature_string(ps,item_feat_string(s,"name"), "vc"))) return VAL_STRING_0; if (cst_streq(ctype,phone_feature_string(ps,item_feat_string(s,"name"), "ctype"))) return VAL_STRING_1; } return VAL_STRING_0;} static const cst_val *seg_onset_ctype(const cst_item *seg, const char *ctype){ const cst_item *s; const cst_phoneset *ps = item_phoneset(seg); for (s=item_daughter(item_parent(item_as(seg,"SylStructure"))); s; s=item_next(s)) { if (cst_streq("+",phone_feature_string(ps,item_feat_string(s,"name"), "vc"))) return VAL_STRING_0; if (cst_streq(ctype,phone_feature_string(ps,item_feat_string(s,"name"), "ctype"))) return VAL_STRING_1; } return VAL_STRING_0;} static const cst_val *seg_coda_fric(const cst_item *seg){ return seg_coda_ctype(seg,"f");} static const cst_val *seg_onset_fric(const cst_item *seg){ return seg_onset_ctype(seg,"f");} static const cst_val *seg_coda_stop(const cst_item *seg){ return seg_coda_ctype(seg,"s");} static const cst_val *seg_onset_stop(const cst_item *seg){ return seg_onset_ctype(seg,"s");} static const cst_val *seg_coda_nasal(const cst_item *seg){ return seg_coda_ctype(seg,"n");} static const cst_val *seg_onset_nasal(const cst_item *seg){ return seg_onset_ctype(seg,"n");} static const cst_val *seg_coda_glide(const cst_item *seg){ if (seg_coda_ctype(seg,"r") == VAL_STRING_0) return seg_coda_ctype(seg,"l"); return VAL_STRING_1;} static const cst_val *seg_onset_glide(const cst_item *seg){ if (seg_onset_ctype(seg,"r") == VAL_STRING_0) return seg_onset_ctype(seg,"l"); return VAL_STRING_1;} static const cst_val *seg_onsetcoda(const cst_item *seg){ const cst_item *s; const cst_phoneset *ps = item_phoneset(seg); if (!seg) return VAL_STRING_0; for (s=item_next(item_as(seg,"SylStructure")); s; s=item_next(s)) { if (cst_streq("+",phone_feature_string(ps,item_feat_string(s,"name"), "vc"))) return (cst_val *)&val_string_onset; } return (cst_val *)&val_string_coda;} static const cst_val *pos_in_syl(const cst_item *seg){ const cst_item *s; int c; for (c=-1,s=item_as(seg,"SylStructure"); s; s=item_prev(s),c++); return val_string_n(c);} static const cst_val *position_type(const cst_item *syl){ const cst_item *s = item_as(syl,"SylStructure"); if (s == 0) return (cst_val *)&val_string_single; else if (item_next(s) == 0) { if (item_prev(s) == 0) return (cst_val *)&val_string_single; else return (cst_val *)&val_string_final; } else if (item_prev(s) == 0) return (cst_val *)&val_string_initial; else return (cst_val *)&val_string_mid;} static const cst_val *sub_phrases(const cst_item *syl){ const cst_item *s; int c; for (c=0,s=path_to_item(syl,"R:SylStructure.parent.R:Phrase.parent.p"); s && (c < CST_CONST_INT_MAX); s=item_prev(s),c++); return val_string_n(c);} static const cst_val *last_accent(const cst_item *syl){ const cst_item *s; int c; for (c=0,s=item_as(syl,"Syllable"); s && (c < CST_CONST_INT_MAX); s=item_prev(s),c++) {Lines 1–500 of 907. Load more
/*************************************************************************/ /* */ /* Language Technologies Institute */ /* Carnegie Mellon University */ /* Copyright (c) 2007 */ /* All Rights Reserved. */ /* */ /* Permission is hereby granted, free of charge, to use and distribute */ /* this software and its documentation without restriction, including */ /* without limitation the rights to use, copy, modify, merge, publish, */ /* distribute, sublicense, and/or sell copies of this work, and to */ /* permit persons to whom this work is furnished to do so, subject to */ /* the following conditions: */ /* 1. The code must retain the above copyright notice, this list of */ /* conditions and the following disclaimer. */ /* 2. Any modifications must be clearly marked as such. */ /* 3. Original authors' names are not deleted. */ /* 4. The authors' names are not used to endorse or promote products */ /* derived from this software without specific prior written */ /* permission. */ /* */ /* CARNEGIE MELLON UNIVERSITY AND THE CONTRIBUTORS TO THIS WORK */ /* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */ /* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */ /* SHALL CARNEGIE MELLON UNIVERSITY NOR THE CONTRIBUTORS BE LIABLE */ /* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */ /* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */ /* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */ /* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */ /* THIS SOFTWARE. */ /* */ /*************************************************************************/ /* Author: Alan W Black (awb@cs.cmu.edu) */ /* Date: November 2007 */ /*************************************************************************/ /* */ /* Some language independent features */ /* */ #include "cst_hrg.h" #include "cst_phoneset.h" #include "cst_regex.h" static const cst_val *word_break(const cst_item *word); static const cst_val *word_punc(const cst_item *word); static const cst_val *word_numsyls(const cst_item *word); static const cst_val *ssyl_in(const cst_item *syl); static const cst_val *syl_in(const cst_item *syl); static const cst_val *syl_out(const cst_item *syl); static const cst_val *syl_break(const cst_item *syl); static const cst_val *syl_codasize(const cst_item *syl); static const cst_val *syl_onsetsize(const cst_item *syl); static const cst_val *accented(const cst_item *p); DEF_STATIC_CONST_VAL_STRING(val_string_onset,"onset"); DEF_STATIC_CONST_VAL_STRING(val_string_coda,"coda"); DEF_STATIC_CONST_VAL_STRING(val_string_initial,"initial"); DEF_STATIC_CONST_VAL_STRING(val_string_single,"single"); DEF_STATIC_CONST_VAL_STRING(val_string_final,"final"); DEF_STATIC_CONST_VAL_STRING(val_string_mid,"mid"); DEF_STATIC_CONST_VAL_STRING(val_string_empty,""); const cst_val *ph_vc(const cst_item *p) { return phone_feature(item_phoneset(p),item_name(p),"vc"); } const cst_val *ph_vlng(const cst_item *p) { return phone_feature(item_phoneset(p),item_name(p),"vlng"); } const cst_val *ph_vheight(const cst_item *p) { return phone_feature(item_phoneset(p),item_name(p),"vheight"); } const cst_val *ph_vrnd(const cst_item *p) { return phone_feature(item_phoneset(p),item_name(p),"vrnd"); } const cst_val *ph_vfront(const cst_item *p) { return phone_feature(item_phoneset(p),item_name(p),"vfront"); } const cst_val *ph_ctype(const cst_item *p) { return phone_feature(item_phoneset(p),item_name(p),"ctype"); } const cst_val *ph_cplace(const cst_item *p) { return phone_feature(item_phoneset(p),item_name(p),"cplace"); } const cst_val *ph_cvox(const cst_item *p) { return phone_feature(item_phoneset(p),item_name(p),"cvox"); } const cst_val *cg_duration(const cst_item *p) { /* Note this constructs float vals, these will be freed when the */ /* cart cache is freed, so this should only be used in carts */ if (!p) return float_val(0.0); else if (!item_prev(p)) return item_feat(p,"end"); else return float_val(item_feat_float(p,"end") - item_feat_float(item_prev(p),"end")); } DEF_STATIC_CONST_VAL_STRING(val_string_pos_b,"b"); DEF_STATIC_CONST_VAL_STRING(val_string_pos_m,"m"); DEF_STATIC_CONST_VAL_STRING(val_string_pos_e,"e"); const cst_val *cg_state_pos(const cst_item *p) { const char *name; name = item_feat_string(p,"name"); if (!cst_streq(name,ffeature_string(p,"p.name"))) return (cst_val *)&val_string_pos_b; if (cst_streq(name,ffeature_string(p,"n.name"))) return (cst_val *)&val_string_pos_m; else return (cst_val *)&val_string_pos_e; } const cst_val *cg_state_place(const cst_item *p) { float start, end; int thisone; start = (float)ffeature_int(p,"R:mcep_link.parent.daughter1.frame_number"); end = (float)ffeature_int(p,"R:mcep_link.parent.daughtern.frame_number"); thisone = item_feat_int(p,"frame_number"); if ((end-start) == 0.0) return float_val(0.0); else return float_val((thisone-start)/(end-start)); } const cst_val *cg_state_index(const cst_item *p) { float start; int thisone; start = (float)ffeature_int(p,"R:mcep_link.parent.daughter1.frame_number"); thisone = item_feat_int(p,"frame_number"); return float_val(thisone-start); } const cst_val *cg_state_rindex(const cst_item *p) { float end; int thisone; end = (float)ffeature_int(p,"R:mcep_link.parent.daughtern.frame_number"); thisone = item_feat_int(p,"frame_number"); return float_val(end-thisone); } const cst_val *cg_phone_place(const cst_item *p) { float start, end; int thisone; start = (float)ffeature_int(p,"R:mcep_link.parent.R:segstate.parent.daughter1.R:mcep_link.daughter1.frame_number"); end = (float)ffeature_int(p,"R:mcep_link.parent.R:segstate.parent.daughtern.R:mcep_link.daughtern.frame_number"); thisone = item_feat_int(p,"frame_number"); if ((end-start) == 0.0) return float_val(0.0); else return float_val((thisone-start)/(end-start)); } const cst_val *cg_phone_index(const cst_item *p) { float start; int thisone; start = (float)ffeature_int(p,"R:mcep_link.parent.R:segstate.parent.daughter1.R:mcep_link.daughter1.frame_number"); thisone = item_feat_int(p,"frame_number"); return float_val(thisone-start); } const cst_val *cg_phone_rindex(const cst_item *p) { float end; int thisone; end = (float)ffeature_int(p,"R:mcep_link.parent.R:segstate.parent.daughtern.R:mcep_link.daughtern.frame_number"); thisone = item_feat_int(p,"frame_number"); return float_val(end-thisone); } const cst_val *cg_is_pau(const cst_item *p) { if (p && cst_streq("pau",item_feat_string(p,"name"))) return &val_int_1; else return &val_int_0; } const cst_val *cg_find_phrase_number(const cst_item *p) { const cst_item *v; int x = 0; for (v=item_prev(p); v; v=item_prev(v)) x++; return val_int_n(x); } const cst_val *cg_position_in_phrasep(const cst_item *p) { float pstart, pend, phrasenumber; float x; #define CG_FRAME_SHIFT 0.005 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"); 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"); phrasenumber = ffeature_float(p,"R:mcep_link.parent.R:segstate.parent.R:SylStructure.parent.parent.R:Phrase.parent.lisp_cg_find_phrase_number"); if ((pend - pstart) == 0.0) return float_val(-1.0); else { x = phrasenumber + ((CG_FRAME_SHIFT*item_feat_float(p,"frame_number"))-pstart) / (pend - pstart); return float_val(x); } } const cst_val *cg_position_in_phrase(const cst_item *p) { float pstart, pend; float x; #define CG_FRAME_SHIFT 0.005 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"); 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"); if ((pend - pstart) == 0.0) return float_val(-1.0); else { x = 0 + ((CG_FRAME_SHIFT*item_feat_float(p,"frame_number"))-pstart) / (pend - pstart); return float_val(x); } } const cst_val *cg_position_in_sentence(const cst_item *p) { float sstart, send; float x; #define CG_FRAME_SHIFT 0.005 sstart = ffeature_float(p,"R:mcep_link.parent.R:segstate.parent.R:SylStructure.parent.parent.R:Word.first.R:SylStructure.daughter1.daughter1.R:Segment.p.end"); send = ffeature_float(p,"R:mcep_link.parent.R:segstate.parent.R:SylStructure.parent.parent.R:Word.last.R:SylStructure.daughtern.daughtern.R:Segment.end"); if ((send - sstart) == 0.0) return float_val(-1.0); else { x = ((CG_FRAME_SHIFT*item_feat_float(p,"frame_number"))-sstart) / (send - sstart); return float_val(x); } } /* Spam specific features, but may be useful for others */ const cst_val *pos_in_word(const cst_item *p) { const cst_item *s; int i=0; p=item_as(p,"Syllable"); s=item_as(path_to_item(p,"R:SylStructure.parent.daughter1"),"Syllable"); for (;s && !item_equal(p,s);s=item_next(s),i++){} return val_string_n(i); } const cst_val *syllable_duration(const cst_item *p) { return float_val(ffeature_float(p,"R:SylStructure.daughtern.R:Segment.end") - ffeature_float(p,"R:SylStructure.daughter1.R:Segment.p.end")); } const cst_val *syl_vowel(const cst_item *p) { const cst_item *s,*ls; s=item_as(path_to_item(p,"R:SylStructure.daughter1"),"Segment"); ls=item_as(path_to_item(p,"R:SylStructure.daughtern"),"Segment"); for(;s && !item_equal(s,ls);s=item_next(s)) { if (cst_streq("+",val_string(ph_vc(s)))) { return string_val(item_name(s)); } } if (cst_streq("+",val_string(ph_vc(s)))) { return string_val(item_name(s)); } return (cst_val *) NULL; } const cst_val *syl_numphones(const cst_item *p) { int i; const cst_item *s,*ls; s=item_as(path_to_item(p,"R:SylStructure.daughter1"),"Segment"); ls=item_as(path_to_item(p,"R:SylStructure.daughtern"),"Segment"); for(i=1;s && !item_equal(s,ls);s=item_next(s)){i++;} return val_string_n(i); } const cst_val *pos_in_phrase(const cst_item *p) { const cst_item *s; int i=0; p=item_as(p,"Word"); s=item_as(path_to_item(p,"R:SylStructure.R:Phrase.parent.daughter1"),"Word"); for (;s && !item_equal(p,s);s=item_next(s),i++){} return val_string_n(i); } const cst_val *cg_syl_ratio(const cst_item *p) { return float_val (( 1 + ffeature_float(p,"syl_in"))/(1 + ffeature_float(p,"syl_in") + ffeature_float(p,"syl_out"))); } const cst_val *cg_phrase_ratio(const cst_item *p) { const cst_item *lp=p; while(item_next(lp)){lp=item_next(lp);} return float_val ((1 + ffeature_float(p,"lisp_cg_find_phrase_number"))/(1 + ffeature_float(lp,"lisp_cg_find_phrase_number"))); } const cst_val *cg_syls_in_phrase(const cst_item *p) { cst_item *s=item_as(item_daughter(p),"Word"); return float_val(1 + ffeature_float(s,"R:SylStructure.daughter1.R:Syllable.syl_out")); } static const cst_val *accented(const cst_item *syl) { if ((item_feat_present(syl,"accent")) || (item_feat_present(syl,"endtone"))) return VAL_STRING_1; else return VAL_STRING_0; } static const cst_val *seg_coda_ctype(const cst_item *seg, const char *ctype) { const cst_item *s; const cst_phoneset *ps = item_phoneset(seg); for (s=item_last_daughter(item_parent(item_as(seg,"SylStructure"))); s; s=item_prev(s)) { if (cst_streq("+",phone_feature_string(ps,item_feat_string(s,"name"), "vc"))) return VAL_STRING_0; if (cst_streq(ctype,phone_feature_string(ps,item_feat_string(s,"name"), "ctype"))) return VAL_STRING_1; } return VAL_STRING_0; } static const cst_val *seg_onset_ctype(const cst_item *seg, const char *ctype) { const cst_item *s; const cst_phoneset *ps = item_phoneset(seg); for (s=item_daughter(item_parent(item_as(seg,"SylStructure"))); s; s=item_next(s)) { if (cst_streq("+",phone_feature_string(ps,item_feat_string(s,"name"), "vc"))) return VAL_STRING_0; if (cst_streq(ctype,phone_feature_string(ps,item_feat_string(s,"name"), "ctype"))) return VAL_STRING_1; } return VAL_STRING_0; } static const cst_val *seg_coda_fric(const cst_item *seg) { return seg_coda_ctype(seg,"f"); } static const cst_val *seg_onset_fric(const cst_item *seg) { return seg_onset_ctype(seg,"f"); } static const cst_val *seg_coda_stop(const cst_item *seg) { return seg_coda_ctype(seg,"s"); } static const cst_val *seg_onset_stop(const cst_item *seg) { return seg_onset_ctype(seg,"s"); } static const cst_val *seg_coda_nasal(const cst_item *seg) { return seg_coda_ctype(seg,"n"); } static const cst_val *seg_onset_nasal(const cst_item *seg) { return seg_onset_ctype(seg,"n"); } static const cst_val *seg_coda_glide(const cst_item *seg) { if (seg_coda_ctype(seg,"r") == VAL_STRING_0) return seg_coda_ctype(seg,"l"); return VAL_STRING_1; } static const cst_val *seg_onset_glide(const cst_item *seg) { if (seg_onset_ctype(seg,"r") == VAL_STRING_0) return seg_onset_ctype(seg,"l"); return VAL_STRING_1; } static const cst_val *seg_onsetcoda(const cst_item *seg) { const cst_item *s; const cst_phoneset *ps = item_phoneset(seg); if (!seg) return VAL_STRING_0; for (s=item_next(item_as(seg,"SylStructure")); s; s=item_next(s)) { if (cst_streq("+",phone_feature_string(ps,item_feat_string(s,"name"), "vc"))) return (cst_val *)&val_string_onset; } return (cst_val *)&val_string_coda; } static const cst_val *pos_in_syl(const cst_item *seg) { const cst_item *s; int c; for (c=-1,s=item_as(seg,"SylStructure"); s; s=item_prev(s),c++); return val_string_n(c); } static const cst_val *position_type(const cst_item *syl) { const cst_item *s = item_as(syl,"SylStructure"); if (s == 0) return (cst_val *)&val_string_single; else if (item_next(s) == 0) { if (item_prev(s) == 0) return (cst_val *)&val_string_single; else return (cst_val *)&val_string_final; } else if (item_prev(s) == 0) return (cst_val *)&val_string_initial; else return (cst_val *)&val_string_mid; } static const cst_val *sub_phrases(const cst_item *syl) { const cst_item *s; int c; for (c=0,s=path_to_item(syl,"R:SylStructure.parent.R:Phrase.parent.p"); s && (c < CST_CONST_INT_MAX); s=item_prev(s),c++); return val_string_n(c); } static const cst_val *last_accent(const cst_item *syl) { const cst_item *s; int c; for (c=0,s=item_as(syl,"Syllable"); s && (c < CST_CONST_INT_MAX); s=item_prev(s),c++) {