41 #include "EST_TMatrix.h"
43 #include "EST_FeatureData.h"
44 #include "EST_string_aux.h"
45 #include "EST_Token.h"
46 #include "EST_FileType.h"
47 #include "EST_error.h"
51 #include "EST_THash.h"
54 EST_FeatureData::EST_FeatureData()
67 EST_FeatureData::~EST_FeatureData(
void)
71 int EST_FeatureData::num_samples()
const
76 int EST_FeatureData::num_features()
const
82 void EST_FeatureData::default_vals()
90 void EST_FeatureData::set_num_samples(
int num_samples,
bool preserve)
95 void EST_FeatureData::resize(
int num_samples,
int num_features,
bool preserve)
108 for (; i < num_features; ++i)
109 info.
set(
"unnamed_" + itoString(i),
"<STRING>");
112 fd.
resize(num_samples, num_features, preserve);
115 void EST_FeatureData::resize(
int num_samples,
EST_Features &f,
bool preserve)
137 if ((t ==
"<FLOAT>") || (t ==
"<INT>") || (t ==
"<STRING>"))
140 StringtoStrList(t, v);
144 int EST_FeatureData::feature_position(
const EST_String &feature_name)
150 for (i = 0, p.
begin(info); p; ++p, ++i)
154 if (p->k == feature_name)
158 EST_error(
"No such feature %s\n", (
const char *) feature_name);
162 int EST_FeatureData::update_values(
const EST_String &feature_name,
int max)
172 col = feature_position(feature_name);
174 for (i = 0; i < num_samples(); ++i)
179 if (values.
length() > max)
184 for(p.
begin(values); p; ++p)
188 info.
set(feature_name, v);
237 EST_Val &EST_FeatureData::a(
int i,
int j)
247 const EST_Val &EST_FeatureData::a(
int i,
int j)
const
394 EST_write_status EST_FeatureData::save(
const EST_String &filename,
397 if ((file_type ==
"est") || (file_type ==
""))
398 return save_est(*
this, filename);
405 cerr <<
"Can't save feature data in format \"" << file_type << endl;
411 EST_read_status EST_FeatureData::load(
const EST_String &filename)
422 if (((filename ==
"-") ? ts.
open(cin) : ts.
open(filename)) != 0)
424 cerr <<
"Can't open track file " << filename << endl;
425 return misc_read_error;
431 if ((r = read_est_header(ts, hinfo, ascii, t)) != format_ok)
433 cerr <<
"Error reading est header of file " << filename << endl;
437 if (t != est_file_feature_data)
439 cerr <<
"Not a EST Feature Data file: " << filename << endl;
440 return misc_read_error;
443 ns = hinfo.
ival(
"NumSamples");
444 nf = hinfo.
ival(
"NumFeatures");
446 cout <<
"ns: " << ns << endl;
447 cout <<
"nf: " << nf << endl;
452 for (i = 0; i < nf; ++i)
454 k =
"Feature_" + itoString(i+1);
459 cout <<
"value: " << v.
after(
" ") << endl;
462 EST_error(
"No feature definition given for feature %d\n", i);
465 for (i = 0; i < ns; ++i)
468 for (p.
begin(info), j = 0; j < nf; ++j, ++p)
470 if (p->k ==
"<FLOAT>")
471 a(i, j) = atof(ts.
get().string());
472 else if (p->k ==
"<BOOL>")
473 a(i, j) = atoi(ts.
get().string());
474 else if (p->k ==
"<INT>")
475 a(i, j) = atoi(ts.
get().string());
477 a(i, j) = ts.
get().string();
504 for (i = 0; i < d.num_samples(); ++i)
506 for (j = 0; j < d.num_features(); ++j)