44#include "ling_class/EST_Relation.h"
45#include "EST_string_aux.h"
46#include "EST_cutils.h"
48#include "EST_Option.h"
49#include "relation_io.h"
51#define DEF_SAMPLE_RATE 16000
52#define HTK_UNITS_PER_SECOND 10000000
54static EST_Regex RXleadingwhitespace(
"^[ \t\n\r][ \t\n\r]*.*$");
61 ts.set_SingleCharSymbols(
";");
62 ts.set_quotes(
'"',
'\\');
68 key =
ts.get().string();
72 val =
ts.get_upto_eoln().string();
74 if (val.matches(RXleadingwhitespace))
75 val = val.after(RXwhite);
79 if (
ts.peek() ==
"")
return format_ok;
86 si->set(
"end",(
float)
atof(
ts.get().string()));
89 for (name =
""; (!
ts.eoln()) && (
ts.peek() !=
";"); )
93 name += t.whitespace();
98 if (
ts.peek().string() ==
";")
101 si->features().load(
ts);
107EST_write_status save_esps_label(
const EST_String &filename,
119 cerr <<
"save_esps_label: can't open label output file \"" <<
120 filename <<
"\"" <<
endl;
138 *
outf <<
"separator ;\n";
140 *
outf <<
"nfields 1\n";
143 for (p.
begin(s.
f); p; ++p)
153 for (ptr = s.
head(); ptr != 0; ptr = inext(ptr))
157 outf->setf(ios::scientific, ios::floatfield);
160 if (s.
f(
"timing_style",
"0") ==
"event")
161 *
outf << ptr->
F(
"time",0);
163 *
outf << ptr->
F(
"end",0);
165 *
outf <<
" 26 \t" << ptr->
S(
"name",
"0");
168 f2 = ptr->features();
194 ts.set_SingleCharSymbols(
";");
200 if ((
ts.peek().col() == 0) && (
ts.peek() ==
"END"))
202 if (
ts.peek() ==
"END")
210 key =
ts.get().string();
211 val =
ts.get().string();
219 cerr <<
"Error: couldn't find header in label file "
224 if (read_label_portion(
ts, s,
isr) == misc_read_error)
226 cerr <<
"error: in label file " <<
ts.filename() <<
" at line " <<
228 return misc_read_error;
243 item->
set(
"end",0.0);
249static float convert_long_num_string_to_time(
const char *s,
int sample)
256 return atof(s)/sample;
262 (
strchr(
" \n\r\t",s[i]) != NULL) && (s[i] !=
'\0');
266 (s[i] !=
'\0') && (s[i] >=
'0') && (s[i] <=
'9');
286 str =
ts.get().string();
292 str =
ts.get().string();
293 hend = convert_long_num_string_to_time(str,sample);
296 item->
set(
"name",
ts.get().string());
299 item->
set(
"rest_lab",
ts.get_upto_eoln().string());
310 sample = DEF_SAMPLE_RATE;
313 ts.set_SingleCharSymbols(
";");
316 if (read_label_portion(
ts, s, sample) == misc_read_error)
318 cerr <<
"error: in label file " <<
ts.filename() <<
" at line " <<
320 return misc_read_error;
325EST_write_status save_htk_label(
const EST_String &filename,
336 cerr <<
"save_htk_label: can't open label output file \"" <<
337 filename <<
"\"" <<
endl;
341 EST_write_status s = save_htk_label(
outf, a);
359 for (ptr = a.
head(); ptr != 0; ptr = inext(ptr))
362 cout.setf(ios::left,ios::adjustfield);
363 *
outf << (int)(start * HTK_UNITS_PER_SECOND);
365 end = ptr->
F(
"end",0.0);
366 *
outf << (int)(end * HTK_UNITS_PER_SECOND);
367 *
outf <<
" " << ptr->name() <<
endl;
388 cerr <<
"save_label_spn: can't open label output file \""
389 << filename <<
"\"" <<
endl;
395 outf->setf(ios::left, ios::adjustfield);
397 *
outf << ptr->name();
398 outf->setf(ios::scientific, ios::floatfield);
400 *
outf << (ptr->dur() * 1000.0) <<
"\t (0,140)" <<
endl;
402 for (; inext(ptr) != 0; ptr = inext(ptr))
405 outf->setf(ios::left, ios::adjustfield);
407 *
outf << ptr->name();
408 outf->setf(ios::scientific, ios::floatfield);
410 *
outf << (ptr->dur() * 1000.0) <<
endl;
415 *
outf << ptr->name();
416 outf->setf(ios::scientific, ios::floatfield);
418 *
outf << (ptr->dur() * 1000.0) <<
"\t (99,80)" <<
endl;
440 cerr <<
"save_label_name: can't open label output file \""
441 << filename <<
"\"" <<
endl;
442 return misc_write_error;
445 for (ptr = a.
head(); inext(ptr) != 0; ptr = inext(ptr))
447 *
outf << ptr->name();
448 if ((features !=
"") && (features !=
"OneLine"))
462EST_write_status save_RelationList(
const EST_String &filename,
479 cerr <<
"save_StreamList: can't open MLF output file \""
480 << filename <<
"\"\n";
484 *
outf <<
"#!MLF!#\n";
488 for (p =
plist.head(); p != 0; p = p->next())
492 for (ptr =
plist(p).head(); ptr != 0; ptr = inext(ptr))
497 cout.setf(ios::left,ios::adjustfield);
498 *
outf << (int)(start * HTK_UNITS_PER_SECOND);
500 end = ptr->
F(
"end",0.0);
501 *
outf << (int)(end * HTK_UNITS_PER_SECOND) <<
" ";
514EST_write_status save_WordList(
const EST_String &filename,
529 cerr <<
"save:WordList: can't open WordList output file \""
530 << filename <<
"\"\n";
534 for (p =
plist.head(); p != 0; p = p->next())
536 for (ptr =
plist(p).head(); inext(ptr) != 0; ptr = inext(ptr))
538 *
outf << ptr->name();
553EST_write_status save_ind_RelationList(
const EST_String &filename,
563 for (p =
plist.head(); p != 0; p = p->next())
567 return misc_write_error;
573EST_read_status load_RelationList(
const EST_String &filename,
579 if (((filename ==
"-") ?
ts.open(
cin) :
ts.open(filename)) != 0)
581 cerr <<
"Can't open label input file " << filename <<
endl;
582 return misc_read_error;
585 ts.set_SingleCharSymbols(
";");
588 if (
ts.get().string() !=
"#!MLF!#")
590 cerr <<
"Not MLF file\n";
598 fns =
ts.get().string();
601 s.f.set(
"name",
fns);
604 if (read_label_portion(
ts,
plist.last(), 10000000) == misc_read_error)
606 cerr <<
"error: in reading MLF file\n";
607 cerr <<
"section for file " <<
fns <<
608 " at line " <<
ts.linenum() <<
" is badly formatted\n";
610 return misc_read_error;
623 for (i = 0, p = s.
head(); p; p = inext(p), ++i)
624 p->
set(
"end",(length *
float(i)/
float(s.
length())));
632 if (
al.val(
"-itype", 0) ==
"mlf")
634 if (load_RelationList(
files.first(),
plist) != format_ok)
638 for (p =
files.head(); p; p = p->next())
643 if (
al.present(
"-itype"))
650 if ((
al.val(
"-itype", 0) ==
"words") && (
al.present(
"-length")))
651 pad_ends(s,
al.fval(
"-length"));
void set(const EST_String &name, int ival)
void remove(const EST_String &name)
EST_write_status save(ostream &outf) const
save features in already opened ostream
int present(const EST_String &name) const
void set(const EST_String &name, int ival)
const EST_String S(const EST_String &name) const
const float F(const EST_String &name) const
int length(void) const
Length of string ({not} length of underlying chunk)
void begin(const Container &over)
Set the iterator ready to run over this container.