diff options
author | heafield <heafield@1f5c12ca-751b-0410-a591-d2e778427230> | 2011-10-10 15:15:13 +0400 |
---|---|---|
committer | heafield <heafield@1f5c12ca-751b-0410-a591-d2e778427230> | 2011-10-10 15:15:13 +0400 |
commit | 5a0d84da9a524277d045c85aecb601754cabee70 (patch) | |
tree | 2c74828f732cbdfe21d3bde996a0d6566fe719fd /moses | |
parent | 235dda25e7eb5cb4619a8c2a88ada0cafcb8d13c (diff) |
Move LanguageModelChartState into LanguageModelImplementation in preparation for moving responsibility for boundary word tracking
from ChartHypothesis to LanguageModelChartState.
git-svn-id: https://mosesdecoder.svn.sourceforge.net/svnroot/mosesdecoder/trunk@4316 1f5c12ca-751b-0410-a591-d2e778427230
Diffstat (limited to 'moses')
-rw-r--r-- | moses/src/LanguageModel.cpp | 1 | ||||
-rw-r--r-- | moses/src/LanguageModelChartState.cpp | 49 | ||||
-rw-r--r-- | moses/src/LanguageModelChartState.h | 60 | ||||
-rw-r--r-- | moses/src/LanguageModelImplementation.cpp | 55 | ||||
-rw-r--r-- | moses/src/Makefile.am | 2 |
5 files changed, 54 insertions, 113 deletions
diff --git a/moses/src/LanguageModel.cpp b/moses/src/LanguageModel.cpp index 0c0bd423b..cdad5a236 100644 --- a/moses/src/LanguageModel.cpp +++ b/moses/src/LanguageModel.cpp @@ -28,7 +28,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA #include "FFState.h" #include "LanguageModel.h" #include "LanguageModelImplementation.h" -#include "LanguageModelChartState.h" #include "TypeDef.h" #include "Util.h" #include "Manager.h" diff --git a/moses/src/LanguageModelChartState.cpp b/moses/src/LanguageModelChartState.cpp deleted file mode 100644 index b7fb2849e..000000000 --- a/moses/src/LanguageModelChartState.cpp +++ /dev/null @@ -1,49 +0,0 @@ -// -// LanguageModelChartState.cpp -// moses -// -// Created by Hieu Hoang on 06/09/2011. -// Copyright 2011 __MyCompanyName__. All rights reserved. -// - -#include "LanguageModelChartState.h" -#include "ChartHypothesis.h" -#include "ChartManager.h" - -namespace Moses -{ - -int LanguageModelChartState::Compare(const FFState& o) const -{ - const LanguageModelChartState &other = - dynamic_cast<const LanguageModelChartState &>( o ); - - // prefix - if (m_hypo->GetCurrSourceRange().GetStartPos() > 0) // not for "<s> ..." - { - int ret = m_hypo->GetPrefix().Compare(other.GetHypothesis()->GetPrefix()); - if (ret != 0) - return ret; - } - - // suffix - size_t inputSize = m_hypo->GetManager().GetSource().GetSize(); - if (m_hypo->GetCurrSourceRange().GetEndPos() < inputSize - 1)// not for "... </s>" - { - int ret = other.GetRightContext()->Compare( *m_lmRightContext ); - if (ret != 0) - return ret; - } - - // size_t inputSize = m_hypo->GetManager().GetSource().GetSize(); - // if (m_hypo->GetCurrSourceRange().GetEndPos() < inputSize - 1) - // { - // int ret2 = m_hypo->GetSuffix().Compare(other.GetHypothesis()->GetSuffix()); - // if (ret != 0) - // return ret; - // } - - return 0; -} - -} // namespace diff --git a/moses/src/LanguageModelChartState.h b/moses/src/LanguageModelChartState.h deleted file mode 100644 index 2f827510c..000000000 --- a/moses/src/LanguageModelChartState.h +++ /dev/null @@ -1,60 +0,0 @@ -// $Id$ - -/*********************************************************************** -Moses - statistical machine translation system -Copyright (C) 2006-2011 University of Edinburgh - -This library is free software; you can redistribute it and/or -modify it under the terms of the GNU Lesser General Public -License as published by the Free Software Foundation; either -version 2.1 of the License, or (at your option) any later version. - -This library is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -Lesser General Public License for more details. - -You should have received a copy of the GNU Lesser General Public -License along with this library; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -***********************************************************************/ - -#pragma once - -#include "FFState.h" - -namespace Moses -{ - -class ChartHypothesis; -class Phrase; - -//! Abstract class for lexical reordering model states -class LanguageModelChartState : public FFState -{ -private: - float m_prefixScore; - FFState* m_lmRightContext; - const ChartHypothesis *m_hypo; - -public: - LanguageModelChartState(float prefixScore, - FFState *lmRightContext, - const ChartHypothesis &hypo) - :m_prefixScore(prefixScore) - ,m_lmRightContext(lmRightContext) - ,m_hypo(&hypo) - {} - - ~LanguageModelChartState() { - delete m_lmRightContext; - } - - float GetPrefixScore() const { return m_prefixScore; } - FFState* GetRightContext() const { return m_lmRightContext; } - const ChartHypothesis* GetHypothesis() const { return m_hypo; } - - int Compare(const FFState& o) const; -}; - -} diff --git a/moses/src/LanguageModelImplementation.cpp b/moses/src/LanguageModelImplementation.cpp index fb47b7ae0..924dd0b43 100644 --- a/moses/src/LanguageModelImplementation.cpp +++ b/moses/src/LanguageModelImplementation.cpp @@ -33,7 +33,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA #include "FactorCollection.h" #include "Phrase.h" #include "StaticData.h" -#include "LanguageModelChartState.h" +#include "ChartManager.h" #include "ChartHypothesis.h" using namespace std; @@ -68,6 +68,59 @@ void LanguageModelImplementation::GetState( GetValueForgotState(contextFactor, state); } +namespace { + +// This is the FFState used by LanguageModelImplementation::EvaluateChart. +class LanguageModelChartState : public FFState +{ +private: + float m_prefixScore; + FFState* m_lmRightContext; + const ChartHypothesis *m_hypo; + +public: + LanguageModelChartState(float prefixScore, + FFState *lmRightContext, + const ChartHypothesis &hypo) + :m_prefixScore(prefixScore) + ,m_lmRightContext(lmRightContext) + ,m_hypo(&hypo) + {} + + ~LanguageModelChartState() { + delete m_lmRightContext; + } + + float GetPrefixScore() const { return m_prefixScore; } + FFState* GetRightContext() const { return m_lmRightContext; } + const ChartHypothesis* GetHypothesis() const { return m_hypo; } + + int Compare(const FFState& o) const { + const LanguageModelChartState &other = + dynamic_cast<const LanguageModelChartState &>( o ); + + // prefix + if (m_hypo->GetCurrSourceRange().GetStartPos() > 0) // not for "<s> ..." + { + int ret = m_hypo->GetPrefix().Compare(other.GetHypothesis()->GetPrefix()); + if (ret != 0) + return ret; + } + + // suffix + size_t inputSize = m_hypo->GetManager().GetSource().GetSize(); + if (m_hypo->GetCurrSourceRange().GetEndPos() < inputSize - 1)// not for "... </s>" + { + int ret = other.GetRightContext()->Compare( *m_lmRightContext ); + if (ret != 0) + return ret; + } + return 0; + } +}; + +} // namespace + FFState* LanguageModelImplementation::EvaluateChart(const ChartHypothesis& hypo, int featureID, ScoreComponentCollection* out, const LanguageModel *scorer) const { // data structure for factored context phrase (history and predicted word) vector<const Word*> contextFactor; diff --git a/moses/src/Makefile.am b/moses/src/Makefile.am index f0819475a..36179dc18 100644 --- a/moses/src/Makefile.am +++ b/moses/src/Makefile.am @@ -59,7 +59,6 @@ libmoses_la_HEADERS = \ LMList.h \ LVoc.h \ LanguageModel.h \ - LanguageModelChartState.h \ LanguageModelJoint.h \ LanguageModelFactory.h \ LanguageModelImplementation.h \ @@ -222,7 +221,6 @@ libmoses_la_SOURCES = \ LMList.cpp \ LVoc.cpp \ LanguageModel.cpp \ - LanguageModelChartState.cpp \ LanguageModelFactory.cpp \ LanguageModelImplementation.cpp \ LanguageModelInternal.cpp \ |