forked from aesuli/mp-boost
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexampleset.cpp
50 lines (42 loc) · 1.66 KB
/
exampleset.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/************************************************************************/
/* */
/* MPBoost++ */
/* */
/* Copyright: Andrea Esuli */
/* Date: 16 august 2010 */
/* License and Info: http://www.esuli.it/ */
/* */
/************************************************************************/
#include "exampleset.h"
#include <string>
#include <sstream>
ExampleSet * ExampleSet::Read(std::istream & in,std::set<int> * features) {
ExampleSet * exampleSet = new ExampleSet();
std::string line;
while(std::getline(in,line)) {
std::istringstream buffer(line);
Example * example = Example::Read(buffer,features);
int count = example->GetFeatureCount();
if(count>0) {
int feature = *(--example->GetFeatureIteratorEnd());
if(exampleSet->featureCount<=feature)
exampleSet->featureCount = feature+1;
}
count = example->GetCategoryCount();
if(count>0) {
int category = *(--example->GetCategoryIteratorEnd());
if(exampleSet->categoryCount<=category)
exampleSet->categoryCount = category+1;
}
exampleSet->push_back(example);
}
return exampleSet;
}
void ExampleSet::Write(std::ostream & out) {
std::vector<Example *>::const_iterator it = begin();
std::vector<Example *>::const_iterator tend = end();
while(it!=tend) {
(*it)->Write(out);
++it;
}
}