EST_Utterance.cc (speech_tools-2.4-release) | : | EST_Utterance.cc (speech_tools-2.5.0-release) | ||
---|---|---|---|---|
skipping to change at line 121 | skipping to change at line 121 | |||
} | } | |||
static EST_Item *item_id(EST_Item *p, const EST_String &n) | static EST_Item *item_id(EST_Item *p, const EST_String &n) | |||
{ | { | |||
EST_Item *s, *t; | EST_Item *s, *t; | |||
t = 0; | t = 0; | |||
if ((p == 0) || (p->S("id","0") == n)) | if ((p == 0) || (p->S("id","0") == n)) | |||
return p; | return p; | |||
for (s = daughter1(p); s; s = s->next()) | for (s = daughter1(p); s; s = inext(s)) | |||
{ | { | |||
t = item_id(s, n); | t = item_id(s, n); | |||
if (t != 0) | if (t != 0) | |||
return t; | return t; | |||
} | } | |||
return 0; | return 0; | |||
} | } | |||
EST_Item *EST_Utterance::id(const EST_String &n) const | EST_Item *EST_Utterance::id(const EST_String &n) const | |||
skipping to change at line 245 | skipping to change at line 245 | |||
static void merge_tree(EST_Relation *urel, | static void merge_tree(EST_Relation *urel, | |||
EST_Relation *rel, | EST_Relation *rel, | |||
EST_Item *uroot, | EST_Item *uroot, | |||
EST_Item *root, | EST_Item *root, | |||
EST_Features &items, | EST_Features &items, | |||
EST_String feature) | EST_String feature) | |||
{ | { | |||
EST_Item *n=0; | EST_Item *n=0; | |||
merge_features(uroot->features(), root->features()); | merge_features(uroot->features(), root->features()); | |||
// copy horizontally | // copy horizontally | |||
if (root->next()!= NULL) | if (inext(root)!= NULL) | |||
{ | { | |||
EST_Item *old = item(items.f(root->next()->S(feature),est_val(n))); | EST_Item *old = item(items.f(inext(root)->S(feature),est_val(n))); | |||
EST_Item *new_root = old?uroot->insert_after(old):uroot->insert_after(); | EST_Item *new_root = old?uroot->insert_after(old):uroot->insert_after(); | |||
merge_tree(urel, rel, new_root, root->next(), items, feature); | merge_tree(urel, rel, new_root, inext(root), items, feature); | |||
} | } | |||
// vertically | // vertically | |||
if (root->down()!= NULL) | if (idown(root)!= NULL) | |||
{ | { | |||
EST_Item *old = item(items.f(root->down()->S(feature),est_val(n))); | EST_Item *old = item(items.f(idown(root)->S(feature),est_val(n))); | |||
EST_Item *new_root = old?uroot->insert_below(old):uroot->insert_below(); | EST_Item *new_root = old?uroot->insert_below(old):uroot->insert_below(); | |||
merge_tree(urel, rel, new_root, root->down(), items, feature); | merge_tree(urel, rel, new_root, idown(root), items, feature); | |||
} | } | |||
} | } | |||
int utterance_merge(EST_Utterance &utt, | int utterance_merge(EST_Utterance &utt, | |||
EST_Utterance &extra, | EST_Utterance &extra, | |||
EST_String feature) | EST_String feature) | |||
{ | { | |||
// Global merge. Uses the feature to determine which items correspond. | // Global merge. Uses the feature to determine which items correspond. | |||
// First build a table of existing contents. | // First build a table of existing contents. | |||
EST_Features items; | EST_Features items; | |||
EST_Features::Entries ri; | EST_Features::Entries ri; | |||
for(ri.begin(utt.relations); ri; ri++) | for(ri.begin(utt.relations); ri; ri++) | |||
{ | { | |||
EST_Relation *rel = relation(ri->v); | EST_Relation *rel = relation(ri->v); | |||
for(EST_Item *i=rel->head(); i != NULL; i=i->next_item()) | for(EST_Item *i=rel->head(); i != NULL; i=next_item(i)) | |||
{ | { | |||
EST_String id = i->S(feature); | EST_String id = i->S(feature); | |||
items.set_val(id,est_val(i)); | items.set_val(id,est_val(i)); | |||
} | } | |||
} | } | |||
EST_Features::Entries eri; | EST_Features::Entries eri; | |||
for(eri.begin(extra.relations); eri; eri++) | for(eri.begin(extra.relations); eri; eri++) | |||
{ | { | |||
EST_Relation *rel = relation(eri->v); | EST_Relation *rel = relation(eri->v); | |||
skipping to change at line 359 | skipping to change at line 359 | |||
clear_up_sisilist(sisilist); | clear_up_sisilist(sisilist); | |||
return TRUE; | return TRUE; | |||
} | } | |||
static void copy_relation(EST_Item *to,EST_Item *from, | static void copy_relation(EST_Item *to,EST_Item *from, | |||
EST_TKVL<EST_Item_Content *,EST_Item *> &slist) | EST_TKVL<EST_Item_Content *,EST_Item *> &slist) | |||
{ | { | |||
// Construct next and down nodes of from, into to, mapping | // Construct next and down nodes of from, into to, mapping | |||
// stream_items through slist | // stream_items through slist | |||
if (from->next()) | if (inext(from)) | |||
copy_relation(to->insert_after(map_ling_item(from->next(),slist)), | copy_relation(to->insert_after(map_ling_item(inext(from),slist)), | |||
from->next(), | inext(from), | |||
slist); | slist); | |||
if (from->down()) | if (idown(from)) | |||
copy_relation(to->insert_below(map_ling_item(from->down(),slist)), | copy_relation(to->insert_below(map_ling_item(idown(from),slist)), | |||
from->down(), | idown(from), | |||
slist); | slist); | |||
} | } | |||
static EST_Item *map_ling_item(EST_Item *si, | static EST_Item *map_ling_item(EST_Item *si, | |||
EST_TKVL<EST_Item_Content *,EST_Item *> &s) | EST_TKVL<EST_Item_Content *,EST_Item *> &s) | |||
{ | { | |||
// If si is already in s return its map otherwise copy | // If si is already in s return its map otherwise copy | |||
// si and add it to the list | // si and add it to the list | |||
EST_Item *msi; | EST_Item *msi; | |||
EST_Item *def = 0; | EST_Item *def = 0; | |||
skipping to change at line 432 | skipping to change at line 432 | |||
{ | { | |||
EST_String relname = i->relations().list(r).k; | EST_String relname = i->relations().list(r).k; | |||
if (!sub.relation_present(relname)) | if (!sub.relation_present(relname)) | |||
sub.create_relation(relname)->append(ni); | sub.create_relation(relname)->append(ni); | |||
else if ((np=mapped_parent(i,relname,s)) != 0) | else if ((np=mapped_parent(i,relname,s)) != 0) | |||
np->append_daughter(ni); | np->append_daughter(ni); | |||
else | else | |||
sub.relation(relname)->append(ni); | sub.relation(relname)->append(ni); | |||
// Do its daughters | // Do its daughters | |||
for (d = daughter1(i,relname); d ; d=d->next()) | for (d = daughter1(i,relname); d ; d=inext(d)) | |||
sub_utt_copy(sub,d,s); | sub_utt_copy(sub,d,s); | |||
} | } | |||
} | } | |||
} | } | |||
void sub_utterance(EST_Utterance &sub,EST_Item *i) | void sub_utterance(EST_Utterance &sub,EST_Item *i) | |||
{ | { | |||
// Extract i and all its relations, and daughters ... to build | // Extract i and all its relations, and daughters ... to build | |||
// a new utterance in sub. | // a new utterance in sub. | |||
EST_TKVL<EST_Item_Content *,EST_Item *> sisilist; | EST_TKVL<EST_Item_Content *,EST_Item *> sisilist; | |||
skipping to change at line 561 | skipping to change at line 561 | |||
cerr << "Can't save utterances to files type " << save_type << endl; | cerr << "Can't save utterances to files type " << save_type << endl; | |||
return write_fail; | return write_fail; | |||
} | } | |||
return (*s_fun)(outf, *this); | return (*s_fun)(outf, *this); | |||
} | } | |||
void utt_2_flat_repr( const EST_Utterance &utt, | void utt_2_flat_repr( const EST_Utterance &utt, | |||
EST_String &flat_repr ) | EST_String &flat_repr ) | |||
{ | { | |||
EST_Item *phrase = utt.relation("Phrase")->head(); | EST_Item *phrase = utt.relation("Phrase")->head(); | |||
for( ; phrase; phrase=phrase->next() ){ | for( ; phrase; phrase=inext(phrase) ){ | |||
flat_repr += "<"; | flat_repr += "<"; | |||
EST_Item *word = daughter1(phrase); | EST_Item *word = daughter1(phrase); | |||
for( ; word; word=word->next() ){ | for( ; word; word=inext(word) ){ | |||
flat_repr += "{"; | flat_repr += "{"; | |||
EST_Item *syllable = daughter1(word, "SylStructure"); | EST_Item *syllable = daughter1(word, "SylStructure"); | |||
for( ; syllable; syllable=syllable->next() ){ | for( ; syllable; syllable=inext(syllable) ){ | |||
flat_repr += EST_String::cat( "(", syllable->S("stress") ); | flat_repr += EST_String::cat( "(", syllable->S("stress") ); | |||
EST_Item *phone = daughter1(syllable); | EST_Item *phone = daughter1(syllable); | |||
for( ; phone; phone=phone->next() ) | for( ; phone; phone=inext(phone) ) | |||
flat_repr += EST_String::cat( " ", phone->S("name"), " " ); | flat_repr += EST_String::cat( " ", phone->S("name"), " " ); | |||
flat_repr += ")"; | flat_repr += ")"; | |||
} | } | |||
flat_repr += "}"; | flat_repr += "}"; | |||
} | ||||
flat_repr += EST_String::cat( "> _", phrase->S("name"), " " ); | ||||
} | } | |||
flat_repr += EST_String::cat( "> _", phrase->S("name"), " " ); | ||||
} | ||||
} | } | |||
End of changes. 13 change blocks. | ||||
35 lines changed or deleted | 35 lines changed or added |