58 float ins,
float del,
float sub);
63 return (n->
prev() == 0) ? 0.0 : n->
prev()->
F(
"end");
68 return n->
F(
"end") -
start(n);
76 for (a_ptr = a.
head(); a_ptr != 0; a_ptr = a_ptr->
next())
78 end = a_ptr->
F(
"end") / q;
81 a_ptr->
set(
"end", end);
98 fp = fopen(file1,
"wb");
101 fprintf(stderr,
"edit_labels: cannot open \"%s\" for writing\n",
102 (
const char *)file1);
105 for (a_ptr = a.
head(); a_ptr != 0; a_ptr = a_ptr->
next())
107 fprintf(fp,
"%s\n", (
const char*) a_ptr->
name());
111 command =
"cat \"" + file1 +
"\" | sed -f \"" + sedfile +
"\" > " + file2;
113 printf(
"command: %s\n", (
const char*) command);
114 system_result = system((
const char*) command);
115 if (system_result != 0)
117 fprintf(stderr,
"Error running command. Command returned %d\n",
122 fp = fopen(file2,
"rb");
125 fprintf(stderr,
"edit_labels: cannot open \"%s\" for reading\n",
126 (
const char *)file2);
129 for (a_ptr = a.
head(); a_ptr != 0; a_ptr = a_ptr->
next())
131 if (fscanf(fp,
"%99s", newname) != 1)
132 cerr <<
"Error reading newname from file" << endl;
147 for (a = orig.
head(); a != 0; a = a->
next())
148 if ((a->
F(
"end") > s) && (
start(a) < e))
151 if ((a->
F(
"end") > e))
161 for (a_ptr = seg.
head(); a_ptr != seg.
tail(); a_ptr = n_ptr)
163 n_ptr = a_ptr->
next();
174 for (a_ptr = seg.
head(); a_ptr != 0; a_ptr = a_ptr->
next())
175 if (a_ptr->
name() == oname)
185 for (a_ptr = seg.
head(); a_ptr != 0; a_ptr = a_ptr->
next())
186 for (p = oname.
head(); p ; p = p->
next())
187 if (a_ptr->
name() == oname(p))
195 for (p = s.
head(); p; p = p->
next())
205 for (s = a.
head(); s; s = s->
next())
208 cerr<<
"Illegal entry in file " <<a.
name()<<
":\"" << *s <<
"\"\n";
220 EST_String tmp_class_type = class_type +
"_list";
227 pos_list.append(ts.
get().string());
236 if (broad_name ==
"")
239 for (a_ptr = seg.
head(); a_ptr != 0; a_ptr = a_ptr->
next())
240 if (is_in_class(a_ptr->
name(), pos_list))
241 a_ptr->
set(broad_name, (polarity) ? 1 : 0);
243 a_ptr->
set(broad_name, (polarity) ? 0 : 1);
250 for (p = seg.
head(); p != 0; p = n)
255 if (map.
val(p->
name()) ==
"!DELETE")
269 for (a_ptr = seg.
head(); a_ptr != 0; a_ptr = a_ptr->
next())
270 a_ptr->
set(
"end", a_ptr->
F(
"end") + shift);
283 for (ptr = filenames.
head(); ptr !=
NULL; ptr = ptr->
next())
285 tmp_filenames.
append( filenames(ptr) );
292 for (ptr = tmp_filenames.
head(); ptr !=
NULL; ptr = ptr->
next())
295 if(tmp_filenames(ptr) == mlf(fptr).name())
301 else if(mlf(fptr).name().contains(tmp_filenames(ptr)))
319 tmp_filenames.
clear();
331 for (p = mlf.
head(); p; p = p->
next())
337 for (p = mlf.
head(); p; p = p->
next())
343 cerr <<
"No match for file " << filename <<
" found in mlf\n";
356 for (p = mlf.
head(); p; p = p->
next())
358 for (s = mlf(p).
head(); s; s = s->
next())
361 t->
set(
"name", s->
S(
"name"));
362 t->
set(
"end", s->
F(
"end") + last);
363 cout <<
"appended t " << t << endl;
365 last = (t != 0) ? t->
F(
"end") : 0.0;
379 cerr <<
"RelationList has " << mlf.
length() <<
" elements: expected " 380 << key.
length() <<
" from key file\n";
387 for (s = mlf(p).head(); s; s = s->
next())
390 t->
set(
"name", s->
S(
"name"));
391 t->
set(
"end", (s->
F(
"end") + st));
413 if ((keylab.
tail())->F(
"end") < (lab.
tail())->F(
"end"))
415 cerr <<
"Key file must extend beyond end of label file\n";
420 for (k = keylab.
head(); k ; k = k->
next())
421 if (k->
F(
"end") > lab.
head()->
F(
"end"))
426 filename =
"no_name";
427 a.
f.
set(
"name", (filename + ext));
430 for (s = lab.
head(); s; s = s->
next())
436 t->
set(
"end", (s->
F(
"end") - kstart));
439 if (n->F(
"end") > k->
F(
"end"))
441 if (((n->F(
"end") - k->
F(
"end")) <
442 (k->
F(
"end") -
start(n))) ||
443 is_in_class(n->name(), blank))
446 t->
set(
"end", (s->
F(
"end") - kstart));
449 t->
set(
"end", (k->
F(
"end") - kstart));
451 if (!is_in_class(n->name(), blank))
457 t->
set(
"end", (k->
F(
"end") - kstart));
465 a.
f.
set(
"name", (filename + ext));
470 t->
set(
"end", (s->
F(
"end") - kstart));
487 if ((keylab.
tail())->F(
"end") < (lab.
tail())->F(
"end"))
489 cerr <<
"Key file must extend beyond end of label file\n";
497 for (s = lab.
head(); s; s = s->
next())
501 t->
set(
"end", (s->
F(
"end") - kstart));
503 if (s->
F(
"end") > k->
F(
"end"))
505 cout <<
"appending " << a;
508 kstart = s->
F(
"end");
509 k->
set(
"end", (s->
F(
"end")));
512 a.
f.set(
"name", (k->
name() + ext));
515 cout <<
"appending " << a;
528 float prev_end, inc, first_end, last_end;
541 for (s = target.
head(); s; s = s->
next())
545 s->
set(time_name +
"end", t->
F(
"end"));
547 s->
set(time_name +
"start", t->
F(
"start"));
549 last_end = t->
F(
"end");
551 first_end = t->
F(
"end");
557 target.
head()->
set(time_name +
"end", first_end / 2.0);
559 target.
head()->
set(time_name +
"start", 0.0);
564 target.
tail()->
set(time_name +
"end", last_end + 0.01);
566 target.
tail()->
set(time_name +
"start", last_end);
569 for (s = target.
head(); s; s = s->
next())
574 for (i = 1, p = s; p; p = p->
next(), ++i)
577 inc = (p->
F(time_name +
"end") - prev_end) / ((
float) i);
582 for (i = 1; s !=p ; s = s->
next(), ++i)
584 s->
set(time_name +
"end", (prev_end + ((
float) i * inc)));
586 s->
set(time_name +
"start", (prev_end+((
float) (i - 1 )* inc)));
589 prev_end = s->
F(
"end");
601 *utt.
relation(
"Match"), 7.0, 7.0, 7.0);
613 for (p = mlf.
head(); p; p = p->
next())
619 for (p = mlf.
head(); p; p = p->
next())
620 if (mlf(p).name() == filename)
623 cerr <<
"No match for file " << filename <<
" found in mlf\n";
635 al.
fval(
"-extend",0) * lab.
tail()->
F(
"end"));
644 cerr <<
"-start option must be used with -end option\n";
676 for (s = stream.
head(); s; s = s->
next())
678 cout << s->
name() <<
"\t:";
694 for (p = mlf.
head(); p; p = p->
next())
698 for (p = mlf.
head(); p; p = p->
next())
715 d=hash_table.
val(fname,found);
722 cerr <<
"No match for file " << fname <<
" found in mlf\n";
EST_TokenStream & get(EST_Token &t)
get next token in stream
float end(const EST_Item &item)
void print_relation_features(EST_Relation &stream)
void shift_label(EST_Relation &seg, float shift)
void relation_convert(EST_Relation &lab, EST_Option &al, EST_Option &op)
const EST_String name() const
Utility IO Function header file.
void change_label(EST_Relation &seg, const EST_String &oname, const EST_String &nname)
void remove_item(EST_Item *item)
void convert_to_broad(EST_Relation &seg, EST_StrList &pos_list, EST_String broad_name, int polarity)
EST_Relation * create_relation(const EST_String &relname)
create a new relation called n.
const EST_String name(void)
void set(const EST_String &name, ssize_t ival)
int override_fval(const EST_String rkey, const float rval)
add to end of list or overwrite. If rval is empty, do nothing
void label_map(EST_Relation &seg, EST_Option &map)
float fval(const EST_String &rkey, int m=1) const
int edit_labels(EST_Relation &a, EST_String sedfile)
void set(const EST_String &name, int ival)
A specialised hash table for when the key is an EST_String.
EST_String make_tmp_filename()
Make a unique temporary filename.
int check_vocab(EST_Relation &a, EST_StrList &vocab)
EST_Item * as_relation(const char *relname) const
View item from another relation (const char *) method.
void convert_to_broad_class(EST_Relation &seg, const EST_String &class_type, EST_Option &options)
void quantize(EST_Relation &a, float q)
float duration(EST_Item *n)
const EST_Val f(const EST_String &name) const
int open_string(const EST_String &newbuffer)
open a EST_TokenStream for string rather than a file
void RelationList_select(EST_RelationList &mlf, EST_StrList filenames, bool exact_match)
EST_Relation RelationList_combine(EST_RelationList &mlf)
void set_name(const EST_String &name) const
void map_match_times(EST_Relation &target, const EST_String &match_name, const EST_String &time_name, bool do_start)
const EST_String & name() const
EST_FMatrix sub(const EST_FMatrix &a, ssize_t row, ssize_t col)
EST_read_status load(const EST_String &filename, const EST_String &comment=";")
float F(const EST_String &name) const
V & val(const K &key, int &found) const
void StringtoStrList(EST_String s, EST_StrList &l, EST_String sep)
Convert a EST_String to a EST_StrList by separating tokens in s delimited by the separator sep...
void build_RelationList_hash_table(EST_RelationList &mlf, EST_hashedRelationList &hash_table, const bool base)
hashed relation lists for super speed
int relation_divide2(EST_RelationList &mlf, EST_Relation &lab, EST_Relation &keylab, EST_String ext)
bool dp_match(const EST_Relation &lexical, const EST_Relation &surface, EST_Relation &match, float ins, float del, float sub)
EST_Features & features() const
bool hashed_RelationList_extract(EST_Relation *&rel, const EST_hashedRelationList &hash_table, const EST_String &filename, bool base)
const V & val(const K &rkey, bool m=0) const
return value according to key (const)
EST_Relation RelationList_extract(EST_RelationList &mlf, const EST_String &filename, bool base)
void append(const T &item)
add item onto end of list
EST_String basename(EST_String full, EST_String ext="")
This acts like the bourne shell basename command. By default, it strips any leading path from a strin...
int add_item(const K &key, const V &value, int no_search=0)
Add an entry to the table.
void begin(const Container &over)
Set the iterator ready to run over this container.
void extract(const EST_Relation &orig, float s, float e, EST_Relation &ex)
int relation_divide(EST_RelationList &slist, EST_Relation &lab, EST_Relation &keylab, EST_StrList &blank, EST_String ext)
int present(const K &rkey) const
Returns true if key is present.
EST_Litem * RelationList_ptr_extract(EST_RelationList &mlf, const EST_String &filename, bool base)
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
EST_Item * append(EST_Item *si)
void dp_time_align(EST_Utterance &utt, const EST_String &source_name, const EST_String &target_name, const EST_String &time_name, bool do_start)
void merge_all_label(EST_Relation &seg, const EST_String &labtype)
EST_Item * daughter1(const EST_Item *n)
return first daughter of n
void clear(void)
remove all items in list
EST_Litem * remove(EST_Litem *ptr)
Utility EST_String Functions header file.
int f_present(const EST_String &name) const