2010-09-17 16:42:33 +04:00
|
|
|
#include "TargetBigramFeature.h"
|
2010-09-17 17:55:00 +04:00
|
|
|
#include "InputFileStream.h"
|
2010-09-17 18:43:38 +04:00
|
|
|
#include "Phrase.h"
|
|
|
|
#include "TargetPhrase.h"
|
|
|
|
#include "Hypothesis.h"
|
|
|
|
#include "ScoreComponentCollection.h"
|
2010-09-17 16:42:33 +04:00
|
|
|
|
|
|
|
namespace Moses {
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
2010-09-17 17:55:00 +04:00
|
|
|
bool TargetBigramFeature::Load(const std::string &filePath)
|
|
|
|
{
|
|
|
|
InputFileStream inFile(filePath);
|
|
|
|
if (!inFile)
|
|
|
|
return false;
|
|
|
|
|
2010-09-17 19:01:14 +04:00
|
|
|
size_t lineNo = 0;
|
2010-09-17 17:55:00 +04:00
|
|
|
std::string line;
|
|
|
|
while (getline(inFile, line)) {
|
2010-09-17 19:20:16 +04:00
|
|
|
m_wordMap[line] = lineNo++;
|
2010-09-17 17:55:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
inFile.Close();
|
|
|
|
}
|
|
|
|
|
2010-09-17 16:42:33 +04:00
|
|
|
size_t TargetBigramFeature::GetNumScoreComponents() const
|
|
|
|
{
|
2010-09-17 19:01:14 +04:00
|
|
|
return m_wordMap.size() * m_wordMap.size();
|
2010-09-17 16:42:33 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
string TargetBigramFeature::GetScoreProducerWeightShortName() const
|
|
|
|
{
|
2010-09-17 18:18:37 +04:00
|
|
|
return "tbf";
|
2010-09-17 16:42:33 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
size_t TargetBigramFeature::GetNumInputScores() const
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-17 19:01:14 +04:00
|
|
|
const FFState* TargetBigramFeature::EmptyHypothesisState(const InputType &/*input*/) const
|
2010-09-17 16:42:33 +04:00
|
|
|
{
|
2010-09-17 18:18:37 +04:00
|
|
|
return NULL;
|
2010-09-17 16:42:33 +04:00
|
|
|
}
|
|
|
|
|
2010-09-17 16:50:29 +04:00
|
|
|
FFState* TargetBigramFeature::Evaluate(const Hypothesis& cur_hypo,
|
|
|
|
const FFState* prev_state,
|
|
|
|
ScoreComponentCollection* accumulator) const
|
2010-09-17 16:42:33 +04:00
|
|
|
{
|
2010-09-17 19:20:16 +04:00
|
|
|
vector<string> words;
|
|
|
|
if (cur_hypo.GetPrevHypo() != NULL) {
|
|
|
|
size_t prevPhraseSize = cur_hypo.GetPrevHypo()->GetCurrTargetPhrase().GetSize();
|
2010-09-17 18:43:38 +04:00
|
|
|
if (prevPhraseSize > 0) {
|
2010-09-17 19:20:16 +04:00
|
|
|
words.push_back(cur_hypo.GetPrevHypo()->GetCurrTargetPhrase().GetWord(prevPhraseSize - 1).ToString());
|
2010-09-17 18:43:38 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
size_t currPhraseSize = cur_hypo.GetCurrTargetPhrase().GetSize();
|
|
|
|
for (size_t i = 0; i < currPhraseSize; ++i) {
|
2010-09-17 19:20:16 +04:00
|
|
|
words.push_back(cur_hypo.GetCurrTargetPhrase().GetWord(i).ToString());
|
2010-09-17 18:43:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
for (size_t i = 1; i < words.size(); ++i) {
|
2010-09-17 19:20:16 +04:00
|
|
|
map<string,size_t>::const_iterator first, second;
|
|
|
|
if ((first = m_wordMap.find(words[i-1])) != m_wordMap.end() &&
|
|
|
|
(second = m_wordMap.find(words[i])) != m_wordMap.end()) {
|
2010-10-07 02:06:49 +04:00
|
|
|
cerr << "FIXME" << endl;
|
|
|
|
assert(0);
|
|
|
|
//accumulator->Assign(first->second * second->second, 1);
|
2010-09-17 19:20:16 +04:00
|
|
|
}
|
2010-09-17 18:43:38 +04:00
|
|
|
}
|
|
|
|
|
2010-09-17 18:18:37 +04:00
|
|
|
return NULL;
|
2010-09-17 16:42:33 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|