40#include "EST_Features.h"
41#include "ling_class/EST_Item.h"
43#include "EST_String.h"
49 EST_Item_featfunc
f = get_featfunc(funcname,1);
54void EST_Features::save_fpair(ostream &outf,
59 if (fvalue.
type() == val_type_feats)
62 if (
f->features->list.head() == 0)
65 outf << fname <<
" () ; ";
71 fname+
"."+
f->features->list(q).k,
72 f->features->list(q).v);
83 outf << quote_string(fname,
"\"",
"\\",1) <<
" ";
88 else if ((fvalue.
type() == val_string) &&
95 outf << quote_string(fvalue.
string(),
"\"",
"\\",1);
96 else if (fvalue.
type() == val_float)
99 sprintf(b,
"%g",fvalue.
Float());
102 else if (fvalue.
type() == val_type_featfunc)
104 outf <<
"F:"<<get_featname(featfunc(fvalue));
107 outf << quote_string(fvalue.
string());
114 if (features->
list.head() == 0)
117 for (
EST_Litem *p=features->
list.head(); p != 0; p=p->next() )
120 features->
list(p).v);
129 for (
EST_Litem *p=features->
list.head(); p != 0; p=p->next() )
140 outf << quote_string(fname,
"\"",
"\\",1);
146 else if ((fvalue.
type() == val_string) &&
153 outf << quote_string(fvalue.
string(),
"\"",
"\\",1);
154 else if (fvalue.
type() == val_float)
157 sprintf(b,
"%g",fvalue.
Float());
160 else if (fvalue.
type() == val_type_featfunc)
162 outf <<
"F:"<<get_featname(featfunc(fvalue));
164 else if (fvalue.
type() == val_type_feats)
166 feats(fvalue)->save_sexpr(outf);
169 outf << quote_string(fvalue.
string());
183 if (ts.
peek() !=
"(")
185 cerr <<
"load_features: no sexpression found\n";
186 return misc_read_error;
193 for (; ts.
peek() !=
")"; )
195 if (ts.
peek() !=
"(")
197 cerr <<
"load_features: no sexpression found\n";
198 return misc_read_error;
201 f = ts.
get().string();
213 else if (v.string().
matches(RXint))
214 set(
f,atoi(v.string()));
215 else if (v.string().
matches(RXdouble))
216 set(
f,atof(v.string()));
219 EST_Item_featfunc func =
220 get_featfunc(v.string().
after(
"F:"));
225 cerr <<
"load_features: Unknown Function '" <<
f <<
"'\n";
235 cerr <<
"load_features: no sexpression found\n";
236 return misc_read_error;
241 cerr <<
"load_features: no sexpression found\n";
242 return misc_read_error;
259 cerr <<
"load_features: unexpected end of file\n";
260 return misc_read_error;
262 f = ts.
get().string();
270 + ts.
peek().whitespace()
272 if (v.
quoted() || (v.string() ==
""))
274 else if (v.string() ==
"0")
276 else if ((strchr(
"0123456789-.",v.string()(0)) != NULL) &&
277 (v.string().
matches(RXdouble)))
286 EST_Item_featfunc func = get_featfunc(v.string().
after(
"F:"));
291 cerr <<
"load_features: Unknown Function '" <<
f <<
"'\n";
295 else if (v.string() ==
"()")
300 else if (v !=
"<contents>")
302 if (ts.
peek() ==
";")
307 " missing semicolon in feature list\n";
308 return misc_read_error;
EST_Features & A(const EST_String &path) const
void set(const EST_String &name, int ival)
void set_path(const EST_String &name, const EST_Val &sval)
void set_function(const EST_String &name, const EST_String &f)
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_read_status load_sexpr(EST_TokenStream &ts)
load features from sexpression, contained in already opened EST_TokenStream
EST_write_status save(ostream &outf) const
save features in already opened ostream
const EST_Val & f(const EST_String &path) const
EST_write_status save_sexpr(ostream &outf) const
save features as s-expression in already opened ostream
static const EST_String Empty
Constant empty string.
int contains(const char *s, int pos=-1) const
Does it contain this substring?
EST_String after(int pos, int len=1) const
Part after pos+len.
int matches(const char *e, int pos=0) const
Exactly match this string?
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.
const EST_String pos_description()
A string describing current position, suitable for error messages.
EST_Token & peek(void)
peek at next token
EST_TokenStream & get(EST_Token &t)
get next token in stream
int quoted() const
TRUE is token was quoted.
const EST_String & string(void) const
const val_type type(void) const
const float Float(void) const