43 #include "EST_error.h" 44 #include "EST_string_aux.h" 45 #include "ling_class/EST_Utterance.h" 46 #include "EST_UtteranceFile.h" 47 #include "EST_string_aux.h" 60 #if defined(INSTANTIATE_TEMPLATES) 62 #include "../base_class/EST_TList.cc" 63 #include "../base_class/EST_TKVL.cc" 118 if ((p == 0) || (p->
S(
"id",
"0") == n))
121 for (s = daughter1(p); s; s = s->next())
138 if ((t = item_id(s, n)) != 0)
140 EST_error(
"Could not find item matching id %s\n", (
const char *)n);
167 return ::relation(
relations.
f(name,est_val(r)));
176 BracketStringtoStrList(name, s);
182 for (
EST_Litem *p = names.head(); p ; p = p->next())
196 u.
save(st,
"est_ascii");
218 rnode = nrel->append(map_ling_item(rr->
head(),sisilist));
219 copy_relation(rnode,rr->
head(),sisilist);
222 clear_up_sisilist(sisilist);
230 void EST_Utterance::sub_utterance(
EST_Item *i)
232 extra_sub_utterance(*
this,i);
243 merge_features(uroot->features(), root->features());
245 if (root->next()!= NULL)
247 EST_Item *old = item(items.
f(root->next()->
S(feature),est_val(n)));
248 EST_Item *new_root = old?uroot->insert_after(old):uroot->insert_after();
249 merge_tree(urel, rel, new_root, root->next(), items, feature);
252 if (root->down()!= NULL)
254 EST_Item *old = item(items.
f(root->down()->
S(feature),est_val(n)));
255 EST_Item *new_root = old?uroot->insert_below(old):uroot->insert_below();
256 merge_tree(urel, rel, new_root, root->down(), items, feature);
273 for(
EST_Item *i=rel->
head(); i != NULL; i=i->next_item())
291 if (rel->
head() != NULL)
294 EST_Item *old = item(items.
f(rel->
head()->
S(feature),est_val(n)));
295 EST_Item *new_root = old?urel->append(old):urel->append();
296 merge_tree(urel, rel, new_root, rel->
head(), items, feature);
317 EST_error(
"utterance_merge: items not is same relation");
319 if ((utt_root == 0) || (sub_root == 0))
320 EST_error(
"utterance_merge: items are null");
324 merge_features(utt_root->features(), sub_root->features());
325 utt_root->
set(
"id", root_id);
327 sisilist.
add_item(sub_root->contents(),utt_root);
328 copy_relation(utt_root,sub_root,sisilist);
343 rnode = nrel->append(nn);
344 copy_relation(rnode,rr->
head(),sisilist);
349 clear_up_sisilist(sisilist);
360 copy_relation(to->insert_after(map_ling_item(from->next(),slist)),
364 copy_relation(to->insert_below(map_ling_item(from->down(),slist)),
377 msi = s.
val_def(si->contents(),def);
403 if ((p=parent(i,relname)) == 0)
405 else if (s.
present(p->contents()))
426 else if ((np=mapped_parent(i,relname,s)) != 0)
427 np->append_daughter(ni);
432 for (d = daughter1(i,relname); d ; d=d->next())
433 sub_utt_copy(sub,d,s);
445 sub_utt_copy(sub,i,sisilist);
447 clear_up_sisilist(sisilist);
453 EST_read_status v=format_ok;
455 if (((filename ==
"-") ? ts.
open(cin) : ts.
open(filename)) != 0)
457 cerr <<
"load_utt: can't open utterance input file " 459 return misc_read_error;
465 f.
set(
"filename", filename);
474 EST_read_status stat=read_error;
480 for(
int n=0; n< EST_UtteranceFile::map.n() ; n++)
482 EST_UtteranceFileType t = EST_UtteranceFile::map.token(n);
487 EST_UtteranceFile::Info *info = &(EST_UtteranceFile::map.info(t));
489 if (! info->recognise)
492 EST_UtteranceFile::Load_TokenStream * l_fun = info->load;
499 stat = (*l_fun)(ts, *
this, max_id);
521 outf =
new ofstream(filename);
526 v =
save(*outf,type);
537 EST_String save_type = (type ==
"") ? DEF_FILE_TYPE : type;
539 EST_UtteranceFileType t = EST_UtteranceFile::map.token(save_type);
543 cerr <<
"Utterance: unknown filetype in saving " << save_type << endl;
547 EST_UtteranceFile::Save_TokenStream * s_fun = EST_UtteranceFile::map.info(t).save;
551 cerr <<
"Can't save utterances to files type " << save_type << endl;
555 return (*s_fun)(outf, *
this);
562 for( ; phrase; phrase=phrase->next() ){
566 for( ; word; word=word->next() ){
569 EST_Item *syllable = daughter1(word,
"SylStructure");
570 for( ; syllable; syllable=syllable->next() ){
573 EST_Item *phone = daughter1(syllable);
574 for( ; phone; phone=phone->next() )
void clear_relations()
clear the contents of the relations only
EST_write_status save(const EST_String &filename, const EST_String &type="est_ascii") const
EST_read_status load(const EST_String &filename)
void clear()
remove everything in utterance
EST_Relation * create_relation(const EST_String &relname)
create a new relation called <parameter>n</parameter>.
void set_val(const EST_String &name, const EST_Val &sval)
const int Int(void) const
void close(void)
Close stream.
int tell(void) const
tell, synonym for filepos
void set(const EST_String &name, int ival)
EST_Features f
Utterance level features.
void evaluate_all_features()
Evaluate all feature functions in utterance.
EST_Features relations
The list of named relations.
EST_Item * as_relation(const char *relname) const
View item from another relation (const char *) method.
int open(const EST_String &filename)
open a {EST_TokenStream} for a file.
static EST_String cat(const EST_String s1, const EST_String s2=Empty, const EST_String s3=Empty, const EST_String s4=Empty, const EST_String s5=Empty, const EST_String s6=Empty, const EST_String s7=Empty, const EST_String s8=Empty, const EST_String s9=Empty)
void set_utt(EST_Utterance *u)
void evaluate_item_features()
void set(const EST_String &name, int ival)
const EST_Val & f(const EST_String &path) const
EST_Utterance()
default constructor
const V & val_def(const K &rkey, const V &def) const
value or default
EST_Item * id(const EST_String &n) const
return EST_Item whose id is <parameter>n</parameter>.
const EST_String & name() const
const EST_String & relation_name() const
The relation name of this particular item.
EST_TKVL< EST_String, EST_Val > & relations()
Access to the relation links.
EST_TList< EST_TKVI< K, V > > list
Linked list of key-val pairs. Don't use this as it will be made private in the future.
void remove(const EST_String &name)
int remove_item(const K &rkey, int quiet=0)
remove key and val pair from list
int present(const EST_String &name) const
const int present(const K &rkey) const
Returns true if key is present.
int add_item(const K &rkey, const V &rval, int no_search=0)
add key-val pair to list
void init()
initialise utterance
int contains(const char *s, int pos=-1) const
Does it contain this substring?
void begin(const Container &over)
Set the iterator ready to run over this container.
int next_id()
return the id of the next item
const EST_String S(const EST_String &name) const
EST_Relation * relation(const char *name, int err_on_not_found=1) const
get relation by name
bool relation_present(const EST_String name) const
const EST_Val & val(const char *name) const
void f_remove(const EST_String &name)
int seek(int position)
seek, reposition file pointer
void remove_relation(const EST_String &relname)
remove the relation called <parameter>n</parameter>.