forked from aesuli/mp-boost
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdocumentset.cpp
43 lines (36 loc) · 1.42 KB
/
documentset.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
/************************************************************************/
/* */
/* MPBoost++ */
/* */
/* Copyright: Andrea Esuli */
/* Date: 16 august 2010 */
/* License and Info: http://www.esuli.it/ */
/* */
/************************************************************************/
#include "documentset.h"
#include <string>
#include <sstream>
DocumentSet * DocumentSet::Read(std::istream & in) {
DocumentSet * documentSet = new DocumentSet();
std::string line;
while(std::getline(in,line)) {
std::istringstream buffer(line);
Document * doc = Document::Read(buffer);
int count = doc->GetFeatureCount();
if(count>0) {
int feature = *(--doc->GetFeatureIteratorEnd());
if(documentSet->featureCount<=feature)
documentSet->featureCount = feature+1;
}
documentSet->push_back(doc);
}
return documentSet;
}
void DocumentSet::Write(std::ostream & out) {
std::vector<Document *>::const_iterator it = begin();
std::vector<Document *>::const_iterator tend = end();
while(it!=tend) {
(*it)->Write(out);
++it;
}
}