-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFeatureForBuild.h
More file actions
executable file
·176 lines (152 loc) · 5.65 KB
/
FeatureForBuild.h
File metadata and controls
executable file
·176 lines (152 loc) · 5.65 KB
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#ifndef FEATUREFORBUILD_H_INCLUDED
#define FEATUREFORBUILD_H_INCLUDED
#include"SynTreePT.h"
#include"SynTreeSQ.h"
#include "SegScore.h"
typedef RelationTree::TreeNode RTreeNode;
struct EduFeature
{
TreeNode* nodeHead;
TreeNode* nodeDomin;
string nHLabel;
string nHWord;
string nDLabel;
string nDWord;
int eduNum;
int nHLevel;
string uniGram;
string biGram;
string triGram;
string uniGramBack;
string biGramBack;
string triGramBack;
string uniPOS;
string uniBackPOS;
string biPOS;
string biBackPOS;
string triPOS;
string triBackPOS;
int Begin;
int Back;
void defaultValue(){
nDLabel="NULL";nDWord="NULL";uniGram="NULL";biGram="NULL";triGram="NULL";
nHLabel="NULL";nHWord="NULL";nHLevel=0;
}
};
struct FullFeature
{
EduFeature *eduA;
EduFeature *eduB;
TreeNode *nodeDomin;
TreeNode *nodeHead;
string nDLabel;
string nDWord;
string nDLeftSiblingLabel;
string nDRightSiblingLabel;
string nHLabel;
string nHWord;
int nHLevel;
int dominRel;
int delta;
int AdeltaLh;
int BdeltaLh;
int Begin;
int Back;
void defaultValue(){
nDLabel="NULL";nDWord="NULL";nDLeftSiblingLabel="NULL";nDRightSiblingLabel="NULL";
nHLabel="NULL";nHWord="NULL";nHLevel=0;dominRel=2;delta=0;AdeltaLh=0;BdeltaLh=0;
}
};
struct Feature
{
EduFeature left;
EduFeature right;
FullFeature both;
//Feature():left(NULL),right(NULL),both(NULL){}
};
class FeatureForBuild
{
public:
int InitTrain(const string&m_pureStr,const string&m_relStr,const string& m_synStr);//0:成功 -1:不成功
int InitTest(const string&m_pureStr,const string& m_synStr,const string&segStr);
void GetManuPOS(vector<string>&senVec,vector<string>& posVec);
void GetInstance();
void GetBaseSpanForDecode(const string& segStr);
void AddHeadWordMap(TreeNode* p);
string GetPOSTag(TreeNode* a);
int GetEduNumers(int beg,int back);
TreeNode *GetHighestNode(TreeNode *node);
TreeNode *GetHeadNode(int beg,int back);
TreeNode *GetDominantNode(int beg,int back);
TreeNode *GetDominantNode(TreeNode* node);
int GetLevel(TreeNode*node);
int DominanceRelation(TreeNode*a,TreeNode*b);
string GetNodeHeadWord(TreeNode*node);
TreeNode* GetLeftSibling(TreeNode*node);
TreeNode* GetRightSibling(TreeNode*node);
int GetDelta(TreeNode*a,TreeNode*b);
string GetUniGram(int beg,TreeNode* node=NULL);
string GetBiGram(int beg, int back,TreeNode* node=NULL);
string GetTriGram(int beg,int back,TreeNode* node=NULL);
string GetUniGramBack(int back,TreeNode* node=NULL);
string GetBiGramBack(int beg,int back,TreeNode* node=NULL);
string GetTriGramBack(int beg,int back,TreeNode* node=NULL);
string GetUniPos(int beg);
string GetBiPos(int beg, int back);
string GetTriPos(int beg,int back);
string GetUniBackPos(int back);
string GetBiBackPos(int beg,int back);
string GetTriBackPos(int beg,int back);
void ExtractSingleSpanFeature(int beg,int back,EduFeature&edu);
void ExtractSingleSpanFeature(FullFeature&fSpan,EduFeature&edu);
void ExtractSingleSpanFeatureDecode(int beg,int back,EduFeature&edu,int level=0);
void ExtractFullFeature(EduFeature&eduA,EduFeature&eduB,FullFeature&fSpan);
void ExtractPositiveInstance(RTreeNode* a,Feature &feat);
void NegativeInstance(RTreeNode* a,RTreeNode*b);
void ExtractNegFeature(RTreeNode *node);
void ExtractTestInstance();
void LoadTestFeatMat();
void LoadTestEduFeatMat();
int TrainingProcess(const string&m_pureStr,const string&m_relStr,const string& m_synStr);
int TestingProcess(const string&m_pureStr,const string&m_segStr,const string& m_synStr,SegScore &Strm1,SegScore &Lbm2,SegScore &lbm3);
int TestingLabelForStdStr(const string&m_pureStr,const string&m_relStr,const string& m_synStr,SegScore &Lbm2);
RTreeNode CYKDecode(SegScore &strModel,SegScore&labModel,SegScore&labModel1); //同时找到最佳路径以及标签
int CYKDecode_Search(SegScore &strModel,SegScore &lbModel);
void ConstructDecodeTree(int curLevel,int curIndex,int sibLevel,int sibIndex,int leftorright,SegScore&labModel,RTreeNode *node);
double ScoreforDeocdeLabel(vector<string> &featVec,SegScore&labModel);
double ScoreForStructure(vector<string> &featVec,SegScore &strModel);
string GetDeocdeLabel(vector<string> &featVec,SegScore&labModel);
void GetStructureFeat(Feature &a,vector<string>& featVec);
void GetStructureFeat(EduFeature &a,EduFeature&b, FullFeature&c, vector<string>& featVec);
int GetStructureFeatForEdu(EduFeature&a, int count,vector<string>& featVec);
int GetStructureFeatForFull(FullFeature&a,int count,vector<string>&featVec);
void GetLabelFeat(Feature &a, EduFeature&b,int leftorright, vector<string>& featVec);
void GetLabelFeat(EduFeature &a, EduFeature&b,EduFeature &c,int leftorright, vector<string>& featVec);
void LabelingForStdStr(SegScore&labModel);
void PrintStrFeature();
void PrintLabelFeature();
void PrintStrFeature(vector<Feature> &vec);
void RecursiveEachNode(RTreeNode *a);
void ClearAll();
private:
public:
SynTree *mySynTree;
SynTreeSQ *myRelTree;
vector<RTreeNode *> instanceVec;
vector<string> posVec;
vector<pair<int,int> > baSpanVec;//pair:begin,back
vector<string> sentenceVec;
map<TreeNode *,int> headWordMap;
vector<Feature *> posFeatVec;
map<RTreeNode*, Feature> posFeatMap;
vector<Feature > negFeatVec;
vector<vector<vector<Feature > > > testFeatMat;
vector<vector<EduFeature> > testEduFeatMat;
vector<vector<int> > pathOfConstruct;
vector<vector<float> > scoreVec;
vector<string> labelVec;
map<RTreeNode*,string> posLabel;
};
void PrintFull(FullFeature&a,int count);
int PrintEdu(EduFeature&a, int count);
#endif // FEATUREFORBUILD_H_INCLUDED