def add_relational_stanford_dependency(context_skeleton, phoneme): """Adds the relational elements of stanford parse information to a phoneme context.""" c = context_skeleton #Word w = phoneme.parent_word ###### Stanford Dependency Parse Information ###### add_basic_stanford_dependency(c, phoneme) #Word relational distance to parent relation #We subtract 1 because label pos and num phonemes start from 1 but to_relational starts from 0 #If the current phoneme is sil/pau etc. the label is None and we can just add "xx" all through if w.parent_dependency.label == None and phoneme.id in phoneme.parent_utt.phoneme_features.get_sil_phonemes(): c.add("wdpr", "xx") c.add("wdgpr", "xx") c.add("wdggpr", "xx") return dep_pos = to_relational(w.parent_dependency.utt_pos-1, w.parent_utt.num_words()-1, True) if w.parent_dependency.parent != None and w.parent_dependency.parent.label != "ROOT": p_dep_pos = to_relational(w.parent_dependency.parent.utt_pos-1, w.parent_utt.num_words()-1, True) c.add("wdpr", str(abs(dep_pos-p_dep_pos))) else: c.add("wdpr", "xx") #Word relational distance to grandparent relation if w.grandparent_dependency.parent != None and w.grandparent_dependency.parent.label != "ROOT": p_dep_pos = to_relational(w.grandparent_dependency.parent.utt_pos-1, w.parent_utt.num_words()-1, True) c.add("wdgpr", str(abs(dep_pos-p_dep_pos))) else: c.add("wdgpr", "xx") #Word relational position in greatgrandparent phrase if w.greatgrandparent_dependency.parent != None and w.greatgrandparent_dependency.parent.label != "ROOT": p_dep_pos = to_relational(w.greatgrandparent_dependency.parent.utt_pos-1, w.parent_utt.num_words()-1, True) c.add("wdggpr", str(abs(dep_pos-p_dep_pos))) else: c.add("wdggpr", "xx")
def add_relational(context_skeleton, phoneme): """Adds the relational context set. Relational means that positions in segments are relational.""" utt = phoneme.parent_utt phoneme_features = utt.phoneme_features c = context_skeleton syll = phoneme.parent_syllable word = phoneme.parent_word #Add the basic features add_basic(c, phoneme) #Add phoneme syll and word pos if phoneme.id in phoneme_features.get_sil_phonemes(): #Phone forward pos in syll c.add("pfwsp", str(0.0)) #Phone backward pos in syll c.add("pbwsp", str(0.0)) #Phone forward pos in word c.add("pfwwp", str(0.0)) #Phone backward pos in word c.add("pbwwp", str(0.0)) else: #Phone forward pos in syll s_n_p = syll.num_phonemes() c.add("pfwsp", str(to_relational(phoneme.pos_in_syllable(), s_n_p - 1, True))) #Phone backward pos in syll c.add("pbwsp", str(to_relational(phoneme.pos_in_syllable(), s_n_p - 1, False))) #Phone forward pos in word w_n_p = word.num_phonemes() c.add("pfwwp", str(to_relational(phoneme.pos_in_word(), w_n_p - 1, True))) #Phone backward pos in word c.add("pbwwp", str(to_relational(phoneme.pos_in_word(), w_n_p - 1, False))) #Add syllable forward and backward word pos #If this is a silence segment we have no relational pos. if phoneme.id in phoneme_features.get_sil_phonemes(): #Syllable forward pos in word c.add("sfwwp", str(0.0)) #Syllable backward pos in word c.add("sbwwp", str(0.0)) else: #Syllable forward pos in word w_n_s = syll.parent_word.num_syllables() c.add("sfwwp", str(to_relational(syll.pos_in_word(), w_n_s - 1, True))) #Syllable backward pos in word c.add("sbwwp", str(to_relational(syll.pos_in_word(), w_n_s - 1, False))) #Add pos in utt #Word forward pos in utterance u_n_w = word.parent_utt.num_words() c.add("wfwup", str(to_relational(word.pos_in_utt(), u_n_w - 1, True))) #Word forward pos in utterance c.add("wbwup", str(to_relational(word.pos_in_utt(), u_n_w - 1, False)))
def add_relational_stanford_dependency(context_skeleton, phoneme): """Adds the relational elements of stanford parse information to a phoneme context.""" c = context_skeleton #Word w = phoneme.parent_word ###### Stanford Dependency Parse Information ###### add_basic_stanford_dependency(c, phoneme) #Word relational distance to parent relation #We subtract 1 because label pos and num phonemes start from 1 but to_relational starts from 0 #If the current phoneme is sil/pau etc. the label is None and we can just add "xx" all through if w.parent_dependency.label == None and phoneme.id in phoneme.parent_utt.phoneme_features.get_sil_phonemes( ): c.add("wdpr", "xx") c.add("wdgpr", "xx") c.add("wdggpr", "xx") return dep_pos = to_relational(w.parent_dependency.utt_pos - 1, w.parent_utt.num_words() - 1, True) if w.parent_dependency.parent != None and w.parent_dependency.parent.label != "ROOT": p_dep_pos = to_relational(w.parent_dependency.parent.utt_pos - 1, w.parent_utt.num_words() - 1, True) c.add("wdpr", str(abs(dep_pos - p_dep_pos))) else: c.add("wdpr", "xx") #Word relational distance to grandparent relation if w.grandparent_dependency.parent != None and w.grandparent_dependency.parent.label != "ROOT": p_dep_pos = to_relational(w.grandparent_dependency.parent.utt_pos - 1, w.parent_utt.num_words() - 1, True) c.add("wdgpr", str(abs(dep_pos - p_dep_pos))) else: c.add("wdgpr", "xx") #Word relational position in greatgrandparent phrase if w.greatgrandparent_dependency.parent != None and w.greatgrandparent_dependency.parent.label != "ROOT": p_dep_pos = to_relational( w.greatgrandparent_dependency.parent.utt_pos - 1, w.parent_utt.num_words() - 1, True) c.add("wdggpr", str(abs(dep_pos - p_dep_pos))) else: c.add("wdggpr", "xx")
def add_relational_stanford(context_skeleton, phoneme): """Adds the relational elements of stanford parse information to a phoneme context.""" c = context_skeleton #Add basic info add_basic_stanford(c, phoneme) #Word w = phoneme.parent_word #Word relational position in parent phrase c.add("wfwrppp", str(to_relational(w.parent_phrase.pos_in_parent, w.parent_phrase.num_siblings, True, True))) c.add("wbwrppp", str(to_relational(w.parent_phrase.pos_in_parent, w.parent_phrase.num_siblings, False, True))) #Word relational position in grandparent phrase c.add("wfwrgppp", str(to_relational(w.grandparent_phrase.pos_in_parent, w.grandparent_phrase.num_siblings, True, True))) c.add("wbwrgppp", str(to_relational(w.grandparent_phrase.pos_in_parent, w.grandparent_phrase.num_siblings, False, True))) #Word relational position in greatgrandparent phrase c.add("wfwrggppp", str(to_relational(w.greatgrandparent_phrase.pos_in_parent, w.greatgrandparent_phrase.num_siblings, True, True))) c.add("wbwrggppp", str(to_relational(w.greatgrandparent_phrase.pos_in_parent, w.greatgrandparent_phrase.num_siblings, False, True)))
def add_relational_stanford_pcfg(context_skeleton, phoneme): """Adds the relational elements of stanford parse information to a phoneme context.""" c = context_skeleton #Add basic info add_basic_stanford_pcfg(c, phoneme) #Word w = phoneme.parent_word #Word relational position in parent phrase c.add( "wfwrppp", str( to_relational(w.parent_phrase.pos_in_parent, w.parent_phrase.num_siblings, True, True))) c.add( "wbwrppp", str( to_relational(w.parent_phrase.pos_in_parent, w.parent_phrase.num_siblings, False, True))) #Word relational position in grandparent phrase c.add( "wfwrgppp", str( to_relational(w.grandparent_phrase.pos_in_parent, w.grandparent_phrase.num_siblings, True, True))) c.add( "wbwrgppp", str( to_relational(w.grandparent_phrase.pos_in_parent, w.grandparent_phrase.num_siblings, False, True))) #Word relational position in greatgrandparent phrase c.add( "wfwrggppp", str( to_relational(w.greatgrandparent_phrase.pos_in_parent, w.greatgrandparent_phrase.num_siblings, True, True))) c.add( "wbwrggppp", str( to_relational(w.greatgrandparent_phrase.pos_in_parent, w.greatgrandparent_phrase.num_siblings, False, True)))