blob: 1d430e430e2315ef561c33409d05cda98106baf0 (
plain)
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
#ifndef DATAPROV_H
#define DATAPROV_H
#include<Eigen/Dense>
#include "../tools/easylogging++.h"
#include<vector>
// TODO decide how to construct training data
// One possible way for training data:
// Matrix composed of an array of feature vectors
// Labels are composed of linked list, such as
// 6,3,4,0,5,0,0
// => 0->6 | 1->3 | 2->4->5
// How to compensate for non exhaustive labeling?
// Use -1 to indicate not yet labeled data
// -1s will be excluded from training
typedef struct DataEntry{
std::string qid;
double rank;
Eigen::VectorXd feature;
} DataEntry;
class DataList{
private:
int n;
std::vector<DataEntry*> data;
public:
unsigned long getSize(){return data.size();}
void addEntry(DataEntry* d){data.push_back(d);}
void setfSize(int fsize){n=fsize;}
int getfSize(){return n;}
void clear(){
for (int i=0;i<data.size();++i)
delete data[i];
data.clear();
}
static DataEntry* copyEntry(DataEntry* d)
{
DataEntry* dat = new DataEntry;
dat->rank = d->rank;
dat->qid = d->qid;
dat->feature = d->feature;
return dat;
}
inline std::vector<DataEntry*>& getData(){
return data;
}
~DataList(){
clear();
}
};
class DataProvider //Virtual base class for data input
{
protected:
bool eof;
public:
DataProvider():eof(false){};
bool EOFile(){return eof;}
void getAllData(DataList &out){\
out.clear();
DataList buf;
while (!EOFile())
{
getDataSet(buf);
// won't work as data are discarded with every call to getDataSet
// out.getData().insert(out.getData().end(),buf.getData().begin(),buf.getData().end());
for (int i=0;i<buf.getSize();++i)
out.addEntry(out.copyEntry(buf.getData()[i]));
out.setfSize(buf.getfSize());
}
}
virtual int getDataSet(DataList &out) = 0;
virtual int open()=0;
virtual int close()=0;
};
#endif
|