diff options
93 files changed, 1116 insertions, 1142 deletions
diff --git a/misc/GenerateSequences.cpp b/misc/GenerateSequences.cpp index 9439da258..a86b8a41c 100644 --- a/misc/GenerateSequences.cpp +++ b/misc/GenerateSequences.cpp @@ -22,39 +22,34 @@ int stringToInteger(string s) void loadInput(const char * fileName, vector <string> & input) { - ifstream sr (fileName); - string line; - - if(sr.is_open()) - { - while(getline(sr , line )) - { - input.push_back(line); - } - - sr.close(); - } - else - { - cout<<"Unable to read "<<fileName<<endl; - exit(1); - } + ifstream sr (fileName); + string line; + + if(sr.is_open()) { + while(getline(sr , line )) { + input.push_back(line); + } + + sr.close(); + } else { + cout<<"Unable to read "<<fileName<<endl; + exit(1); + } } void getWords(string s, vector <string> & currInput) { - istringstream iss(s); - currInput.clear(); - do - { - string sub; - iss >> sub; - currInput.push_back(sub); + istringstream iss(s); + currInput.clear(); + do { + string sub; + iss >> sub; + currInput.push_back(sub); - } while (iss); + } while (iss); - currInput.pop_back(); + currInput.pop_back(); } string getTranslation(int index, vector < pair <string , vector <int> > > & gCepts , vector <string> & currF , map <string,int> & singletons) @@ -463,58 +458,57 @@ void constructCepts(vector < pair < set <int> , set <int> > > & ceptsInPhrase, s int main(int argc, char * argv[]) { - vector <string> e; - vector <string> f; - vector <string> a; - vector <string> singletons; - map <string,int> sTons; - vector < pair < set <int> , set <int> > > ceptsInPhrase; - vector < pair < string , vector <int> > > gCepts; - - set <int> sourceNullWords; - set <int> targetNullWords; - - vector <string> currE; - vector <string> currF; - vector <string> currA; - - loadInput(argv[4],singletons); - - for(int i=0; i<singletons.size(); i++) - sTons[singletons[i]]=i; - - loadInput(argv[1],e); - loadInput(argv[2],f); - loadInput(argv[3],a); - - - for (int i=0; i<a.size(); i++) - { - - - getWords(e[i],currE); - getWords(f[i],currF); - getWords(a[i],currA); - - constructCepts(ceptsInPhrase, sourceNullWords , targetNullWords, currA , currE.size(), currF.size()); - //cout<<"CC done"<<endl; - ceptsInGenerativeStoryFormat(ceptsInPhrase , gCepts , sourceNullWords, currE); - //cout<<"format done"<<endl; - // printCepts(gCepts, currF); - generateStory(gCepts, targetNullWords ,currF,sTons); - - - /* - cout<<"________________________________________"<<endl; - - cout<<"Press any integer to continue ..."<<endl; - int xx; - cin>>xx; - */ - - } - - - return 0; - + vector <string> e; + vector <string> f; + vector <string> a; + vector <string> singletons; + map <string,int> sTons; + vector < pair < set <int> , set <int> > > ceptsInPhrase; + vector < pair < string , vector <int> > > gCepts; + + set <int> sourceNullWords; + set <int> targetNullWords; + + vector <string> currE; + vector <string> currF; + vector <string> currA; + + loadInput(argv[4],singletons); + + for(int i=0; i<singletons.size(); i++) + sTons[singletons[i]]=i; + + loadInput(argv[1],e); + loadInput(argv[2],f); + loadInput(argv[3],a); + + + for (int i=0; i<a.size(); i++) { + + + getWords(e[i],currE); + getWords(f[i],currF); + getWords(a[i],currA); + + constructCepts(ceptsInPhrase, sourceNullWords , targetNullWords, currA , currE.size(), currF.size()); + //cout<<"CC done"<<endl; + ceptsInGenerativeStoryFormat(ceptsInPhrase , gCepts , sourceNullWords, currE); + //cout<<"format done"<<endl; + // printCepts(gCepts, currF); + generateStory(gCepts, targetNullWords ,currF,sTons); + + + /* + cout<<"________________________________________"<<endl; + + cout<<"Press any integer to continue ..."<<endl; + int xx; + cin>>xx; + */ + + } + + + return 0; + } diff --git a/moses-chart-cmd/Main.cpp b/moses-chart-cmd/Main.cpp index 17c9bdf08..6035ff67e 100644 --- a/moses-chart-cmd/Main.cpp +++ b/moses-chart-cmd/Main.cpp @@ -130,12 +130,12 @@ public: //DIMw if (staticData.IsDetailedAllTranslationReportingEnabled()) { - const Sentence &sentence = dynamic_cast<const Sentence &>(*m_source); - size_t nBestSize = staticData.GetNBestSize(); - ChartTrellisPathList nBestList; - manager.CalcNBest(nBestSize, nBestList, staticData.GetDistinctNBest()); - m_ioWrapper.OutputDetailedAllTranslationReport(nBestList, manager, sentence, translationId); - } + const Sentence &sentence = dynamic_cast<const Sentence &>(*m_source); + size_t nBestSize = staticData.GetNBestSize(); + ChartTrellisPathList nBestList; + manager.CalcNBest(nBestSize, nBestList, staticData.GetDistinctNBest()); + m_ioWrapper.OutputDetailedAllTranslationReport(nBestList, manager, sentence, translationId); + } // n-best size_t nBestSize = staticData.GetNBestSize(); diff --git a/moses-cmd/IOWrapper.cpp b/moses-cmd/IOWrapper.cpp index eadab05be..ac85271d7 100644 --- a/moses-cmd/IOWrapper.cpp +++ b/moses-cmd/IOWrapper.cpp @@ -199,12 +199,12 @@ std::map<size_t, const Factor*> GetPlaceholders(const Hypothesis &hypo, FactorTy std::map<size_t, const Factor*> ret; for (size_t sourcePos = 0; sourcePos < inputPhrase.GetSize(); ++sourcePos) { - const Factor *factor = inputPhrase.GetFactor(sourcePos, placeholderFactor); - if (factor) { - std::set<size_t> targetPos = hypo.GetTranslationOption().GetTargetPhrase().GetAlignTerm().GetAlignmentsForSource(sourcePos); - CHECK(targetPos.size() == 1); - ret[*targetPos.begin()] = factor; - } + const Factor *factor = inputPhrase.GetFactor(sourcePos, placeholderFactor); + if (factor) { + std::set<size_t> targetPos = hypo.GetTranslationOption().GetTargetPhrase().GetAlignTerm().GetAlignmentsForSource(sourcePos); + CHECK(targetPos.size() == 1); + ret[*targetPos.begin()] = factor; + } } return ret; @@ -226,8 +226,8 @@ void OutputSurface(std::ostream &out, const Hypothesis &edge, const std::vector< std::map<size_t, const Factor*> placeholders; if (placeholderFactor != NOT_FOUND) { - // creates map of target position -> factor for placeholders - placeholders = GetPlaceholders(edge, placeholderFactor); + // creates map of target position -> factor for placeholders + placeholders = GetPlaceholders(edge, placeholderFactor); } size_t size = phrase.GetSize(); @@ -235,11 +235,11 @@ void OutputSurface(std::ostream &out, const Hypothesis &edge, const std::vector< const Factor *factor = phrase.GetFactor(pos, outputFactorOrder[0]); if (placeholders.size()) { - // do placeholders - std::map<size_t, const Factor*>::const_iterator iter = placeholders.find(pos); - if (iter != placeholders.end()) { - factor = iter->second; - } + // do placeholders + std::map<size_t, const Factor*>::const_iterator iter = placeholders.find(pos); + if (iter != placeholders.end()) { + factor = iter->second; + } } CHECK(factor); diff --git a/moses-cmd/Main.cpp b/moses-cmd/Main.cpp index 98aba3c62..0bb9708d7 100644 --- a/moses-cmd/Main.cpp +++ b/moses-cmd/Main.cpp @@ -303,9 +303,8 @@ public: IFVERBOSE(1) { debug << "BEST TRANSLATION: " << *bestHypo << endl; } - } - else { - VERBOSE(1, "NO BEST TRANSLATION" << endl); + } else { + VERBOSE(1, "NO BEST TRANSLATION" << endl); } out << endl; diff --git a/moses/ChartCell.cpp b/moses/ChartCell.cpp index e3d6f4243..eb4bd81c1 100644 --- a/moses/ChartCell.cpp +++ b/moses/ChartCell.cpp @@ -127,11 +127,11 @@ const ChartHypothesis *ChartCell::GetBestHypothesis() const for (iter = m_hypoColl.begin(); iter != m_hypoColl.end(); ++iter) { const HypoList &sortedList = iter->second.GetSortedHypotheses(); if (sortedList.size() > 0) { - const ChartHypothesis *hypo = sortedList[0]; - if (hypo->GetTotalScore() > bestScore) { - bestScore = hypo->GetTotalScore(); - ret = hypo; - } + const ChartHypothesis *hypo = sortedList[0]; + if (hypo->GetTotalScore() > bestScore) { + bestScore = hypo->GetTotalScore(); + ret = hypo; + } } } diff --git a/moses/ChartHypothesis.cpp b/moses/ChartHypothesis.cpp index 72c1c76a6..18811a97f 100644 --- a/moses/ChartHypothesis.cpp +++ b/moses/ChartHypothesis.cpp @@ -102,19 +102,19 @@ void ChartHypothesis::GetOutputPhrase(Phrase &outPhrase) const outPhrase.AddWord(word); if (placeholderFactor != NOT_FOUND) { - std::set<size_t> sourcePosSet = GetCurrTargetPhrase().GetAlignTerm().GetAlignmentsForTarget(pos); - if (sourcePosSet.size() == 1) { - const std::vector<const Word*> *ruleSourceFromInputPath = GetTranslationOption().GetSourceRuleFromInputPath(); - CHECK(ruleSourceFromInputPath); - - size_t sourcePos = *sourcePosSet.begin(); - const Word *sourceWord = ruleSourceFromInputPath->at(sourcePos); - CHECK(sourceWord); - const Factor *factor = sourceWord->GetFactor(placeholderFactor); - if (factor) { - outPhrase.Back()[0] = factor; - } - } + std::set<size_t> sourcePosSet = GetCurrTargetPhrase().GetAlignTerm().GetAlignmentsForTarget(pos); + if (sourcePosSet.size() == 1) { + const std::vector<const Word*> *ruleSourceFromInputPath = GetTranslationOption().GetSourceRuleFromInputPath(); + CHECK(ruleSourceFromInputPath); + + size_t sourcePos = *sourcePosSet.begin(); + const Word *sourceWord = ruleSourceFromInputPath->at(sourcePos); + CHECK(sourceWord); + const Factor *factor = sourceWord->GetFactor(placeholderFactor); + if (factor) { + outPhrase.Back()[0] = factor; + } + } } } diff --git a/moses/ChartHypothesisCollection.cpp b/moses/ChartHypothesisCollection.cpp index 8cccf3083..f3116fb43 100644 --- a/moses/ChartHypothesisCollection.cpp +++ b/moses/ChartHypothesisCollection.cpp @@ -61,10 +61,10 @@ ChartHypothesisCollection::~ChartHypothesisCollection() bool ChartHypothesisCollection::AddHypothesis(ChartHypothesis *hypo, ChartManager &manager) { if (hypo->GetTotalScore() == - std::numeric_limits<float>::infinity()) { - manager.GetSentenceStats().AddDiscarded(); - VERBOSE(3,"discarded, -inf score" << std::endl); - ChartHypothesis::Delete(hypo); - return false; + manager.GetSentenceStats().AddDiscarded(); + VERBOSE(3,"discarded, -inf score" << std::endl); + ChartHypothesis::Delete(hypo); + return false; } if (hypo->GetTotalScore() < m_bestScore + m_beamWidth) { diff --git a/moses/ChartParser.cpp b/moses/ChartParser.cpp index bc5b86a3e..55a67af22 100644 --- a/moses/ChartParser.cpp +++ b/moses/ChartParser.cpp @@ -221,7 +221,7 @@ void ChartParser::CreateInputPaths(const InputType &input) const InputPath &ChartParser::GetInputPath(WordsRange &range) const { - return GetInputPath(range.GetStartPos(), range.GetEndPos()); + return GetInputPath(range.GetStartPos(), range.GetEndPos()); } const InputPath &ChartParser::GetInputPath(size_t startPos, size_t endPos) const diff --git a/moses/ChartTranslationOption.cpp b/moses/ChartTranslationOption.cpp index 05d83f567..8e7d79897 100644 --- a/moses/ChartTranslationOption.cpp +++ b/moses/ChartTranslationOption.cpp @@ -23,8 +23,8 @@ void ChartTranslationOption::Evaluate(const InputType &input, const InputPath &i std::ostream& operator<<(std::ostream &out, const ChartTranslationOption &transOpt) { - out << transOpt.m_targetPhrase << " " << transOpt.m_scoreBreakdown; - return out; + out << transOpt.m_targetPhrase << " " << transOpt.m_scoreBreakdown; + return out; } } diff --git a/moses/ChartTranslationOption.h b/moses/ChartTranslationOption.h index 7eab52f65..d307cd359 100644 --- a/moses/ChartTranslationOption.h +++ b/moses/ChartTranslationOption.h @@ -10,7 +10,7 @@ class InputType; class ChartTranslationOption { - friend std::ostream& operator<<(std::ostream&, const ChartTranslationOption&); + friend std::ostream& operator<<(std::ostream&, const ChartTranslationOption&); protected: const TargetPhrase &m_targetPhrase; @@ -25,15 +25,19 @@ public: return m_targetPhrase; } - const InputPath *GetInputPath() const - { return m_inputPath; } - void SetInputPath(const InputPath *inputPath) - { m_inputPath = inputPath; } + const InputPath *GetInputPath() const { + return m_inputPath; + } + void SetInputPath(const InputPath *inputPath) { + m_inputPath = inputPath; + } - const std::vector<const Word*> *GetSourceRuleFromInputPath() const - { return m_ruleSourceFromInputPath; } - void SetSourceRuleFromInputPath(const std::vector<const Word*> *obj) - { m_ruleSourceFromInputPath = obj; } + const std::vector<const Word*> *GetSourceRuleFromInputPath() const { + return m_ruleSourceFromInputPath; + } + void SetSourceRuleFromInputPath(const std::vector<const Word*> *obj) { + m_ruleSourceFromInputPath = obj; + } const ScoreComponentCollection &GetScores() const { return m_scoreBreakdown; diff --git a/moses/ChartTranslationOptionList.cpp b/moses/ChartTranslationOptionList.cpp index 965797df1..c12035f18 100644 --- a/moses/ChartTranslationOptionList.cpp +++ b/moses/ChartTranslationOptionList.cpp @@ -68,11 +68,11 @@ void ChartTranslationOptionList::Add(const TargetPhraseCollection &tpc, } for (size_t i = 0; i < stackVec.size(); ++i) { - const ChartCellLabel &chartCellLabel = *stackVec[i]; - size_t numHypos = chartCellLabel.GetStack().cube->size(); - if (numHypos == 0) { - return; // empty stack. These rules can't be used - } + const ChartCellLabel &chartCellLabel = *stackVec[i]; + size_t numHypos = chartCellLabel.GetStack().cube->size(); + if (numHypos == 0) { + return; // empty stack. These rules can't be used + } } float score = ChartTranslationOptions::CalcEstimateOfBestScore(tpc, stackVec); diff --git a/moses/ChartTranslationOptions.cpp b/moses/ChartTranslationOptions.cpp index bcfca72a5..e31667d37 100644 --- a/moses/ChartTranslationOptions.cpp +++ b/moses/ChartTranslationOptions.cpp @@ -72,7 +72,7 @@ void ChartTranslationOptions::Evaluate(const InputType &input, const InputPath & { SetInputPath(&inputPath); if (StaticData::Instance().GetPlaceholderFactor() != NOT_FOUND) { - CreateSourceRuleFromInputPath(); + CreateSourceRuleFromInputPath(); } CollType::iterator iter; @@ -88,52 +88,49 @@ void ChartTranslationOptions::SetInputPath(const InputPath *inputPath) { CollType::iterator iter; for (iter = m_collection.begin(); iter != m_collection.end(); ++iter) { - ChartTranslationOption &transOpt = **iter; - transOpt.SetInputPath(inputPath); + ChartTranslationOption &transOpt = **iter; + transOpt.SetInputPath(inputPath); } } void ChartTranslationOptions::CreateSourceRuleFromInputPath() { - if (m_collection.size() == 0) { - return; - } - - const InputPath *inputPath = m_collection.front()->GetInputPath(); - CHECK(inputPath); - std::vector<const Word*> &ruleSourceFromInputPath = inputPath->AddRuleSourceFromInputPath(); - - size_t chartCellIndex = 0; - const ChartCellLabel *chartCellLabel = (chartCellIndex < m_stackVec.size()) ? m_stackVec[chartCellIndex] : NULL; - - size_t ind = 0; - for (size_t sourcePos = m_wordsRange->GetStartPos(); sourcePos <= m_wordsRange->GetEndPos(); ++sourcePos, ++ind) { - if (chartCellLabel) { - if (sourcePos == chartCellLabel->GetCoverage().GetEndPos()) { - // end of child range. push an empty word to denote non-term - ruleSourceFromInputPath.push_back(NULL); - ++chartCellIndex; - chartCellLabel = (chartCellIndex < m_stackVec.size()) ? m_stackVec[chartCellIndex] : NULL; - } - else if (sourcePos >= chartCellLabel->GetCoverage().GetStartPos()) { - // in the range of child hypo. do nothing - } - else { - // not yet reached child range. add word - ruleSourceFromInputPath.push_back(&inputPath->GetPhrase().GetWord(ind)); - } - } - else { - // no child in sight. add word - ruleSourceFromInputPath.push_back(&inputPath->GetPhrase().GetWord(ind)); - } - } - - // save it to each trans opt + if (m_collection.size() == 0) { + return; + } + + const InputPath *inputPath = m_collection.front()->GetInputPath(); + CHECK(inputPath); + std::vector<const Word*> &ruleSourceFromInputPath = inputPath->AddRuleSourceFromInputPath(); + + size_t chartCellIndex = 0; + const ChartCellLabel *chartCellLabel = (chartCellIndex < m_stackVec.size()) ? m_stackVec[chartCellIndex] : NULL; + + size_t ind = 0; + for (size_t sourcePos = m_wordsRange->GetStartPos(); sourcePos <= m_wordsRange->GetEndPos(); ++sourcePos, ++ind) { + if (chartCellLabel) { + if (sourcePos == chartCellLabel->GetCoverage().GetEndPos()) { + // end of child range. push an empty word to denote non-term + ruleSourceFromInputPath.push_back(NULL); + ++chartCellIndex; + chartCellLabel = (chartCellIndex < m_stackVec.size()) ? m_stackVec[chartCellIndex] : NULL; + } else if (sourcePos >= chartCellLabel->GetCoverage().GetStartPos()) { + // in the range of child hypo. do nothing + } else { + // not yet reached child range. add word + ruleSourceFromInputPath.push_back(&inputPath->GetPhrase().GetWord(ind)); + } + } else { + // no child in sight. add word + ruleSourceFromInputPath.push_back(&inputPath->GetPhrase().GetWord(ind)); + } + } + + // save it to each trans opt CollType::iterator iter; for (iter = m_collection.begin(); iter != m_collection.end(); ++iter) { - ChartTranslationOption &transOpt = **iter; - transOpt.SetSourceRuleFromInputPath(&ruleSourceFromInputPath); + ChartTranslationOption &transOpt = **iter; + transOpt.SetSourceRuleFromInputPath(&ruleSourceFromInputPath); } } diff --git a/moses/ChartTrellisNode.cpp b/moses/ChartTrellisNode.cpp index 4ceef780f..11ea4e6d8 100644 --- a/moses/ChartTrellisNode.cpp +++ b/moses/ChartTrellisNode.cpp @@ -93,19 +93,19 @@ Phrase ChartTrellisNode::GetOutputPhrase() const ret.AddWord(word); if (placeholderFactor != NOT_FOUND) { - std::set<size_t> sourcePosSet = m_hypo.GetCurrTargetPhrase().GetAlignTerm().GetAlignmentsForTarget(pos); - if (sourcePosSet.size() == 1) { - const std::vector<const Word*> *ruleSourceFromInputPath = m_hypo.GetTranslationOption().GetSourceRuleFromInputPath(); - CHECK(ruleSourceFromInputPath); - - size_t sourcePos = *sourcePosSet.begin(); - const Word *sourceWord = ruleSourceFromInputPath->at(sourcePos); - CHECK(sourceWord); - const Factor *factor = sourceWord->GetFactor(placeholderFactor); - if (factor) { - ret.Back()[0] = factor; - } - } + std::set<size_t> sourcePosSet = m_hypo.GetCurrTargetPhrase().GetAlignTerm().GetAlignmentsForTarget(pos); + if (sourcePosSet.size() == 1) { + const std::vector<const Word*> *ruleSourceFromInputPath = m_hypo.GetTranslationOption().GetSourceRuleFromInputPath(); + CHECK(ruleSourceFromInputPath); + + size_t sourcePos = *sourcePosSet.begin(); + const Word *sourceWord = ruleSourceFromInputPath->at(sourcePos); + CHECK(sourceWord); + const Factor *factor = sourceWord->GetFactor(placeholderFactor); + if (factor) { + ret.Back()[0] = factor; + } + } } } } diff --git a/moses/ConfusionNet.cpp b/moses/ConfusionNet.cpp index b1b2b521c..fdfde0a86 100644 --- a/moses/ConfusionNet.cpp +++ b/moses/ConfusionNet.cpp @@ -81,8 +81,8 @@ ConfusionNet::ConfusionNet(Sentence const& s) { data.resize(s.GetSize()); for(size_t i=0; i<s.GetSize(); ++i) { - ScorePair scorePair; - std::pair<Word, ScorePair > temp = std::make_pair(s.GetWord(i), scorePair); + ScorePair scorePair; + std::pair<Word, ScorePair > temp = std::make_pair(s.GetWord(i), scorePair); data[i].push_back(temp); } } diff --git a/moses/FF/BleuScoreFeature.h b/moses/FF/BleuScoreFeature.h index b3095bcab..9629c49a0 100644 --- a/moses/FF/BleuScoreFeature.h +++ b/moses/FF/BleuScoreFeature.h @@ -119,14 +119,14 @@ public: int featureID, ScoreComponentCollection* accumulator) const; void Evaluate(const InputType &input - , const InputPath &inputPath - , const TargetPhrase &targetPhrase - , ScoreComponentCollection &scoreBreakdown) const + , const InputPath &inputPath + , const TargetPhrase &targetPhrase + , ScoreComponentCollection &scoreBreakdown) const {} void Evaluate(const Phrase &source - , const TargetPhrase &targetPhrase - , ScoreComponentCollection &scoreBreakdown - , ScoreComponentCollection &estimatedFutureScore) const + , const TargetPhrase &targetPhrase + , ScoreComponentCollection &scoreBreakdown + , ScoreComponentCollection &estimatedFutureScore) const {} bool Enabled() const { diff --git a/moses/FF/ConstrainedDecoding.cpp b/moses/FF/ConstrainedDecoding.cpp index 7beff4cee..b23fd344a 100644 --- a/moses/FF/ConstrainedDecoding.cpp +++ b/moses/FF/ConstrainedDecoding.cpp @@ -14,75 +14,74 @@ namespace Moses { ConstrainedDecodingState::ConstrainedDecodingState(const Hypothesis &hypo) { - hypo.GetOutputPhrase(m_outputPhrase); + hypo.GetOutputPhrase(m_outputPhrase); } ConstrainedDecodingState::ConstrainedDecodingState(const ChartHypothesis &hypo) { - hypo.GetOutputPhrase(m_outputPhrase); + hypo.GetOutputPhrase(m_outputPhrase); } int ConstrainedDecodingState::Compare(const FFState& other) const { - const ConstrainedDecodingState &otherFF = static_cast<const ConstrainedDecodingState&>(other); - bool ret = m_outputPhrase.Compare(otherFF.m_outputPhrase); - return ret; + const ConstrainedDecodingState &otherFF = static_cast<const ConstrainedDecodingState&>(other); + bool ret = m_outputPhrase.Compare(otherFF.m_outputPhrase); + return ret; } ////////////////////////////////////////////////////////////////// void ConstrainedDecoding::Load() { - const StaticData &staticData = StaticData::Instance(); - bool addBeginEndWord = (staticData.GetSearchAlgorithm() == ChartDecoding) || (staticData.GetSearchAlgorithm() == ChartIncremental); - - InputFileStream constraintFile(m_path); - std::string line; - long sentenceID = staticData.GetStartTranslationId() - 1; - while (getline(constraintFile, line)) { - vector<string> vecStr = Tokenize(line, "\t"); - - Phrase phrase(0); - if (vecStr.size() == 1) { - sentenceID++; - phrase.CreateFromString(Output, staticData.GetOutputFactorOrder(), vecStr[0], staticData.GetFactorDelimiter(), NULL); - } else if (vecStr.size() == 2) { - sentenceID = Scan<long>(vecStr[0]); - phrase.CreateFromString(Output, staticData.GetOutputFactorOrder(), vecStr[1], staticData.GetFactorDelimiter(), NULL); - } else { - CHECK(false); - } - - if (addBeginEndWord) { - phrase.InitStartEndWord(); - } - m_constraints.insert(make_pair(sentenceID,phrase)); - - } + const StaticData &staticData = StaticData::Instance(); + bool addBeginEndWord = (staticData.GetSearchAlgorithm() == ChartDecoding) || (staticData.GetSearchAlgorithm() == ChartIncremental); + + InputFileStream constraintFile(m_path); + std::string line; + long sentenceID = staticData.GetStartTranslationId() - 1; + while (getline(constraintFile, line)) { + vector<string> vecStr = Tokenize(line, "\t"); + + Phrase phrase(0); + if (vecStr.size() == 1) { + sentenceID++; + phrase.CreateFromString(Output, staticData.GetOutputFactorOrder(), vecStr[0], staticData.GetFactorDelimiter(), NULL); + } else if (vecStr.size() == 2) { + sentenceID = Scan<long>(vecStr[0]); + phrase.CreateFromString(Output, staticData.GetOutputFactorOrder(), vecStr[1], staticData.GetFactorDelimiter(), NULL); + } else { + CHECK(false); + } + + if (addBeginEndWord) { + phrase.InitStartEndWord(); + } + m_constraints.insert(make_pair(sentenceID,phrase)); + + } } std::vector<float> ConstrainedDecoding::DefaultWeights() const { - CHECK(m_numScoreComponents == 1); - vector<float> ret(1, 1); - return ret; + CHECK(m_numScoreComponents == 1); + vector<float> ret(1, 1); + return ret; } template <class H, class M> const Phrase *GetConstraint(const std::map<long,Phrase> &constraints, const H &hypo) { - const M &mgr = hypo.GetManager(); - const InputType &input = mgr.GetSource(); - long id = input.GetTranslationId(); - - map<long,Phrase>::const_iterator iter; - iter = constraints.find(id); - - if (iter == constraints.end()) { - return NULL; - } - else { - return &iter->second; - } + const M &mgr = hypo.GetManager(); + const InputType &input = mgr.GetSource(); + long id = input.GetTranslationId(); + + map<long,Phrase>::const_iterator iter; + iter = constraints.find(id); + + if (iter == constraints.end()) { + return NULL; + } else { + return &iter->second; + } } FFState* ConstrainedDecoding::Evaluate( @@ -90,27 +89,26 @@ FFState* ConstrainedDecoding::Evaluate( const FFState* prev_state, ScoreComponentCollection* accumulator) const { - const Phrase *ref = GetConstraint<Hypothesis, Manager>(m_constraints, hypo); - CHECK(ref); + const Phrase *ref = GetConstraint<Hypothesis, Manager>(m_constraints, hypo); + CHECK(ref); - ConstrainedDecodingState *ret = new ConstrainedDecodingState(hypo); - const Phrase &outputPhrase = ret->GetPhrase(); + ConstrainedDecodingState *ret = new ConstrainedDecodingState(hypo); + const Phrase &outputPhrase = ret->GetPhrase(); - size_t searchPos = ref->Find(outputPhrase, m_maxUnknowns); + size_t searchPos = ref->Find(outputPhrase, m_maxUnknowns); - float score; - if (hypo.IsSourceCompleted()) { - // translated entire sentence. - score = (searchPos == 0) && (ref->GetSize() == outputPhrase.GetSize()) - ? 0 : - std::numeric_limits<float>::infinity(); - } - else { - score = (searchPos != NOT_FOUND) ? 0 : - std::numeric_limits<float>::infinity(); - } + float score; + if (hypo.IsSourceCompleted()) { + // translated entire sentence. + score = (searchPos == 0) && (ref->GetSize() == outputPhrase.GetSize()) + ? 0 : - std::numeric_limits<float>::infinity(); + } else { + score = (searchPos != NOT_FOUND) ? 0 : - std::numeric_limits<float>::infinity(); + } - accumulator->PlusEquals(this, score); + accumulator->PlusEquals(this, score); - return ret; + return ret; } FFState* ConstrainedDecoding::EvaluateChart( @@ -118,41 +116,38 @@ FFState* ConstrainedDecoding::EvaluateChart( int /* featureID - used to index the state in the previous hypotheses */, ScoreComponentCollection* accumulator) const { - const Phrase *ref = GetConstraint<ChartHypothesis, ChartManager>(m_constraints, hypo); - CHECK(ref); - - const ChartManager &mgr = hypo.GetManager(); - const Sentence &source = static_cast<const Sentence&>(mgr.GetSource()); - - ConstrainedDecodingState *ret = new ConstrainedDecodingState(hypo); - const Phrase &outputPhrase = ret->GetPhrase(); - size_t searchPos = ref->Find(outputPhrase, m_maxUnknowns); - - float score; - if (hypo.GetCurrSourceRange().GetStartPos() == 0 && - hypo.GetCurrSourceRange().GetEndPos() == source.GetSize() - 1) { - // translated entire sentence. - score = (searchPos == 0) && (ref->GetSize() == outputPhrase.GetSize()) - ? 0 : - std::numeric_limits<float>::infinity(); - } - else { - score = (searchPos != NOT_FOUND) ? 0 : - std::numeric_limits<float>::infinity(); - } - - accumulator->PlusEquals(this, score); - - return ret; + const Phrase *ref = GetConstraint<ChartHypothesis, ChartManager>(m_constraints, hypo); + CHECK(ref); + + const ChartManager &mgr = hypo.GetManager(); + const Sentence &source = static_cast<const Sentence&>(mgr.GetSource()); + + ConstrainedDecodingState *ret = new ConstrainedDecodingState(hypo); + const Phrase &outputPhrase = ret->GetPhrase(); + size_t searchPos = ref->Find(outputPhrase, m_maxUnknowns); + + float score; + if (hypo.GetCurrSourceRange().GetStartPos() == 0 && + hypo.GetCurrSourceRange().GetEndPos() == source.GetSize() - 1) { + // translated entire sentence. + score = (searchPos == 0) && (ref->GetSize() == outputPhrase.GetSize()) + ? 0 : - std::numeric_limits<float>::infinity(); + } else { + score = (searchPos != NOT_FOUND) ? 0 : - std::numeric_limits<float>::infinity(); + } + + accumulator->PlusEquals(this, score); + + return ret; } void ConstrainedDecoding::SetParameter(const std::string& key, const std::string& value) { if (key == "path") { - m_path = value; - } - else if (key == "max-unknowns") { - m_maxUnknowns = Scan<int>(value); - } - else { + m_path = value; + } else if (key == "max-unknowns") { + m_maxUnknowns = Scan<int>(value); + } else { StatefulFeatureFunction::SetParameter(key, value); } } diff --git a/moses/FF/ConstrainedDecoding.h b/moses/FF/ConstrainedDecoding.h index 6519c0a03..6d382abc9 100644 --- a/moses/FF/ConstrainedDecoding.h +++ b/moses/FF/ConstrainedDecoding.h @@ -11,19 +11,20 @@ namespace Moses class ConstrainedDecodingState : public FFState { public: - ConstrainedDecodingState() - {} + ConstrainedDecodingState() + {} - ConstrainedDecodingState(const Hypothesis &hypo); - ConstrainedDecodingState(const ChartHypothesis &hypo); + ConstrainedDecodingState(const Hypothesis &hypo); + ConstrainedDecodingState(const ChartHypothesis &hypo); - int Compare(const FFState& other) const; + int Compare(const FFState& other) const; - const Phrase &GetPhrase() const - { return m_outputPhrase; } + const Phrase &GetPhrase() const { + return m_outputPhrase; + } protected: - Phrase m_outputPhrase; + Phrase m_outputPhrase; }; ////////////////////////////////////////////////////////////////// @@ -32,52 +33,51 @@ protected: class ConstrainedDecoding : public StatefulFeatureFunction { public: - ConstrainedDecoding(const std::string &line) - :StatefulFeatureFunction("ConstrainedDecoding", 1, line) - ,m_maxUnknowns(0) - { - m_tuneable = false; - ReadParameters(); - } - - void Load(); - - bool IsUseable(const FactorMask &mask) const - { return true; } - - void Evaluate(const Phrase &source - , const TargetPhrase &targetPhrase - , ScoreComponentCollection &scoreBreakdown - , ScoreComponentCollection &estimatedFutureScore) const - {} - void Evaluate(const InputType &input - , const InputPath &inputPath - , const TargetPhrase &targetPhrase - , ScoreComponentCollection &scoreBreakdown) const - {} - FFState* Evaluate( - const Hypothesis& cur_hypo, - const FFState* prev_state, - ScoreComponentCollection* accumulator) const; - - FFState* EvaluateChart( - const ChartHypothesis& /* cur_hypo */, - int /* featureID - used to index the state in the previous hypotheses */, - ScoreComponentCollection* accumulator) const; - - virtual const FFState* EmptyHypothesisState(const InputType &input) const - { - return new ConstrainedDecodingState(); - } - - std::vector<float> DefaultWeights() const; - - void SetParameter(const std::string& key, const std::string& value); + ConstrainedDecoding(const std::string &line) + :StatefulFeatureFunction("ConstrainedDecoding", 1, line) + ,m_maxUnknowns(0) { + m_tuneable = false; + ReadParameters(); + } + + void Load(); + + bool IsUseable(const FactorMask &mask) const { + return true; + } + + void Evaluate(const Phrase &source + , const TargetPhrase &targetPhrase + , ScoreComponentCollection &scoreBreakdown + , ScoreComponentCollection &estimatedFutureScore) const + {} + void Evaluate(const InputType &input + , const InputPath &inputPath + , const TargetPhrase &targetPhrase + , ScoreComponentCollection &scoreBreakdown) const + {} + FFState* Evaluate( + const Hypothesis& cur_hypo, + const FFState* prev_state, + ScoreComponentCollection* accumulator) const; + + FFState* EvaluateChart( + const ChartHypothesis& /* cur_hypo */, + int /* featureID - used to index the state in the previous hypotheses */, + ScoreComponentCollection* accumulator) const; + + virtual const FFState* EmptyHypothesisState(const InputType &input) const { + return new ConstrainedDecodingState(); + } + + std::vector<float> DefaultWeights() const; + + void SetParameter(const std::string& key, const std::string& value); protected: - std::string m_path; - std::map<long,Phrase> m_constraints; - int m_maxUnknowns; + std::string m_path; + std::map<long,Phrase> m_constraints; + int m_maxUnknowns; }; diff --git a/moses/FF/ControlRecombination.cpp b/moses/FF/ControlRecombination.cpp index b955bedc8..2396d81e3 100644 --- a/moses/FF/ControlRecombination.cpp +++ b/moses/FF/ControlRecombination.cpp @@ -13,48 +13,45 @@ using namespace std; namespace Moses { ControlRecombinationState::ControlRecombinationState(const Hypothesis &hypo, const ControlRecombination &ff) -:m_ff(ff) + :m_ff(ff) { - if (ff.GetType() == SameOutput) { - UTIL_THROW(util::Exception, "Implemented not yet completed for phrase-based model. Need to take into account the coverage"); - hypo.GetOutputPhrase(m_outputPhrase); - } - else { - m_hypo = &hypo; - } + if (ff.GetType() == SameOutput) { + UTIL_THROW(util::Exception, "Implemented not yet completed for phrase-based model. Need to take into account the coverage"); + hypo.GetOutputPhrase(m_outputPhrase); + } else { + m_hypo = &hypo; + } } ControlRecombinationState::ControlRecombinationState(const ChartHypothesis &hypo, const ControlRecombination &ff) -:m_ff(ff) + :m_ff(ff) { - if (ff.GetType() == SameOutput) { - hypo.GetOutputPhrase(m_outputPhrase); - } - else { - m_hypo = &hypo; - } + if (ff.GetType() == SameOutput) { + hypo.GetOutputPhrase(m_outputPhrase); + } else { + m_hypo = &hypo; + } } int ControlRecombinationState::Compare(const FFState& other) const { - const ControlRecombinationState &otherFF = static_cast<const ControlRecombinationState&>(other); - if (m_ff.GetType() == SameOutput) { - bool ret = m_outputPhrase.Compare(otherFF.m_outputPhrase); - return ret; - } - else { - // compare hypo address. Won't be equal unless they're actually the same hypo - if (m_hypo == otherFF.m_hypo) - return 0; - return (m_hypo < otherFF.m_hypo) ? -1 : +1; - } + const ControlRecombinationState &otherFF = static_cast<const ControlRecombinationState&>(other); + if (m_ff.GetType() == SameOutput) { + bool ret = m_outputPhrase.Compare(otherFF.m_outputPhrase); + return ret; + } else { + // compare hypo address. Won't be equal unless they're actually the same hypo + if (m_hypo == otherFF.m_hypo) + return 0; + return (m_hypo < otherFF.m_hypo) ? -1 : +1; + } } std::vector<float> ControlRecombination::DefaultWeights() const { - CHECK(m_numScoreComponents == 0); - vector<float> ret(0); - return ret; + CHECK(m_numScoreComponents == 0); + vector<float> ret(0); + return ret; } FFState* ControlRecombination::Evaluate( @@ -62,7 +59,7 @@ FFState* ControlRecombination::Evaluate( const FFState* prev_state, ScoreComponentCollection* accumulator) const { - return new ControlRecombinationState(hypo, *this); + return new ControlRecombinationState(hypo, *this); } FFState* ControlRecombination::EvaluateChart( @@ -70,17 +67,16 @@ FFState* ControlRecombination::EvaluateChart( int /* featureID - used to index the state in the previous hypotheses */, ScoreComponentCollection* accumulator) const { - return new ControlRecombinationState(hypo, *this); + return new ControlRecombinationState(hypo, *this); } void ControlRecombination::SetParameter(const std::string& key, const std::string& value) { - if (key == "type") { - m_type = (ControlRecombinationType) Scan<int>(value); - } - else { - StatefulFeatureFunction::SetParameter(key, value); - } + if (key == "type") { + m_type = (ControlRecombinationType) Scan<int>(value); + } else { + StatefulFeatureFunction::SetParameter(key, value); + } } } diff --git a/moses/FF/ControlRecombination.h b/moses/FF/ControlRecombination.h index d99dc9791..2ac4aa8e3 100644 --- a/moses/FF/ControlRecombination.h +++ b/moses/FF/ControlRecombination.h @@ -8,8 +8,8 @@ namespace Moses { -enum ControlRecombinationType -{ // when to recombine +enum ControlRecombinationType { + // when to recombine SameOutput = 1, Never = 2 }; @@ -19,22 +19,23 @@ class ControlRecombination; class ControlRecombinationState : public FFState { public: - ControlRecombinationState(const ControlRecombination &ff) - :m_ff(ff) - {} + ControlRecombinationState(const ControlRecombination &ff) + :m_ff(ff) + {} - ControlRecombinationState(const Hypothesis &hypo, const ControlRecombination &ff); - ControlRecombinationState(const ChartHypothesis &hypo, const ControlRecombination &ff); + ControlRecombinationState(const Hypothesis &hypo, const ControlRecombination &ff); + ControlRecombinationState(const ChartHypothesis &hypo, const ControlRecombination &ff); - int Compare(const FFState& other) const; + int Compare(const FFState& other) const; - const Phrase &GetPhrase() const - { return m_outputPhrase; } + const Phrase &GetPhrase() const { + return m_outputPhrase; + } protected: - Phrase m_outputPhrase; - const ControlRecombination &m_ff; - const void *m_hypo; + Phrase m_outputPhrase; + const ControlRecombination &m_ff; + const void *m_hypo; }; ////////////////////////////////////////////////////////////////// @@ -43,51 +44,52 @@ protected: class ControlRecombination : public StatefulFeatureFunction { public: - ControlRecombination(const std::string &line) - :StatefulFeatureFunction("ControlRecombination", 0, line) - ,m_type(SameOutput) - - { - m_tuneable = false; - ReadParameters(); - } - - bool IsUseable(const FactorMask &mask) const - { return true; } - - void Evaluate(const Phrase &source - , const TargetPhrase &targetPhrase - , ScoreComponentCollection &scoreBreakdown - , ScoreComponentCollection &estimatedFutureScore) const - {} - void Evaluate(const InputType &input - , const InputPath &inputPath - , const TargetPhrase &targetPhrase - , ScoreComponentCollection &scoreBreakdown) const - {} - FFState* Evaluate( - const Hypothesis& cur_hypo, - const FFState* prev_state, - ScoreComponentCollection* accumulator) const; - - FFState* EvaluateChart( - const ChartHypothesis& /* cur_hypo */, - int /* featureID - used to index the state in the previous hypotheses */, - ScoreComponentCollection* accumulator) const; - - virtual const FFState* EmptyHypothesisState(const InputType &input) const - { - return new ControlRecombinationState(*this); - } - - std::vector<float> DefaultWeights() const; - - void SetParameter(const std::string& key, const std::string& value); - - ControlRecombinationType GetType() const - { return m_type; } + ControlRecombination(const std::string &line) + :StatefulFeatureFunction("ControlRecombination", 0, line) + ,m_type(SameOutput) + + { + m_tuneable = false; + ReadParameters(); + } + + bool IsUseable(const FactorMask &mask) const { + return true; + } + + void Evaluate(const Phrase &source + , const TargetPhrase &targetPhrase + , ScoreComponentCollection &scoreBreakdown + , ScoreComponentCollection &estimatedFutureScore) const + {} + void Evaluate(const InputType &input + , const InputPath &inputPath + , const TargetPhrase &targetPhrase + , ScoreComponentCollection &scoreBreakdown) const + {} + FFState* Evaluate( + const Hypothesis& cur_hypo, + const FFState* prev_state, + ScoreComponentCollection* accumulator) const; + + FFState* EvaluateChart( + const ChartHypothesis& /* cur_hypo */, + int /* featureID - used to index the state in the previous hypotheses */, + ScoreComponentCollection* accumulator) const; + + virtual const FFState* EmptyHypothesisState(const InputType &input) const { + return new ControlRecombinationState(*this); + } + + std::vector<float> DefaultWeights() const; + + void SetParameter(const std::string& key, const std::string& value); + + ControlRecombinationType GetType() const { + return m_type; + } protected: - ControlRecombinationType m_type; + ControlRecombinationType m_type; }; diff --git a/moses/FF/DecodeFeature.h b/moses/FF/DecodeFeature.h index 8b952d873..71fffecfa 100644 --- a/moses/FF/DecodeFeature.h +++ b/moses/FF/DecodeFeature.h @@ -64,20 +64,20 @@ public: void SetParameter(const std::string& key, const std::string& value); void Evaluate(const Hypothesis& hypo, - ScoreComponentCollection* accumulator) const + ScoreComponentCollection* accumulator) const {} void EvaluateChart(const ChartHypothesis &hypo, - ScoreComponentCollection* accumulator) const + ScoreComponentCollection* accumulator) const {} void Evaluate(const InputType &input - , const InputPath &inputPath - , const TargetPhrase &targetPhrase - , ScoreComponentCollection &scoreBreakdown) const + , const InputPath &inputPath + , const TargetPhrase &targetPhrase + , ScoreComponentCollection &scoreBreakdown) const {} void Evaluate(const Phrase &source - , const TargetPhrase &targetPhrase - , ScoreComponentCollection &scoreBreakdown - , ScoreComponentCollection &estimatedFutureScore) const + , const TargetPhrase &targetPhrase + , ScoreComponentCollection &scoreBreakdown + , ScoreComponentCollection &estimatedFutureScore) const {} protected: diff --git a/moses/FF/DistortionScoreProducer.h b/moses/FF/DistortionScoreProducer.h index 7ba729a7b..62512ab04 100644 --- a/moses/FF/DistortionScoreProducer.h +++ b/moses/FF/DistortionScoreProducer.h @@ -42,14 +42,14 @@ public: } void Evaluate(const InputType &input - , const InputPath &inputPath - , const TargetPhrase &targetPhrase - , ScoreComponentCollection &scoreBreakdown) const + , const InputPath &inputPath + , const TargetPhrase &targetPhrase + , ScoreComponentCollection &scoreBreakdown) const {} void Evaluate(const Phrase &source - , const TargetPhrase &targetPhrase - , ScoreComponentCollection &scoreBreakdown - , ScoreComponentCollection &estimatedFutureScore) const + , const TargetPhrase &targetPhrase + , ScoreComponentCollection &scoreBreakdown + , ScoreComponentCollection &estimatedFutureScore) const {} }; diff --git a/moses/FF/ExternalFeature.cpp b/moses/FF/ExternalFeature.cpp index 9e966bffe..2b32d01d6 100644 --- a/moses/FF/ExternalFeature.cpp +++ b/moses/FF/ExternalFeature.cpp @@ -7,9 +7,9 @@ namespace Moses { ExternalFeatureState::ExternalFeatureState(int stateSize, void *data) { - m_stateSize = stateSize; - m_data = malloc(stateSize); - memcpy(m_data, data, stateSize); + m_stateSize = stateSize; + m_data = malloc(stateSize); + memcpy(m_data, data, stateSize); } void ExternalFeature::Load() @@ -17,27 +17,28 @@ void ExternalFeature::Load() string nparam = "testing"; if (m_path.size() < 1) { - cerr << "External requires a path to a dynamic library!\n"; - abort(); + cerr << "External requires a path to a dynamic library!\n"; + abort(); } lib_handle = dlopen(m_path.c_str(), RTLD_LAZY); if (!lib_handle) { - cerr << "dlopen reports: " << dlerror() << endl; - cerr << "Did you provide a full path to the dynamic library?\n"; - abort(); + cerr << "dlopen reports: " << dlerror() << endl; + cerr << "Did you provide a full path to the dynamic library?\n"; + abort(); } CdecFF* (*fn)(const string&) = - (CdecFF* (*)(const string&))(dlsym(lib_handle, "create_ff")); + (CdecFF* (*)(const string&))(dlsym(lib_handle, "create_ff")); if (!fn) { - cerr << "dlsym reports: " << dlerror() << endl; - abort(); + cerr << "dlsym reports: " << dlerror() << endl; + abort(); } ff_ext = (*fn)(nparam); m_stateSize = ff_ext->StateSize(); } -ExternalFeature::~ExternalFeature() { +ExternalFeature::~ExternalFeature() +{ delete ff_ext; dlclose(lib_handle); } @@ -45,9 +46,8 @@ ExternalFeature::~ExternalFeature() { void ExternalFeature::SetParameter(const std::string& key, const std::string& value) { if (key == "path") { - m_path = value; - } - else { + m_path = value; + } else { StatefulFeatureFunction::SetParameter(key, value); } } @@ -57,7 +57,7 @@ FFState* ExternalFeature::Evaluate( const FFState* prev_state, ScoreComponentCollection* accumulator) const { - return new ExternalFeatureState(m_stateSize); + return new ExternalFeatureState(m_stateSize); } FFState* ExternalFeature::EvaluateChart( @@ -65,7 +65,7 @@ FFState* ExternalFeature::EvaluateChart( int /* featureID - used to index the state in the previous hypotheses */, ScoreComponentCollection* accumulator) const { - return new ExternalFeatureState(m_stateSize); + return new ExternalFeatureState(m_stateSize); } diff --git a/moses/FF/ExternalFeature.h b/moses/FF/ExternalFeature.h index dcb0949c0..04414f0a8 100644 --- a/moses/FF/ExternalFeature.h +++ b/moses/FF/ExternalFeature.h @@ -12,82 +12,79 @@ class CdecFF; class ExternalFeatureState : public FFState { protected: - int m_stateSize; - void *m_data; + int m_stateSize; + void *m_data; public: - ExternalFeatureState(int stateSize) - :m_stateSize(stateSize) - ,m_data(NULL) - {} - ExternalFeatureState(int stateSize, void *data); - - ~ExternalFeatureState() - { - free(m_data); - } - - int Compare(const FFState& other) const - { - const ExternalFeatureState &otherFF = static_cast<const ExternalFeatureState&>(other); - int ret = memcmp(m_data, otherFF.m_data, m_stateSize); - return ret; - } + ExternalFeatureState(int stateSize) + :m_stateSize(stateSize) + ,m_data(NULL) + {} + ExternalFeatureState(int stateSize, void *data); + + ~ExternalFeatureState() { + free(m_data); + } + + int Compare(const FFState& other) const { + const ExternalFeatureState &otherFF = static_cast<const ExternalFeatureState&>(other); + int ret = memcmp(m_data, otherFF.m_data, m_stateSize); + return ret; + } }; // copied from cdec class ExternalFeature : public StatefulFeatureFunction { public: - ExternalFeature(const std::string &line) - :StatefulFeatureFunction("ExternalFeature", line) - { - ReadParameters(); - } - ~ExternalFeature(); - - void Load(); - - bool IsUseable(const FactorMask &mask) const - { return true; } - - void SetParameter(const std::string& key, const std::string& value); - - void Evaluate(const Phrase &source - , const TargetPhrase &targetPhrase - , ScoreComponentCollection &scoreBreakdown - , ScoreComponentCollection &estimatedFutureScore) const - {} - void Evaluate(const InputType &input - , const InputPath &inputPath - , const TargetPhrase &targetPhrase - , ScoreComponentCollection &scoreBreakdown) const - {} - FFState* Evaluate( - const Hypothesis& cur_hypo, - const FFState* prev_state, - ScoreComponentCollection* accumulator) const; - - FFState* EvaluateChart( - const ChartHypothesis& /* cur_hypo */, - int /* featureID - used to index the state in the previous hypotheses */, - ScoreComponentCollection* accumulator) const; - - virtual const FFState* EmptyHypothesisState(const InputType &input) const - { - return new ExternalFeatureState(m_stateSize); - } + ExternalFeature(const std::string &line) + :StatefulFeatureFunction("ExternalFeature", line) { + ReadParameters(); + } + ~ExternalFeature(); + + void Load(); + + bool IsUseable(const FactorMask &mask) const { + return true; + } + + void SetParameter(const std::string& key, const std::string& value); + + void Evaluate(const Phrase &source + , const TargetPhrase &targetPhrase + , ScoreComponentCollection &scoreBreakdown + , ScoreComponentCollection &estimatedFutureScore) const + {} + void Evaluate(const InputType &input + , const InputPath &inputPath + , const TargetPhrase &targetPhrase + , ScoreComponentCollection &scoreBreakdown) const + {} + FFState* Evaluate( + const Hypothesis& cur_hypo, + const FFState* prev_state, + ScoreComponentCollection* accumulator) const; + + FFState* EvaluateChart( + const ChartHypothesis& /* cur_hypo */, + int /* featureID - used to index the state in the previous hypotheses */, + ScoreComponentCollection* accumulator) const; + + virtual const FFState* EmptyHypothesisState(const InputType &input) const { + return new ExternalFeatureState(m_stateSize); + } protected: - std::string m_path; - void* lib_handle; - CdecFF *ff_ext; - int m_stateSize; + std::string m_path; + void* lib_handle; + CdecFF *ff_ext; + int m_stateSize; }; class CdecFF { public: - virtual int StateSize() const = 0; + virtual int StateSize() const = 0; }; } diff --git a/moses/FF/FeatureFunction.cpp b/moses/FF/FeatureFunction.cpp index db959634b..14a7527cf 100644 --- a/moses/FF/FeatureFunction.cpp +++ b/moses/FF/FeatureFunction.cpp @@ -30,8 +30,8 @@ FeatureFunction &FeatureFunction::FindFeatureFunction(const std::string& name) } FeatureFunction:: -FeatureFunction(const std::string& description, - const std::string& line) +FeatureFunction(const std::string& description, + const std::string& line) : m_tuneable(true) , m_numScoreComponents(1) { @@ -39,16 +39,16 @@ FeatureFunction(const std::string& description, } FeatureFunction:: -FeatureFunction(const std::string& description, - size_t numScoreComponents, - const std::string& line) +FeatureFunction(const std::string& description, + size_t numScoreComponents, + const std::string& line) : m_tuneable(true) , m_numScoreComponents(numScoreComponents) { Initialize(description, line); } -void +void FeatureFunction:: Initialize(const std::string& description, const std::string &line) { diff --git a/moses/FF/GlobalLexicalModel.h b/moses/FF/GlobalLexicalModel.h index dc8e430e3..c87ec6200 100644 --- a/moses/FF/GlobalLexicalModel.h +++ b/moses/FF/GlobalLexicalModel.h @@ -81,14 +81,14 @@ public: } void Evaluate(const InputType &input - , const InputPath &inputPath - , const TargetPhrase &targetPhrase - , ScoreComponentCollection &scoreBreakdown) const + , const InputPath &inputPath + , const TargetPhrase &targetPhrase + , ScoreComponentCollection &scoreBreakdown) const {} void Evaluate(const Phrase &source - , const TargetPhrase &targetPhrase - , ScoreComponentCollection &scoreBreakdown - , ScoreComponentCollection &estimatedFutureScore) const + , const TargetPhrase &targetPhrase + , ScoreComponentCollection &scoreBreakdown + , ScoreComponentCollection &estimatedFutureScore) const {} diff --git a/moses/FF/GlobalLexicalModelUnlimited.cpp b/moses/FF/GlobalLexicalModelUnlimited.cpp index 455c79cae..f1f4b693b 100644 --- a/moses/FF/GlobalLexicalModelUnlimited.cpp +++ b/moses/FF/GlobalLexicalModelUnlimited.cpp @@ -134,7 +134,7 @@ void GlobalLexicalModelUnlimited::Evaluate(const Hypothesis& cur_hypo, ScoreComp boost::unordered_set<uint64_t> alreadyScored; for(size_t sourceIndex = 0; sourceIndex < input.GetSize(); sourceIndex++ ) { - const StringPiece sourceString = input.GetWord(sourceIndex).GetString(0); + const StringPiece sourceString = input.GetWord(sourceIndex).GetString(0); // TODO: change for other factors if (m_ignorePunctuation) { diff --git a/moses/FF/GlobalLexicalModelUnlimited.h b/moses/FF/GlobalLexicalModelUnlimited.h index 66fb9057a..83a5bbbbd 100644 --- a/moses/FF/GlobalLexicalModelUnlimited.h +++ b/moses/FF/GlobalLexicalModelUnlimited.h @@ -91,14 +91,14 @@ public: } void Evaluate(const InputType &input - , const InputPath &inputPath - , const TargetPhrase &targetPhrase - , ScoreComponentCollection &scoreBreakdown) const + , const InputPath &inputPath + , const TargetPhrase &targetPhrase + , ScoreComponentCollection &scoreBreakdown) const {} void Evaluate(const Phrase &source - , const TargetPhrase &targetPhrase - , ScoreComponentCollection &scoreBreakdown - , ScoreComponentCollection &estimatedFutureScore) const + , const TargetPhrase &targetPhrase + , ScoreComponentCollection &scoreBreakdown + , ScoreComponentCollection &estimatedFutureScore) const {} void AddFeature(ScoreComponentCollection* accumulator, diff --git a/moses/FF/InputFeature.cpp b/moses/FF/InputFeature.cpp index eabf70f61..14efa12f0 100644 --- a/moses/FF/InputFeature.cpp +++ b/moses/FF/InputFeature.cpp @@ -19,11 +19,11 @@ InputFeature::InputFeature(const std::string &line) void InputFeature::Load() { - const StaticData &staticData = StaticData::Instance(); - const PhraseDictionary *pt = staticData.GetTranslationScoreProducer(0); - const PhraseDictionaryTreeAdaptor *ptBin = dynamic_cast<const PhraseDictionaryTreeAdaptor*>(pt); + const StaticData &staticData = StaticData::Instance(); + const PhraseDictionary *pt = staticData.GetTranslationScoreProducer(0); + const PhraseDictionaryTreeAdaptor *ptBin = dynamic_cast<const PhraseDictionaryTreeAdaptor*>(pt); - m_legacy = (ptBin != NULL); + m_legacy = (ptBin != NULL); } void InputFeature::SetParameter(const std::string& key, const std::string& value) @@ -43,16 +43,16 @@ void InputFeature::Evaluate(const InputType &input , const TargetPhrase &targetPhrase , ScoreComponentCollection &scoreBreakdown) const { - if (m_legacy) { - //binary phrase-table does input feature itself - return; - } - /* + if (m_legacy) { + //binary phrase-table does input feature itself + return; + } + /* const ScorePair *scores = inputPath.GetInputScore(); if (scores) { scoreBreakdown.PlusEquals(this, *scores); } - */ + */ } } // namespace diff --git a/moses/FF/InputFeature.h b/moses/FF/InputFeature.h index abfbd602a..612fdcdc0 100644 --- a/moses/FF/InputFeature.h +++ b/moses/FF/InputFeature.h @@ -33,20 +33,20 @@ public: } void Evaluate(const Phrase &source - , const TargetPhrase &targetPhrase - , ScoreComponentCollection &scoreBreakdown - , ScoreComponentCollection &estimatedFutureScore) const + , const TargetPhrase &targetPhrase + , ScoreComponentCollection &scoreBreakdown + , ScoreComponentCollection &estimatedFutureScore) const {} void Evaluate(const InputType &input - , const InputPath &inputPath - , const TargetPhrase &targetPhrase - , ScoreComponentCollection &scoreBreakdown) const; + , const InputPath &inputPath + , const TargetPhrase &targetPhrase + , ScoreComponentCollection &scoreBreakdown) const; void Evaluate(const Hypothesis& hypo, - ScoreComponentCollection* accumulator) const + ScoreComponentCollection* accumulator) const {} void EvaluateChart(const ChartHypothesis &hypo, - ScoreComponentCollection* accumulator) const + ScoreComponentCollection* accumulator) const {} diff --git a/moses/FF/LexicalReordering/LexicalReordering.h b/moses/FF/LexicalReordering/LexicalReordering.h index 358f70d28..72be04f45 100644 --- a/moses/FF/LexicalReordering/LexicalReordering.h +++ b/moses/FF/LexicalReordering/LexicalReordering.h @@ -52,14 +52,14 @@ public: UTIL_THROW(util::Exception, "LexicalReordering is not valid for chart decoder"); } void Evaluate(const InputType &input - , const InputPath &inputPath - , const TargetPhrase &targetPhrase - , ScoreComponentCollection &scoreBreakdown) const + , const InputPath &inputPath + , const TargetPhrase &targetPhrase + , ScoreComponentCollection &scoreBreakdown) const {} void Evaluate(const Phrase &source - , const TargetPhrase &targetPhrase - , ScoreComponentCollection &scoreBreakdown - , ScoreComponentCollection &estimatedFutureScore) const + , const TargetPhrase &targetPhrase + , ScoreComponentCollection &scoreBreakdown + , ScoreComponentCollection &estimatedFutureScore) const {} private: diff --git a/moses/FF/OSM-Feature/OpSequenceModel.cpp b/moses/FF/OSM-Feature/OpSequenceModel.cpp index 912d8cf08..e35e31a33 100644 --- a/moses/FF/OSM-Feature/OpSequenceModel.cpp +++ b/moses/FF/OSM-Feature/OpSequenceModel.cpp @@ -237,9 +237,9 @@ void OpSequenceModel::SetParameter(const std::string& key, const std::string& va m_lmPath = value; } else if (key == "support-features") { if(value == "no") - numFeatures = 1; + numFeatures = 1; else - numFeatures = 5; + numFeatures = 5; } else if (key == "input-factor") { sFactor = Scan<int>(value); } else if (key == "output-factor") { diff --git a/moses/FF/OSM-Feature/OpSequenceModel.h b/moses/FF/OSM-Feature/OpSequenceModel.h index 092019b7d..565724c2a 100644 --- a/moses/FF/OSM-Feature/OpSequenceModel.h +++ b/moses/FF/OSM-Feature/OpSequenceModel.h @@ -39,9 +39,9 @@ public: ScoreComponentCollection* accumulator) const; void Evaluate(const InputType &input - , const InputPath &inputPath - , const TargetPhrase &targetPhrase - , ScoreComponentCollection &scoreBreakdown) const + , const InputPath &inputPath + , const TargetPhrase &targetPhrase + , ScoreComponentCollection &scoreBreakdown) const {} void Evaluate(const Phrase &source , const TargetPhrase &targetPhrase diff --git a/moses/FF/PhraseBoundaryFeature.h b/moses/FF/PhraseBoundaryFeature.h index 2e2669894..88c0ed45b 100644 --- a/moses/FF/PhraseBoundaryFeature.h +++ b/moses/FF/PhraseBoundaryFeature.h @@ -54,14 +54,14 @@ public: } void Evaluate(const InputType &input - , const InputPath &inputPath - , const TargetPhrase &targetPhrase - , ScoreComponentCollection &scoreBreakdown) const + , const InputPath &inputPath + , const TargetPhrase &targetPhrase + , ScoreComponentCollection &scoreBreakdown) const {} void Evaluate(const Phrase &source - , const TargetPhrase &targetPhrase - , ScoreComponentCollection &scoreBreakdown - , ScoreComponentCollection &estimatedFutureScore) const + , const TargetPhrase &targetPhrase + , ScoreComponentCollection &scoreBreakdown + , ScoreComponentCollection &estimatedFutureScore) const {} void SetParameter(const std::string& key, const std::string& value); diff --git a/moses/FF/PhraseLengthFeature.h b/moses/FF/PhraseLengthFeature.h index 9eb3595f9..2d5d53e25 100644 --- a/moses/FF/PhraseLengthFeature.h +++ b/moses/FF/PhraseLengthFeature.h @@ -25,7 +25,7 @@ public: } void Evaluate(const Hypothesis& hypo, - ScoreComponentCollection* accumulator) const + ScoreComponentCollection* accumulator) const {} void EvaluateChart(const ChartHypothesis& hypo, @@ -34,9 +34,9 @@ public: } void Evaluate(const InputType &input - , const InputPath &inputPath - , const TargetPhrase &targetPhrase - , ScoreComponentCollection &scoreBreakdown) const + , const InputPath &inputPath + , const TargetPhrase &targetPhrase + , ScoreComponentCollection &scoreBreakdown) const {} virtual void Evaluate(const Phrase &source diff --git a/moses/FF/PhrasePairFeature.h b/moses/FF/PhrasePairFeature.h index 0d770ea95..b998881e6 100644 --- a/moses/FF/PhrasePairFeature.h +++ b/moses/FF/PhrasePairFeature.h @@ -46,14 +46,14 @@ public: } void Evaluate(const InputType &input - , const InputPath &inputPath - , const TargetPhrase &targetPhrase - , ScoreComponentCollection &scoreBreakdown) const + , const InputPath &inputPath + , const TargetPhrase &targetPhrase + , ScoreComponentCollection &scoreBreakdown) const {} void Evaluate(const Phrase &source - , const TargetPhrase &targetPhrase - , ScoreComponentCollection &scoreBreakdown - , ScoreComponentCollection &estimatedFutureScore) const + , const TargetPhrase &targetPhrase + , ScoreComponentCollection &scoreBreakdown + , ScoreComponentCollection &estimatedFutureScore) const {} void Load(); diff --git a/moses/FF/PhrasePenalty.h b/moses/FF/PhrasePenalty.h index ed2154b0d..476f9fc0d 100644 --- a/moses/FF/PhrasePenalty.h +++ b/moses/FF/PhrasePenalty.h @@ -20,16 +20,16 @@ public: , ScoreComponentCollection &estimatedFutureScore) const; void Evaluate(const Hypothesis& hypo, - ScoreComponentCollection* accumulator) const + ScoreComponentCollection* accumulator) const {} void EvaluateChart(const ChartHypothesis &hypo, - ScoreComponentCollection* accumulator) const + ScoreComponentCollection* accumulator) const {} void Evaluate(const InputType &input - , const InputPath &inputPath - , const TargetPhrase &targetPhrase - , ScoreComponentCollection &scoreBreakdown) const + , const InputPath &inputPath + , const TargetPhrase &targetPhrase + , ScoreComponentCollection &scoreBreakdown) const {} }; diff --git a/moses/FF/SkeletonStatefulFF.cpp b/moses/FF/SkeletonStatefulFF.cpp index 50d27c31e..a01e7f6d9 100644 --- a/moses/FF/SkeletonStatefulFF.cpp +++ b/moses/FF/SkeletonStatefulFF.cpp @@ -9,51 +9,51 @@ namespace Moses { int SkeletonState::Compare(const FFState& other) const { - const SkeletonState &otherState = static_cast<const SkeletonState&>(other); + const SkeletonState &otherState = static_cast<const SkeletonState&>(other); - if (m_targetLen == otherState.m_targetLen) - return 0; - return (m_targetLen < otherState.m_targetLen) ? -1 : +1; + if (m_targetLen == otherState.m_targetLen) + return 0; + return (m_targetLen < otherState.m_targetLen) ? -1 : +1; } void SkeletonStatefulFF::Evaluate(const Phrase &source - , const TargetPhrase &targetPhrase - , ScoreComponentCollection &scoreBreakdown - , ScoreComponentCollection &estimatedFutureScore) const + , const TargetPhrase &targetPhrase + , ScoreComponentCollection &scoreBreakdown + , ScoreComponentCollection &estimatedFutureScore) const {} void SkeletonStatefulFF::Evaluate(const InputType &input - , const InputPath &inputPath - , const TargetPhrase &targetPhrase - , ScoreComponentCollection &scoreBreakdown) const + , const InputPath &inputPath + , const TargetPhrase &targetPhrase + , ScoreComponentCollection &scoreBreakdown) const {} FFState* SkeletonStatefulFF::Evaluate( - const Hypothesis& cur_hypo, - const FFState* prev_state, - ScoreComponentCollection* accumulator) const + const Hypothesis& cur_hypo, + const FFState* prev_state, + ScoreComponentCollection* accumulator) const { - // dense scores - vector<float> newScores(m_numScoreComponents); - newScores[0] = 1.5; - newScores[1] = 0.3; - newScores[2] = 0.4; - accumulator->PlusEquals(this, newScores); - - // sparse scores - accumulator->PlusEquals(this, "sparse-name", 2.4); - - int targetLen = cur_hypo.GetCurrTargetPhrase().GetSize(); - return new SkeletonState(0); + // dense scores + vector<float> newScores(m_numScoreComponents); + newScores[0] = 1.5; + newScores[1] = 0.3; + newScores[2] = 0.4; + accumulator->PlusEquals(this, newScores); + + // sparse scores + accumulator->PlusEquals(this, "sparse-name", 2.4); + + int targetLen = cur_hypo.GetCurrTargetPhrase().GetSize(); + return new SkeletonState(0); } - FFState* SkeletonStatefulFF::EvaluateChart( - const ChartHypothesis& /* cur_hypo */, - int /* featureID - used to index the state in the previous hypotheses */, - ScoreComponentCollection* accumulator) const - { - return new SkeletonState(0); - } +FFState* SkeletonStatefulFF::EvaluateChart( + const ChartHypothesis& /* cur_hypo */, + int /* featureID - used to index the state in the previous hypotheses */, + ScoreComponentCollection* accumulator) const +{ + return new SkeletonState(0); +} } diff --git a/moses/FF/SkeletonStatefulFF.h b/moses/FF/SkeletonStatefulFF.h index 374fdc712..c3bb10e37 100644 --- a/moses/FF/SkeletonStatefulFF.h +++ b/moses/FF/SkeletonStatefulFF.h @@ -9,45 +9,45 @@ namespace Moses class SkeletonState : public FFState { - int m_targetLen; + int m_targetLen; public: - SkeletonState(int targetLen) - :m_targetLen(targetLen) - {} + SkeletonState(int targetLen) + :m_targetLen(targetLen) + {} - int Compare(const FFState& other) const; + int Compare(const FFState& other) const; }; class SkeletonStatefulFF : public StatefulFeatureFunction { public: - SkeletonStatefulFF(const std::string &line) - :StatefulFeatureFunction("SkeletonStatefulFF", 3, line) - {} - - bool IsUseable(const FactorMask &mask) const - { return true; } - virtual const FFState* EmptyHypothesisState(const InputType &input) const - { - return new SkeletonState(0); + SkeletonStatefulFF(const std::string &line) + :StatefulFeatureFunction("SkeletonStatefulFF", 3, line) + {} + + bool IsUseable(const FactorMask &mask) const { + return true; + } + virtual const FFState* EmptyHypothesisState(const InputType &input) const { + return new SkeletonState(0); } - void Evaluate(const Phrase &source - , const TargetPhrase &targetPhrase - , ScoreComponentCollection &scoreBreakdown - , ScoreComponentCollection &estimatedFutureScore) const; - void Evaluate(const InputType &input - , const InputPath &inputPath - , const TargetPhrase &targetPhrase - , ScoreComponentCollection &scoreBreakdown) const; - FFState* Evaluate( - const Hypothesis& cur_hypo, - const FFState* prev_state, - ScoreComponentCollection* accumulator) const; - FFState* EvaluateChart( - const ChartHypothesis& /* cur_hypo */, - int /* featureID - used to index the state in the previous hypotheses */, - ScoreComponentCollection* accumulator) const; + void Evaluate(const Phrase &source + , const TargetPhrase &targetPhrase + , ScoreComponentCollection &scoreBreakdown + , ScoreComponentCollection &estimatedFutureScore) const; + void Evaluate(const InputType &input + , const InputPath &inputPath + , const TargetPhrase &targetPhrase + , ScoreComponentCollection &scoreBreakdown) const; + FFState* Evaluate( + const Hypothesis& cur_hypo, + const FFState* prev_state, + ScoreComponentCollection* accumulator) const; + FFState* EvaluateChart( + const ChartHypothesis& /* cur_hypo */, + int /* featureID - used to index the state in the previous hypotheses */, + ScoreComponentCollection* accumulator) const; }; diff --git a/moses/FF/SkeletonStatelessFF.cpp b/moses/FF/SkeletonStatelessFF.cpp index 4e9562978..f372b46c2 100644 --- a/moses/FF/SkeletonStatelessFF.cpp +++ b/moses/FF/SkeletonStatelessFF.cpp @@ -7,33 +7,33 @@ using namespace std; namespace Moses { void SkeletonStatelessFF::Evaluate(const Phrase &source - , const TargetPhrase &targetPhrase - , ScoreComponentCollection &scoreBreakdown - , ScoreComponentCollection &estimatedFutureScore) const + , const TargetPhrase &targetPhrase + , ScoreComponentCollection &scoreBreakdown + , ScoreComponentCollection &estimatedFutureScore) const { - // dense scores - vector<float> newScores(m_numScoreComponents); - newScores[0] = 1.5; - newScores[1] = 0.3; - scoreBreakdown.PlusEquals(this, newScores); + // dense scores + vector<float> newScores(m_numScoreComponents); + newScores[0] = 1.5; + newScores[1] = 0.3; + scoreBreakdown.PlusEquals(this, newScores); - // sparse scores - scoreBreakdown.PlusEquals(this, "sparse-name", 2.4); + // sparse scores + scoreBreakdown.PlusEquals(this, "sparse-name", 2.4); } void SkeletonStatelessFF::Evaluate(const InputType &input - , const InputPath &inputPath - , const TargetPhrase &targetPhrase - , ScoreComponentCollection &scoreBreakdown) const + , const InputPath &inputPath + , const TargetPhrase &targetPhrase + , ScoreComponentCollection &scoreBreakdown) const {} void SkeletonStatelessFF::Evaluate(const Hypothesis& hypo, - ScoreComponentCollection* accumulator) const + ScoreComponentCollection* accumulator) const {} void SkeletonStatelessFF::EvaluateChart(const ChartHypothesis &hypo, - ScoreComponentCollection* accumulator) const + ScoreComponentCollection* accumulator) const {} } diff --git a/moses/FF/SkeletonStatelessFF.h b/moses/FF/SkeletonStatelessFF.h index a09e078ed..f3c494a94 100644 --- a/moses/FF/SkeletonStatelessFF.h +++ b/moses/FF/SkeletonStatelessFF.h @@ -9,25 +9,26 @@ namespace Moses class SkeletonStatelessFF : public StatelessFeatureFunction { public: - SkeletonStatelessFF(const std::string &line) - :StatelessFeatureFunction("SkeletonStatelessFF", 2, line) - {} - - bool IsUseable(const FactorMask &mask) const - { return true; } - - void Evaluate(const Phrase &source - , const TargetPhrase &targetPhrase - , ScoreComponentCollection &scoreBreakdown - , ScoreComponentCollection &estimatedFutureScore) const; - void Evaluate(const InputType &input - , const InputPath &inputPath - , const TargetPhrase &targetPhrase - , ScoreComponentCollection &scoreBreakdown) const; - void Evaluate(const Hypothesis& hypo, - ScoreComponentCollection* accumulator) const; - void EvaluateChart(const ChartHypothesis &hypo, - ScoreComponentCollection* accumulator) const; + SkeletonStatelessFF(const std::string &line) + :StatelessFeatureFunction("SkeletonStatelessFF", 2, line) + {} + + bool IsUseable(const FactorMask &mask) const { + return true; + } + + void Evaluate(const Phrase &source + , const TargetPhrase &targetPhrase + , ScoreComponentCollection &scoreBreakdown + , ScoreComponentCollection &estimatedFutureScore) const; + void Evaluate(const InputType &input + , const InputPath &inputPath + , const TargetPhrase &targetPhrase + , ScoreComponentCollection &scoreBreakdown) const; + void Evaluate(const Hypothesis& hypo, + ScoreComponentCollection* accumulator) const; + void EvaluateChart(const ChartHypothesis &hypo, + ScoreComponentCollection* accumulator) const; }; diff --git a/moses/FF/SourceWordDeletionFeature.h b/moses/FF/SourceWordDeletionFeature.h index 79466e8c2..1e47b78c7 100644 --- a/moses/FF/SourceWordDeletionFeature.h +++ b/moses/FF/SourceWordDeletionFeature.h @@ -29,19 +29,19 @@ public: bool IsUseable(const FactorMask &mask) const; void Evaluate(const Phrase &source - , const TargetPhrase &targetPhrase - , ScoreComponentCollection &scoreBreakdown - , ScoreComponentCollection &estimatedFutureScore) const; + , const TargetPhrase &targetPhrase + , ScoreComponentCollection &scoreBreakdown + , ScoreComponentCollection &estimatedFutureScore) const; void Evaluate(const InputType &input - , const InputPath &inputPath - , const TargetPhrase &targetPhrase - , ScoreComponentCollection &scoreBreakdown) const + , const InputPath &inputPath + , const TargetPhrase &targetPhrase + , ScoreComponentCollection &scoreBreakdown) const {} void Evaluate(const Hypothesis& hypo, - ScoreComponentCollection* accumulator) const + ScoreComponentCollection* accumulator) const {} void EvaluateChart(const ChartHypothesis &hypo, - ScoreComponentCollection* accumulator) const + ScoreComponentCollection* accumulator) const {} void ComputeFeatures(const Phrase &source, diff --git a/moses/FF/TargetBigramFeature.h b/moses/FF/TargetBigramFeature.h index 217b61753..5e22506c8 100644 --- a/moses/FF/TargetBigramFeature.h +++ b/moses/FF/TargetBigramFeature.h @@ -48,14 +48,14 @@ public: throw std::logic_error("TargetBigramFeature not valid in chart decoder"); } void Evaluate(const InputType &input - , const InputPath &inputPath - , const TargetPhrase &targetPhrase - , ScoreComponentCollection &scoreBreakdown) const + , const InputPath &inputPath + , const TargetPhrase &targetPhrase + , ScoreComponentCollection &scoreBreakdown) const {} void Evaluate(const Phrase &source - , const TargetPhrase &targetPhrase - , ScoreComponentCollection &scoreBreakdown - , ScoreComponentCollection &estimatedFutureScore) const + , const TargetPhrase &targetPhrase + , ScoreComponentCollection &scoreBreakdown + , ScoreComponentCollection &estimatedFutureScore) const {} void SetParameter(const std::string& key, const std::string& value); diff --git a/moses/FF/TargetNgramFeature.h b/moses/FF/TargetNgramFeature.h index e5578f486..122bfc2d9 100644 --- a/moses/FF/TargetNgramFeature.h +++ b/moses/FF/TargetNgramFeature.h @@ -193,14 +193,14 @@ public: ScoreComponentCollection* accumulator) const; void Evaluate(const InputType &input - , const InputPath &inputPath - , const TargetPhrase &targetPhrase - , ScoreComponentCollection &scoreBreakdown) const + , const InputPath &inputPath + , const TargetPhrase &targetPhrase + , ScoreComponentCollection &scoreBreakdown) const {} void Evaluate(const Phrase &source - , const TargetPhrase &targetPhrase - , ScoreComponentCollection &scoreBreakdown - , ScoreComponentCollection &estimatedFutureScore) const + , const TargetPhrase &targetPhrase + , ScoreComponentCollection &scoreBreakdown + , ScoreComponentCollection &estimatedFutureScore) const {} void SetParameter(const std::string& key, const std::string& value); diff --git a/moses/FF/TargetWordInsertionFeature.h b/moses/FF/TargetWordInsertionFeature.h index 0bcda0031..f3daa68a8 100644 --- a/moses/FF/TargetWordInsertionFeature.h +++ b/moses/FF/TargetWordInsertionFeature.h @@ -33,15 +33,15 @@ public: , ScoreComponentCollection &scoreBreakdown , ScoreComponentCollection &estimatedFutureScore) const; void Evaluate(const InputType &input - , const InputPath &inputPath - , const TargetPhrase &targetPhrase - , ScoreComponentCollection &scoreBreakdown) const + , const InputPath &inputPath + , const TargetPhrase &targetPhrase + , ScoreComponentCollection &scoreBreakdown) const {} void Evaluate(const Hypothesis& hypo, - ScoreComponentCollection* accumulator) const + ScoreComponentCollection* accumulator) const {} void EvaluateChart(const ChartHypothesis &hypo, - ScoreComponentCollection* accumulator) const + ScoreComponentCollection* accumulator) const {} void ComputeFeatures(const Phrase &source, diff --git a/moses/FF/UnknownWordPenaltyProducer.h b/moses/FF/UnknownWordPenaltyProducer.h index 0140804b9..3c11deee3 100644 --- a/moses/FF/UnknownWordPenaltyProducer.h +++ b/moses/FF/UnknownWordPenaltyProducer.h @@ -23,20 +23,20 @@ public: std::vector<float> DefaultWeights() const; void Evaluate(const Hypothesis& hypo, - ScoreComponentCollection* accumulator) const + ScoreComponentCollection* accumulator) const {} void EvaluateChart(const ChartHypothesis &hypo, - ScoreComponentCollection* accumulator) const + ScoreComponentCollection* accumulator) const {} void Evaluate(const InputType &input - , const InputPath &inputPath - , const TargetPhrase &targetPhrase - , ScoreComponentCollection &scoreBreakdown) const + , const InputPath &inputPath + , const TargetPhrase &targetPhrase + , ScoreComponentCollection &scoreBreakdown) const {} void Evaluate(const Phrase &source - , const TargetPhrase &targetPhrase - , ScoreComponentCollection &scoreBreakdown - , ScoreComponentCollection &estimatedFutureScore) const + , const TargetPhrase &targetPhrase + , ScoreComponentCollection &scoreBreakdown + , ScoreComponentCollection &estimatedFutureScore) const {} }; diff --git a/moses/FF/WordPenaltyProducer.h b/moses/FF/WordPenaltyProducer.h index 3cd0bce8d..f6e3d2aa2 100644 --- a/moses/FF/WordPenaltyProducer.h +++ b/moses/FF/WordPenaltyProducer.h @@ -23,15 +23,15 @@ public: , ScoreComponentCollection &scoreBreakdown , ScoreComponentCollection &estimatedFutureScore) const; void Evaluate(const Hypothesis& hypo, - ScoreComponentCollection* accumulator) const + ScoreComponentCollection* accumulator) const {} void EvaluateChart(const ChartHypothesis &hypo, - ScoreComponentCollection* accumulator) const + ScoreComponentCollection* accumulator) const {} void Evaluate(const InputType &input - , const InputPath &inputPath - , const TargetPhrase &targetPhrase - , ScoreComponentCollection &scoreBreakdown) const + , const InputPath &inputPath + , const TargetPhrase &targetPhrase + , ScoreComponentCollection &scoreBreakdown) const {} }; diff --git a/moses/FF/WordTranslationFeature.h b/moses/FF/WordTranslationFeature.h index addcfe7f5..014033d9a 100644 --- a/moses/FF/WordTranslationFeature.h +++ b/moses/FF/WordTranslationFeature.h @@ -54,14 +54,14 @@ public: void EvaluateChart(const ChartHypothesis &hypo, ScoreComponentCollection* accumulator) const; void Evaluate(const InputType &input - , const InputPath &inputPath - , const TargetPhrase &targetPhrase - , ScoreComponentCollection &scoreBreakdown) const + , const InputPath &inputPath + , const TargetPhrase &targetPhrase + , ScoreComponentCollection &scoreBreakdown) const {} void Evaluate(const Phrase &source - , const TargetPhrase &targetPhrase - , ScoreComponentCollection &scoreBreakdown - , ScoreComponentCollection &estimatedFutureScore) const + , const TargetPhrase &targetPhrase + , ScoreComponentCollection &scoreBreakdown + , ScoreComponentCollection &estimatedFutureScore) const {} }; diff --git a/moses/Hypothesis.cpp b/moses/Hypothesis.cpp index 6335a285b..52b1d040a 100644 --- a/moses/Hypothesis.cpp +++ b/moses/Hypothesis.cpp @@ -159,10 +159,10 @@ Hypothesis* Hypothesis::Create(const Hypothesis &prevHypo, const TranslationOpti { #ifdef USE_HYPO_POOL - Hypothesis *ptr = s_objectPool.getPtr(); - return new(ptr) Hypothesis(prevHypo, transOpt); + Hypothesis *ptr = s_objectPool.getPtr(); + return new(ptr) Hypothesis(prevHypo, transOpt); #else - return new Hypothesis(prevHypo, transOpt); + return new Hypothesis(prevHypo, transOpt); #endif } /*** diff --git a/moses/HypothesisStackCubePruning.cpp b/moses/HypothesisStackCubePruning.cpp index 7de62b0c1..8929c974e 100644 --- a/moses/HypothesisStackCubePruning.cpp +++ b/moses/HypothesisStackCubePruning.cpp @@ -82,10 +82,10 @@ pair<HypothesisStackCubePruning::iterator, bool> HypothesisStackCubePruning::Add bool HypothesisStackCubePruning::AddPrune(Hypothesis *hypo) { if (hypo->GetTotalScore() == - std::numeric_limits<float>::infinity()) { - m_manager.GetSentenceStats().AddDiscarded(); - VERBOSE(3,"discarded, constraint" << std::endl); - FREEHYPO(hypo); - return false; + m_manager.GetSentenceStats().AddDiscarded(); + VERBOSE(3,"discarded, constraint" << std::endl); + FREEHYPO(hypo); + return false; } if (hypo->GetTotalScore() < m_worstScore) { diff --git a/moses/HypothesisStackNormal.cpp b/moses/HypothesisStackNormal.cpp index ae632a8de..559035e18 100644 --- a/moses/HypothesisStackNormal.cpp +++ b/moses/HypothesisStackNormal.cpp @@ -89,10 +89,10 @@ pair<HypothesisStackNormal::iterator, bool> HypothesisStackNormal::Add(Hypothesi bool HypothesisStackNormal::AddPrune(Hypothesis *hypo) { if (hypo->GetTotalScore() == - std::numeric_limits<float>::infinity()) { - m_manager.GetSentenceStats().AddDiscarded(); - VERBOSE(3,"discarded, constraint" << std::endl); - FREEHYPO(hypo); - return false; + m_manager.GetSentenceStats().AddDiscarded(); + VERBOSE(3,"discarded, constraint" << std::endl); + FREEHYPO(hypo); + return false; } // too bad for stack. don't bother adding hypo into collection diff --git a/moses/InputPath.cpp b/moses/InputPath.cpp index 651d7b424..d6e78e7ae 100644 --- a/moses/InputPath.cpp +++ b/moses/InputPath.cpp @@ -10,10 +10,10 @@ using namespace std; namespace Moses { - InputPath:: - InputPath(const Phrase &phrase, const NonTerminalSet &sourceNonTerms, - const WordsRange &range, const InputPath *prevNode, - const ScorePair *inputScore) +InputPath:: +InputPath(const Phrase &phrase, const NonTerminalSet &sourceNonTerms, + const WordsRange &range, const InputPath *prevNode, + const ScorePair *inputScore) :m_prevNode(prevNode) ,m_phrase(phrase) ,m_range(range) diff --git a/moses/InputPath.h b/moses/InputPath.h index d7993e08c..f05f1ffcb 100644 --- a/moses/InputPath.h +++ b/moses/InputPath.h @@ -81,10 +81,9 @@ public: return m_inputScore; } - std::vector<const Word*> &AddRuleSourceFromInputPath() const - { - m_ruleSourceFromInputPath.push_back(std::vector<const Word*>()); - return m_ruleSourceFromInputPath.back(); + std::vector<const Word*> &AddRuleSourceFromInputPath() const { + m_ruleSourceFromInputPath.push_back(std::vector<const Word*>()); + return m_ruleSourceFromInputPath.back(); } }; diff --git a/moses/LM/Base.h b/moses/LM/Base.h index 4e7507265..186cfe101 100644 --- a/moses/LM/Base.h +++ b/moses/LM/Base.h @@ -91,9 +91,9 @@ public: , ScoreComponentCollection &scoreBreakdown , ScoreComponentCollection &estimatedFutureScore) const; void Evaluate(const InputType &input - , const InputPath &inputPath - , const TargetPhrase &targetPhrase - , ScoreComponentCollection &scoreBreakdown) const + , const InputPath &inputPath + , const TargetPhrase &targetPhrase + , ScoreComponentCollection &scoreBreakdown) const {} }; diff --git a/moses/LM/Ken.cpp b/moses/LM/Ken.cpp index eb597242a..c49b9d2f7 100644 --- a/moses/LM/Ken.cpp +++ b/moses/LM/Ken.cpp @@ -138,7 +138,7 @@ private: }; } // namespace - + template <class Model> LanguageModelKen<Model>::LanguageModelKen(const std::string &line, const std::string &file, FactorType factorType, bool lazy) :LanguageModel("KENLM", line) ,m_factorType(factorType) @@ -351,10 +351,11 @@ template <class Model> FFState *LanguageModelKen<Model>::EvaluateChart(const Cha return newState; } -template <class Model> void LanguageModelKen<Model>::IncrementalCallback(Incremental::Manager &manager) const { +template <class Model> void LanguageModelKen<Model>::IncrementalCallback(Incremental::Manager &manager) const +{ manager.LMCallback(*m_ngram, m_lmIdLookup); } - + template <class Model> bool LanguageModelKen<Model>::IsUseable(const FactorMask &mask) const { diff --git a/moses/LM/Ken.h b/moses/LM/Ken.h index 2c03a7851..1c83df6ef 100644 --- a/moses/LM/Ken.h +++ b/moses/LM/Ken.h @@ -36,7 +36,7 @@ namespace Moses { //class LanguageModel; - class FFState; +class FFState; LanguageModel *ConstructKenLM(const std::string &line); @@ -49,37 +49,37 @@ LanguageModel *ConstructKenLM(const std::string &line, const std::string &file, template <class Model> class LanguageModelKen : public LanguageModel { public: - LanguageModelKen(const std::string &line, const std::string &file, FactorType factorType, bool lazy); - - virtual const FFState *EmptyHypothesisState(const InputType &/*input*/) const; - - virtual void CalcScore(const Phrase &phrase, float &fullScore, float &ngramScore, size_t &oovCount) const; - - virtual FFState *Evaluate(const Hypothesis &hypo, const FFState *ps, ScoreComponentCollection *out) const; - - virtual FFState *EvaluateChart(const ChartHypothesis& cur_hypo, int featureID, ScoreComponentCollection *accumulator) const; - - virtual void IncrementalCallback(Incremental::Manager &manager) const; - - virtual bool IsUseable(const FactorMask &mask) const; - + LanguageModelKen(const std::string &line, const std::string &file, FactorType factorType, bool lazy); + + virtual const FFState *EmptyHypothesisState(const InputType &/*input*/) const; + + virtual void CalcScore(const Phrase &phrase, float &fullScore, float &ngramScore, size_t &oovCount) const; + + virtual FFState *Evaluate(const Hypothesis &hypo, const FFState *ps, ScoreComponentCollection *out) const; + + virtual FFState *EvaluateChart(const ChartHypothesis& cur_hypo, int featureID, ScoreComponentCollection *accumulator) const; + + virtual void IncrementalCallback(Incremental::Manager &manager) const; + + virtual bool IsUseable(const FactorMask &mask) const; + protected: - boost::shared_ptr<Model> m_ngram; - - const Factor *m_beginSentenceFactor; - - FactorType m_factorType; - - lm::WordIndex TranslateID(const Word &word) const { - std::size_t factor = word.GetFactor(m_factorType)->GetId(); - return (factor >= m_lmIdLookup.size() ? 0 : m_lmIdLookup[factor]); - } + boost::shared_ptr<Model> m_ngram; + + const Factor *m_beginSentenceFactor; + + FactorType m_factorType; + + lm::WordIndex TranslateID(const Word &word) const { + std::size_t factor = word.GetFactor(m_factorType)->GetId(); + return (factor >= m_lmIdLookup.size() ? 0 : m_lmIdLookup[factor]); + } private: - LanguageModelKen(const LanguageModelKen<Model> ©_from); - - // Convert last words of hypothesis into vocab ids, returning an end pointer. - lm::WordIndex *LastIDs(const Hypothesis &hypo, lm::WordIndex *indices) const { + LanguageModelKen(const LanguageModelKen<Model> ©_from); + + // Convert last words of hypothesis into vocab ids, returning an end pointer. + lm::WordIndex *LastIDs(const Hypothesis &hypo, lm::WordIndex *indices) const { lm::WordIndex *index = indices; lm::WordIndex *end = indices + m_ngram->Order() - 1; int position = hypo.GetCurrTargetWordsRange().GetEndPos(); @@ -93,8 +93,8 @@ private: } } - std::vector<lm::WordIndex> m_lmIdLookup; - + std::vector<lm::WordIndex> m_lmIdLookup; + }; } // namespace Moses diff --git a/moses/LM/LDHT.cpp b/moses/LM/LDHT.cpp index c14970a78..07ea91a3d 100644 --- a/moses/LM/LDHT.cpp +++ b/moses/LM/LDHT.cpp @@ -2,9 +2,9 @@ // Oliver Wilson <oliver.wilson@ed.ac.uk> // -// This file should be compiled only when the LM_RAND flag is enabled. +// This file should be compiled only when the LM_RAND flag is enabled. // -// The following ifdef prevents XCode and other non-bjam build systems +// The following ifdef prevents XCode and other non-bjam build systems // from attempting to compile this file when LM_RAND is disabled. // #ifdef LM_RAND diff --git a/moses/LM/ParallelBackoff.cpp b/moses/LM/ParallelBackoff.cpp index 6af828d9f..3d67e9c90 100644 --- a/moses/LM/ParallelBackoff.cpp +++ b/moses/LM/ParallelBackoff.cpp @@ -36,14 +36,14 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA #include "moses/Util.h" // By default, SRILM defines a function called zopen. -// +// // However, on Mac OS X (and possibly other BSDs), // <stdio.h> already defines a zopen function. // // To resolve this conflict, SRILM checks to see if HAVE_ZOPEN is defined. // If it is, SRILM will rename its zopen function as my_zopen. // -// So, before importing any SRILM headers, +// So, before importing any SRILM headers, // it is important to define HAVE_ZOPEN if we are on an Apple OS: // #ifdef __APPLE__ diff --git a/moses/LM/Rand.cpp b/moses/LM/Rand.cpp index 301679581..0f11fea07 100644 --- a/moses/LM/Rand.cpp +++ b/moses/LM/Rand.cpp @@ -17,9 +17,9 @@ License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ***********************************************************************/ -// This file should be compiled only when the LM_RAND flag is enabled. +// This file should be compiled only when the LM_RAND flag is enabled. // -// The following ifdef prevents XCode and other non-bjam build systems +// The following ifdef prevents XCode and other non-bjam build systems // from attempting to compile this file when LM_RAND is disabled. // #ifdef LM_RAND diff --git a/moses/LM/SRI.cpp b/moses/LM/SRI.cpp index 712c93c39..6182bd22c 100644 --- a/moses/LM/SRI.cpp +++ b/moses/LM/SRI.cpp @@ -32,14 +32,14 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA #include "moses/StaticData.h" // By default, SRILM defines a function called zopen. -// +// // However, on Mac OS X (and possibly other BSDs), // <stdio.h> already defines a zopen function. // // To resolve this conflict, SRILM checks to see if HAVE_ZOPEN is defined. // If it is, SRILM will rename its zopen function as my_zopen. // -// So, before importing any SRILM headers, +// So, before importing any SRILM headers, // it is important to define HAVE_ZOPEN if we are on an Apple OS: // #ifdef __APPLE__ diff --git a/moses/LM/SkeletonLM.cpp b/moses/LM/SkeletonLM.cpp index 8a923514f..6bf47e108 100644 --- a/moses/LM/SkeletonLM.cpp +++ b/moses/LM/SkeletonLM.cpp @@ -12,7 +12,7 @@ SkeletonLM::SkeletonLM(const std::string &line) ReadParameters(); if (m_factorType == NOT_FOUND) { - m_factorType = 0; + m_factorType = 0; } FactorCollection &factorCollection = FactorCollection::Instance(); @@ -39,10 +39,9 @@ LMResult SkeletonLM::GetValue(const vector<const Word*> &contextFactor, State* f const Factor *factor; size_t hash_value(const Factor &f); if (contextFactor.size()) { - factor = contextFactor.back()->GetFactor(m_factorType); - } - else { - factor = NULL; + factor = contextFactor.back()->GetFactor(m_factorType); + } else { + factor = NULL; } (*finalState) = (State*) factor; diff --git a/moses/LM/SkeletonLM.h b/moses/LM/SkeletonLM.h index 87afa7a13..988c9def9 100644 --- a/moses/LM/SkeletonLM.h +++ b/moses/LM/SkeletonLM.h @@ -12,7 +12,7 @@ class SkeletonLM : public LanguageModelSingleFactor protected: public: - SkeletonLM(const std::string &line); + SkeletonLM(const std::string &line); ~SkeletonLM(); virtual LMResult GetValue(const std::vector<const Word*> &contextFactor, State* finalState = 0) const; diff --git a/moses/Manager.cpp b/moses/Manager.cpp index 15f5ecc2b..197942222 100644 --- a/moses/Manager.cpp +++ b/moses/Manager.cpp @@ -60,7 +60,7 @@ Manager::Manager(size_t lineNumber, InputType const& source, SearchAlgorithm sea ,m_lineNumber(lineNumber) ,m_source(source) { - StaticData::Instance().InitializeForInput(m_source); + StaticData::Instance().InitializeForInput(m_source); } Manager::~Manager() diff --git a/moses/PCNTools.cpp b/moses/PCNTools.cpp index 1e6d475b2..1ed1aa4cd 100644 --- a/moses/PCNTools.cpp +++ b/moses/PCNTools.cpp @@ -33,7 +33,7 @@ std::string getString(const std::string& in, int &c) std::string ret; eatws(in,c); while (c < (int)in.size() && get(in,c) != ' ' && get(in,c) != ')' && get(in,c) != ',') { - ret += get(in,c++); + ret += get(in,c++); } eatws(in,c); return ret; @@ -111,26 +111,25 @@ CNAlt getCNAlt(const std::string& in, int &c) // dense scores size_t ind; for (ind = 0; ind < toks.size() - 1; ++ind) { - const string &tok = toks[ind]; - - if (tok.find('=') == tok.npos) { - float val = Moses::Scan<float>(tok); - probs.push_back(val); - } - else { - // beginning of sparse feature - break; - } + const string &tok = toks[ind]; + + if (tok.find('=') == tok.npos) { + float val = Moses::Scan<float>(tok); + probs.push_back(val); + } else { + // beginning of sparse feature + break; + } } // sparse features std::map<string, float> sparseFeatures; for (; ind < toks.size() - 1; ++ind) { - const string &tok = toks[ind]; - vector<string> keyValue = Moses::Tokenize(tok, "="); - CHECK(keyValue.size() == 2); - float prob = Moses::Scan<float>(keyValue[1]); - sparseFeatures[ keyValue[0] ] = prob; + const string &tok = toks[ind]; + vector<string> keyValue = Moses::Tokenize(tok, "="); + CHECK(keyValue.size() == 2); + float prob = Moses::Scan<float>(keyValue[1]); + sparseFeatures[ keyValue[0] ] = prob; } //last item is column increment diff --git a/moses/PCNTools.h b/moses/PCNTools.h index 64b9ebec2..c36ed67e3 100644 --- a/moses/PCNTools.h +++ b/moses/PCNTools.h @@ -34,24 +34,23 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA namespace PCN { -struct CNAlt -{ - CNAlt() - {} - CNAlt(const std::string &word, - const std::vector<float> &denseFeatures, - const std::map<std::string, float> &sparseFeatures, - size_t next) - :m_word(word) - ,m_denseFeatures(denseFeatures) - ,m_sparseFeatures(sparseFeatures) - ,m_next(next) - {} +struct CNAlt { + CNAlt() + {} + CNAlt(const std::string &word, + const std::vector<float> &denseFeatures, + const std::map<std::string, float> &sparseFeatures, + size_t next) + :m_word(word) + ,m_denseFeatures(denseFeatures) + ,m_sparseFeatures(sparseFeatures) + ,m_next(next) + {} - std::string m_word; - std::vector<float> m_denseFeatures; - std::map<std::string, float> m_sparseFeatures; - size_t m_next; + std::string m_word; + std::vector<float> m_denseFeatures; + std::map<std::string, float> m_sparseFeatures; + size_t m_next; }; //typedef std::pair<std::pair<std::string, std::vector<float> >, size_t> CNAlt; diff --git a/moses/Phrase.cpp b/moses/Phrase.cpp index 025702192..91e41cf2f 100644 --- a/moses/Phrase.cpp +++ b/moses/Phrase.cpp @@ -120,9 +120,9 @@ std::string Phrase::GetStringRep(const vector<FactorType> factorsToPrint) const stringstream strme; for (size_t pos = 0 ; pos < GetSize() ; pos++) { - if(markUnknown && GetWord(pos).IsOOV()) { - strme << "UNK"; - } + if(markUnknown && GetWord(pos).IsOOV()) { + strme << "UNK"; + } strme << GetWord(pos).GetString(factorsToPrint, (pos != GetSize()-1)); } @@ -388,25 +388,23 @@ size_t Phrase::Find(const Phrase &sought, int maxUnknown) const for (soughtPos = 0; soughtPos < sought.GetSize(); ++soughtPos) { const Word &soughtWord = sought.GetWord(soughtPos); const Word &thisWord = GetWord(thisPos); - + if (soughtWord == thisWord) { - ++thisPos; - } - else if (soughtWord.IsOOV() && (maxUnknown < 0 || currUnknowns < maxUnknown)) { - // the output has an OOV word. Allow a certain number of OOVs - ++currUnknowns; - ++thisPos; - } - else { - break; + ++thisPos; + } else if (soughtWord.IsOOV() && (maxUnknown < 0 || currUnknowns < maxUnknown)) { + // the output has an OOV word. Allow a certain number of OOVs + ++currUnknowns; + ++thisPos; + } else { + break; } } - + if (soughtPos == sought.GetSize()) { return startThisPos; } } - + return NOT_FOUND; } diff --git a/moses/ScoreComponentCollection.cpp b/moses/ScoreComponentCollection.cpp index bf65d89ea..e252d1a7a 100644 --- a/moses/ScoreComponentCollection.cpp +++ b/moses/ScoreComponentCollection.cpp @@ -10,64 +10,63 @@ namespace Moses { void ScorePair::PlusEquals(const ScorePair &other) { - PlusEquals(other.denseScores); - std::map<StringPiece, float>::const_iterator iter; - for (iter = other.sparseScores.begin(); iter != other.sparseScores.end(); ++iter) { - PlusEquals(iter->first, iter->second); - } + PlusEquals(other.denseScores); + std::map<StringPiece, float>::const_iterator iter; + for (iter = other.sparseScores.begin(); iter != other.sparseScores.end(); ++iter) { + PlusEquals(iter->first, iter->second); + } } void ScorePair::PlusEquals(const StringPiece &key, float value) { - std::map<StringPiece, float>::iterator iter; - iter = sparseScores.find(key); - if (iter == sparseScores.end()) { - sparseScores[key] = value; - } - else { - float &existingval = iter->second; - existingval += value; - } + std::map<StringPiece, float>::iterator iter; + iter = sparseScores.find(key); + if (iter == sparseScores.end()) { + sparseScores[key] = value; + } else { + float &existingval = iter->second; + existingval += value; + } } std::ostream& operator<<(std::ostream& os, const ScorePair& rhs) { - for (size_t i = 0; i < rhs.denseScores.size(); ++i) { - os << rhs.denseScores[i] << ","; - } + for (size_t i = 0; i < rhs.denseScores.size(); ++i) { + os << rhs.denseScores[i] << ","; + } - std::map<StringPiece, float>::const_iterator iter; - for (iter = rhs.sparseScores.begin(); iter != rhs.sparseScores.end(); ++iter) { - os << iter->first << "=" << iter->second << ","; - } + std::map<StringPiece, float>::const_iterator iter; + for (iter = rhs.sparseScores.begin(); iter != rhs.sparseScores.end(); ++iter) { + os << iter->first << "=" << iter->second << ","; + } - return os; + return os; } ScoreComponentCollection::ScoreIndexMap ScoreComponentCollection::s_scoreIndexes; size_t ScoreComponentCollection::s_denseVectorSize = 0; ScoreComponentCollection:: -ScoreComponentCollection() +ScoreComponentCollection() : m_scores(s_denseVectorSize) {} -void +void ScoreComponentCollection:: RegisterScoreProducer(const FeatureFunction* scoreProducer) { size_t start = s_denseVectorSize; size_t end = start + scoreProducer->GetNumScoreComponents(); - VERBOSE(1, "FeatureFunction: " - << scoreProducer->GetScoreProducerDescription() - << " start: " << start << " end: " << (end-1) << endl); + VERBOSE(1, "FeatureFunction: " + << scoreProducer->GetScoreProducerDescription() + << " start: " << start << " end: " << (end-1) << endl); s_scoreIndexes[scoreProducer] = pair<size_t,size_t>(start,end); s_denseVectorSize = end; } -float +float ScoreComponentCollection:: GetWeightedScore() const { @@ -213,7 +212,7 @@ void ScoreComponentCollection::Save(const string& filename) const out.close(); } -void +void ScoreComponentCollection:: Assign(const FeatureFunction* sp, const string line) { @@ -229,18 +228,18 @@ Assign(const FeatureFunction* sp, const string line) } } -void +void ScoreComponentCollection:: -Assign(const FeatureFunction* sp, const std::vector<float>& scores) +Assign(const FeatureFunction* sp, const std::vector<float>& scores) { IndexPair indexes = GetIndexes(sp); size_t numScores = indexes.second - indexes.first; if (scores.size() != numScores) { - UTIL_THROW(util::Exception, "Feature function " - << sp->GetScoreProducerDescription() << " specified " - << numScores << " dense scores or weights. Actually has " - << scores.size()); + UTIL_THROW(util::Exception, "Feature function " + << sp->GetScoreProducerDescription() << " specified " + << numScores << " dense scores or weights. Actually has " + << scores.size()); } for (size_t i = 0; i < scores.size(); ++i) { @@ -286,14 +285,14 @@ FVector ScoreComponentCollection::GetVectorForProducer(const FeatureFunction* sp void ScoreComponentCollection::PlusEquals(const FeatureFunction* sp, const ScorePair &scorePair) { - PlusEquals(sp, scorePair.denseScores); + PlusEquals(sp, scorePair.denseScores); - std::map<StringPiece, float>::const_iterator iter; - for (iter = scorePair.sparseScores.begin(); iter != scorePair.sparseScores.end(); ++iter) { - const StringPiece &key = iter->first; - float value = iter->second; - PlusEquals(sp, key, value); - } + std::map<StringPiece, float>::const_iterator iter; + for (iter = scorePair.sparseScores.begin(); iter != scorePair.sparseScores.end(); ++iter) { + const StringPiece &key = iter->first; + float value = iter->second; + PlusEquals(sp, key, value); + } } } diff --git a/moses/ScoreComponentCollection.h b/moses/ScoreComponentCollection.h index 6501242ec..31b28d1c7 100644 --- a/moses/ScoreComponentCollection.h +++ b/moses/ScoreComponentCollection.h @@ -44,31 +44,29 @@ namespace Moses /** * Smaller version for just 1 FF. */ -struct ScorePair -{ - friend std::ostream& operator<<(std::ostream& os, const ScorePair& rhs); - - std::vector<float> denseScores; - std::map<StringPiece, float> sparseScores; - - ScorePair() - {} - ScorePair(const std::vector<float> &other) - :denseScores(other) - {} - - void PlusEquals(const ScorePair &other); - void PlusEquals(const StringPiece &key, float value); - - void PlusEquals(const std::vector<float> &other) - { - CHECK(denseScores.size() == other.size()); - std::transform(denseScores.begin(), - denseScores.end(), - other.begin(), - denseScores.begin(), - std::plus<float>()); - } +struct ScorePair { + friend std::ostream& operator<<(std::ostream& os, const ScorePair& rhs); + + std::vector<float> denseScores; + std::map<StringPiece, float> sparseScores; + + ScorePair() + {} + ScorePair(const std::vector<float> &other) + :denseScores(other) + {} + + void PlusEquals(const ScorePair &other); + void PlusEquals(const StringPiece &key, float value); + + void PlusEquals(const std::vector<float> &other) { + CHECK(denseScores.size() == other.size()); + std::transform(denseScores.begin(), + denseScores.end(), + other.begin(), + denseScores.begin(), + std::plus<float>()); + } }; /*** An unweighted collection of scores for a translation or step in a translation. diff --git a/moses/ScoreComponentCollectionTest.cpp b/moses/ScoreComponentCollectionTest.cpp index 3f331b0a0..f44595aec 100644 --- a/moses/ScoreComponentCollectionTest.cpp +++ b/moses/ScoreComponentCollectionTest.cpp @@ -37,14 +37,14 @@ public: void Evaluate(const Hypothesis&, ScoreComponentCollection*) const {} void EvaluateChart(const ChartHypothesis&, ScoreComponentCollection*) const {} void Evaluate(const InputType &input - , const InputPath &inputPath - , const TargetPhrase &targetPhrase - , ScoreComponentCollection &scoreBreakdown) const + , const InputPath &inputPath + , const TargetPhrase &targetPhrase + , ScoreComponentCollection &scoreBreakdown) const {} void Evaluate(const Phrase &source - , const TargetPhrase &targetPhrase - , ScoreComponentCollection &scoreBreakdown - , ScoreComponentCollection &estimatedFutureScore) const + , const TargetPhrase &targetPhrase + , ScoreComponentCollection &scoreBreakdown + , ScoreComponentCollection &estimatedFutureScore) const {} }; diff --git a/moses/SearchNormal.cpp b/moses/SearchNormal.cpp index 5f6fd3df3..7340802e1 100644 --- a/moses/SearchNormal.cpp +++ b/moses/SearchNormal.cpp @@ -32,7 +32,7 @@ SearchNormal::SearchNormal(Manager& manager, const InputType &source, const Tran for (size_t ind = 0 ; ind < m_hypoStackColl.size() ; ++ind) { HypothesisStackNormal *sourceHypoColl = new HypothesisStackNormal(m_manager); sourceHypoColl->SetMaxHypoStackSize(staticData.GetMaxHypoStackSize(), - staticData.GetMinHypoStackDiversity()); + staticData.GetMinHypoStackDiversity()); sourceHypoColl->SetBeamWidth(staticData.GetBeamWidth()); m_hypoStackColl[ind] = sourceHypoColl; diff --git a/moses/SearchNormalBatch.cpp b/moses/SearchNormalBatch.cpp index 5c06d3f77..40ce124e7 100644 --- a/moses/SearchNormalBatch.cpp +++ b/moses/SearchNormalBatch.cpp @@ -109,10 +109,10 @@ void SearchNormalBatch::ProcessSentence() * (base hypothesis score plus future score estimation) */ -void +void SearchNormalBatch:: -ExpandHypothesis(const Hypothesis &hypothesis, - const TranslationOption &transOpt, float expectedScore) +ExpandHypothesis(const Hypothesis &hypothesis, + const TranslationOption &transOpt, float expectedScore) { // Check if the number of partial hypotheses exceeds the batch size. if (m_partial_hypos.size() >= m_batch_size) { diff --git a/moses/StaticData.cpp b/moses/StaticData.cpp index fcb007623..cb52ed042 100644 --- a/moses/StaticData.cpp +++ b/moses/StaticData.cpp @@ -171,8 +171,8 @@ bool StaticData::LoadData(Parameter *parameter) if (m_parameter->GetParam("n-best-list").size() >= 2) { m_nBestFilePath = m_parameter->GetParam("n-best-list")[0]; m_nBestSize = Scan<size_t>( m_parameter->GetParam("n-best-list")[1] ); - m_onlyDistinctNBest=(m_parameter->GetParam("n-best-list").size()>2 - && m_parameter->GetParam("n-best-list")[2]=="distinct"); + m_onlyDistinctNBest=(m_parameter->GetParam("n-best-list").size()>2 + && m_parameter->GetParam("n-best-list")[2]=="distinct"); } else if (m_parameter->GetParam("n-best-list").size() == 1) { UserMessage::Add(string("wrong format for switch -n-best-list file size")); return false; @@ -879,8 +879,8 @@ void StaticData::CleanUpAfterSentenceProcessing(const InputType& source) const void StaticData::LoadFeatureFunctions() { - const std::vector<FeatureFunction*> &ffs - = FeatureFunction::GetFeatureFunctions(); + const std::vector<FeatureFunction*> &ffs + = FeatureFunction::GetFeatureFunctions(); std::vector<FeatureFunction*>::const_iterator iter; for (iter = ffs.begin(); iter != ffs.end(); ++iter) { FeatureFunction *ff = *iter; @@ -889,15 +889,15 @@ void StaticData::LoadFeatureFunctions() if (PhraseDictionary *ffCast = dynamic_cast<PhraseDictionary*>(ff)) { m_phraseDictionary.push_back(ffCast); doLoad = false; - } else if (const GenerationDictionary *ffCast - = dynamic_cast<const GenerationDictionary*>(ff)) { + } else if (const GenerationDictionary *ffCast + = dynamic_cast<const GenerationDictionary*>(ff)) { m_generationDictionary.push_back(ffCast); - } else if (WordPenaltyProducer *ffCast - = dynamic_cast<WordPenaltyProducer*>(ff)) { + } else if (WordPenaltyProducer *ffCast + = dynamic_cast<WordPenaltyProducer*>(ff)) { CHECK(m_wpProducer == NULL); // max 1 feature; m_wpProducer = ffCast; - } else if (UnknownWordPenaltyProducer *ffCast - = dynamic_cast<UnknownWordPenaltyProducer*>(ff)) { + } else if (UnknownWordPenaltyProducer *ffCast + = dynamic_cast<UnknownWordPenaltyProducer*>(ff)) { CHECK(m_unknownWordPenaltyProducer == NULL); // max 1 feature; m_unknownWordPenaltyProducer = ffCast; } else if (const InputFeature *ffCast = dynamic_cast<const InputFeature*>(ff)) { @@ -994,12 +994,12 @@ bool StaticData::LoadAlternateWeightSettings() vector<string> featureFunctionName = Tokenize(args[1], ","); for(size_t k=0; k<featureFunctionName.size(); k++) { // check if a valid nane - map<string,FeatureFunction*>::iterator ffLookUp - = nameToFF.find(featureFunctionName[k]); + map<string,FeatureFunction*>::iterator ffLookUp + = nameToFF.find(featureFunctionName[k]); if (ffLookUp == nameToFF.end()) { - cerr << "ERROR: alternate weight setting " << currentId - << " specifies to ignore feature function " << featureFunctionName[k] - << " but there is no such feature function" << endl; + cerr << "ERROR: alternate weight setting " << currentId + << " specifies to ignore feature function " << featureFunctionName[k] + << " but there is no such feature function" << endl; hasErrors = true; } else { m_weightSettingIgnoreFF[ currentId ].insert( featureFunctionName[k] ); @@ -1027,9 +1027,9 @@ bool StaticData::LoadAlternateWeightSettings() // check if a valid nane map<string,FeatureFunction*>::iterator ffLookUp = nameToFF.find(name); if (ffLookUp == nameToFF.end()) { - cerr << "ERROR: alternate weight setting " << currentId - << " specifies weight(s) for " << name - << " but there is no such feature function" << endl; + cerr << "ERROR: alternate weight setting " << currentId + << " specifies weight(s) for " << name + << " but there is no such feature function" << endl; hasErrors = true; } else { m_weightSetting[ currentId ]->Assign( nameToFF[name], weights); diff --git a/moses/StaticData.h b/moses/StaticData.h index d90e9a109..d18c9ad98 100644 --- a/moses/StaticData.h +++ b/moses/StaticData.h @@ -354,8 +354,8 @@ public: } bool IsDetailedAllTranslationReportingEnabled() const { - return !m_detailedAllTranslationReportingFilePath.empty(); - } + return !m_detailedAllTranslationReportingFilePath.empty(); + } const std::string &GetDetailedTranslationReportingFilePath() const { return m_detailedTranslationReportingFilePath; diff --git a/moses/SyntacticLanguageModel.cpp b/moses/SyntacticLanguageModel.cpp index 7127e9f7d..3c1fa7af8 100644 --- a/moses/SyntacticLanguageModel.cpp +++ b/moses/SyntacticLanguageModel.cpp @@ -1,6 +1,6 @@ -// This file should be compiled only when the HAVE_SYNLM flag is enabled. +// This file should be compiled only when the HAVE_SYNLM flag is enabled. // -// The following ifdef prevents XCode and other non-bjam build systems +// The following ifdef prevents XCode and other non-bjam build systems // from attempting to compile this file when HAVE_SYNLM is disabled. // #ifdef HAVE_SYNLM diff --git a/moses/TargetPhrase.cpp b/moses/TargetPhrase.cpp index dd5859350..bda687fc7 100644 --- a/moses/TargetPhrase.cpp +++ b/moses/TargetPhrase.cpp @@ -90,10 +90,9 @@ TargetPhrase::TargetPhrase(const TargetPhrase ©) } if (copy.m_ruleSource) { - m_ruleSource = new Phrase(*copy.m_ruleSource); - } - else { - m_ruleSource = NULL; + m_ruleSource = new Phrase(*copy.m_ruleSource); + } else { + m_ruleSource = NULL; } } @@ -213,24 +212,24 @@ void TargetPhrase::Merge(const TargetPhrase ©, const std::vector<FactorType> void TargetPhrase::SetProperties(const StringPiece &str) { - if (str.size() == 0) { - return; - } + if (str.size() == 0) { + return; + } vector<string> toks; TokenizeMultiCharSeparator(toks, str.as_string(), "{{"); for (size_t i = 0; i < toks.size(); ++i) { - string &tok = toks[i]; - if (tok.empty()) { - continue; - } - size_t endPos = tok.rfind("}"); + string &tok = toks[i]; + if (tok.empty()) { + continue; + } + size_t endPos = tok.rfind("}"); - tok = tok.substr(0, endPos - 1); + tok = tok.substr(0, endPos - 1); - vector<string> keyValue = TokenizeFirstOnly(tok, " "); - CHECK(keyValue.size() == 2); - SetProperty(keyValue[0], keyValue[1]); + vector<string> keyValue = TokenizeFirstOnly(tok, " "); + CHECK(keyValue.size() == 2); + SetProperty(keyValue[0], keyValue[1]); } } @@ -249,7 +248,7 @@ void TargetPhrase::GetProperty(const std::string &key, std::string &value, bool void TargetPhrase::SetRuleSource(const Phrase &ruleSource) const { if (m_ruleSource == NULL) { - m_ruleSource = new Phrase(ruleSource); + m_ruleSource = new Phrase(ruleSource); } } diff --git a/moses/TargetPhrase.h b/moses/TargetPhrase.h index 95bedfe7d..476d32910 100644 --- a/moses/TargetPhrase.h +++ b/moses/TargetPhrase.h @@ -124,8 +124,9 @@ public: return *m_alignNonTerm; } - const Phrase *GetRuleSource() const - { return m_ruleSource; } + const Phrase *GetRuleSource() const { + return m_ruleSource; + } // To be set by the FF that needs it, by default the rule source = NULL // make a copy of the source side of the rule diff --git a/moses/TargetPhraseCollection.cpp b/moses/TargetPhraseCollection.cpp index 814544446..31dc98be8 100644 --- a/moses/TargetPhraseCollection.cpp +++ b/moses/TargetPhraseCollection.cpp @@ -29,14 +29,14 @@ namespace Moses { // helper for sort bool -CompareTargetPhrase:: -operator() (const TargetPhrase *a, const TargetPhrase *b) const +CompareTargetPhrase:: +operator() (const TargetPhrase *a, const TargetPhrase *b) const { return a->GetFutureScore() > b->GetFutureScore(); } -bool -CompareTargetPhrase:: +bool +CompareTargetPhrase:: operator() (const TargetPhrase &a, const TargetPhrase &b) const { return a.GetFutureScore() > b.GetFutureScore(); diff --git a/moses/TargetPhraseCollection.h b/moses/TargetPhraseCollection.h index 2bbf5c106..1945bbaf6 100644 --- a/moses/TargetPhraseCollection.h +++ b/moses/TargetPhraseCollection.h @@ -118,8 +118,7 @@ public: void Add(TargetPhrase *targetPhrase, const Phrase &sourcePhrase); }; -struct CompareTargetPhrase -{ +struct CompareTargetPhrase { bool operator() (const TargetPhrase *a, const TargetPhrase *b) const; bool operator() (const TargetPhrase &a, const TargetPhrase &b) const; }; diff --git a/moses/TranslationModel/BilingualDynSuffixArray.h b/moses/TranslationModel/BilingualDynSuffixArray.h index c2c784830..daad0f41e 100644 --- a/moses/TranslationModel/BilingualDynSuffixArray.h +++ b/moses/TranslationModel/BilingualDynSuffixArray.h @@ -80,7 +80,7 @@ class ScoresComp { public: ScoresComp(const vector<float>& weights) - {} + {} bool operator()(const Scores& s1, const Scores& s2) const { return s1[0] < s2[0]; // just p(e|f) as approximation // float score1(0), score2(0); diff --git a/moses/TranslationModel/CYKPlusParser/ChartRuleLookupManagerSkeleton.cpp b/moses/TranslationModel/CYKPlusParser/ChartRuleLookupManagerSkeleton.cpp index 3bdbd7421..4a76dce6d 100644 --- a/moses/TranslationModel/CYKPlusParser/ChartRuleLookupManagerSkeleton.cpp +++ b/moses/TranslationModel/CYKPlusParser/ChartRuleLookupManagerSkeleton.cpp @@ -39,8 +39,8 @@ ChartRuleLookupManagerSkeleton::ChartRuleLookupManagerSkeleton( const ChartParser &parser, const ChartCellCollectionBase &cellColl, const SkeletonPT &skeletonPt) -: ChartRuleLookupManagerCYKPlus(parser, cellColl) -, m_skeletonPT(skeletonPt) + : ChartRuleLookupManagerCYKPlus(parser, cellColl) + , m_skeletonPT(skeletonPt) { } @@ -52,34 +52,34 @@ void ChartRuleLookupManagerSkeleton::GetChartRuleCollection( const WordsRange &range, ChartParserCallback &outColl) { - const ChartCellLabel &sourceWordLabel = GetSourceAt(range.GetStartPos()); - const Word &sourceWord = sourceWordLabel.GetLabel(); + const ChartCellLabel &sourceWordLabel = GetSourceAt(range.GetStartPos()); + const Word &sourceWord = sourceWordLabel.GetLabel(); - // almost the same as for SkeletonPT::GetTargetPhraseCollectionBatch() - TargetPhrase *tp = CreateTargetPhrase(sourceWord); - TargetPhraseCollection *tpColl = new TargetPhraseCollection(); - tpColl->Add(tp); + // almost the same as for SkeletonPT::GetTargetPhraseCollectionBatch() + TargetPhrase *tp = CreateTargetPhrase(sourceWord); + TargetPhraseCollection *tpColl = new TargetPhraseCollection(); + tpColl->Add(tp); - //outColl.Add(*tpColl, ) + //outColl.Add(*tpColl, ) } TargetPhrase *ChartRuleLookupManagerSkeleton::CreateTargetPhrase(const Word &sourceWord) const { - // create a target phrase from the 1st word of the source, prefix with 'ChartManagerSkeleton:' - string str = sourceWord.GetFactor(0)->GetString().as_string(); - str = "ChartManagerSkeleton:" + str; + // create a target phrase from the 1st word of the source, prefix with 'ChartManagerSkeleton:' + string str = sourceWord.GetFactor(0)->GetString().as_string(); + str = "ChartManagerSkeleton:" + str; - TargetPhrase *tp = new TargetPhrase(); - Word &word = tp->AddWord(); - word.CreateFromString(Output, m_skeletonPT.GetOutput(), str, false); + TargetPhrase *tp = new TargetPhrase(); + Word &word = tp->AddWord(); + word.CreateFromString(Output, m_skeletonPT.GetOutput(), str, false); - // score for this phrase table - vector<float> scores(m_skeletonPT.GetNumScoreComponents(), 1.3); - tp->GetScoreBreakdown().PlusEquals(&m_skeletonPT, scores); + // score for this phrase table + vector<float> scores(m_skeletonPT.GetNumScoreComponents(), 1.3); + tp->GetScoreBreakdown().PlusEquals(&m_skeletonPT, scores); - // score of all other ff when this rule is being loaded - //tp->Evaluate(sourcePhrase, m_skeletonPT.GetFeaturesToApply()); + // score of all other ff when this rule is being loaded + //tp->Evaluate(sourcePhrase, m_skeletonPT.GetFeaturesToApply()); - return tp; + return tp; } } // namespace Moses diff --git a/moses/TranslationModel/CYKPlusParser/ChartRuleLookupManagerSkeleton.h b/moses/TranslationModel/CYKPlusParser/ChartRuleLookupManagerSkeleton.h index 77f6e9d0d..00f1c7813 100644 --- a/moses/TranslationModel/CYKPlusParser/ChartRuleLookupManagerSkeleton.h +++ b/moses/TranslationModel/CYKPlusParser/ChartRuleLookupManagerSkeleton.h @@ -40,8 +40,8 @@ class ChartRuleLookupManagerSkeleton : public ChartRuleLookupManagerCYKPlus { public: ChartRuleLookupManagerSkeleton(const ChartParser &parser, - const ChartCellCollectionBase &cellColl, - const SkeletonPT &skeletonPt); + const ChartCellCollectionBase &cellColl, + const SkeletonPT &skeletonPt); ~ChartRuleLookupManagerSkeleton(); diff --git a/moses/TranslationModel/CompactPT/PhraseDictionaryCompact.cpp b/moses/TranslationModel/CompactPT/PhraseDictionaryCompact.cpp index abb2dd01b..c60d0f944 100644 --- a/moses/TranslationModel/CompactPT/PhraseDictionaryCompact.cpp +++ b/moses/TranslationModel/CompactPT/PhraseDictionaryCompact.cpp @@ -100,13 +100,13 @@ void PhraseDictionaryCompact::Load() CHECK(indexSize && coderSize && phraseSize); } - // now properly declared in TargetPhraseCollection.h - // and defined in TargetPhraseCollection.cpp - // struct CompareTargetPhrase { - // bool operator() (const TargetPhrase &a, const TargetPhrase &b) { - // return a.GetFutureScore() > b.GetFutureScore(); - // } - // }; +// now properly declared in TargetPhraseCollection.h +// and defined in TargetPhraseCollection.cpp +// struct CompareTargetPhrase { +// bool operator() (const TargetPhrase &a, const TargetPhrase &b) { +// return a.GetFutureScore() > b.GetFutureScore(); +// } +// }; const TargetPhraseCollection* PhraseDictionaryCompact::GetTargetPhraseCollectionNonCacheLEGACY(const Phrase &sourcePhrase) const diff --git a/moses/TranslationModel/PhraseDictionary.cpp b/moses/TranslationModel/PhraseDictionary.cpp index 5786d9af3..885bad77a 100644 --- a/moses/TranslationModel/PhraseDictionary.cpp +++ b/moses/TranslationModel/PhraseDictionary.cpp @@ -83,14 +83,14 @@ GetTargetPhraseCollectionNonCacheLEGACY(const Phrase& src) const } -TargetPhraseCollectionWithSourcePhrase const* +TargetPhraseCollectionWithSourcePhrase const* PhraseDictionary:: GetTargetPhraseCollectionLEGACY(InputType const& src,WordsRange const& range) const { UTIL_THROW(util::Exception, "Legacy method not implemented"); } -void +void PhraseDictionary:: SetParameter(const std::string& key, const std::string& value) { @@ -105,7 +105,7 @@ SetParameter(const std::string& key, const std::string& value) } } -void +void PhraseDictionary:: SetFeaturesToApply() { @@ -119,7 +119,7 @@ SetFeaturesToApply() } } -void +void PhraseDictionary:: GetTargetPhraseCollectionBatch(const InputPathList &phraseDictionaryQueue) const { diff --git a/moses/TranslationModel/PhraseDictionary.h b/moses/TranslationModel/PhraseDictionary.h index 4dd001b1c..e3a343753 100644 --- a/moses/TranslationModel/PhraseDictionary.h +++ b/moses/TranslationModel/PhraseDictionary.h @@ -69,17 +69,17 @@ public: return m_tableLimit; } - // LEGACY! + // LEGACY! // The preferred method is to override GetTargetPhraseCollectionBatch(). // See class PhraseDictionaryMemory or PhraseDictionaryOnDisk for details //! find list of translations that can translates src. Only for phrase input - virtual + virtual TargetPhraseCollection const * GetTargetPhraseCollectionLEGACY(const Phrase& src) const; - virtual - void + virtual + void GetTargetPhraseCollectionBatch(const InputPathList &phraseDictionaryQueue) const; //! Create entry for translation of source to targetPhrase diff --git a/moses/TranslationModel/PhraseDictionaryDynSuffixArray.cpp b/moses/TranslationModel/PhraseDictionaryDynSuffixArray.cpp index 0c0e49415..f9022eeee 100644 --- a/moses/TranslationModel/PhraseDictionaryDynSuffixArray.cpp +++ b/moses/TranslationModel/PhraseDictionaryDynSuffixArray.cpp @@ -17,7 +17,7 @@ PhraseDictionaryDynSuffixArray(const std::string &line) } -void +void PhraseDictionaryDynSuffixArray:: Load() { @@ -33,7 +33,7 @@ PhraseDictionaryDynSuffixArray:: delete m_biSA; } -void +void PhraseDictionaryDynSuffixArray:: SetParameter(const std::string& key, const std::string& value) { diff --git a/moses/TranslationModel/PhraseDictionaryMemory.cpp b/moses/TranslationModel/PhraseDictionaryMemory.cpp index 55d5d022b..3264b0a01 100644 --- a/moses/TranslationModel/PhraseDictionaryMemory.cpp +++ b/moses/TranslationModel/PhraseDictionaryMemory.cpp @@ -133,7 +133,7 @@ void PhraseDictionaryMemory::SortAndPrune() } } -void +void PhraseDictionaryMemory:: GetTargetPhraseCollectionBatch(const InputPathList &phraseDictionaryQueue) const { diff --git a/moses/TranslationModel/SkeletonPT.cpp b/moses/TranslationModel/SkeletonPT.cpp index 5b61368c4..4eba6f8ec 100644 --- a/moses/TranslationModel/SkeletonPT.cpp +++ b/moses/TranslationModel/SkeletonPT.cpp @@ -14,7 +14,7 @@ SkeletonPT::SkeletonPT(const std::string &line) void SkeletonPT::CleanUpAfterSentenceProcessing(const InputType& source) { - RemoveAllInColl(m_allTPColl); + RemoveAllInColl(m_allTPColl); } void SkeletonPT::GetTargetPhraseCollectionBatch(const InputPathList &phraseDictionaryQueue) const @@ -34,29 +34,29 @@ void SkeletonPT::GetTargetPhraseCollectionBatch(const InputPathList &phraseDicti TargetPhrase *SkeletonPT::CreateTargetPhrase(const Phrase &sourcePhrase) const { - // create a target phrase from the 1st word of the source, prefix with 'SkeletonPT:' - CHECK(sourcePhrase.GetSize()); - CHECK(m_output.size() == 1); + // create a target phrase from the 1st word of the source, prefix with 'SkeletonPT:' + CHECK(sourcePhrase.GetSize()); + CHECK(m_output.size() == 1); - string str = sourcePhrase.GetWord(0).GetFactor(0)->GetString().as_string(); - str = "SkeletonPT:" + str; + string str = sourcePhrase.GetWord(0).GetFactor(0)->GetString().as_string(); + str = "SkeletonPT:" + str; - TargetPhrase *tp = new TargetPhrase(); - Word &word = tp->AddWord(); - word.CreateFromString(Output, m_output, str, false); + TargetPhrase *tp = new TargetPhrase(); + Word &word = tp->AddWord(); + word.CreateFromString(Output, m_output, str, false); - // score for this phrase table - vector<float> scores(m_numScoreComponents, 1.3); - tp->GetScoreBreakdown().PlusEquals(this, scores); + // score for this phrase table + vector<float> scores(m_numScoreComponents, 1.3); + tp->GetScoreBreakdown().PlusEquals(this, scores); - // score of all other ff when this rule is being loaded - tp->Evaluate(sourcePhrase, GetFeaturesToApply()); + // score of all other ff when this rule is being loaded + tp->Evaluate(sourcePhrase, GetFeaturesToApply()); - return tp; + return tp; } ChartRuleLookupManager* SkeletonPT::CreateRuleLookupManager(const ChartParser &parser, - const ChartCellCollectionBase &cellCollection) + const ChartCellCollectionBase &cellCollection) { return new ChartRuleLookupManagerSkeleton(parser, cellCollection, *this); } diff --git a/moses/TranslationOptionCollection.cpp b/moses/TranslationOptionCollection.cpp index 5b4e5104b..016b49604 100644 --- a/moses/TranslationOptionCollection.cpp +++ b/moses/TranslationOptionCollection.cpp @@ -202,9 +202,9 @@ void TranslationOptionCollection::ProcessUnknownWord() * \param inputScores a set of scores associated with unknown word (input scores from latties/CNs) */ void TranslationOptionCollection::ProcessOneUnknownWord(const InputPath &inputPath, - size_t sourcePos, - size_t length, - const ScorePair *inputScores) + size_t sourcePos, + size_t length, + const ScorePair *inputScores) { const StaticData &staticData = StaticData::Instance(); const UnknownWordPenaltyProducer *unknownWordPenaltyProducer = staticData.GetUnknownWordPenaltyProducer(); diff --git a/moses/WordLattice.cpp b/moses/WordLattice.cpp index 95f4294ce..ae52eeb35 100644 --- a/moses/WordLattice.cpp +++ b/moses/WordLattice.cpp @@ -9,7 +9,7 @@ namespace Moses { -WordLattice::WordLattice() +WordLattice::WordLattice() { CHECK(StaticData::Instance().GetInputFeature()); } diff --git a/phrase-extract/PhraseExtractionOptions.h b/phrase-extract/PhraseExtractionOptions.h index a410473f4..d70c2a117 100644 --- a/phrase-extract/PhraseExtractionOptions.h +++ b/phrase-extract/PhraseExtractionOptions.h @@ -109,7 +109,7 @@ public: void initInstanceWeightsFile(const char* initInstanceWeightsFile) { instanceWeightsFile = std::string(initInstanceWeightsFile); } - void initFlexScoreFlag(const bool initflexScoreFlag){ + void initFlexScoreFlag(const bool initflexScoreFlag) { flexScoreFlag=initflexScoreFlag; } diff --git a/phrase-extract/SentenceAlignment.cpp b/phrase-extract/SentenceAlignment.cpp index 4420ec5ae..c3d71d525 100644 --- a/phrase-extract/SentenceAlignment.cpp +++ b/phrase-extract/SentenceAlignment.cpp @@ -124,15 +124,15 @@ bool SentenceAlignment::create( char targetString[], char sourceString[], char a void SentenceAlignment::invertAlignment() { - alignedToS.resize(source.size()); - for (size_t targetPos = 0; targetPos < alignedToT.size(); ++targetPos) { - const std::vector<int> &vec = alignedToT[targetPos]; - for (size_t i = 0; i < vec.size(); ++i) { - int sourcePos = vec[i]; - alignedToS[sourcePos].push_back(targetPos); - } - - } + alignedToS.resize(source.size()); + for (size_t targetPos = 0; targetPos < alignedToT.size(); ++targetPos) { + const std::vector<int> &vec = alignedToT[targetPos]; + for (size_t i = 0; i < vec.size(); ++i) { + int sourcePos = vec[i]; + alignedToS[sourcePos].push_back(targetPos); + } + + } } } diff --git a/phrase-extract/extract-main.cpp b/phrase-extract/extract-main.cpp index 1b545d136..0b21eb19a 100644 --- a/phrase-extract/extract-main.cpp +++ b/phrase-extract/extract-main.cpp @@ -300,7 +300,7 @@ int main(int argc, char* argv[]) } if (sentence.create( englishString, foreignString, alignmentString, weightString, i, false)) { if (options.placeholders.size()) { - sentence.invertAlignment(); + sentence.invertAlignment(); } ExtractTask *task = new ExtractTask(i-1, sentence, options, extractFile , extractFileInv, extractFileOrientation, extractFileContext, extractFileContextInv); task->Run(); @@ -863,10 +863,10 @@ void ExtractTask::writePhrasesToFile() for(vector<string>::const_iterator phrase=m_extractedPhrasesOri.begin(); phrase!=m_extractedPhrasesOri.end(); phrase++) { outextractFileOrientation<<phrase->data(); } - for(vector<string>::const_iterator phrase=m_extractedPhrasesContext.begin();phrase!=m_extractedPhrasesContext.end();phrase++){ + for(vector<string>::const_iterator phrase=m_extractedPhrasesContext.begin(); phrase!=m_extractedPhrasesContext.end(); phrase++) { outextractFileContext<<phrase->data(); } - for(vector<string>::const_iterator phrase=m_extractedPhrasesContextInv.begin();phrase!=m_extractedPhrasesContextInv.end();phrase++){ + for(vector<string>::const_iterator phrase=m_extractedPhrasesContextInv.begin(); phrase!=m_extractedPhrasesContextInv.end(); phrase++) { outextractFileContextInv<<phrase->data(); } @@ -921,15 +921,14 @@ bool ExtractTask::checkPlaceholders (const SentenceAlignment &sentence, int star const string &sourceWord = sentence.source[pos]; if (isPlaceholder(sourceWord)) { if (sentence.alignedToS.at(pos).size() != 1) { - return false; - } - else { - // check it actually lines up to another placeholder - int targetPos = sentence.alignedToS.at(pos).at(0); - const string &otherWord = sentence.target[targetPos]; - if (!isPlaceholder(otherWord)) { - return false; - } + return false; + } else { + // check it actually lines up to another placeholder + int targetPos = sentence.alignedToS.at(pos).at(0); + const string &otherWord = sentence.target[targetPos]; + if (!isPlaceholder(otherWord)) { + return false; + } } } } @@ -939,14 +938,13 @@ bool ExtractTask::checkPlaceholders (const SentenceAlignment &sentence, int star if (isPlaceholder(targetWord)) { if (sentence.alignedToT.at(pos).size() != 1) { return false; - } - else { - // check it actually lines up to another placeholder - int sourcePos = sentence.alignedToT.at(pos).at(0); - const string &otherWord = sentence.source[sourcePos]; - if (!isPlaceholder(otherWord)) { - return false; - } + } else { + // check it actually lines up to another placeholder + int sourcePos = sentence.alignedToT.at(pos).at(0); + const string &otherWord = sentence.source[sourcePos]; + if (!isPlaceholder(otherWord)) { + return false; + } } } } diff --git a/phrase-extract/extract-rules-main.cpp b/phrase-extract/extract-rules-main.cpp index c625c3582..f5f44316e 100644 --- a/phrase-extract/extract-rules-main.cpp +++ b/phrase-extract/extract-rules-main.cpp @@ -315,8 +315,8 @@ int main(int argc, char* argv[]) string fileNameExtractContext = fileNameExtract + ".context" + (options.gzOutput?".gz":""); extractFileContext.Open(fileNameExtractContext.c_str()); if (!options.onlyDirectFlag) { - string fileNameExtractContextInv = fileNameExtract + ".context.inv" + (options.gzOutput?".gz":""); - extractFileContextInv.Open(fileNameExtractContextInv.c_str()); + string fileNameExtractContextInv = fileNameExtract + ".context.inv" + (options.gzOutput?".gz":""); + extractFileContextInv.Open(fileNameExtractContextInv.c_str()); } } @@ -716,44 +716,43 @@ void ExtractTask::saveHieroPhrase( int startT, int endT, int startS, int endS // context (words to left and right) if (m_options.flexScoreFlag) { - rule.sourceContextLeft = startS == 0 ? "<s>" : m_sentence.source[startS-1]; - rule.sourceContextRight = endS+1 == m_sentence.source.size() ? "<s>" : m_sentence.source[endS+1]; - rule.targetContextLeft = startT == 0 ? "<s>" : m_sentence.target[startT-1]; - rule.targetContextRight = endT+1 == m_sentence.target.size() ? "<s>" : m_sentence.target[endT+1]; - rule.sourceHoleString = ""; - rule.targetHoleString = ""; - - HoleList::const_iterator iterHole; - for (iterHole = holeColl.GetHoles().begin(); iterHole != holeColl.GetHoles().end(); ++iterHole) { - const Hole &hole = *iterHole; - rule.sourceHoleString += hole.GetLabel(0) + ": "; - - // rule starts with nonterminal; end of NT is considered left context - if (hole.GetStart(0) == startS) { - rule.sourceContextLeft = m_sentence.source[hole.GetEnd(0)]; - } - // rule ends with nonterminal; start of NT is considered right context - else if (hole.GetEnd(0) == endS) { - rule.sourceContextRight = m_sentence.source[hole.GetStart(0)]; - } + rule.sourceContextLeft = startS == 0 ? "<s>" : m_sentence.source[startS-1]; + rule.sourceContextRight = endS+1 == m_sentence.source.size() ? "<s>" : m_sentence.source[endS+1]; + rule.targetContextLeft = startT == 0 ? "<s>" : m_sentence.target[startT-1]; + rule.targetContextRight = endT+1 == m_sentence.target.size() ? "<s>" : m_sentence.target[endT+1]; + rule.sourceHoleString = ""; + rule.targetHoleString = ""; + + HoleList::const_iterator iterHole; + for (iterHole = holeColl.GetHoles().begin(); iterHole != holeColl.GetHoles().end(); ++iterHole) { + const Hole &hole = *iterHole; + rule.sourceHoleString += hole.GetLabel(0) + ": "; + + // rule starts with nonterminal; end of NT is considered left context + if (hole.GetStart(0) == startS) { + rule.sourceContextLeft = m_sentence.source[hole.GetEnd(0)]; + } + // rule ends with nonterminal; start of NT is considered right context + else if (hole.GetEnd(0) == endS) { + rule.sourceContextRight = m_sentence.source[hole.GetStart(0)]; + } - if (hole.GetStart(1) == startT) { - rule.targetContextLeft = m_sentence.target[hole.GetEnd(1)]; - } - else if (hole.GetEnd(1) == endT) { - rule.targetContextRight = m_sentence.target[hole.GetStart(1)]; - } + if (hole.GetStart(1) == startT) { + rule.targetContextLeft = m_sentence.target[hole.GetEnd(1)]; + } else if (hole.GetEnd(1) == endT) { + rule.targetContextRight = m_sentence.target[hole.GetStart(1)]; + } - for (int i = hole.GetStart(0); i <= hole.GetEnd(0); ++i) { - rule.sourceHoleString += m_sentence.source[i] + " "; - } - rule.targetHoleString += hole.GetLabel(1) + ": "; - for (int i = hole.GetStart(1); i <= hole.GetEnd(1); ++i) { - rule.targetHoleString += m_sentence.target[i] + " "; - } + for (int i = hole.GetStart(0); i <= hole.GetEnd(0); ++i) { + rule.sourceHoleString += m_sentence.source[i] + " "; } + rule.targetHoleString += hole.GetLabel(1) + ": "; + for (int i = hole.GetStart(1); i <= hole.GetEnd(1); ++i) { + rule.targetHoleString += m_sentence.target[i] + " "; + } + } } - + addRuleToCollection( rule ); } @@ -996,10 +995,10 @@ void ExtractTask::addRule( int startT, int endT, int startS, int endS, int count // context (words to left and right) if (m_options.flexScoreFlag) { - rule.sourceContextLeft = startS == 0 ? "<s>" : m_sentence.source[startS-1]; - rule.sourceContextRight = endS+1 == m_sentence.source.size() ? "<s>" : m_sentence.source[endS+1]; - rule.targetContextLeft = startT == 0 ? "<s>" : m_sentence.target[startT-1]; - rule.targetContextRight = endT+1 == m_sentence.target.size() ? "<s>" : m_sentence.target[endT+1]; + rule.sourceContextLeft = startS == 0 ? "<s>" : m_sentence.source[startS-1]; + rule.sourceContextRight = endS+1 == m_sentence.source.size() ? "<s>" : m_sentence.source[endS+1]; + rule.targetContextLeft = startT == 0 ? "<s>" : m_sentence.target[startT-1]; + rule.targetContextRight = endT+1 == m_sentence.target.size() ? "<s>" : m_sentence.target[endT+1]; } rule.alignment.erase(rule.alignment.size()-1); @@ -1084,33 +1083,33 @@ void ExtractTask::writeRulesToFile() } if (m_options.flexScoreFlag) { - for(int iContext=0;iContext<2;iContext++){ - outContext << rule->source << " ||| " - << rule->target << " ||| " - << rule->alignment << " ||| "; - iContext ? outContext << "< " << rule->sourceContextLeft << "\n" : outContext << "> " << rule->sourceContextRight << "\n"; - - if (!m_options.onlyDirectFlag) { - outContextInv << rule->target << " ||| " - << rule->source << " ||| " - << rule->alignmentInv << " ||| "; - iContext ? outContextInv << "< " << rule->targetContextLeft << "\n" : outContextInv << "> " << rule->targetContextRight << "\n"; - } + for(int iContext=0; iContext<2; iContext++) { + outContext << rule->source << " ||| " + << rule->target << " ||| " + << rule->alignment << " ||| "; + iContext ? outContext << "< " << rule->sourceContextLeft << "\n" : outContext << "> " << rule->sourceContextRight << "\n"; + + if (!m_options.onlyDirectFlag) { + outContextInv << rule->target << " ||| " + << rule->source << " ||| " + << rule->alignmentInv << " ||| "; + iContext ? outContextInv << "< " << rule->targetContextLeft << "\n" : outContextInv << "> " << rule->targetContextRight << "\n"; } + } - if (rule->sourceHoleString != "") { - outContext << rule->source << " ||| " - << rule->target << " ||| " - << rule->alignment << " ||| v " - << rule->sourceHoleString << "\n"; - } + if (rule->sourceHoleString != "") { + outContext << rule->source << " ||| " + << rule->target << " ||| " + << rule->alignment << " ||| v " + << rule->sourceHoleString << "\n"; + } - if (!m_options.onlyDirectFlag and rule->targetHoleString != "") { - outContextInv << rule->target << " ||| " - << rule->source << " ||| " - << rule->alignmentInv << " ||| v " - << rule->targetHoleString << "\n"; - } + if (!m_options.onlyDirectFlag and rule->targetHoleString != "") { + outContextInv << rule->target << " ||| " + << rule->source << " ||| " + << rule->alignmentInv << " ||| v " + << rule->targetHoleString << "\n"; + } } } m_extractFile << out.str(); diff --git a/scripts/other/beautify.perl b/scripts/other/beautify.perl index 78864244b..bee7758f2 100755 --- a/scripts/other/beautify.perl +++ b/scripts/other/beautify.perl @@ -39,6 +39,7 @@ sub Beautify($) next if ($name eq "randlm"); next if ($name eq "srilm"); next if ($name eq "irstlm"); + next if ($name eq "UG"); $name = $path ."/" .$name; if (-d $name) { |