76 tmp_name =
f.S(
"name",
"");
78 f.set(
"name", tmp_name);
95 EST_warning(
"EST_Relation: no relation to append to");
129 EST_warning(
"EST_Relation: no relation to prepend to");
132 else if (p_head == 0)
156 for (i=0,node=p_head; node; node=node->
next())
164 s->evaluate_features();
171 for (nn = p_head; nn != 0; nn = nnn)
182 p_head = node->
next();
184 p_tail = node->
prev();
201 if (from.
root() != 0)
210 bool evaluate_ff)
const 214 else if (type ==
"htk")
218 EST_warning(
"EST_Relation: unsupported type: \"%s\"", (
const char *)type);
225 bool evaluate_ff)
const 229 else if (type ==
"htk")
233 EST_warning(
"EST_Relation: unsupported type: \"%s\"", (
const char *)type);
239 bool evaluate_ff)
const 241 return save(filename,
"esps",evaluate_ff);
249 outf <<
"Relation " <<
name() <<
" ; ";
252 save_items(p_head,outf,contents,nodenames,node_count);
253 outf <<
"End_of_Relation" << endl;
261 int &node_count)
const 270 myname = node_count++;
280 save_items(n->
down(),outf,cnames,nodenames,node_count);
281 outf << nodenames.val(n) <<
" " <<
283 (n->
up() == 0 ? 0 : nodenames.val(n->
up())) <<
" " <<
284 (n->
down() == 0 ? 0 : nodenames.val(n->
down())) <<
" " <<
285 (n->
next() == 0 ? 0 : nodenames.val(n->
next())) <<
" " <<
286 (n->
prev() == 0 ? 0 : nodenames.val(n->
prev())) << endl;
297 if (ts.
get() !=
"Relation")
300 " no new Relation" << endl;
303 p_name = ts.
get().string();
307 " semicolon missing after Relation name \"" <<
308 p_name <<
"\"" << endl;
313 if (load_items(ts,contents) !=
format_ok)
324 if (ts.
get() !=
"Relation")
327 " no new Relation" << endl;
330 p_name = ts.
get().string();
334 " semicolon missing after Relation name \"" <<
335 p_name <<
"\"" << endl;
340 if (load_items(ts,contents) !=
format_ok)
346 void EST_Relation::node_tidy_up_val(
int &k,
EST_Val &v)
385 while (ts.
peek() !=
"End_of_Relation")
387 int name = atoi(ts.
get().string());
390 node = get_item_from_name(nodenames,name);
401 siname = atoi(ts.
get().string());
409 " node's item contents" << siname <<
" doesn't exist\n";
417 node->u = get_item_from_name(nodenames,atoi(ts.
get().string()));
418 node->d = get_item_from_name(nodenames,atoi(ts.
get().string()));
419 node->n = get_item_from_name(nodenames,atoi(ts.
get().string()));
420 node->p = get_item_from_name(nodenames,atoi(ts.
get().string()));
427 int numlinks = atoi(ts.
get().string());
429 for (
int i=0;i<numlinks;++i)
431 EST_Item * item = get_item_from_name(nodenames,atoi(ts.
get().string()));
444 p_head = get_item_from_name(nodenames,1);
445 p_tail = p_head->last();
446 if (!p_head->verify())
449 " nodes do not form consistent graph" << endl;
461 nodenames.
map(node_tidy_up_val);
483 while (ts.
peek() !=
"End_of_Relation")
485 int name = atoi(ts.
get().string());
488 node = get_item_from_name(nodenames,name);
499 siname = atoi(ts.
get().string());
506 " node's stream item " << siname <<
" doesn't exist\n";
514 node->u = get_item_from_name(nodenames,atoi(ts.
get().string()));
515 node->d = get_item_from_name(nodenames,atoi(ts.
get().string()));
516 node->n = get_item_from_name(nodenames,atoi(ts.
get().string()));
517 node->p = get_item_from_name(nodenames,atoi(ts.
get().string()));
523 int numlinks = atoi(ts.
get().string());
525 for (
int i=0;i<numlinks;++i)
527 EST_Item * item = get_item_from_name(nodenames,atoi(ts.
get().string()));
539 p_head = get_item_from_name(nodenames,1);
540 p_tail = p_head->last();
541 if (!p_head->verify())
544 " nodes do not form consistent graph" << endl;
558 node_tidy_up(ni, node);
594 if (name >= nodenames.
length())
596 nodenames.
resize(name*2, 1);
603 nodenames[
name] = node;
615 f.set(
"filename",filename);
619 else if (type ==
"ogi")
621 else if (type ==
"htk")
623 else if ((type ==
"ascii") || (type ==
"timit"))
625 else if (type ==
"words")
640 if (((filename ==
"-") ? ts.
open(cin) : ts.
open(filename)) != 0)
642 cerr <<
"load_relation: can't open relation input file " 646 r =
load(filename, ts, type);
EST_TokenStream & get(EST_Token &t)
get next token in stream
EST_Item * last_leaf() const
EST_Item * next_item(const EST_Item *node)
void set_contents(EST_Item_Content *li)
void remove_item(EST_Item *item)
const EST_String name(void)
EST_Utterance * get_utt(EST_Item *s)
EST_Val est_val(const EST_Item_featfunc f)
bool save(Lattice &lattice, EST_String filename)
void close(void)
Close stream.
EST_Item * last_leaf() const
LISP append(LISP l1, LISP l2)
bool load(Lattice &lattice, EST_String filename)
EST_String itoString(int n)
Make a EST_String object from an integer.
void map(void(*func)(K &, V &))
Apply func to each entry in the table.
#define VAL_REGISTER_CLASS(NAME, CLASS)
int open(const EST_String &filename)
open a EST_TokenStream for a file.
void evaluate_item_features()
EST_Relation & operator=(const EST_Relation &s)
EST_read_status load_esps_label(EST_TokenStream &ts, EST_Relation &rel)
void resize(ssize_t n, int set=1)
INLINE ssize_t length() const
number of items in vector.
int num_leaves(const EST_Item *h)
EST_read_status load_words_label(EST_TokenStream &ts, EST_Relation &s)
V & val(const K &key, int &found) const
The file was written successfully.
EST_Item_Content * contents() const
void set_val(const EST_String &name, const EST_Val &sval)
EST_Item * insert_before(EST_Item *li=0)
void copy_node_tree_contents(EST_Item *from, EST_Item *to)
EST_Item * first_leaf() const
EST_read_status load_ogi_label(EST_TokenStream &ts, EST_Relation &s)
EST_TVector< T > & copy(EST_TVector< T > a, const EST_TList< T > &in)
Templated Key-Value list. Objects of type EST_TKVL contain lists which are accessed by a key of type ...
void copy_node_tree(EST_Item *from, EST_Item *to)
EST_Item * insert_after(EST_Item *li=0)
EST_Token & peek(void)
peek at next token
EST_Relation * relation(void) const
The relation of this particular item.
The file was not written successfully.
int add_item(const K &key, const V &value, int no_search=0)
Add an entry to the table.
void copy_relation(const EST_Relation &from, EST_Relation &to)
EST_Utterance * utt(void)
int add_item(const K &rkey, const V &rval, int no_search=0)
add key-val pair to list
EST_write_status save_esps_label(const EST_String &filename, const EST_Relation &s, bool evaluate_ff)
const EST_String pos_description()
A string describing current position, suitable for error messages.
An open hash table. The number of buckets should be set to allow enough space that there are relative...
EST_write_status save_htk_label(const EST_String &filename, const EST_Relation &a)
EST_write_status save(const EST_String &filename, bool evaluate_ff=false) const
ostream & operator<<(ostream &s, const EST_Relation &a)
EST_Item * append(EST_Item *si)
void remove_item_feature(const EST_String &name)
EST_read_status load(const EST_String &filename, const EST_String &type="esps")
EST_Item * first_leaf() const
EST_Item * next_leaf() const
EST_read_status load_sample_label(EST_TokenStream &ts, EST_Relation &s, int sample)