00001
00002
00003
00004
00005
00006 #ifdef HAVE_SYNLM
00007
00008
00009
00010 #include "StaticData.h"
00011 #include "SyntacticLanguageModel.h"
00012 #include "HHMMLangModel-gf.h"
00013 #include "TextObsModel.h"
00014 #include "SyntacticLanguageModelFiles.h"
00015 #include "SyntacticLanguageModelState.h"
00016
00017
00018 namespace Moses
00019 {
00020 SyntacticLanguageModel::SyntacticLanguageModel(const std::string &line)
00021
00022
00023
00024
00025
00026
00027
00028 {
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00059
00060
00061
00062
00063
00064
00065
00066
00067
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081 }
00082
00083 SyntacticLanguageModel::~SyntacticLanguageModel()
00084 {
00085 VERBOSE(3,"Destructing SyntacticLanguageModel" << std::endl);
00086 delete m_files;
00087 }
00088
00089 size_t SyntacticLanguageModel::GetNumScoreComponents() const
00090 {
00091 return m_NumScoreComponents;
00092 }
00093
00094 std::string SyntacticLanguageModel::GetScoreProducerDescription() const
00095 {
00096 return "SyntacticLM";
00097 }
00098
00099 const FFState* SyntacticLanguageModel::EmptyHypothesisState(const InputType &input) const
00100 {
00101
00102 return new SyntacticLanguageModelState<YModel,XModel,S,R>(m_files,m_beamWidth);
00103
00104 }
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136 FFState* SyntacticLanguageModel::Evaluate(const Hypothesis& cur_hypo,
00137 const FFState* prev_state,
00138 ScoreComponentCollection* accumulator) const
00139 {
00140
00141 VERBOSE(3,"Evaluating SyntacticLanguageModel for a hypothesis" << endl);
00142
00143 SyntacticLanguageModelState<YModel,XModel,S,R>* tmpState = NULL;
00144 SyntacticLanguageModelState<YModel,XModel,S,R>* nextState = NULL;
00145
00146
00147 const TargetPhrase& targetPhrase = cur_hypo.GetCurrTargetPhrase();
00148
00149 for (size_t i=0, n=targetPhrase.GetSize(); i<n; i++) {
00150
00151 const Word& word = targetPhrase.GetWord(i);
00152 const Factor* factor = word.GetFactor(m_factorType);
00153
00154 const std::string& string = factor->GetString();
00155
00156 if (i==0) {
00157 nextState = new SyntacticLanguageModelState<YModel,XModel,S,R>((const SyntacticLanguageModelState<YModel,XModel,S,R>*)prev_state, string);
00158 } else {
00159 tmpState = nextState;
00160 nextState = new SyntacticLanguageModelState<YModel,XModel,S,R>(tmpState, string);
00161 delete tmpState;
00162 }
00163
00164 double score = nextState->getScore();
00165 VERBOSE(3,"SynLM evaluated a score of " << score << endl);
00166 accumulator->Assign( this, score );
00167 }
00168
00169
00170
00171 return nextState;
00172
00173 }
00174
00175 }
00176
00177 #endif