44#include "EST_string_aux.h"
45#include "EST_FileType.h"
47#include "ling_class/EST_Utterance.h"
48#include "EST_UtteranceFile.h"
60static EST_write_status utt_save_all_contents(
ostream &
outf,
63static EST_write_status utt_save_all_contents(
ostream &
outf,
67static EST_write_status utt_save_ling_content(
ostream &
outf,
77 if (
node->unref_relation(
"__READ__"))
94 ts.set_SingleCharSymbols(
";()");
95 ts.set_quotes(
'"',
'\\');
97 if ((r = read_est_header(
ts,
hinfo,
ascii, t)) != format_ok)
99 if (t != est_file_utterance)
100 return misc_read_error;
101 if (
hinfo.ival(
"version") != 2)
103 if (
hinfo.ival(
"version") == 3)
104 EST_warning(
"Loading est utterance format version 3, ladders will not be understood");
107 EST_error(
"utt_load: %s wrong version of utterance format expected 2 (or 3) but found %d",
108 (
const char *)
ts.pos_description(),
hinfo.ival(
"version"));
113 if (
ts.get() !=
"Features")
115 cerr <<
"utt_load: " <<
ts.pos_description() <<
116 " missing utterance features section" <<
endl;
117 return misc_read_error;
122 if (
ts.get() !=
"Stream_Items")
124 cerr <<
"utt_load: " <<
ts.pos_description() <<
125 " missing Items section" <<
endl;
126 return misc_read_error;
132 if (
ts.peek() ==
"Streams")
134 cerr <<
"utt.load: streams found in utterance file, " <<
135 "no longer supported" <<
endl;
136 return misc_read_error;
140 if ((r == format_ok) && (
ts.get() !=
"Relations"))
142 cerr <<
"utt_load: " <<
ts.pos_description() <<
143 " missing Relations section" <<
endl;
144 return misc_read_error;
149 if ((r == format_ok) && (
ts.get() !=
"End_of_Utterance"))
151 cerr <<
"utt_load: " <<
ts.pos_description() <<
152 " End_of_Utterance expected but not found" <<
endl;
153 return misc_read_error;
183 while (
ts.peek() !=
"End_of_Stream_Items")
187 si->relations.add_item(
"__READ__", est_val((
EST_Item *)NULL), 1);
191 Sid =
ts.get().string();
196 cerr <<
"utt_load: " <<
ts.pos_description() <<
197 " Item name not a number: " <<
Sid <<
endl;
198 return misc_read_error;
200 if (
id >=
sitems.length())
206 if (
si->f.load(
ts) != format_ok)
207 return misc_read_error;
212 return misc_read_error;
228 while (
ts.peek() !=
"End_of_Relations")
235 return misc_read_error;
241 return misc_read_error;
252 EST_write_status v = write_ok;
255 outf.setf(ios::fixed, ios::floatfield);
258 outf <<
"EST_File utterance\n";
259 outf <<
"DataType ascii\n";
260 outf <<
"version 2\n";
261 outf <<
"EST_Header_End\n";
268 outf <<
"Stream_Items\n";
271 if (v == write_fail)
return v;
272 outf <<
"End_of_Stream_Items\n";
275 outf <<
"Relations\n";
280 if (v == write_fail)
return v;
282 outf <<
"End_of_Relations\n";
284 outf <<
"End_of_Utterance\n";
288static EST_write_status utt_save_all_contents(
ostream &
outf,
297 EST_write_status v = write_ok;
303 v = utt_save_all_contents(
outf,relation(p->
v)->head(),
305 if (v == write_fail)
return v;
311static EST_write_status utt_save_all_contents(
ostream &
outf,
329static EST_write_status utt_save_ling_content(
ostream &
outf,
336 if ((
si != 0) && (!
sinames.present(
si->contents())))
340 si->features().save(
outf);
352 EST_read_status
status = read_ok;
373EST_write_status EST_UtteranceFile::save_xlabel(
ostream &
outf,
376 EST_write_status
status = write_error;
384 rel = ::relation(p->
v);
391 if (iup(
hd) || idown(
hd))
406#if defined(INCLUDE_XML_FORMATS)
418 if ((
stream=
ts.filedescriptor())==NULL)
429 return read_format_error;
434 return read_format_error;
456 if ((
stream=
ts.filedescriptor())==NULL)
467 return read_format_error;
480EST_write_status EST_UtteranceFile::save_genxml(
ostream &
outf,
483 EST_write_status
status=write_ok;
495 for (fp.begin(
hd->features()); fp; ++fp)
496 features.add_item(fp->
k, 1);
501 outf <<
"<?xml version='1.0'?>\n";
503 outf <<
"<!DOCTYPE utterance PUBLIC '//CSTR EST//DTD cstrutt//EN' 'cstrutt.dtd'\n\t[\n";
507 outf <<
"\t<!ATTLIST item\n";
508 for (f.begin(features); f; ++f)
512 outf <<
"\t\t" << f->k <<
"\tCDATA #IMPLIED\n";
518 outf <<
"<utterance>\n";
519 outf <<
"<language name='unknown'/>\n";
530 if (iup(
hd) || idown(
hd))
538 outf <<
"<relation name='"<< rel->
name()<<
"' structure-type='list'>\n";
546 for (p.
begin(
hd->features()); p; ++p)
547 if (p->
k !=
"estContentFeature")
548 outf <<
" " << p->
k <<
"='" << p->
v <<
"'\n";
555 outf <<
"</relation>\n";
562 outf <<
"</utterance>\n";
569EST_String EST_UtteranceFile::options_short(
void)
573 for(
int n=0; n< EST_UtteranceFile::map.n() ; n++)
575 EST_UtteranceFileType type = EST_UtteranceFile::map.nth_token(n);
576 if (type != uff_none)
578 for(
int ni=0;
ni<NAMED_ENUM_MAX_SYNONYMS;
ni++)
580 const char *
nm = EST_UtteranceFile::map.name(type,
ni);
594EST_String EST_UtteranceFile::options_supported(
void)
596 EST_String s(
"Available utterance file formats:\n");
598 for(
int n=0; n< EST_UtteranceFile::map.n() ; n++)
600 EST_UtteranceFileType type = EST_UtteranceFile::map.nth_token(n);
601 if (type != uff_none)
603 const char *d = EST_UtteranceFile::map.info(type).description;
604 for(
int ni=0;
ni<NAMED_ENUM_MAX_SYNONYMS;
ni++)
606 const char *
nm = EST_UtteranceFile::map.name(type,
ni);
620Start_TNamedEnumI_T(EST_UtteranceFileType, EST_UtteranceFile::Info, EST_UtteranceFile::map,
utterancefile)
621 { uff_none, { NULL },
622 { FALSE, NULL, NULL,
"unknown utterance file type"} },
623 { uff_est, {
"est",
"est_ascii"},
624 { TRUE, EST_UtteranceFile::load_est_ascii, EST_UtteranceFile::save_est_ascii,
"Standard EST Utterance File" } },
625#if defined(INCLUDE_XML_FORMATS)
626 { uff_apml, {
"apml",
"xml"},
627 { TRUE, EST_UtteranceFile::load_apml, NULL,
"Utterance in APML" } },
628 { uff_genxml, {
"genxml",
"xml"},
629 { TRUE, EST_UtteranceFile::load_genxml, EST_UtteranceFile::save_genxml,
"Utterance in XML, Any DTD" } },
631 { uff_xlabel, {
"xlabel"},
632 { TRUE, EST_UtteranceFile::load_xlabel, EST_UtteranceFile::save_xlabel,
"Xwaves Label File" } },
634 { FALSE, NULL, NULL,
"unknown utterance file type"} }
636End_TNamedEnumI_T(EST_UtteranceFileType, EST_UtteranceFile::Info, EST_UtteranceFile::map,
utterancefile)
638Declare_TNamedEnumI(EST_UtteranceFileType, EST_UtteranceFile::Info)
640#if defined(INSTANTIATE_TEMPLATES)
641#include "../base_class/EST_TNamedEnum.cc"
642Instantiate_TNamedEnumI(EST_UtteranceFileType, EST_UtteranceFile::Info)
647#if defined(INSTANTIATE_TEMPLATES)
649#include "../base_class/EST_TSimpleVector.cc"
650#include "../base_class/EST_TVector.cc"
651#include "../base_class/EST_Tvectlist.cc"
void set_val(const EST_String &name, const EST_Val &sval)
EST_read_status load(EST_TokenStream &ts)
load features from already opened EST_TokenStream
EST_write_status save(ostream &outf) const
save features in already opened ostream
void set(const EST_String &name, int ival)
const float F(const EST_String &name) const
EST_read_status load(const EST_String &filename, const EST_String &type="esps")
EST_write_status save(const EST_String &filename, bool evaluate_ff=false) const
const EST_String & name() const
void set_utt(EST_Utterance *u)
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 begin(const Container &over)
Set the iterator ready to run over this container.
EST_Features f
Utterance level features.
EST_Features relations
The list of named relations.
void clear()
remove everything in utterance
EST_Relation * create_relation(const EST_String &relname)
create a new relation called <parameter>n</parameter>.