-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathhypothesis.cc
115 lines (93 loc) · 1.8 KB
/
hypothesis.cc
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
#include "hypothesis.h"
#include<iostream>
#include<cstdlib>
hypothesis::hypothesis(){
m_bexpand = false;
m_stropt.clear();
m_cover.reset();
m_end = -1;
m_parent.clear();
m_score = 0;
m_history = NULL;
}
hypothesis::~hypothesis(){
}
int hypothesis::len(){
return m_end + 1;
}
void hypothesis::setparent( hypothesis* p ){
std::list<hypothesis*>::iterator iter = m_parent.begin();
while( iter != m_parent.end() ){
if( *iter == p )
break;
iter++;
}
if( iter == m_parent.end() ){
m_parent.push_back( p );
}
if( !m_history ){
m_history = p;
}
}
void hypothesis::settrans( std::string& opt ){
m_stropt = opt;
}
void hypothesis::setphrases( phrase& p ){
m_end = p.end;
for( int i=p.start; i<=p.end; ++i ){
m_cover.set(i);
}
}
void hypothesis::GetOpt(std::string& ret){
ret = m_stropt;
}
int hypothesis::GetDepth(){
if( !m_history )
return 1;
else
return 1 + m_history->GetDepth();
}
std::string hypothesis::GetHistory(){
std::string h="";
if( m_history ){
std::string tmp;
m_history->GetOpt(tmp);
h = tmp + h;
if( m_history->m_history ){
m_history->m_history->GetOpt(tmp);
h = tmp + " " + h;
}
}
return h;
}
std::string hypothesis::FullPath(){
if( !m_history )
return m_stropt;
else {
std::string his = m_history->FullPath();
return his + " " + m_stropt;
}
}
bool hypothesis::stest(){
bool ret = true;
for( int i=0; i<=m_end; ++i ){
ret = m_cover[i];
}
return ret;
}
int hypothesis::nextphrase(){
if( !stest() ){
std::cerr << "hypothesis::nextphrase error \n";
abort();
}
return m_end + 1;
}
void hypothesis::setexpand(){
m_bexpand = true;
}
bool hypothesis::expand(){
return m_bexpand;
}
std::bitset<64> hypothesis::cover() const {
return m_cover;
}