From 1cbe245919fc4bfaf927831743a6816ec402335c Mon Sep 17 00:00:00 2001 From: phkoehn Date: Fri, 11 Mar 2011 13:08:43 +0000 Subject: [PATCH] re-organized syntax code for clarity - part I git-svn-id: https://mosesdecoder.svn.sourceforge.net/svnroot/mosesdecoder/trunk@3924 1f5c12ca-751b-0410-a591-d2e778427230 --- Makefile.am | 2 +- configure.in | 2 +- moses-chart-cmd/src/IOWrapper.cpp | 49 ++- moses-chart-cmd/src/IOWrapper.h | 18 +- moses-chart-cmd/src/Main.cpp | 16 +- moses-chart-cmd/src/Makefile.am | 4 +- moses-chart-cmd/src/TranslationAnalysis.h | 2 +- moses-chart/moses-chart.vcproj | 262 --------------- .../moses-chart.xcodeproj/project.pbxproj | 298 ------------------ moses-chart/src/Makefile.am | 20 -- moses/src/CellCollection.h | 2 +- {moses-chart => moses}/src/ChartCell.cpp | 89 +++--- {moses-chart => moses}/src/ChartCell.h | 37 +-- .../src/ChartCellCollection.cpp | 8 +- .../src/ChartCellCollection.h | 17 +- .../src/ChartHypothesis.cpp | 86 ++--- {moses-chart => moses}/src/ChartHypothesis.h | 58 ++-- .../src/ChartHypothesisCollection.cpp | 64 ++-- .../src/ChartHypothesisCollection.h | 33 +- {moses-chart => moses}/src/ChartManager.cpp | 34 +- {moses-chart => moses}/src/ChartManager.h | 30 +- moses/src/ChartRuleLookupManagerMemory.cpp | 74 ++--- moses/src/ChartRuleLookupManagerMemory.h | 10 +- moses/src/ChartRuleLookupManagerOnDisk.cpp | 78 ++--- moses/src/ChartRuleLookupManagerOnDisk.h | 2 +- .../src/ChartTranslationOptionCollection.cpp | 40 +-- .../src/ChartTranslationOptionCollection.h | 22 +- moses/src/ChartTranslationOptionList.cpp | 2 +- .../src/ChartTrellisNode.cpp | 42 +-- {moses-chart => moses}/src/ChartTrellisNode.h | 33 +- .../src/ChartTrellisPath.cpp | 50 +-- {moses-chart => moses}/src/ChartTrellisPath.h | 36 +-- .../src/ChartTrellisPathCollection.cpp | 10 +- .../src/ChartTrellisPathCollection.h | 20 +- .../src/ChartTrellisPathList.cpp | 6 +- .../src/ChartTrellisPathList.h | 12 +- {moses-chart => moses}/src/Cube.cpp | 4 +- {moses-chart => moses}/src/Cube.h | 2 +- moses/src/DotChart.cpp | 12 +- moses/src/DotChart.h | 44 +-- moses/src/DotChartOnDisk.cpp | 18 +- moses/src/DotChartOnDisk.h | 62 ++-- moses/src/Makefile.am | 24 ++ moses/src/PhraseDictionaryOnDisk.h | 2 +- moses/src/PhraseDictionarySCFG.cpp | 2 +- moses/src/PhraseDictionarySCFG.h | 4 +- {moses-chart => moses}/src/QueueEntry.cpp | 25 +- {moses-chart => moses}/src/QueueEntry.h | 21 +- moses/src/WordConsumed.h | 2 +- 49 files changed, 593 insertions(+), 1197 deletions(-) delete mode 100644 moses-chart/moses-chart.vcproj delete mode 100644 moses-chart/moses-chart.xcodeproj/project.pbxproj delete mode 100644 moses-chart/src/Makefile.am rename {moses-chart => moses}/src/ChartCell.cpp (65%) rename {moses-chart => moses}/src/ChartCell.h (73%) rename {moses-chart => moses}/src/ChartCellCollection.cpp (93%) rename {moses-chart => moses}/src/ChartCellCollection.h (82%) rename {moses-chart => moses}/src/ChartHypothesis.cpp (85%) rename {moses-chart => moses}/src/ChartHypothesis.h (73%) rename {moses-chart => moses}/src/ChartHypothesisCollection.cpp (81%) rename {moses-chart => moses}/src/ChartHypothesisCollection.h (79%) rename {moses-chart => moses}/src/ChartManager.cpp (87%) rename {moses-chart => moses}/src/ChartManager.h (75%) rename {moses-chart => moses}/src/ChartTranslationOptionCollection.cpp (88%) rename {moses-chart => moses}/src/ChartTranslationOptionCollection.h (86%) rename {moses-chart => moses}/src/ChartTrellisNode.cpp (71%) rename {moses-chart => moses}/src/ChartTrellisNode.h (68%) rename {moses-chart => moses}/src/ChartTrellisPath.cpp (63%) rename {moses-chart => moses}/src/ChartTrellisPath.h (66%) rename {moses-chart => moses}/src/ChartTrellisPathCollection.cpp (87%) rename {moses-chart => moses}/src/ChartTrellisPathCollection.h (75%) rename {moses-chart => moses}/src/ChartTrellisPathList.cpp (92%) rename {moses-chart => moses}/src/ChartTrellisPathList.h (88%) rename {moses-chart => moses}/src/Cube.cpp (96%) rename {moses-chart => moses}/src/Cube.h (99%) rename {moses-chart => moses}/src/QueueEntry.cpp (88%) rename {moses-chart => moses}/src/QueueEntry.h (88%) diff --git a/Makefile.am b/Makefile.am index d4207a43c..bf75e0d88 100644 --- a/Makefile.am +++ b/Makefile.am @@ -11,4 +11,4 @@ endif if WITH_SERVER SERVER = server endif -SUBDIRS = kenlm moses/src moses-chart/src OnDiskPt/src moses-cmd/src misc moses-chart-cmd/src CreateOnDisk/src $(MERT) $(SERVER) +SUBDIRS = kenlm moses/src OnDiskPt/src moses-cmd/src misc moses-chart-cmd/src CreateOnDisk/src $(MERT) $(SERVER) diff --git a/configure.in b/configure.in index 156475a4f..8778fa91a 100644 --- a/configure.in +++ b/configure.in @@ -281,6 +281,6 @@ fi LIBS="$LIBS -lz" -AC_CONFIG_FILES(Makefile OnDiskPt/src/Makefile moses/src/Makefile moses-chart/src/Makefile moses-cmd/src/Makefile moses-chart-cmd/src/Makefile misc/Makefile mert/Makefile server/Makefile CreateOnDisk/src/Makefile kenlm/Makefile) +AC_CONFIG_FILES(Makefile OnDiskPt/src/Makefile moses/src/Makefile moses-cmd/src/Makefile moses-chart-cmd/src/Makefile misc/Makefile mert/Makefile server/Makefile CreateOnDisk/src/Makefile kenlm/Makefile) AC_OUTPUT() diff --git a/moses-chart-cmd/src/IOWrapper.cpp b/moses-chart-cmd/src/IOWrapper.cpp index d8cb918dd..39498104b 100644 --- a/moses-chart-cmd/src/IOWrapper.cpp +++ b/moses-chart-cmd/src/IOWrapper.cpp @@ -41,12 +41,11 @@ POSSIBILITY OF SUCH DAMAGE. #include "DummyScoreProducers.h" #include "InputFileStream.h" #include "PhraseDictionary.h" -#include "../../moses-chart/src/ChartTrellisPathList.h" -#include "../../moses-chart/src/ChartTrellisPath.h" +#include "ChartTrellisPathList.h" +#include "ChartTrellisPath.h" using namespace std; using namespace Moses; -using namespace MosesChart; IOWrapper::IOWrapper(const std::vector &inputFactorOrder , const std::vector &outputFactorOrder @@ -163,30 +162,30 @@ void OutputSurface(std::ostream &out, const Phrase &phrase, const std::vector &outputFactorOrder +void OutputSurface(std::ostream &out, const ChartHypothesis *hypo, const std::vector &outputFactorOrder ,bool reportSegmentation, bool reportAllFactors) { if ( hypo != NULL) { //OutputSurface(out, hypo->GetCurrTargetPhrase(), outputFactorOrder, reportAllFactors); - const vector &prevHypos = hypo->GetPrevHypos(); + const vector &prevHypos = hypo->GetPrevHypos(); - vector::const_iterator iter; + vector::const_iterator iter; for (iter = prevHypos.begin(); iter != prevHypos.end(); ++iter) { - const MosesChart::Hypothesis *prevHypo = *iter; + const ChartHypothesis *prevHypo = *iter; OutputSurface(out, prevHypo, outputFactorOrder, reportSegmentation, reportAllFactors); } } } -void IOWrapper::Backtrack(const MosesChart::Hypothesis *hypo) +void IOWrapper::Backtrack(const ChartHypothesis *hypo) { - const vector &prevHypos = hypo->GetPrevHypos(); + const vector &prevHypos = hypo->GetPrevHypos(); - vector::const_iterator iter; + vector::const_iterator iter; for (iter = prevHypos.begin(); iter != prevHypos.end(); ++iter) { - const MosesChart::Hypothesis *prevHypo = *iter; + const ChartHypothesis *prevHypo = *iter; VERBOSE(3,prevHypo->GetId() << " <= "); Backtrack(prevHypo); @@ -201,7 +200,7 @@ void IOWrapper::OutputBestHypo(const std::vector& mbrBestHypo, l } } /* -void OutputInput(std::vector& map, const MosesChart::Hypothesis* hypo) +void OutputInput(std::vector& map, const ChartHypothesis* hypo) { if (hypo->GetPrevHypos()) { @@ -210,7 +209,7 @@ void OutputInput(std::vector& map, const MosesChart::Hypothesis* } } -void OutputInput(std::ostream& os, const MosesChart::Hypothesis* hypo) +void OutputInput(std::ostream& os, const ChartHypothesis* hypo) { size_t len = StaticData::Instance().GetInput()->GetSize(); std::vector inp_phrases(len, 0); @@ -220,7 +219,7 @@ void OutputInput(std::ostream& os, const MosesChart::Hypothesis* hypo) } */ -void OutputTranslationOptions(std::ostream &out, const MosesChart::Hypothesis *hypo, long translationId) +void OutputTranslationOptions(std::ostream &out, const ChartHypothesis *hypo, long translationId) { // recursive if (hypo != NULL) { @@ -229,16 +228,16 @@ void OutputTranslationOptions(std::ostream &out, const MosesChart::Hypothesis *h << endl; } - const std::vector &prevHypos = hypo->GetPrevHypos(); - std::vector::const_iterator iter; + const std::vector &prevHypos = hypo->GetPrevHypos(); + std::vector::const_iterator iter; for (iter = prevHypos.begin(); iter != prevHypos.end(); ++iter) { - const MosesChart::Hypothesis *prevHypo = *iter; + const ChartHypothesis *prevHypo = *iter; OutputTranslationOptions(out, prevHypo, translationId); } } void IOWrapper::OutputDetailedTranslationReport( - const MosesChart::Hypothesis *hypo, + const ChartHypothesis *hypo, long translationId) { if (hypo == NULL) { @@ -250,7 +249,7 @@ void IOWrapper::OutputDetailedTranslationReport( m_detailOutputCollector->Write(translationId, out.str()); } -void IOWrapper::OutputBestHypo(const MosesChart::Hypothesis *hypo, long translationId, bool /* reportSegmentation */, bool /* reportAllFactors */) +void IOWrapper::OutputBestHypo(const ChartHypothesis *hypo, long translationId, bool /* reportSegmentation */, bool /* reportAllFactors */) { std::ostringstream out; IOWrapper::FixPrecision(out); @@ -262,7 +261,7 @@ void IOWrapper::OutputBestHypo(const MosesChart::Hypothesis *hypo, long translat if (StaticData::Instance().GetOutputHypoScore()) { out << hypo->GetTotalScore() << " " - << MosesChart::Hypothesis::GetHypoCount() << " "; + << ChartHypothesis::GetHypoCount() << " "; } if (!m_surpressSingleBestOutput) { @@ -296,7 +295,7 @@ void IOWrapper::OutputBestHypo(const MosesChart::Hypothesis *hypo, long translat } } -void IOWrapper::OutputNBestList(const MosesChart::TrellisPathList &nBestList, const MosesChart::Hypothesis *bestHypo, const TranslationSystem* system, long translationId) +void IOWrapper::OutputNBestList(const ChartTrellisPathList &nBestList, const ChartHypothesis *bestHypo, const TranslationSystem* system, long translationId) { std::ostringstream out; @@ -310,7 +309,7 @@ void IOWrapper::OutputNBestList(const MosesChart::TrellisPathList &nBestList, co if (StaticData::Instance().GetOutputHypoScore()) { if (bestHypo != NULL) { out << bestHypo->GetTotalScore() << " " - << MosesChart::Hypothesis::GetHypoCount() << " "; + << ChartHypothesis::GetHypoCount() << " "; } else { out << "0 "; } @@ -320,9 +319,9 @@ void IOWrapper::OutputNBestList(const MosesChart::TrellisPathList &nBestList, co bool labeledOutput = StaticData::Instance().IsLabeledNBestList(); //bool includeAlignment = StaticData::Instance().NBestIncludesAlignment(); - MosesChart::TrellisPathList::const_iterator iter; + ChartTrellisPathList::const_iterator iter; for (iter = nBestList.begin() ; iter != nBestList.end() ; ++iter) { - const MosesChart::TrellisPath &path = **iter; + const ChartTrellisPath &path = **iter; //cerr << path << endl << endl; Moses::Phrase outputPhrase = path.GetOutputPhrase(); @@ -431,7 +430,7 @@ void IOWrapper::OutputNBestList(const MosesChart::TrellisPathList &nBestList, co *m_nBestStream << " |||"; for (int currEdge = (int)edges.size() - 2 ; currEdge >= 0 ; currEdge--) { - const MosesChart::Hypothesis &edge = *edges[currEdge]; + const ChartHypothesis &edge = *edges[currEdge]; WordsRange sourceRange = edge.GetCurrSourceWordsRange(); WordsRange targetRange = edge.GetCurrTargetWordsRange(); *m_nBestStream << " " << sourceRange.GetStartPos(); diff --git a/moses-chart-cmd/src/IOWrapper.h b/moses-chart-cmd/src/IOWrapper.h index fca183436..c606774e1 100644 --- a/moses-chart-cmd/src/IOWrapper.h +++ b/moses-chart-cmd/src/IOWrapper.h @@ -40,18 +40,14 @@ POSSIBILITY OF SUCH DAMAGE. #include "Sentence.h" #include "FactorTypeSet.h" #include "TranslationSystem.h" -#include "TrellisPathList.h" +#include "ChartTrellisPathList.h" #include "OutputCollector.h" -#include "../../moses-chart/src/ChartHypothesis.h" +#include "ChartHypothesis.h" namespace Moses { class FactorCollection; -} - -namespace MosesChart -{ -class TrellisPathList; +class ChartTrellisPathList; } class IOWrapper @@ -83,11 +79,11 @@ public: ~IOWrapper(); Moses::InputType* GetInput(Moses::InputType *inputType); - void OutputBestHypo(const MosesChart::Hypothesis *hypo, long translationId, bool reportSegmentation, bool reportAllFactors); + void OutputBestHypo(const Moses::ChartHypothesis *hypo, long translationId, bool reportSegmentation, bool reportAllFactors); void OutputBestHypo(const std::vector& mbrBestHypo, long translationId, bool reportSegmentation, bool reportAllFactors); - void OutputNBestList(const MosesChart::TrellisPathList &nBestList, const MosesChart::Hypothesis *bestHypo, const Moses::TranslationSystem* system, long translationId); - void OutputDetailedTranslationReport(const MosesChart::Hypothesis *hypo, long translationId); - void Backtrack(const MosesChart::Hypothesis *hypo); + void OutputNBestList(const Moses::ChartTrellisPathList &nBestList, const Moses::ChartHypothesis *bestHypo, const Moses::TranslationSystem* system, long translationId); + void OutputDetailedTranslationReport(const Moses::ChartHypothesis *hypo, long translationId); + void Backtrack(const Moses::ChartHypothesis *hypo); void ResetTranslationId() { m_translationId = 0; diff --git a/moses-chart-cmd/src/Main.cpp b/moses-chart-cmd/src/Main.cpp index 25da8b5ba..92490f58f 100644 --- a/moses-chart-cmd/src/Main.cpp +++ b/moses-chart-cmd/src/Main.cpp @@ -39,12 +39,10 @@ POSSIBILITY OF SUCH DAMAGE. #include #include "Main.h" -#include "TrellisPath.h" #include "FactorCollection.h" #include "Manager.h" #include "Phrase.h" #include "Util.h" -#include "TrellisPathList.h" #include "Timer.h" #include "IOWrapper.h" #include "Sentence.h" @@ -54,9 +52,10 @@ POSSIBILITY OF SUCH DAMAGE. #include "TranslationAnalysis.h" #include "mbr.h" #include "ThreadPool.h" -#include "../../moses-chart/src/ChartManager.h" -#include "../../moses-chart/src/ChartHypothesis.h" -#include "../../moses-chart/src/ChartTrellisPathList.h" +#include "ChartManager.h" +#include "ChartHypothesis.h" +#include "ChartTrellisPath.h" +#include "ChartTrellisPathList.h" #if HAVE_CONFIG_H #include "config.h" @@ -67,7 +66,6 @@ POSSIBILITY OF SUCH DAMAGE. using namespace std; using namespace Moses; -using namespace MosesChart; /** * Translates a sentence. @@ -91,13 +89,13 @@ public: VERBOSE(2,"\nTRANSLATING(" << lineNumber << "): " << *m_source); - MosesChart::Manager manager(*m_source, &system); + ChartManager manager(*m_source, &system); manager.ProcessSentence(); assert(!staticData.UseMBR()); // 1-best - const MosesChart::Hypothesis *bestHypo = manager.GetBestHypothesis(); + const ChartHypothesis *bestHypo = manager.GetBestHypothesis(); m_ioWrapper.OutputBestHypo(bestHypo, lineNumber, staticData.GetReportSegmentation(), staticData.GetReportAllFactors()); @@ -113,7 +111,7 @@ public: size_t nBestSize = staticData.GetNBestSize(); if (nBestSize > 0) { VERBOSE(2,"WRITING " << nBestSize << " TRANSLATION ALTERNATIVES TO " << staticData.GetNBestFilePath() << endl); - MosesChart::TrellisPathList nBestList; + ChartTrellisPathList nBestList; manager.CalcNBest(nBestSize, nBestList,staticData.GetDistinctNBest()); m_ioWrapper.OutputNBestList(nBestList, bestHypo, &system, lineNumber); IFVERBOSE(2) { diff --git a/moses-chart-cmd/src/Makefile.am b/moses-chart-cmd/src/Makefile.am index bab006ca7..b6e7cc4ff 100644 --- a/moses-chart-cmd/src/Makefile.am +++ b/moses-chart-cmd/src/Makefile.am @@ -2,8 +2,8 @@ bin_PROGRAMS = moses_chart moses_chart_SOURCES = Main.cpp mbr.cpp IOWrapper.cpp TranslationAnalysis.cpp AM_CPPFLAGS = -W -Wall -ffor-scope -D_FILE_OFFSET_BITS=64 -D_LARGE_FILES -DUSE_HYPO_POOL -I$(top_srcdir)/moses/src $(BOOST_CPPFLAGS) -moses_chart_LDADD = -L$(top_srcdir)/moses/src -L$(top_srcdir)/moses-chart/src -L$(top_srcdir)/OnDiskPt/src -lmoses -lmoses-chart -lOnDiskPt @KENLM_LDFLAGS@ $(BOOST_THREAD_LDFLAGS) $(BOOST_THREAD_LIBS) -moses_chart_DEPENDENCIES = $(top_srcdir)/moses/src/libmoses.la $(top_srcdir)/moses-chart/src/libmoses-chart.a $(top_srcdir)/OnDiskPt/src/libOnDiskPt.a @KENLM_DEPS@ +moses_chart_LDADD = -L$(top_srcdir)/moses/src -L$(top_srcdir)/OnDiskPt/src -lmoses -lOnDiskPt @KENLM_LDFLAGS@ $(BOOST_THREAD_LDFLAGS) $(BOOST_THREAD_LIBS) +moses_chart_DEPENDENCIES = $(top_srcdir)/moses/src/libmoses.la $(top_srcdir)/OnDiskPt/src/libOnDiskPt.a @KENLM_DEPS@ diff --git a/moses-chart-cmd/src/TranslationAnalysis.h b/moses-chart-cmd/src/TranslationAnalysis.h index 426158a42..1291548f8 100644 --- a/moses-chart-cmd/src/TranslationAnalysis.h +++ b/moses-chart-cmd/src/TranslationAnalysis.h @@ -8,7 +8,7 @@ #define _TRANSLATION_ANALYSIS_H_ #include -#include "Hypothesis.h" +#include "ChartHypothesis.h" namespace TranslationAnalysis { diff --git a/moses-chart/moses-chart.vcproj b/moses-chart/moses-chart.vcproj deleted file mode 100644 index 73127014d..000000000 --- a/moses-chart/moses-chart.vcproj +++ /dev/null @@ -1,262 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/moses-chart/moses-chart.xcodeproj/project.pbxproj b/moses-chart/moses-chart.xcodeproj/project.pbxproj deleted file mode 100644 index 090f5cb36..000000000 --- a/moses-chart/moses-chart.xcodeproj/project.pbxproj +++ /dev/null @@ -1,298 +0,0 @@ -// !$*UTF8*$! -{ - archiveVersion = 1; - classes = { - }; - objectVersion = 45; - objects = { - -/* Begin PBXBuildFile section */ - 1ED4FBB511BDBC9F004E826A /* ChartCell.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1ED4FB9611BDBC9F004E826A /* ChartCell.cpp */; }; - 1ED4FBB611BDBC9F004E826A /* ChartCell.h in Headers */ = {isa = PBXBuildFile; fileRef = 1ED4FB9711BDBC9F004E826A /* ChartCell.h */; }; - 1ED4FBB711BDBC9F004E826A /* ChartCellCollection.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1ED4FB9811BDBC9F004E826A /* ChartCellCollection.cpp */; }; - 1ED4FBB811BDBC9F004E826A /* ChartCellCollection.h in Headers */ = {isa = PBXBuildFile; fileRef = 1ED4FB9911BDBC9F004E826A /* ChartCellCollection.h */; }; - 1ED4FBB911BDBC9F004E826A /* ChartHypothesis.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1ED4FB9A11BDBC9F004E826A /* ChartHypothesis.cpp */; }; - 1ED4FBBA11BDBC9F004E826A /* ChartHypothesis.h in Headers */ = {isa = PBXBuildFile; fileRef = 1ED4FB9B11BDBC9F004E826A /* ChartHypothesis.h */; }; - 1ED4FBBB11BDBC9F004E826A /* ChartHypothesisCollection.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1ED4FB9C11BDBC9F004E826A /* ChartHypothesisCollection.cpp */; }; - 1ED4FBBC11BDBC9F004E826A /* ChartHypothesisCollection.h in Headers */ = {isa = PBXBuildFile; fileRef = 1ED4FB9D11BDBC9F004E826A /* ChartHypothesisCollection.h */; }; - 1ED4FBBD11BDBC9F004E826A /* ChartManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1ED4FB9E11BDBC9F004E826A /* ChartManager.cpp */; }; - 1ED4FBBE11BDBC9F004E826A /* ChartManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 1ED4FB9F11BDBC9F004E826A /* ChartManager.h */; }; - 1ED4FBC111BDBC9F004E826A /* ChartTranslationOptionCollection.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1ED4FBA211BDBC9F004E826A /* ChartTranslationOptionCollection.cpp */; }; - 1ED4FBC211BDBC9F004E826A /* ChartTranslationOptionCollection.h in Headers */ = {isa = PBXBuildFile; fileRef = 1ED4FBA311BDBC9F004E826A /* ChartTranslationOptionCollection.h */; }; - 1ED4FBC511BDBC9F004E826A /* ChartTrellisNode.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1ED4FBA611BDBC9F004E826A /* ChartTrellisNode.cpp */; }; - 1ED4FBC611BDBC9F004E826A /* ChartTrellisNode.h in Headers */ = {isa = PBXBuildFile; fileRef = 1ED4FBA711BDBC9F004E826A /* ChartTrellisNode.h */; }; - 1ED4FBC711BDBC9F004E826A /* ChartTrellisPath.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1ED4FBA811BDBC9F004E826A /* ChartTrellisPath.cpp */; }; - 1ED4FBC811BDBC9F004E826A /* ChartTrellisPath.h in Headers */ = {isa = PBXBuildFile; fileRef = 1ED4FBA911BDBC9F004E826A /* ChartTrellisPath.h */; }; - 1ED4FBC911BDBC9F004E826A /* ChartTrellisPathCollection.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1ED4FBAA11BDBC9F004E826A /* ChartTrellisPathCollection.cpp */; }; - 1ED4FBCA11BDBC9F004E826A /* ChartTrellisPathCollection.h in Headers */ = {isa = PBXBuildFile; fileRef = 1ED4FBAB11BDBC9F004E826A /* ChartTrellisPathCollection.h */; }; - 1ED4FBCB11BDBC9F004E826A /* ChartTrellisPathList.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1ED4FBAC11BDBC9F004E826A /* ChartTrellisPathList.cpp */; }; - 1ED4FBCC11BDBC9F004E826A /* ChartTrellisPathList.h in Headers */ = {isa = PBXBuildFile; fileRef = 1ED4FBAD11BDBC9F004E826A /* ChartTrellisPathList.h */; }; - 1ED4FBCD11BDBC9F004E826A /* Cube.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1ED4FBAE11BDBC9F004E826A /* Cube.cpp */; }; - 1ED4FBCE11BDBC9F004E826A /* Cube.h in Headers */ = {isa = PBXBuildFile; fileRef = 1ED4FBAF11BDBC9F004E826A /* Cube.h */; }; - 1ED4FBD011BDBC9F004E826A /* QueueEntry.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1ED4FBB311BDBC9F004E826A /* QueueEntry.cpp */; }; - 1ED4FBD111BDBC9F004E826A /* QueueEntry.h in Headers */ = {isa = PBXBuildFile; fileRef = 1ED4FBB411BDBC9F004E826A /* QueueEntry.h */; }; -/* End PBXBuildFile section */ - -/* Begin PBXFileReference section */ - 1ED4FB9611BDBC9F004E826A /* ChartCell.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ChartCell.cpp; path = src/ChartCell.cpp; sourceTree = ""; }; - 1ED4FB9711BDBC9F004E826A /* ChartCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ChartCell.h; path = src/ChartCell.h; sourceTree = ""; }; - 1ED4FB9811BDBC9F004E826A /* ChartCellCollection.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ChartCellCollection.cpp; path = src/ChartCellCollection.cpp; sourceTree = ""; }; - 1ED4FB9911BDBC9F004E826A /* ChartCellCollection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ChartCellCollection.h; path = src/ChartCellCollection.h; sourceTree = ""; }; - 1ED4FB9A11BDBC9F004E826A /* ChartHypothesis.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ChartHypothesis.cpp; path = src/ChartHypothesis.cpp; sourceTree = ""; }; - 1ED4FB9B11BDBC9F004E826A /* ChartHypothesis.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ChartHypothesis.h; path = src/ChartHypothesis.h; sourceTree = ""; }; - 1ED4FB9C11BDBC9F004E826A /* ChartHypothesisCollection.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ChartHypothesisCollection.cpp; path = src/ChartHypothesisCollection.cpp; sourceTree = ""; }; - 1ED4FB9D11BDBC9F004E826A /* ChartHypothesisCollection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ChartHypothesisCollection.h; path = src/ChartHypothesisCollection.h; sourceTree = ""; }; - 1ED4FB9E11BDBC9F004E826A /* ChartManager.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ChartManager.cpp; path = src/ChartManager.cpp; sourceTree = ""; }; - 1ED4FB9F11BDBC9F004E826A /* ChartManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ChartManager.h; path = src/ChartManager.h; sourceTree = ""; }; - 1ED4FBA211BDBC9F004E826A /* ChartTranslationOptionCollection.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ChartTranslationOptionCollection.cpp; path = src/ChartTranslationOptionCollection.cpp; sourceTree = ""; }; - 1ED4FBA311BDBC9F004E826A /* ChartTranslationOptionCollection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ChartTranslationOptionCollection.h; path = src/ChartTranslationOptionCollection.h; sourceTree = ""; }; - 1ED4FBA611BDBC9F004E826A /* ChartTrellisNode.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ChartTrellisNode.cpp; path = src/ChartTrellisNode.cpp; sourceTree = ""; }; - 1ED4FBA711BDBC9F004E826A /* ChartTrellisNode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ChartTrellisNode.h; path = src/ChartTrellisNode.h; sourceTree = ""; }; - 1ED4FBA811BDBC9F004E826A /* ChartTrellisPath.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ChartTrellisPath.cpp; path = src/ChartTrellisPath.cpp; sourceTree = ""; }; - 1ED4FBA911BDBC9F004E826A /* ChartTrellisPath.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ChartTrellisPath.h; path = src/ChartTrellisPath.h; sourceTree = ""; }; - 1ED4FBAA11BDBC9F004E826A /* ChartTrellisPathCollection.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ChartTrellisPathCollection.cpp; path = src/ChartTrellisPathCollection.cpp; sourceTree = ""; }; - 1ED4FBAB11BDBC9F004E826A /* ChartTrellisPathCollection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ChartTrellisPathCollection.h; path = src/ChartTrellisPathCollection.h; sourceTree = ""; }; - 1ED4FBAC11BDBC9F004E826A /* ChartTrellisPathList.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ChartTrellisPathList.cpp; path = src/ChartTrellisPathList.cpp; sourceTree = ""; }; - 1ED4FBAD11BDBC9F004E826A /* ChartTrellisPathList.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ChartTrellisPathList.h; path = src/ChartTrellisPathList.h; sourceTree = ""; }; - 1ED4FBAE11BDBC9F004E826A /* Cube.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Cube.cpp; path = src/Cube.cpp; sourceTree = ""; }; - 1ED4FBAF11BDBC9F004E826A /* Cube.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Cube.h; path = src/Cube.h; sourceTree = ""; }; - 1ED4FBB311BDBC9F004E826A /* QueueEntry.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = QueueEntry.cpp; path = src/QueueEntry.cpp; sourceTree = ""; }; - 1ED4FBB411BDBC9F004E826A /* QueueEntry.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = QueueEntry.h; path = src/QueueEntry.h; sourceTree = ""; }; - D2AAC046055464E500DB518D /* libmoses-chart.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libmoses-chart.a"; sourceTree = BUILT_PRODUCTS_DIR; }; -/* End PBXFileReference section */ - -/* Begin PBXFrameworksBuildPhase section */ - D289987405E68DCB004EDB86 /* Frameworks */ = { - isa = PBXFrameworksBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXFrameworksBuildPhase section */ - -/* Begin PBXGroup section */ - 08FB7794FE84155DC02AAC07 /* moses-chart */ = { - isa = PBXGroup; - children = ( - 08FB7795FE84155DC02AAC07 /* Source */, - C6A0FF2B0290797F04C91782 /* Documentation */, - 1AB674ADFE9D54B511CA2CBB /* Products */, - ); - name = "moses-chart"; - sourceTree = ""; - }; - 08FB7795FE84155DC02AAC07 /* Source */ = { - isa = PBXGroup; - children = ( - 1ED4FB9611BDBC9F004E826A /* ChartCell.cpp */, - 1ED4FB9711BDBC9F004E826A /* ChartCell.h */, - 1ED4FB9811BDBC9F004E826A /* ChartCellCollection.cpp */, - 1ED4FB9911BDBC9F004E826A /* ChartCellCollection.h */, - 1ED4FB9A11BDBC9F004E826A /* ChartHypothesis.cpp */, - 1ED4FB9B11BDBC9F004E826A /* ChartHypothesis.h */, - 1ED4FB9C11BDBC9F004E826A /* ChartHypothesisCollection.cpp */, - 1ED4FB9D11BDBC9F004E826A /* ChartHypothesisCollection.h */, - 1ED4FB9E11BDBC9F004E826A /* ChartManager.cpp */, - 1ED4FB9F11BDBC9F004E826A /* ChartManager.h */, - 1ED4FBA211BDBC9F004E826A /* ChartTranslationOptionCollection.cpp */, - 1ED4FBA311BDBC9F004E826A /* ChartTranslationOptionCollection.h */, - 1ED4FBA611BDBC9F004E826A /* ChartTrellisNode.cpp */, - 1ED4FBA711BDBC9F004E826A /* ChartTrellisNode.h */, - 1ED4FBA811BDBC9F004E826A /* ChartTrellisPath.cpp */, - 1ED4FBA911BDBC9F004E826A /* ChartTrellisPath.h */, - 1ED4FBAA11BDBC9F004E826A /* ChartTrellisPathCollection.cpp */, - 1ED4FBAB11BDBC9F004E826A /* ChartTrellisPathCollection.h */, - 1ED4FBAC11BDBC9F004E826A /* ChartTrellisPathList.cpp */, - 1ED4FBAD11BDBC9F004E826A /* ChartTrellisPathList.h */, - 1ED4FBAE11BDBC9F004E826A /* Cube.cpp */, - 1ED4FBAF11BDBC9F004E826A /* Cube.h */, - 1ED4FBB311BDBC9F004E826A /* QueueEntry.cpp */, - 1ED4FBB411BDBC9F004E826A /* QueueEntry.h */, - ); - name = Source; - sourceTree = ""; - }; - 1AB674ADFE9D54B511CA2CBB /* Products */ = { - isa = PBXGroup; - children = ( - D2AAC046055464E500DB518D /* libmoses-chart.a */, - ); - name = Products; - sourceTree = ""; - }; - C6A0FF2B0290797F04C91782 /* Documentation */ = { - isa = PBXGroup; - children = ( - ); - name = Documentation; - sourceTree = ""; - }; -/* End PBXGroup section */ - -/* Begin PBXHeadersBuildPhase section */ - D2AAC043055464E500DB518D /* Headers */ = { - isa = PBXHeadersBuildPhase; - buildActionMask = 2147483647; - files = ( - 1ED4FBB611BDBC9F004E826A /* ChartCell.h in Headers */, - 1ED4FBB811BDBC9F004E826A /* ChartCellCollection.h in Headers */, - 1ED4FBBA11BDBC9F004E826A /* ChartHypothesis.h in Headers */, - 1ED4FBBC11BDBC9F004E826A /* ChartHypothesisCollection.h in Headers */, - 1ED4FBBE11BDBC9F004E826A /* ChartManager.h in Headers */, - 1ED4FBC211BDBC9F004E826A /* ChartTranslationOptionCollection.h in Headers */, - 1ED4FBC611BDBC9F004E826A /* ChartTrellisNode.h in Headers */, - 1ED4FBC811BDBC9F004E826A /* ChartTrellisPath.h in Headers */, - 1ED4FBCA11BDBC9F004E826A /* ChartTrellisPathCollection.h in Headers */, - 1ED4FBCC11BDBC9F004E826A /* ChartTrellisPathList.h in Headers */, - 1ED4FBCE11BDBC9F004E826A /* Cube.h in Headers */, - 1ED4FBD111BDBC9F004E826A /* QueueEntry.h in Headers */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXHeadersBuildPhase section */ - -/* Begin PBXNativeTarget section */ - D2AAC045055464E500DB518D /* moses-chart */ = { - isa = PBXNativeTarget; - buildConfigurationList = 1DEB91EB08733DB70010E9CD /* Build configuration list for PBXNativeTarget "moses-chart" */; - buildPhases = ( - D2AAC043055464E500DB518D /* Headers */, - D2AAC044055464E500DB518D /* Sources */, - D289987405E68DCB004EDB86 /* Frameworks */, - ); - buildRules = ( - ); - dependencies = ( - ); - name = "moses-chart"; - productName = "moses-chart"; - productReference = D2AAC046055464E500DB518D /* libmoses-chart.a */; - productType = "com.apple.product-type.library.static"; - }; -/* End PBXNativeTarget section */ - -/* Begin PBXProject section */ - 08FB7793FE84155DC02AAC07 /* Project object */ = { - isa = PBXProject; - buildConfigurationList = 1DEB91EF08733DB70010E9CD /* Build configuration list for PBXProject "moses-chart" */; - compatibilityVersion = "Xcode 3.1"; - developmentRegion = English; - hasScannedForEncodings = 1; - knownRegions = ( - English, - Japanese, - French, - German, - ); - mainGroup = 08FB7794FE84155DC02AAC07 /* moses-chart */; - projectDirPath = ""; - projectRoot = ""; - targets = ( - D2AAC045055464E500DB518D /* moses-chart */, - ); - }; -/* End PBXProject section */ - -/* Begin PBXSourcesBuildPhase section */ - D2AAC044055464E500DB518D /* Sources */ = { - isa = PBXSourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - 1ED4FBB511BDBC9F004E826A /* ChartCell.cpp in Sources */, - 1ED4FBB711BDBC9F004E826A /* ChartCellCollection.cpp in Sources */, - 1ED4FBB911BDBC9F004E826A /* ChartHypothesis.cpp in Sources */, - 1ED4FBBB11BDBC9F004E826A /* ChartHypothesisCollection.cpp in Sources */, - 1ED4FBBD11BDBC9F004E826A /* ChartManager.cpp in Sources */, - 1ED4FBC111BDBC9F004E826A /* ChartTranslationOptionCollection.cpp in Sources */, - 1ED4FBC511BDBC9F004E826A /* ChartTrellisNode.cpp in Sources */, - 1ED4FBC711BDBC9F004E826A /* ChartTrellisPath.cpp in Sources */, - 1ED4FBC911BDBC9F004E826A /* ChartTrellisPathCollection.cpp in Sources */, - 1ED4FBCB11BDBC9F004E826A /* ChartTrellisPathList.cpp in Sources */, - 1ED4FBCD11BDBC9F004E826A /* Cube.cpp in Sources */, - 1ED4FBD011BDBC9F004E826A /* QueueEntry.cpp in Sources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXSourcesBuildPhase section */ - -/* Begin XCBuildConfiguration section */ - 1DEB91EC08733DB70010E9CD /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - COPY_PHASE_STRIP = NO; - GCC_DYNAMIC_NO_PIC = NO; - GCC_ENABLE_FIX_AND_CONTINUE = YES; - GCC_MODEL_TUNING = G5; - GCC_OPTIMIZATION_LEVEL = 0; - INSTALL_PATH = /usr/local/lib; - PRODUCT_NAME = "moses-chart"; - }; - name = Debug; - }; - 1DEB91ED08733DB70010E9CD /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; - GCC_MODEL_TUNING = G5; - INSTALL_PATH = /usr/local/lib; - PRODUCT_NAME = "moses-chart"; - }; - name = Release; - }; - 1DEB91F008733DB70010E9CD /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - ARCHS = "$(ARCHS_STANDARD_32_64_BIT)"; - GCC_C_LANGUAGE_STANDARD = gnu99; - GCC_OPTIMIZATION_LEVEL = 0; - GCC_PREPROCESSOR_DEFINITIONS = TRACE_ENABLE; - GCC_WARN_ABOUT_RETURN_TYPE = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - ONLY_ACTIVE_ARCH = YES; - PREBINDING = NO; - SDKROOT = macosx10.6; - }; - name = Debug; - }; - 1DEB91F108733DB70010E9CD /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - ARCHS = "$(ARCHS_STANDARD_32_64_BIT)"; - GCC_C_LANGUAGE_STANDARD = gnu99; - GCC_PREPROCESSOR_DEFINITIONS = TRACE_ENABLE; - GCC_WARN_ABOUT_RETURN_TYPE = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - ONLY_ACTIVE_ARCH = YES; - PREBINDING = NO; - SDKROOT = macosx10.6; - }; - name = Release; - }; -/* End XCBuildConfiguration section */ - -/* Begin XCConfigurationList section */ - 1DEB91EB08733DB70010E9CD /* Build configuration list for PBXNativeTarget "moses-chart" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - 1DEB91EC08733DB70010E9CD /* Debug */, - 1DEB91ED08733DB70010E9CD /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; - 1DEB91EF08733DB70010E9CD /* Build configuration list for PBXProject "moses-chart" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - 1DEB91F008733DB70010E9CD /* Debug */, - 1DEB91F108733DB70010E9CD /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; -/* End XCConfigurationList section */ - }; - rootObject = 08FB7793FE84155DC02AAC07 /* Project object */; -} diff --git a/moses-chart/src/Makefile.am b/moses-chart/src/Makefile.am deleted file mode 100644 index 256a0caee..000000000 --- a/moses-chart/src/Makefile.am +++ /dev/null @@ -1,20 +0,0 @@ -lib_LIBRARIES = libmoses-chart.a -AM_CPPFLAGS = -W -Wall -ffor-scope -D_FILE_OFFSET_BITS=64 -D_LARGE_FILES $(BOOST_CPPFLAGS) -libmoses_chart_a_SOURCES = \ - ChartCell.cpp \ - ChartCellCollection.cpp \ - ChartHypothesis.cpp \ - ChartHypothesisCollection.cpp \ - ChartManager.cpp \ - ChartTranslationOptionCollection.cpp \ - ChartTrellisNode.cpp \ - ChartTrellisPath.cpp \ - ChartTrellisPathCollection.cpp \ - ChartTrellisPathList.cpp \ - Cube.cpp \ - QueueEntry.cpp - -CLEANFILES = $(BUILT_SOURCES) - - - diff --git a/moses/src/CellCollection.h b/moses/src/CellCollection.h index 9e73e00fa..6fde30ca1 100644 --- a/moses/src/CellCollection.h +++ b/moses/src/CellCollection.h @@ -34,7 +34,7 @@ class CellCollection public: virtual ~CellCollection() {} - virtual const NonTerminalSet &GetHeadwords(const Moses::WordsRange &coverage) const = 0; + virtual const NonTerminalSet &GetConstituentLabelSet(const Moses::WordsRange &coverage) const = 0; }; } diff --git a/moses-chart/src/ChartCell.cpp b/moses/src/ChartCell.cpp similarity index 65% rename from moses-chart/src/ChartCell.cpp rename to moses/src/ChartCell.cpp index 644a0bf76..fd4f61099 100644 --- a/moses-chart/src/ChartCell.cpp +++ b/moses/src/ChartCell.cpp @@ -25,11 +25,11 @@ #include "ChartCellCollection.h" #include "Cube.h" #include "QueueEntry.h" -#include "../../moses/src/WordsRange.h" -#include "../../moses/src/Util.h" -#include "../../moses/src/StaticData.h" -#include "../../moses/src/ChartTranslationOption.h" -#include "../../moses/src/ChartTranslationOptionList.h" +#include "WordsRange.h" +#include "Util.h" +#include "StaticData.h" +#include "ChartTranslationOption.h" +#include "ChartTranslationOptionList.h" using namespace std; using namespace Moses; @@ -37,12 +37,8 @@ using namespace Moses; namespace Moses { extern bool g_debug; -} -namespace MosesChart -{ - -ChartCell::ChartCell(size_t startPos, size_t endPos, Manager &manager) +ChartCell::ChartCell(size_t startPos, size_t endPos, ChartManager &manager) :m_coverage(startPos, endPos) ,m_manager(manager) { @@ -50,31 +46,37 @@ ChartCell::ChartCell(size_t startPos, size_t endPos, Manager &manager) m_nBestIsEnabled = staticData.IsNBestEnabled(); } -const HypoList &ChartCell::GetSortedHypotheses(const Moses::Word &headWord) const +/** Get all hypotheses in the cell that have the specified constituent label */ +const HypoList &ChartCell::GetSortedHypotheses(const Moses::Word &constituentLabel) const { - std::map::const_iterator - iter = m_hypoColl.find(headWord); + std::map::const_iterator + iter = m_hypoColl.find(constituentLabel); assert(iter != m_hypoColl.end()); return iter->second.GetSortedHypotheses(); } -bool ChartCell::AddHypothesis(Hypothesis *hypo) +/** Add the given hypothesis to the cell */ +bool ChartCell::AddHypothesis(ChartHypothesis *hypo) { const Word &targetLHS = hypo->GetTargetLHS(); return m_hypoColl[targetLHS].AddHypothesis(hypo, m_manager); } +/** Pruning */ void ChartCell::PruneToSize() { - std::map::iterator iter; + std::map::iterator iter; for (iter = m_hypoColl.begin(); iter != m_hypoColl.end(); ++iter) { - HypothesisCollection &coll = iter->second; + ChartHypothesisCollection &coll = iter->second; coll.PruneToSize(m_manager); } } -// decoding at span level: fill chart cell with hypotheses -// (implementation of cube pruning) +/** Decoding at span level: fill chart cell with hypotheses + * (implementation of cube pruning) + * \param transOptList list of applicable rules to create hypotheses for the cell + * \param allChartCells entire chart - needed to look up underlying hypotheses + */ void ChartCell::ProcessSentence(const ChartTranslationOptionList &transOptList , const ChartCellCollection &allChartCells) { @@ -99,41 +101,41 @@ void ChartCell::ProcessSentence(const ChartTranslationOptionList &transOptList QueueEntry *queueEntry = cube.Pop(); // create hypothesis from QueueEntry - Hypothesis *hypo = new Hypothesis(*queueEntry, m_manager); + ChartHypothesis *hypo = new ChartHypothesis(*queueEntry, m_manager); assert(hypo); hypo->CalcScore(); AddHypothesis(hypo); // add neighbors to the queue - queueEntry->CreateDeviants(cube); + queueEntry->CreateNeighbors(cube); } } void ChartCell::SortHypotheses() { // sort each mini cells & fill up target lhs list - assert(m_headWords.empty()); - std::map::iterator iter; + assert(m_constituentLabelSet.empty()); + std::map::iterator iter; for (iter = m_hypoColl.begin(); iter != m_hypoColl.end(); ++iter) { - m_headWords.insert(iter->first); + m_constituentLabelSet.insert(iter->first); - HypothesisCollection &coll = iter->second; + ChartHypothesisCollection &coll = iter->second; coll.SortHypotheses(); } } -const Hypothesis *ChartCell::GetBestHypothesis() const +/** Return the highest scoring hypothesis in the cell */ +const ChartHypothesis *ChartCell::GetBestHypothesis() const { - const Hypothesis *ret = NULL; + const ChartHypothesis *ret = NULL; float bestScore = -std::numeric_limits::infinity(); - - std::map::const_iterator iter; + std::map::const_iterator iter; for (iter = m_hypoColl.begin(); iter != m_hypoColl.end(); ++iter) { const HypoList &sortedList = iter->second.GetSortedHypotheses(); assert(sortedList.size() > 0); - const Hypothesis *hypo = sortedList[0]; + const ChartHypothesis *hypo = sortedList[0]; if (hypo->GetTotalScore() > bestScore) { bestScore = hypo->GetTotalScore(); ret = hypo; @@ -143,10 +145,11 @@ const Hypothesis *ChartCell::GetBestHypothesis() const return ret; } -bool ChartCell::HeadwordExists(const Moses::Word &headWord) const +/** Is there a hypothesis in the cell that has the specified constituent label? */ +bool ChartCell::ConstituentLabelExists(const Moses::Word &constituentLabel) const { - std::map::const_iterator iter; - iter = m_hypoColl.find(headWord); + std::map::const_iterator iter; + iter = m_hypoColl.find(constituentLabel); return (iter != m_hypoColl.end()); } @@ -155,19 +158,19 @@ void ChartCell::CleanupArcList() // only necessary if n-best calculations are enabled if (!m_nBestIsEnabled) return; - std::map::iterator iter; + std::map::iterator iter; for (iter = m_hypoColl.begin(); iter != m_hypoColl.end(); ++iter) { - HypothesisCollection &coll = iter->second; + ChartHypothesisCollection &coll = iter->second; coll.CleanupArcList(); } } void ChartCell::OutputSizes(std::ostream &out) const { - std::map::const_iterator iter; + std::map::const_iterator iter; for (iter = m_hypoColl.begin(); iter != m_hypoColl.end(); ++iter) { const Moses::Word &targetLHS = iter->first; - const HypothesisCollection &coll = iter->second; + const ChartHypothesisCollection &coll = iter->second; out << targetLHS << "=" << coll.GetSize() << " "; } @@ -176,9 +179,9 @@ void ChartCell::OutputSizes(std::ostream &out) const size_t ChartCell::GetSize() const { size_t ret = 0; - std::map::const_iterator iter; + std::map::const_iterator iter; for (iter = m_hypoColl.begin(); iter != m_hypoColl.end(); ++iter) { - const HypothesisCollection &coll = iter->second; + const ChartHypothesisCollection &coll = iter->second; ret += coll.GetSize(); } @@ -188,9 +191,9 @@ size_t ChartCell::GetSize() const void ChartCell::GetSearchGraph(long translationId, std::ostream &outputSearchGraphStream) const { - std::map::const_iterator iterOutside; + std::map::const_iterator iterOutside; for (iterOutside = m_hypoColl.begin(); iterOutside != m_hypoColl.end(); ++iterOutside) { - const HypothesisCollection &coll = iterOutside->second; + const ChartHypothesisCollection &coll = iterOutside->second; coll.GetSearchGraph(translationId, outputSearchGraphStream); } @@ -198,12 +201,12 @@ void ChartCell::GetSearchGraph(long translationId, std::ostream &outputSearchGra std::ostream& operator<<(std::ostream &out, const ChartCell &cell) { - std::map::const_iterator iterOutside; + std::map::const_iterator iterOutside; for (iterOutside = cell.m_hypoColl.begin(); iterOutside != cell.m_hypoColl.end(); ++iterOutside) { const Moses::Word &targetLHS = iterOutside->first; cerr << targetLHS << ":" << endl; - const HypothesisCollection &coll = iterOutside->second; + const ChartHypothesisCollection &coll = iterOutside->second; cerr << coll; } @@ -211,7 +214,7 @@ std::ostream& operator<<(std::ostream &out, const ChartCell &cell) ChartCell::HCType::const_iterator iter; for (iter = cell.m_hypos.begin(); iter != cell.m_hypos.end(); ++iter) { - const Hypothesis &hypo = **iter; + const ChartHypothesis &hypo = **iter; out << hypo << endl; } */ diff --git a/moses-chart/src/ChartCell.h b/moses/src/ChartCell.h similarity index 73% rename from moses-chart/src/ChartCell.h rename to moses/src/ChartCell.h index c35a54971..775b5db1d 100644 --- a/moses-chart/src/ChartCell.h +++ b/moses/src/ChartCell.h @@ -25,9 +25,9 @@ #include #include #include -#include "../../moses/src/Word.h" -#include "../../moses/src/WordsRange.h" -#include "../../moses/src/NonTerminal.h" +#include "Word.h" +#include "WordsRange.h" +#include "NonTerminal.h" #include "ChartHypothesis.h" #include "ChartHypothesisCollection.h" #include "QueueEntry.h" @@ -35,16 +35,9 @@ namespace Moses { class ChartTranslationOptionList; -} - -namespace MosesChart -{ - -class TranslationOptionCollection; -class TranslationOptionList; -class TranslationOption; +class ChartTranslationOptionCollection; class ChartCellCollection; -class Manager; +class ChartManager; class ChartCell { @@ -52,31 +45,31 @@ class ChartCell public: protected: - std::map m_hypoColl; - Moses::NonTerminalSet m_headWords; + std::map m_hypoColl; + Moses::NonTerminalSet m_constituentLabelSet; Moses::WordsRange m_coverage; bool m_nBestIsEnabled; /**< flag to determine whether to keep track of old arcs */ - Manager &m_manager; + ChartManager &m_manager; public: - ChartCell(size_t startPos, size_t endPos, Manager &manager); + ChartCell(size_t startPos, size_t endPos, ChartManager &manager); void ProcessSentence(const Moses::ChartTranslationOptionList &transOptList ,const ChartCellCollection &allChartCells); - const HypoList &GetSortedHypotheses(const Moses::Word &headWord) const; - bool AddHypothesis(Hypothesis *hypo); + const HypoList &GetSortedHypotheses(const Moses::Word &constituentLabel) const; + bool AddHypothesis(ChartHypothesis *hypo); void SortHypotheses(); void PruneToSize(); - const Hypothesis *GetBestHypothesis() const; + const ChartHypothesis *GetBestHypothesis() const; - bool HeadwordExists(const Moses::Word &headWord) const; - const Moses::NonTerminalSet &GetHeadwords() const { - return m_headWords; + bool ConstituentLabelExists(const Moses::Word &constituentLabel) const; + const Moses::NonTerminalSet &GetConstituentLabelSet() const { + return m_constituentLabelSet; } void CleanupArcList(); diff --git a/moses-chart/src/ChartCellCollection.cpp b/moses/src/ChartCellCollection.cpp similarity index 93% rename from moses-chart/src/ChartCellCollection.cpp rename to moses/src/ChartCellCollection.cpp index 1f996944e..a4bbd2214 100644 --- a/moses-chart/src/ChartCellCollection.cpp +++ b/moses/src/ChartCellCollection.cpp @@ -20,12 +20,12 @@ ***********************************************************************/ #include "ChartCellCollection.h" -#include "../../moses/src/InputType.h" -#include "../../moses/src/WordsRange.h" +#include "InputType.h" +#include "WordsRange.h" -namespace MosesChart +namespace Moses { -ChartCellCollection::ChartCellCollection(const Moses::InputType &input, Manager &manager) +ChartCellCollection::ChartCellCollection(const Moses::InputType &input, ChartManager &manager) :m_hypoStackColl(input.GetSize()) { size_t size = input.GetSize(); diff --git a/moses-chart/src/ChartCellCollection.h b/moses/src/ChartCellCollection.h similarity index 82% rename from moses-chart/src/ChartCellCollection.h rename to moses/src/ChartCellCollection.h index d9e2952fc..4a7fb7231 100644 --- a/moses-chart/src/ChartCellCollection.h +++ b/moses/src/ChartCellCollection.h @@ -21,17 +21,13 @@ #pragma once #include "ChartCell.h" -#include "../../moses/src/WordsRange.h" -#include "../../moses/src/CellCollection.h" +#include "WordsRange.h" +#include "CellCollection.h" namespace Moses { class InputType; -} - -namespace MosesChart -{ -class Manager; +class ChartManager; class ChartCellCollection : public Moses::CellCollection { @@ -43,7 +39,7 @@ protected: OuterCollType m_hypoStackColl; public: - ChartCellCollection(const Moses::InputType &input, Manager &manager); + ChartCellCollection(const Moses::InputType &input, ChartManager &manager); ~ChartCellCollection(); ChartCell &Get(const Moses::WordsRange &coverage) { @@ -53,9 +49,10 @@ public: return *m_hypoStackColl[coverage.GetStartPos()][coverage.GetEndPos() - coverage.GetStartPos()]; } - const Moses::NonTerminalSet &GetHeadwords(const Moses::WordsRange &coverage) const { + /** Return set of constituents that have hypotheses in the given span */ + const Moses::NonTerminalSet &GetConstituentLabelSet(const Moses::WordsRange &coverage) const { const ChartCell &cell = Get(coverage); - return cell.GetHeadwords(); + return cell.GetConstituentLabelSet(); } }; diff --git a/moses-chart/src/ChartHypothesis.cpp b/moses/src/ChartHypothesis.cpp similarity index 85% rename from moses-chart/src/ChartHypothesis.cpp rename to moses/src/ChartHypothesis.cpp index 7fbb10a5f..a3d878db8 100644 --- a/moses-chart/src/ChartHypothesis.cpp +++ b/moses/src/ChartHypothesis.cpp @@ -25,26 +25,26 @@ #include "QueueEntry.h" #include "ChartCell.h" #include "ChartManager.h" -#include "../../moses/src/TargetPhrase.h" -#include "../../moses/src/Phrase.h" -#include "../../moses/src/StaticData.h" -#include "../../moses/src/DummyScoreProducers.h" -#include "../../moses/src/LMList.h" -#include "../../moses/src/ChartTranslationOption.h" +#include "TargetPhrase.h" +#include "Phrase.h" +#include "StaticData.h" +#include "DummyScoreProducers.h" +#include "LMList.h" +#include "ChartTranslationOption.h" using namespace std; using namespace Moses; -namespace MosesChart +namespace Moses { -unsigned int Hypothesis::s_HypothesesCreated = 0; +unsigned int ChartHypothesis::s_HypothesesCreated = 0; #ifdef USE_HYPO_POOL -ObjectPool Hypothesis::s_objectPool("Hypothesis", 300000); +ObjectPool ChartHypothesis::s_objectPool("ChartHypothesis", 300000); #endif /** Create a hypothesis from a rule */ -Hypothesis::Hypothesis(const QueueEntry &queueEntry, Manager &manager) +ChartHypothesis::ChartHypothesis(const QueueEntry &queueEntry, ChartManager &manager) :m_transOpt(queueEntry.GetTranslationOption()) ,m_wordsConsumedTargetOrder(queueEntry.GetTranslationOption().GetWordsConsumedTargetOrder()) ,m_id(++s_HypothesesCreated) @@ -69,7 +69,7 @@ Hypothesis::Hypothesis(const QueueEntry &queueEntry, Manager &manager) for (iter = childEntries.begin(); iter != childEntries.end(); ++iter) { const ChildEntry &childEntry = *iter; - const Hypothesis *prevHypo = childEntry.GetHypothesis(); + const ChartHypothesis *prevHypo = childEntry.GetHypothesis(); // keep count of words (= length of generated string) m_numTargetTerminals += prevHypo->GetNumTargetTerminals(); @@ -83,13 +83,13 @@ Hypothesis::Hypothesis(const QueueEntry &queueEntry, Manager &manager) CalcSuffix(m_contextSuffix, maxNGram - 1); } -Hypothesis::~Hypothesis() +ChartHypothesis::~ChartHypothesis() { // delete hypotheses that are not in the chart (recombined away) if (m_arcList) { - ArcList::iterator iter; + ChartArcList::iterator iter; for (iter = m_arcList->begin() ; iter != m_arcList->end() ; ++iter) { - Hypothesis *hypo = *iter; + ChartHypothesis *hypo = *iter; Delete(hypo); } m_arcList->clear(); @@ -101,14 +101,14 @@ Hypothesis::~Hypothesis() /** Create full output phrase that is contained in the hypothesis (and its children) * \param outPhrase full output phrase */ -void Hypothesis::CreateOutputPhrase(Phrase &outPhrase) const +void ChartHypothesis::CreateOutputPhrase(Phrase &outPhrase) const { for (size_t pos = 0; pos < GetCurrTargetPhrase().GetSize(); ++pos) { const Word &word = GetCurrTargetPhrase().GetWord(pos); if (word.IsNonTerminal()) { // non-term. fill out with prev hypo size_t nonTermInd = m_wordsConsumedTargetOrder[pos]; - const Hypothesis *prevHypo = m_prevHypos[nonTermInd]; + const ChartHypothesis *prevHypo = m_prevHypos[nonTermInd]; prevHypo->CreateOutputPhrase(outPhrase); } else { @@ -118,7 +118,7 @@ void Hypothesis::CreateOutputPhrase(Phrase &outPhrase) const } /** Return full output phrase */ -Phrase Hypothesis::GetOutputPhrase() const +Phrase ChartHypothesis::GetOutputPhrase() const { Phrase outPhrase(Output, ARRAY_SIZE_INCR); CreateOutputPhrase(outPhrase); @@ -129,7 +129,7 @@ Phrase Hypothesis::GetOutputPhrase() const * \param ret prefix string * \param size maximum size (typically max lm context window) */ -size_t Hypothesis::CalcPrefix(Phrase &ret, size_t size) const +size_t ChartHypothesis::CalcPrefix(Phrase &ret, size_t size) const { // loop over the rule that is being applied for (size_t pos = 0; pos < GetCurrTargetPhrase().GetSize(); ++pos) { @@ -138,7 +138,7 @@ size_t Hypothesis::CalcPrefix(Phrase &ret, size_t size) const // for non-terminals, retrieve it from underlying hypothesis if (word.IsNonTerminal()) { size_t nonTermInd = m_wordsConsumedTargetOrder[pos]; - const Hypothesis *prevHypo = m_prevHypos[nonTermInd]; + const ChartHypothesis *prevHypo = m_prevHypos[nonTermInd]; size = prevHypo->CalcPrefix(ret, size); } // for words, add word @@ -160,7 +160,7 @@ size_t Hypothesis::CalcPrefix(Phrase &ret, size_t size) const * \param ret suffix phrase * \param size maximum size of suffix */ -size_t Hypothesis::CalcSuffix(Phrase &ret, size_t size) const +size_t ChartHypothesis::CalcSuffix(Phrase &ret, size_t size) const { assert(m_contextPrefix.GetSize() <= m_numTargetTerminals); @@ -186,7 +186,7 @@ size_t Hypothesis::CalcSuffix(Phrase &ret, size_t size) const if (word.IsNonTerminal()) { size_t nonTermInd = m_wordsConsumedTargetOrder[pos]; - const Hypothesis *prevHypo = m_prevHypos[nonTermInd]; + const ChartHypothesis *prevHypo = m_prevHypos[nonTermInd]; size = prevHypo->CalcSuffix(ret, size); } else { @@ -207,7 +207,7 @@ size_t Hypothesis::CalcSuffix(Phrase &ret, size_t size) const * in terms of future search, so the weaker one can be dropped. * \param other other hypothesis for comparison */ -int Hypothesis::LMContextCompare(const Hypothesis &other) const +int ChartHypothesis::LMContextCompare(const ChartHypothesis &other) const { // prefix if (m_currSourceWordsRange.GetStartPos() > 0) { @@ -228,12 +228,12 @@ int Hypothesis::LMContextCompare(const Hypothesis &other) const return 0; } -void Hypothesis::CalcScore() +void ChartHypothesis::CalcScore() { // total scores from prev hypos - std::vector::iterator iter; + std::vector::iterator iter; for (iter = m_prevHypos.begin(); iter != m_prevHypos.end(); ++iter) { - const Hypothesis &prevHypo = **iter; + const ChartHypothesis &prevHypo = **iter; const ScoreComponentCollection &scoreBreakdown = prevHypo.GetScoreBreakdown(); m_scoreBreakdown.PlusEquals(scoreBreakdown); @@ -249,7 +249,7 @@ void Hypothesis::CalcScore() } // compute languane model score for the hypothesis -void Hypothesis::CalcLMScore() +void ChartHypothesis::CalcLMScore() { // get the language models involved const LMList& lmList = m_manager.GetTranslationSystem()->GetLanguageModels(); @@ -278,7 +278,7 @@ void Hypothesis::CalcLMScore() { // look up underlying hypothesis size_t nonTermInd = m_wordsConsumedTargetOrder[targetPhrasePos]; - const Hypothesis *prevHypo = m_prevHypos[nonTermInd]; + const ChartHypothesis *prevHypo = m_prevHypos[nonTermInd]; size_t numTargetTerminals = prevHypo->GetNumTargetTerminals(); // check if we are dealing with a large sub-phrase @@ -346,21 +346,21 @@ void Hypothesis::CalcLMScore() */ } -void Hypothesis::AddArc(Hypothesis *loserHypo) +void ChartHypothesis::AddArc(ChartHypothesis *loserHypo) { if (!m_arcList) { if (loserHypo->m_arcList) { // we don't have an arcList, but loser does this->m_arcList = loserHypo->m_arcList; // take ownership, we'll delete loserHypo->m_arcList = 0; // prevent a double deletion } else { - this->m_arcList = new ArcList(); + this->m_arcList = new ChartArcList(); } } else { if (loserHypo->m_arcList) { // both have an arc list: merge. delete loser size_t my_size = m_arcList->size(); size_t add_size = loserHypo->m_arcList->size(); this->m_arcList->resize(my_size + add_size, 0); - std::memcpy(&(*m_arcList)[0] + my_size, &(*loserHypo->m_arcList)[0], add_size * sizeof(Hypothesis *)); + std::memcpy(&(*m_arcList)[0] + my_size, &(*loserHypo->m_arcList)[0], add_size * sizeof(ChartHypothesis *)); delete loserHypo->m_arcList; loserHypo->m_arcList = 0; } else { // loserHypo doesn't have any arcs @@ -371,13 +371,13 @@ void Hypothesis::AddArc(Hypothesis *loserHypo) } // sorting helper -struct CompareChartHypothesisTotalScore { - bool operator()(const Hypothesis* hypo1, const Hypothesis* hypo2) const { +struct CompareChartChartHypothesisTotalScore { + bool operator()(const ChartHypothesis* hypo1, const ChartHypothesis* hypo2) const { return hypo1->GetTotalScore() > hypo2->GetTotalScore(); } }; -void Hypothesis::CleanupArcList() +void ChartHypothesis::CleanupArcList() { // point this hypo's main hypo to itself m_winningHypo = this; @@ -397,29 +397,29 @@ void Hypothesis::CleanupArcList() nth_element(m_arcList->begin() , m_arcList->begin() + nBestSize - 1 , m_arcList->end() - , CompareChartHypothesisTotalScore()); + , CompareChartChartHypothesisTotalScore()); // delete bad ones - ArcList::iterator iter; + ChartArcList::iterator iter; for (iter = m_arcList->begin() + nBestSize ; iter != m_arcList->end() ; ++iter) { - Hypothesis *arc = *iter; - Hypothesis::Delete(arc); + ChartHypothesis *arc = *iter; + ChartHypothesis::Delete(arc); } m_arcList->erase(m_arcList->begin() + nBestSize , m_arcList->end()); } // set all arc's main hypo variable to this hypo - ArcList::iterator iter = m_arcList->begin(); + ChartArcList::iterator iter = m_arcList->begin(); for (; iter != m_arcList->end() ; ++iter) { - Hypothesis *arc = *iter; + ChartHypothesis *arc = *iter; arc->SetWinningHypo(this); } //cerr << m_arcList->size() << " "; } -void Hypothesis::SetWinningHypo(const Hypothesis *hypo) +void ChartHypothesis::SetWinningHypo(const ChartHypothesis *hypo) { m_winningHypo = hypo; @@ -428,10 +428,10 @@ void Hypothesis::SetWinningHypo(const Hypothesis *hypo) m_contextSuffix.Clear(); } -TO_STRING_BODY(Hypothesis) +TO_STRING_BODY(ChartHypothesis) // friend -ostream& operator<<(ostream& out, const Hypothesis& hypo) +ostream& operator<<(ostream& out, const ChartHypothesis& hypo) { //Phrase outPhrase(Output); //hypo.CreateOutputPhrase(outPhrase); @@ -445,7 +445,7 @@ ostream& operator<<(ostream& out, const Hypothesis& hypo) HypoList::const_iterator iter; for (iter = hypo.GetPrevHypos().begin(); iter != hypo.GetPrevHypos().end(); ++iter) { - const Hypothesis &prevHypo = **iter; + const ChartHypothesis &prevHypo = **iter; out << " " << prevHypo.GetId(); } diff --git a/moses-chart/src/ChartHypothesis.h b/moses/src/ChartHypothesis.h similarity index 73% rename from moses-chart/src/ChartHypothesis.h rename to moses/src/ChartHypothesis.h index 7d4b743bb..9e22e7cea 100644 --- a/moses-chart/src/ChartHypothesis.h +++ b/moses/src/ChartHypothesis.h @@ -22,29 +22,29 @@ #pragma once #include -#include "../../moses/src/Util.h" -#include "../../moses/src/WordsRange.h" -#include "../../moses/src/ScoreComponentCollection.h" -#include "../../moses/src/Phrase.h" -#include "../../moses/src/ChartTranslationOption.h" -#include "../../moses/src/ObjectPool.h" +#include "Util.h" +#include "WordsRange.h" +#include "ScoreComponentCollection.h" +#include "Phrase.h" +#include "ChartTranslationOption.h" +#include "ObjectPool.h" -namespace MosesChart +namespace Moses { class QueueEntry; -class Hypothesis; -class Manager; +class ChartHypothesis; +class ChartManager; -typedef std::vector ArcList; +typedef std::vector ChartArcList; -class Hypothesis +class ChartHypothesis { - friend std::ostream& operator<<(std::ostream&, const Hypothesis&); + friend std::ostream& operator<<(std::ostream&, const ChartHypothesis&); protected: #ifdef USE_HYPO_POOL - static ObjectPool s_objectPool; + static ObjectPool s_objectPool; #endif static unsigned int s_HypothesesCreated; @@ -61,20 +61,20 @@ protected: float m_totalScore; size_t m_numTargetTerminals; - ArcList *m_arcList; /*! all arcs that end at the same trellis point as this hypothesis */ - const Hypothesis *m_winningHypo; + ChartArcList *m_arcList; /*! all arcs that end at the same trellis point as this hypothesis */ + const ChartHypothesis *m_winningHypo; - std::vector m_prevHypos; + std::vector m_prevHypos; - Manager& m_manager; + ChartManager& m_manager; size_t CalcPrefix(Moses::Phrase &ret, size_t size) const; size_t CalcSuffix(Moses::Phrase &ret, size_t size) const; void CalcLMScore(); - Hypothesis(); // not implemented - Hypothesis(const Hypothesis ©); // not implemented + ChartHypothesis(); // not implemented + ChartHypothesis(const ChartHypothesis ©); // not implemented public: static void ResetHypoCount() { @@ -90,17 +90,17 @@ public: return ptr; } - static void Delete(Hypothesis *hypo) { + static void Delete(ChartHypothesis *hypo) { s_objectPool.freeObject(hypo); } #else - static void Delete(Hypothesis *hypo) { + static void Delete(ChartHypothesis *hypo) { delete hypo; } #endif - explicit Hypothesis(const QueueEntry &queueEntry, Manager &manager); - ~Hypothesis(); + explicit ChartHypothesis(const QueueEntry &queueEntry, ChartManager &manager); + ~ChartHypothesis(); int GetId()const { return m_id; @@ -114,14 +114,14 @@ public: const Moses::WordsRange &GetCurrSourceRange()const { return m_currSourceWordsRange; } - inline const ArcList* GetArcList() const { + inline const ChartArcList* GetArcList() const { return m_arcList; } void CreateOutputPhrase(Moses::Phrase &outPhrase) const; Moses::Phrase GetOutputPhrase() const; - int LMContextCompare(const Hypothesis &other) const; + int LMContextCompare(const ChartHypothesis &other) const; const Moses::Phrase &GetPrefix() const { return m_contextPrefix; @@ -132,9 +132,9 @@ public: void CalcScore(); - void AddArc(Hypothesis *loserHypo); + void AddArc(ChartHypothesis *loserHypo); void CleanupArcList(); - void SetWinningHypo(const Hypothesis *hypo); + void SetWinningHypo(const ChartHypothesis *hypo); const Moses::ScoreComponentCollection &GetScoreBreakdown() const { return m_scoreBreakdown; @@ -143,7 +143,7 @@ public: return m_totalScore; } - const std::vector &GetPrevHypos() const { + const std::vector &GetPrevHypos() const { return m_prevHypos; } @@ -162,7 +162,7 @@ public: TO_STRING(); -}; // class Hypothesis +}; // class ChartHypothesis } diff --git a/moses-chart/src/ChartHypothesisCollection.cpp b/moses/src/ChartHypothesisCollection.cpp similarity index 81% rename from moses-chart/src/ChartHypothesisCollection.cpp rename to moses/src/ChartHypothesisCollection.cpp index 873baf056..86c6a4c69 100644 --- a/moses-chart/src/ChartHypothesisCollection.cpp +++ b/moses/src/ChartHypothesisCollection.cpp @@ -20,7 +20,7 @@ ***********************************************************************/ #include -#include "../../moses/src/StaticData.h" +#include "StaticData.h" #include "ChartHypothesisCollection.h" #include "ChartHypothesis.h" #include "ChartManager.h" @@ -28,10 +28,10 @@ using namespace std; using namespace Moses; -namespace MosesChart +namespace Moses { -HypothesisCollection::HypothesisCollection() +ChartHypothesisCollection::ChartHypothesisCollection() { const StaticData &staticData = StaticData::Instance(); @@ -41,23 +41,23 @@ HypothesisCollection::HypothesisCollection() m_bestScore = -std::numeric_limits::infinity(); } -HypothesisCollection::~HypothesisCollection() +ChartHypothesisCollection::~ChartHypothesisCollection() { HCType::iterator iter; for (iter = m_hypos.begin() ; iter != m_hypos.end() ; ++iter) { - Hypothesis *hypo = *iter; - Hypothesis::Delete(hypo); + ChartHypothesis *hypo = *iter; + ChartHypothesis::Delete(hypo); } //Moses::RemoveAllInColl(m_hypos); } -bool HypothesisCollection::AddHypothesis(Hypothesis *hypo, Manager &manager) +bool ChartHypothesisCollection::AddHypothesis(ChartHypothesis *hypo, ChartManager &manager) { if (hypo->GetTotalScore() < m_bestScore + m_beamWidth) { // really bad score. don't bother adding hypo into collection manager.GetSentenceStats().AddDiscarded(); VERBOSE(3,"discarded, too bad for stack" << std::endl); - Hypothesis::Delete(hypo); + ChartHypothesis::Delete(hypo); return false; } @@ -72,7 +72,7 @@ bool HypothesisCollection::AddHypothesis(Hypothesis *hypo, Manager &manager) // equiv hypo exists, recombine with other hypo HCType::iterator &iterExisting = addRet.first; - Hypothesis *hypoExisting = *iterExisting; + ChartHypothesis *hypoExisting = *iterExisting; assert(iterExisting != m_hypos.end()); //StaticData::Instance().GetSentenceStats().AddRecombination(*hypo, **iterExisting); @@ -103,13 +103,13 @@ bool HypothesisCollection::AddHypothesis(Hypothesis *hypo, Manager &manager) hypoExisting->AddArc(hypo); } else { - Hypothesis::Delete(hypo); + ChartHypothesis::Delete(hypo); } return false; } } -pair HypothesisCollection::Add(Hypothesis *hypo, Manager &manager) +pair ChartHypothesisCollection::Add(ChartHypothesis *hypo, ChartManager &manager) { std::pair ret = m_hypos.insert(hypo); if (ret.second) { @@ -135,14 +135,14 @@ pair HypothesisCollection::Add(Hyp } /** Remove hypothesis pointed to by iterator but don't delete the object. */ -void HypothesisCollection::Detach(const HCType::iterator &iter) +void ChartHypothesisCollection::Detach(const HCType::iterator &iter) { m_hypos.erase(iter); } -void HypothesisCollection::Remove(const HCType::iterator &iter) +void ChartHypothesisCollection::Remove(const HCType::iterator &iter) { - Hypothesis *h = *iter; + ChartHypothesis *h = *iter; /* stringstream strme(""); @@ -158,10 +158,10 @@ void HypothesisCollection::Remove(const HCType::iterator &iter) */ Detach(iter); - Hypothesis::Delete(h); + ChartHypothesis::Delete(h); } -void HypothesisCollection::PruneToSize(Manager &manager) +void ChartHypothesisCollection::PruneToSize(ChartManager &manager) { if (GetSize() > m_maxHypoStackSize) { // ok, if not over the limit priority_queue bestScores; @@ -171,7 +171,7 @@ void HypothesisCollection::PruneToSize(Manager &manager) HCType::iterator iter = m_hypos.begin(); float score = 0; while (iter != m_hypos.end()) { - Hypothesis *hypo = *iter; + ChartHypothesis *hypo = *iter; score = hypo->GetTotalScore(); if (score > m_bestScore+m_beamWidth) { bestScores.push(score); @@ -191,7 +191,7 @@ void HypothesisCollection::PruneToSize(Manager &manager) // delete all hypos under score threshold iter = m_hypos.begin(); while (iter != m_hypos.end()) { - Hypothesis *hypo = *iter; + ChartHypothesis *hypo = *iter; float score = hypo->GetTotalScore(); if (score < scoreThreshold) { HCType::iterator iterRemove = iter++; @@ -206,7 +206,7 @@ void HypothesisCollection::PruneToSize(Manager &manager) IFVERBOSE(3) { TRACE_ERR("stack now contains: "); for(iter = m_hypos.begin(); iter != m_hypos.end(); iter++) { - Hypothesis *hypo = *iter; + ChartHypothesis *hypo = *iter; TRACE_ERR( hypo->GetId() << " (" << hypo->GetTotalScore() << ") "); } TRACE_ERR( endl); @@ -214,16 +214,16 @@ void HypothesisCollection::PruneToSize(Manager &manager) // desperation pruning if (m_hypos.size() > m_maxHypoStackSize * 2) { - std::vector hyposOrdered; + std::vector hyposOrdered; // sort hypos std::copy(m_hypos.begin(), m_hypos.end(), std::inserter(hyposOrdered, hyposOrdered.end())); std::sort(hyposOrdered.begin(), hyposOrdered.end(), ChartHypothesisScoreOrderer()); //keep only |size|. delete the rest - std::vector::iterator iter; + std::vector::iterator iter; for (iter = hyposOrdered.begin() + (m_maxHypoStackSize * 2); iter != hyposOrdered.end(); ++iter) { - Hypothesis *hypo = *iter; + ChartHypothesis *hypo = *iter; HCType::iterator iterFindHypo = m_hypos.find(hypo); assert(iterFindHypo != m_hypos.end()); Remove(iterFindHypo); @@ -232,7 +232,7 @@ void HypothesisCollection::PruneToSize(Manager &manager) } } -void HypothesisCollection::SortHypotheses() +void ChartHypothesisCollection::SortHypotheses() { assert(m_hyposOrdered.empty()); if (!m_hypos.empty()) { @@ -245,27 +245,27 @@ void HypothesisCollection::SortHypotheses() } } -void HypothesisCollection::CleanupArcList() +void ChartHypothesisCollection::CleanupArcList() { HCType::iterator iter; for (iter = m_hypos.begin() ; iter != m_hypos.end() ; ++iter) { - Hypothesis *mainHypo = *iter; + ChartHypothesis *mainHypo = *iter; mainHypo->CleanupArcList(); } } -void HypothesisCollection::GetSearchGraph(long translationId, std::ostream &outputSearchGraphStream) const +void ChartHypothesisCollection::GetSearchGraph(long translationId, std::ostream &outputSearchGraphStream) const { HCType::const_iterator iter; for (iter = m_hypos.begin() ; iter != m_hypos.end() ; ++iter) { - Hypothesis &mainHypo = **iter; + ChartHypothesis &mainHypo = **iter; outputSearchGraphStream << translationId << " " << mainHypo << endl; - const ArcList *arcList = mainHypo.GetArcList(); + const ChartArcList *arcList = mainHypo.GetArcList(); if (arcList) { - ArcList::const_iterator iterArc; + ChartArcList::const_iterator iterArc; for (iterArc = arcList->begin(); iterArc != arcList->end(); ++iterArc) { - const Hypothesis &arc = **iterArc; + const ChartHypothesis &arc = **iterArc; outputSearchGraphStream << translationId << " " << arc << endl; } } @@ -273,11 +273,11 @@ void HypothesisCollection::GetSearchGraph(long translationId, std::ostream &outp } } -std::ostream& operator<<(std::ostream &out, const HypothesisCollection &coll) +std::ostream& operator<<(std::ostream &out, const ChartHypothesisCollection &coll) { HypoList::const_iterator iterInside; for (iterInside = coll.m_hyposOrdered.begin(); iterInside != coll.m_hyposOrdered.end(); ++iterInside) { - const Hypothesis &hypo = **iterInside; + const ChartHypothesis &hypo = **iterInside; out << hypo << endl; } diff --git a/moses-chart/src/ChartHypothesisCollection.h b/moses/src/ChartHypothesisCollection.h similarity index 79% rename from moses-chart/src/ChartHypothesisCollection.h rename to moses/src/ChartHypothesisCollection.h index 6a55d42c1..860b9e744 100644 --- a/moses-chart/src/ChartHypothesisCollection.h +++ b/moses/src/ChartHypothesisCollection.h @@ -25,22 +25,22 @@ #include "QueueEntry.h" -namespace MosesChart +namespace Moses { // order by descending score class ChartHypothesisScoreOrderer { public: - bool operator()(const Hypothesis* hypoA, const Hypothesis* hypoB) const { + bool operator()(const ChartHypothesis* hypoA, const ChartHypothesis* hypoB) const { return hypoA->GetTotalScore() > hypoB->GetTotalScore(); } }; -class HypothesisRecombinationOrderer +class ChartHypothesisRecombinationOrderer { public: - bool operator()(const Hypothesis* hypoA, const Hypothesis* hypoB) const { + bool operator()(const ChartHypothesis* hypoA, const ChartHypothesis* hypoB) const { // assert in same cell const Moses::WordsRange &rangeA = hypoA->GetCurrSourceRange() , &rangeB = hypoB->GetCurrSourceRange(); @@ -63,22 +63,13 @@ public: } }; -// order by descending score -class HypothesisScoreOrderer -{ -public: - bool operator()(const Hypothesis* hypoA, const Hypothesis* hypoB) const { - return hypoA->GetTotalScore() > hypoB->GetTotalScore(); - } -}; - // 1 of these for each target LHS in each cell -class HypothesisCollection +class ChartHypothesisCollection { - friend std::ostream& operator<<(std::ostream&, const HypothesisCollection&); + friend std::ostream& operator<<(std::ostream&, const ChartHypothesisCollection&); protected: - typedef std::set HCType; + typedef std::set HCType; HCType m_hypos; HypoList m_hyposOrdered; @@ -90,7 +81,7 @@ protected: /** add hypothesis to stack. Prune if necessary. * Returns false if equiv hypo exists in collection, otherwise returns true */ - std::pair Add(Hypothesis *hypo, Manager &manager); + std::pair Add(ChartHypothesis *hypo, ChartManager &manager); public: typedef HCType::iterator iterator; @@ -103,16 +94,16 @@ public: return m_hypos.end(); } - HypothesisCollection(); - ~HypothesisCollection(); - bool AddHypothesis(Hypothesis *hypo, Manager &manager); + ChartHypothesisCollection(); + ~ChartHypothesisCollection(); + bool AddHypothesis(ChartHypothesis *hypo, ChartManager &manager); //! remove hypothesis pointed to by iterator but don't delete the object void Detach(const HCType::iterator &iter); /** destroy Hypothesis pointed to by iterator (object pool version) */ void Remove(const HCType::iterator &iter); - void PruneToSize(Manager &manager); + void PruneToSize(ChartManager &manager); size_t GetSize() const { return m_hypos.size(); diff --git a/moses-chart/src/ChartManager.cpp b/moses/src/ChartManager.cpp similarity index 87% rename from moses-chart/src/ChartManager.cpp rename to moses/src/ChartManager.cpp index cab415a98..f91bc2f17 100644 --- a/moses-chart/src/ChartManager.cpp +++ b/moses/src/ChartManager.cpp @@ -26,8 +26,8 @@ #include "ChartTrellisPath.h" #include "ChartTrellisPathList.h" #include "ChartTrellisPathCollection.h" -#include "../../moses/src/StaticData.h" -#include "../../moses/src/DecodeStep.h" +#include "StaticData.h" +#include "DecodeStep.h" using namespace std; using namespace Moses; @@ -35,12 +35,8 @@ using namespace Moses; namespace Moses { extern bool g_debug; -} -namespace MosesChart -{ - -Manager::Manager(InputType const& source, const TranslationSystem* system) +ChartManager::ChartManager(InputType const& source, const TranslationSystem* system) :m_source(source) ,m_hypoStackColl(source, *this) ,m_transOptColl(source, system, m_hypoStackColl, m_ruleLookupManagers) @@ -59,7 +55,7 @@ Manager::Manager(InputType const& source, const TranslationSystem* system) } } -Manager::~Manager() +ChartManager::~ChartManager() { m_system->CleanUpAfterSentenceProcessing(); @@ -72,14 +68,14 @@ Manager::~Manager() } -void Manager::ProcessSentence() +void ChartManager::ProcessSentence() { VERBOSE(1,"Translating: " << m_source << endl); ResetSentenceStats(m_source); VERBOSE(2,"Decoding: " << endl); - //Hypothesis::ResetHypoCount(); + //ChartHypothesis::ResetHypoCount(); // MAIN LOOP size_t size = m_source.GetSize(); @@ -110,7 +106,7 @@ void Manager::ProcessSentence() } IFVERBOSE(1) { - cerr << "Num of hypo = " << Hypothesis::GetHypoCount() << " --- cells:" << endl; + cerr << "Num of hypo = " << ChartHypothesis::GetHypoCount() << " --- cells:" << endl; for (size_t startPos = 0; startPos < size; ++startPos) { cerr.width(3); @@ -131,7 +127,7 @@ void Manager::ProcessSentence() } } -const Hypothesis *Manager::GetBestHypothesis() const +const ChartHypothesis *ChartManager::GetBestHypothesis() const { size_t size = m_source.GetSize(); @@ -144,26 +140,26 @@ const Hypothesis *Manager::GetBestHypothesis() const } } -void Manager::CalcNBest(size_t count, TrellisPathList &ret,bool onlyDistinct) const +void ChartManager::CalcNBest(size_t count, ChartTrellisPathList &ret,bool onlyDistinct) const { size_t size = m_source.GetSize(); if (count == 0 || size == 0) return; - TrellisPathCollection contenders; + ChartTrellisPathCollection contenders; set distinctHyps; // add all pure paths WordsRange range(0, size-1); const ChartCell &lastCell = m_hypoStackColl.Get(range); - const Hypothesis *hypo = lastCell.GetBestHypothesis(); + const ChartHypothesis *hypo = lastCell.GetBestHypothesis(); if (hypo == NULL) { // no hypothesis return; } - MosesChart::TrellisPath *purePath = new TrellisPath(hypo); + ChartTrellisPath *purePath = new ChartTrellisPath(hypo); contenders.Add(purePath); // factor defines stopping point for distinct n-best list if too many candidates identical @@ -173,7 +169,7 @@ void Manager::CalcNBest(size_t count, TrellisPathList &ret,bool onlyDistinct) co // MAIN loop for (size_t iteration = 0 ; (onlyDistinct ? distinctHyps.size() : ret.GetSize()) < count && contenders.GetSize() > 0 && (iteration < count * nBestFactor) ; iteration++) { // get next best from list of contenders - TrellisPath *path = contenders.pop(); + ChartTrellisPath *path = contenders.pop(); assert(path); // create deviations from current best @@ -196,11 +192,11 @@ void Manager::CalcNBest(size_t count, TrellisPathList &ret,bool onlyDistinct) co } } -void Manager::CalcDecoderStatistics() const +void ChartManager::CalcDecoderStatistics() const { } -void Manager::GetSearchGraph(long translationId, std::ostream &outputSearchGraphStream) const +void ChartManager::GetSearchGraph(long translationId, std::ostream &outputSearchGraphStream) const { size_t size = m_source.GetSize(); for (size_t width = 1; width <= size; ++width) { diff --git a/moses-chart/src/ChartManager.h b/moses/src/ChartManager.h similarity index 75% rename from moses-chart/src/ChartManager.h rename to moses/src/ChartManager.h index 85ddf1eb6..cc6309efe 100644 --- a/moses-chart/src/ChartManager.h +++ b/moses/src/ChartManager.h @@ -25,36 +25,36 @@ #include "ChartCell.h" #include "ChartTranslationOptionCollection.h" #include "ChartCellCollection.h" -#include "../../moses/src/InputType.h" -#include "../../moses/src/WordsRange.h" -#include "../../moses/src/TrellisPathList.h" -#include "../../moses/src/SentenceStats.h" -#include "../../moses/src/TranslationSystem.h" -#include "../../moses/src/ChartRuleLookupManager.h" +#include "InputType.h" +#include "WordsRange.h" +#include "ChartTrellisPathList.h" +#include "SentenceStats.h" +#include "TranslationSystem.h" +#include "ChartRuleLookupManager.h" -namespace MosesChart +namespace Moses { -class Hypothesis; -class TrellisPathList; +class ChartHypothesis; +class ChartTrellisPathList; -class Manager +class ChartManager { protected: Moses::InputType const& m_source; /**< source sentence to be translated */ ChartCellCollection m_hypoStackColl; - TranslationOptionCollection m_transOptColl; /**< pre-computed list of translation options for the phrases in this sentence */ + ChartTranslationOptionCollection m_transOptColl; /**< pre-computed list of translation options for the phrases in this sentence */ std::auto_ptr m_sentenceStats; const Moses::TranslationSystem* m_system; clock_t m_start; /**< starting time, used for logging */ std::vector m_ruleLookupManagers; public: - Manager(Moses::InputType const& source, const Moses::TranslationSystem* system); - ~Manager(); + ChartManager(Moses::InputType const& source, const Moses::TranslationSystem* system); + ~ChartManager(); void ProcessSentence(); - const Hypothesis *GetBestHypothesis() const; - void CalcNBest(size_t count, MosesChart::TrellisPathList &ret,bool onlyDistinct=0) const; + const ChartHypothesis *GetBestHypothesis() const; + void CalcNBest(size_t count, ChartTrellisPathList &ret,bool onlyDistinct=0) const; void GetSearchGraph(long translationId, std::ostream &outputSearchGraphStream) const; diff --git a/moses/src/ChartRuleLookupManagerMemory.cpp b/moses/src/ChartRuleLookupManagerMemory.cpp index be9dc700b..b21bc53b4 100644 --- a/moses/src/ChartRuleLookupManagerMemory.cpp +++ b/moses/src/ChartRuleLookupManagerMemory.cpp @@ -37,30 +37,30 @@ ChartRuleLookupManagerMemory::ChartRuleLookupManagerMemory( : ChartRuleLookupManager(src, cellColl) , m_ruleTable(ruleTable) { - assert(m_processedRuleColls.size() == 0); + assert(m_dottedRuleColls.size() == 0); size_t sourceSize = src.GetSize(); - m_processedRuleColls.resize(sourceSize); + m_dottedRuleColls.resize(sourceSize); const PhraseDictionaryNodeSCFG &rootNode = m_ruleTable.GetRootNode(); - for (size_t ind = 0; ind < m_processedRuleColls.size(); ++ind) { + for (size_t ind = 0; ind < m_dottedRuleColls.size(); ++ind) { #ifdef USE_BOOST_POOL - ProcessedRule *initProcessedRule = m_processedRulePool.malloc(); - new (initProcessedRule) ProcessedRule(rootNode); + DottedRule *initDottedRule = m_dottedRulePool.malloc(); + new (initDottedRule) DottedRule(rootNode); #else - ProcessedRule *initProcessedRule = new ProcessedRule(rootNode); + DottedRule *initDottedRule = new DottedRule(rootNode); #endif - ProcessedRuleColl *processedRuleColl = new ProcessedRuleColl(sourceSize - ind + 1); - processedRuleColl->Add(0, initProcessedRule); // init rule. stores the top node in tree + DottedRuleColl *dottedRuleColl = new DottedRuleColl(sourceSize - ind + 1); + dottedRuleColl->Add(0, initDottedRule); // init rule. stores the top node in tree - m_processedRuleColls[ind] = processedRuleColl; + m_dottedRuleColls[ind] = dottedRuleColl; } } ChartRuleLookupManagerMemory::~ChartRuleLookupManagerMemory() { - RemoveAllInColl(m_processedRuleColls); + RemoveAllInColl(m_dottedRuleColls); } void ChartRuleLookupManagerMemory::GetChartRuleCollection( @@ -74,19 +74,19 @@ void ChartRuleLookupManagerMemory::GetChartRuleCollection( // MAIN LOOP. create list of nodes of target phrases // get list of all rules that apply to spans at same starting position - ProcessedRuleColl &processedRuleCol = *m_processedRuleColls[range.GetStartPos()]; - const ProcessedRuleList &runningNodes = processedRuleCol.GetRunningNodes(); + DottedRuleColl &dottedRuleCol = *m_dottedRuleColls[range.GetStartPos()]; + const DottedRuleList &expandableDottedRuleList = dottedRuleCol.GetExpandableDottedRuleList(); // loop through the rules - // (note that runningNodes can be expanded as the loop runs + // (note that expandableDottedRuleList can be expanded as the loop runs // through calls to ExtendPartialRuleApplication()) - for (size_t ind = 0; ind < runningNodes.size(); ++ind) { + for (size_t ind = 0; ind < expandableDottedRuleList.size(); ++ind) { // rule we are about to extend - const ProcessedRule &prevProcessedRule = *runningNodes[ind]; + const DottedRule &prevDottedRule = *expandableDottedRuleList[ind]; // note where it was found in the prefix tree of the rule dictionary - const PhraseDictionaryNodeSCFG &prevNode = prevProcessedRule.GetLastNode(); + const PhraseDictionaryNodeSCFG &prevNode = prevDottedRule.GetLastNode(); // look up end position of the span it covers - const WordConsumed *prevWordConsumed = prevProcessedRule.GetLastWordConsumed(); + const WordConsumed *prevWordConsumed = prevDottedRule.GetLastWordConsumed(); // we will now try to extend it, starting after where it ended // (note: prevWordConsumed == NULL matches for the dummy rule // at root of the prefix tree) @@ -108,16 +108,16 @@ void ChartRuleLookupManagerMemory::GetChartRuleCollection( WordConsumed *newWordConsumed = m_wordConsumedPool.malloc(); new (newWordConsumed) WordConsumed(absEndPos, absEndPos, sourceWord, prevWordConsumed); - ProcessedRule *processedRule = m_processedRulePool.malloc(); - new (processedRule) ProcessedRule(*node, newWordConsumed); + DottedRule *dottedRule = m_dottedRulePool.malloc(); + new (dottedRule) DottedRule(*node, newWordConsumed); #else WordConsumed *newWordConsumed = new WordConsumed(absEndPos, absEndPos, sourceWord, prevWordConsumed); - ProcessedRule *processedRule = new ProcessedRule(*node, + DottedRule *dottedRule = new DottedRule(*node, newWordConsumed); #endif - processedRuleCol.Add(relEndPos+1, processedRule); + dottedRuleCol.Add(relEndPos+1, dottedRule); } } @@ -150,19 +150,19 @@ void ChartRuleLookupManagerMemory::GetChartRuleCollection( ExtendPartialRuleApplication(prevNode, prevWordConsumed, startPos, - endPos, stackInd, processedRuleCol); + endPos, stackInd, dottedRuleCol); } // list of rules that that cover the entire span - ProcessedRuleList &rules = processedRuleCol.Get(relEndPos + 1); + DottedRuleList &rules = dottedRuleCol.Get(relEndPos + 1); // look up target sides for the rules size_t rulesLimit = StaticData::Instance().GetRuleLimit(); - ProcessedRuleList::const_iterator iterRule; + DottedRuleList::const_iterator iterRule; for (iterRule = rules.begin(); iterRule != rules.end(); ++iterRule) { - const ProcessedRule &processedRule = **iterRule; - const PhraseDictionaryNodeSCFG &node = processedRule.GetLastNode(); - const WordConsumed *wordConsumed = processedRule.GetLastWordConsumed(); + const DottedRule &dottedRule = **iterRule; + const PhraseDictionaryNodeSCFG &node = dottedRule.GetLastNode(); + const WordConsumed *wordConsumed = dottedRule.GetLastWordConsumed(); assert(wordConsumed); // look up target sides @@ -186,7 +186,7 @@ void ChartRuleLookupManagerMemory::ExtendPartialRuleApplication( size_t startPos, size_t endPos, size_t stackInd, - ProcessedRuleColl & processedRuleColl) + DottedRuleColl & dottedRuleColl) { // source non-terminal labels for the remainder const NonTerminalSet &sourceNonTerms = @@ -194,7 +194,7 @@ void ChartRuleLookupManagerMemory::ExtendPartialRuleApplication( // target non-terminal labels for the remainder const NonTerminalSet &targetNonTerms = - GetCellCollection().GetHeadwords(WordsRange(startPos, endPos)); + GetCellCollection().GetConstituentLabelSet(WordsRange(startPos, endPos)); const PhraseDictionaryNodeSCFG::NonTerminalMap & nonTermMap = node.GetNonTerminalMap(); @@ -242,15 +242,15 @@ void ChartRuleLookupManagerMemory::ExtendPartialRuleApplication( WordConsumed *wc = m_wordConsumedPool.malloc(); new (wc) WordConsumed(startPos, endPos, targetNonTerm, prevWordConsumed); - ProcessedRule *rule = m_processedRulePool.malloc(); - new (rule) ProcessedRule(*child, wc); + DottedRule *rule = m_dottedRulePool.malloc(); + new (rule) DottedRule(*child, wc); #else WordConsumed * wc = new WordConsumed(startPos, endPos, targetNonTerm, prevWordConsumed); - ProcessedRule * rule = new ProcessedRule(*child, wc); + DottedRule * rule = new DottedRule(*child, wc); #endif - processedRuleColl.Add(stackInd, rule); + dottedRuleColl.Add(stackInd, rule); } } } @@ -278,15 +278,15 @@ void ChartRuleLookupManagerMemory::ExtendPartialRuleApplication( WordConsumed *wc = m_wordConsumedPool.malloc(); new (wc) WordConsumed(startPos, endPos, targetNonTerm, prevWordConsumed); - ProcessedRule *rule = m_processedRulePool.malloc(); - new (rule) ProcessedRule(child, wc); + DottedRule *rule = m_dottedRulePool.malloc(); + new (rule) DottedRule(child, wc); #else WordConsumed * wc = new WordConsumed(startPos, endPos, targetNonTerm, prevWordConsumed); - ProcessedRule * rule = new ProcessedRule(child, wc); + DottedRule * rule = new DottedRule(child, wc); #endif - processedRuleColl.Add(stackInd, rule); + dottedRuleColl.Add(stackInd, rule); } } } diff --git a/moses/src/ChartRuleLookupManagerMemory.h b/moses/src/ChartRuleLookupManagerMemory.h index a89292d00..4f9dd9bf6 100644 --- a/moses/src/ChartRuleLookupManagerMemory.h +++ b/moses/src/ChartRuleLookupManagerMemory.h @@ -41,7 +41,7 @@ namespace Moses { class ChartTranslationOptionList; -class ProcessedRuleColl; +class DottedRuleColl; class WordsRange; // Implementation of ChartRuleLookupManager for in-memory rule tables. @@ -66,15 +66,15 @@ private: size_t startPos, size_t endPos, size_t stackInd, - ProcessedRuleColl &processedRuleColl); + DottedRuleColl &dottedRuleColl); - std::vector m_processedRuleColls; + std::vector m_dottedRuleColls; const PhraseDictionarySCFG &m_ruleTable; #ifdef USE_BOOST_POOL - // Use object pools to allocate the ProcessedRule and WordConsumed objects + // Use object pools to allocate the DottedRule and WordConsumed objects // for this sentence. We allocate a lot of them and this has been seen to // significantly improve performance, especially for multithreaded decoding. - boost::object_pool m_processedRulePool; + boost::object_pool m_dottedRulePool; boost::object_pool m_wordConsumedPool; #endif }; diff --git a/moses/src/ChartRuleLookupManagerOnDisk.cpp b/moses/src/ChartRuleLookupManagerOnDisk.cpp index bda9495e4..c86249f5f 100644 --- a/moses/src/ChartRuleLookupManagerOnDisk.cpp +++ b/moses/src/ChartRuleLookupManagerOnDisk.cpp @@ -54,17 +54,17 @@ ChartRuleLookupManagerOnDisk::ChartRuleLookupManagerOnDisk( , m_weight(weight) , m_filePath(filePath) { - assert(m_runningNodesVec.size() == 0); + assert(m_expandableDottedRuleListVec.size() == 0); size_t sourceSize = sentence.GetSize(); - m_runningNodesVec.resize(sourceSize); + m_expandableDottedRuleListVec.resize(sourceSize); - for (size_t ind = 0; ind < m_runningNodesVec.size(); ++ind) { - ProcessedRuleOnDisk *initProcessedRule = new ProcessedRuleOnDisk(m_dbWrapper.GetRootSourceNode()); + for (size_t ind = 0; ind < m_expandableDottedRuleListVec.size(); ++ind) { + DottedRuleOnDisk *initDottedRule = new DottedRuleOnDisk(m_dbWrapper.GetRootSourceNode()); - ProcessedRuleStackOnDisk *processedStack = new ProcessedRuleStackOnDisk(sourceSize - ind + 1); - processedStack->Add(0, initProcessedRule); // init rule. stores the top node in tree + DottedRuleStackOnDisk *processedStack = new DottedRuleStackOnDisk(sourceSize - ind + 1); + processedStack->Add(0, initDottedRule); // init rule. stores the top node in tree - m_runningNodesVec[ind] = processedStack; + m_expandableDottedRuleListVec[ind] = processedStack; } } @@ -76,7 +76,7 @@ ChartRuleLookupManagerOnDisk::~ChartRuleLookupManagerOnDisk() } m_cache.clear(); - RemoveAllInColl(m_runningNodesVec); + RemoveAllInColl(m_expandableDottedRuleListVec); RemoveAllInColl(m_sourcePhraseNode); } @@ -92,23 +92,23 @@ void ChartRuleLookupManagerOnDisk::GetChartRuleCollection( size_t absEndPos = range.GetEndPos(); // MAIN LOOP. create list of nodes of target phrases - ProcessedRuleStackOnDisk &runningNodes = *m_runningNodesVec[range.GetStartPos()]; + DottedRuleStackOnDisk &expandableDottedRuleList = *m_expandableDottedRuleListVec[range.GetStartPos()]; // sort save nodes so only do nodes with most counts - runningNodes.SortSavedNodes(); + expandableDottedRuleList.SortSavedNodes(); size_t numDerivations = 0 ,maxDerivations = 999999; // staticData.GetMaxDerivations(); bool overThreshold = true; - const ProcessedRuleStackOnDisk::SavedNodeColl &savedNodeColl = runningNodes.GetSavedNodeColl(); + const DottedRuleStackOnDisk::SavedNodeColl &savedNodeColl = expandableDottedRuleList.GetSavedNodeColl(); //cerr << "savedNodeColl=" << savedNodeColl.size() << " "; for (size_t ind = 0; ind < (savedNodeColl.size()) && ((numDerivations < maxDerivations) || overThreshold) ; ++ind) { const SavedNodeOnDisk &savedNode = *savedNodeColl[ind]; - const ProcessedRuleOnDisk &prevProcessedRule = savedNode.GetProcessedRule(); - const OnDiskPt::PhraseNode &prevNode = prevProcessedRule.GetLastNode(); - const WordConsumed *prevWordConsumed = prevProcessedRule.GetLastWordConsumed(); + const DottedRuleOnDisk &prevDottedRule = savedNode.GetDottedRule(); + const OnDiskPt::PhraseNode &prevNode = prevDottedRule.GetLastNode(); + const WordConsumed *prevWordConsumed = prevDottedRule.GetLastWordConsumed(); size_t startPos = (prevWordConsumed == NULL) ? range.GetStartPos() : prevWordConsumed->GetWordsRange().GetEndPos() + 1; // search for terminal symbol @@ -125,8 +125,8 @@ void ChartRuleLookupManagerOnDisk::GetChartRuleCollection( WordConsumed *newWordConsumed = new WordConsumed(absEndPos, absEndPos , sourceWord , prevWordConsumed); - ProcessedRuleOnDisk *processedRule = new ProcessedRuleOnDisk(*node, newWordConsumed); - runningNodes.Add(relEndPos+1, processedRule); + DottedRuleOnDisk *dottedRule = new DottedRuleOnDisk(*node, newWordConsumed); + expandableDottedRuleList.Add(relEndPos+1, dottedRule); // cache for cleanup m_sourcePhraseNode.push_back(node); @@ -151,8 +151,8 @@ void ChartRuleLookupManagerOnDisk::GetChartRuleCollection( // size_t nonTermNumWordsCovered = endPos - startPos + 1; - // get target headwords in this span from chart - const NonTerminalSet &headWords = GetCellCollection().GetHeadwords(WordsRange(startPos, endPos)); + // get target nonterminals in this span from chart + const NonTerminalSet &chartNonTermSet = GetCellCollection().GetConstituentLabelSet(WordsRange(startPos, endPos)); //const Word &defaultSourceNonTerm = staticData.GetInputDefaultNonTerminal() // ,&defaultTargetNonTerm = staticData.GetOutputDefaultNonTerminal(); @@ -178,25 +178,25 @@ void ChartRuleLookupManagerOnDisk::GetChartRuleCollection( continue; // didn't find source node // go through each TARGET lhs - NonTerminalSet::const_iterator iterTargetLHS; - for (iterTargetLHS = headWords.begin(); iterTargetLHS != headWords.end(); ++iterTargetLHS) { - const Word &targetLHS = *iterTargetLHS; + NonTerminalSet::const_iterator iterChartNonTerm; + for (iterChartNonTerm = chartNonTermSet.begin(); iterChartNonTerm != chartNonTermSet.end(); ++iterChartNonTerm) { + const Word &chartNonTerm = *iterChartNonTerm; - //cerr << sourceLHS << " " << defaultSourceNonTerm << " " << targetLHS << " " << defaultTargetNonTerm << endl; + //cerr << sourceLHS << " " << defaultSourceNonTerm << " " << chartNonTerm << " " << defaultTargetNonTerm << endl; - //bool isSyntaxNonTerm = (sourceLHS != defaultSourceNonTerm) || (targetLHS != defaultTargetNonTerm); + //bool isSyntaxNonTerm = (sourceLHS != defaultSourceNonTerm) || (chartNonTerm != defaultTargetNonTerm); bool doSearch = true; //isSyntaxNonTerm ? nonTermNumWordsCovered <= maxSyntaxSpan : // nonTermNumWordsCovered <= maxDefaultSpan; if (doSearch) { - OnDiskPt::Word *targetLHSBerkeleyDb = m_dbWrapper.ConvertFromMoses(Output, m_outputFactorsVec, targetLHS); + OnDiskPt::Word *chartNonTermBerkeleyDb = m_dbWrapper.ConvertFromMoses(Output, m_outputFactorsVec, chartNonTerm); - if (targetLHSBerkeleyDb == NULL) + if (chartNonTermBerkeleyDb == NULL) continue; - const OnDiskPt::PhraseNode *node = sourceNode->GetChild(*targetLHSBerkeleyDb, m_dbWrapper); - delete targetLHSBerkeleyDb; + const OnDiskPt::PhraseNode *node = sourceNode->GetChild(*chartNonTermBerkeleyDb, m_dbWrapper); + delete chartNonTermBerkeleyDb; if (node == NULL) continue; @@ -204,36 +204,36 @@ void ChartRuleLookupManagerOnDisk::GetChartRuleCollection( // found matching entry //const Word &sourceWord = node->GetSourceWord(); WordConsumed *newWordConsumed = new WordConsumed(startPos, endPos - , targetLHS + , chartNonTerm , prevWordConsumed); - ProcessedRuleOnDisk *processedRule = new ProcessedRuleOnDisk(*node, newWordConsumed); - runningNodes.Add(stackInd, processedRule); + DottedRuleOnDisk *dottedRule = new DottedRuleOnDisk(*node, newWordConsumed); + expandableDottedRuleList.Add(stackInd, dottedRule); m_sourcePhraseNode.push_back(node); } - } // for (iterHeadWords + } // for (iterChartNonTerm delete sourceNode; } // for (iterLabelListf // return list of target phrases - ProcessedRuleCollOnDisk &nodes = runningNodes.Get(relEndPos + 1); + DottedRuleCollOnDisk &nodes = expandableDottedRuleList.Get(relEndPos + 1); // source LHS - ProcessedRuleCollOnDisk::const_iterator iterProcessedRuleColl; - for (iterProcessedRuleColl = nodes.begin(); iterProcessedRuleColl != nodes.end(); ++iterProcessedRuleColl) { + DottedRuleCollOnDisk::const_iterator iterDottedRuleColl; + for (iterDottedRuleColl = nodes.begin(); iterDottedRuleColl != nodes.end(); ++iterDottedRuleColl) { // node of last source word - const ProcessedRuleOnDisk &prevProcessedRule = **iterProcessedRuleColl; - if (prevProcessedRule.Done()) + const DottedRuleOnDisk &prevDottedRule = **iterDottedRuleColl; + if (prevDottedRule.Done()) continue; - prevProcessedRule.Done(true); + prevDottedRule.Done(true); - const WordConsumed *wordConsumed = prevProcessedRule.GetLastWordConsumed(); + const WordConsumed *wordConsumed = prevDottedRule.GetLastWordConsumed(); assert(wordConsumed); - const OnDiskPt::PhraseNode &prevNode = prevProcessedRule.GetLastNode(); + const OnDiskPt::PhraseNode &prevNode = prevDottedRule.GetLastNode(); //get node for each source LHS const NonTerminalSet &lhsSet = GetSentence().GetLabelSet(range.GetStartPos(), range.GetEndPos()); diff --git a/moses/src/ChartRuleLookupManagerOnDisk.h b/moses/src/ChartRuleLookupManagerOnDisk.h index b52748af6..04a9988e9 100644 --- a/moses/src/ChartRuleLookupManagerOnDisk.h +++ b/moses/src/ChartRuleLookupManagerOnDisk.h @@ -63,7 +63,7 @@ private: const std::vector &m_outputFactorsVec; const std::vector &m_weight; const std::string &m_filePath; - std::vector m_runningNodesVec; + std::vector m_expandableDottedRuleListVec; std::map m_cache; std::list m_sourcePhraseNode; }; diff --git a/moses-chart/src/ChartTranslationOptionCollection.cpp b/moses/src/ChartTranslationOptionCollection.cpp similarity index 88% rename from moses-chart/src/ChartTranslationOptionCollection.cpp rename to moses/src/ChartTranslationOptionCollection.cpp index dbaac6117..f2de03aa1 100644 --- a/moses-chart/src/ChartTranslationOptionCollection.cpp +++ b/moses/src/ChartTranslationOptionCollection.cpp @@ -22,20 +22,20 @@ #include #include "ChartTranslationOptionCollection.h" #include "ChartCellCollection.h" -#include "../../moses/src/InputType.h" -#include "../../moses/src/StaticData.h" -#include "../../moses/src/DecodeStep.h" -#include "../../moses/src/DummyScoreProducers.h" -#include "../../moses/src/WordConsumed.h" -#include "../../moses/src/Util.h" +#include "InputType.h" +#include "StaticData.h" +#include "DecodeStep.h" +#include "DummyScoreProducers.h" +#include "WordConsumed.h" +#include "Util.h" using namespace std; using namespace Moses; -namespace MosesChart +namespace Moses { -TranslationOptionCollection::TranslationOptionCollection(InputType const& source +ChartTranslationOptionCollection::ChartTranslationOptionCollection(InputType const& source , const Moses::TranslationSystem* system , const ChartCellCollection &hypoStackColl , const std::vector &ruleLookupManagers) @@ -56,7 +56,7 @@ TranslationOptionCollection::TranslationOptionCollection(InputType const& source } } -TranslationOptionCollection::~TranslationOptionCollection() +ChartTranslationOptionCollection::~ChartTranslationOptionCollection() { RemoveAllInColl(m_unksrcs); RemoveAllInColl(m_cacheTargetPhrase); @@ -71,7 +71,7 @@ TranslationOptionCollection::~TranslationOptionCollection() } -void TranslationOptionCollection::CreateTranslationOptionsForRange( +void ChartTranslationOptionCollection::CreateTranslationOptionsForRange( size_t startPos , size_t endPos) { @@ -100,7 +100,7 @@ void TranslationOptionCollection::CreateTranslationOptionsForRange( } //! Force a creation of a translation option where there are none for a particular source position. -void TranslationOptionCollection::ProcessUnknownWord(size_t startPos, size_t endPos) +void ChartTranslationOptionCollection::ProcessUnknownWord(size_t startPos, size_t endPos) { if (startPos != endPos) { // only for 1 word phrases @@ -130,20 +130,20 @@ void TranslationOptionCollection::ProcessUnknownWord(size_t startPos, size_t end } -ChartTranslationOptionList &TranslationOptionCollection::GetTranslationOptionList(size_t startPos, size_t endPos) +ChartTranslationOptionList &ChartTranslationOptionCollection::GetTranslationOptionList(size_t startPos, size_t endPos) { size_t sizeVec = m_collection[startPos].size(); assert(endPos-startPos < sizeVec); return m_collection[startPos][endPos - startPos]; } -const ChartTranslationOptionList &TranslationOptionCollection::GetTranslationOptionList(size_t startPos, size_t endPos) const +const ChartTranslationOptionList &ChartTranslationOptionCollection::GetTranslationOptionList(size_t startPos, size_t endPos) const { size_t sizeVec = m_collection[startPos].size(); assert(endPos-startPos < sizeVec); return m_collection[startPos][endPos - startPos]; } -std::ostream& operator<<(std::ostream &out, const TranslationOptionCollection &coll) +std::ostream& operator<<(std::ostream &out, const ChartTranslationOptionCollection &coll) { std::vector< std::vector< ChartTranslationOptionList > >::const_iterator iterOuter; for (iterOuter = coll.m_collection.begin(); iterOuter != coll.m_collection.end(); ++iterOuter) { @@ -160,15 +160,15 @@ std::ostream& operator<<(std::ostream &out, const TranslationOptionCollection &c return out; } -// taken from TranslationOptionCollectionText. -void TranslationOptionCollection::ProcessUnknownWord(size_t sourcePos) +// taken from ChartTranslationOptionCollectionText. +void ChartTranslationOptionCollection::ProcessUnknownWord(size_t sourcePos) { const Word &sourceWord = m_source.GetWord(sourcePos); ProcessOneUnknownWord(sourceWord,sourcePos); } //! special handling of ONE unknown words. -void TranslationOptionCollection::ProcessOneUnknownWord(const Moses::Word &sourceWord, size_t sourcePos, size_t /* length */) +void ChartTranslationOptionCollection::ProcessOneUnknownWord(const Moses::Word &sourceWord, size_t sourcePos, size_t /* length */) { // unknown word, add as trans opt const StaticData &staticData = StaticData::Instance(); @@ -278,20 +278,20 @@ void TranslationOptionCollection::ProcessOneUnknownWord(const Moses::Word &sourc } } -void TranslationOptionCollection::Add(ChartTranslationOption *transOpt, size_t pos) +void ChartTranslationOptionCollection::Add(ChartTranslationOption *transOpt, size_t pos) { ChartTranslationOptionList &transOptList = GetTranslationOptionList(pos, pos); transOptList.Add(transOpt); } //! pruning: only keep the top n (m_maxNoTransOptPerCoverage) elements */ -void TranslationOptionCollection::Prune(size_t /* startPos */, size_t /* endPos */) +void ChartTranslationOptionCollection::Prune(size_t /* startPos */, size_t /* endPos */) { } //! sort all trans opt in each list for cube pruning */ -void TranslationOptionCollection::Sort(size_t startPos, size_t endPos) +void ChartTranslationOptionCollection::Sort(size_t startPos, size_t endPos) { ChartTranslationOptionList &list = GetTranslationOptionList(startPos, endPos); list.Sort(); diff --git a/moses-chart/src/ChartTranslationOptionCollection.h b/moses/src/ChartTranslationOptionCollection.h similarity index 86% rename from moses-chart/src/ChartTranslationOptionCollection.h rename to moses/src/ChartTranslationOptionCollection.h index 8734aae2a..176144ca7 100644 --- a/moses-chart/src/ChartTranslationOptionCollection.h +++ b/moses/src/ChartTranslationOptionCollection.h @@ -22,10 +22,10 @@ #pragma once #include -#include "../../moses/src/InputType.h" -#include "../../moses/src/DecodeGraph.h" -#include "../../moses/src/ChartTranslationOptionList.h" -#include "../../moses/src/ChartRuleLookupManager.h" +#include "InputType.h" +#include "DecodeGraph.h" +#include "ChartTranslationOptionList.h" +#include "ChartRuleLookupManager.h" namespace Moses { @@ -34,15 +34,11 @@ class Word; class ChartTranslationOption; class WordConsumed; class WordPenaltyProducer; -}; - -namespace MosesChart -{ class ChartCellCollection; -class TranslationOptionCollection +class ChartTranslationOptionCollection { - friend std::ostream& operator<<(std::ostream&, const TranslationOptionCollection&); + friend std::ostream& operator<<(std::ostream&, const ChartTranslationOptionCollection&); protected: const Moses::InputType &m_source; const Moses::TranslationSystem* m_system; @@ -63,7 +59,7 @@ protected: void ProcessUnknownWord(size_t startPos, size_t endPos); - // taken from TranslationOptionCollectionText. + // taken from ChartTranslationOptionCollectionText. void ProcessUnknownWord(size_t sourcePos); //! special handling of ONE unknown words. @@ -77,11 +73,11 @@ protected: void Sort(size_t startPos, size_t endPos); public: - TranslationOptionCollection(Moses::InputType const& source + ChartTranslationOptionCollection(Moses::InputType const& source , const Moses::TranslationSystem* system , const ChartCellCollection &hypoStackColl , const std::vector &ruleLookupManagers); - virtual ~TranslationOptionCollection(); + virtual ~ChartTranslationOptionCollection(); void CreateTranslationOptionsForRange(size_t startPos , size_t endPos); diff --git a/moses/src/ChartTranslationOptionList.cpp b/moses/src/ChartTranslationOptionList.cpp index 9eef12c55..3fa2cca08 100644 --- a/moses/src/ChartTranslationOptionList.cpp +++ b/moses/src/ChartTranslationOptionList.cpp @@ -20,7 +20,7 @@ #include #include -#include "../../moses/src/StaticData.h" +#include "StaticData.h" #include "ChartTranslationOptionList.h" #include "ChartTranslationOption.h" #include "WordsRange.h" diff --git a/moses-chart/src/ChartTrellisNode.cpp b/moses/src/ChartTrellisNode.cpp similarity index 71% rename from moses-chart/src/ChartTrellisNode.cpp rename to moses/src/ChartTrellisNode.cpp index e4b7c546f..f71785e61 100644 --- a/moses-chart/src/ChartTrellisNode.cpp +++ b/moses/src/ChartTrellisNode.cpp @@ -21,33 +21,33 @@ #include "ChartTrellisNode.h" #include "ChartHypothesis.h" -#include "../../moses/src/ScoreComponentCollection.h" +#include "ScoreComponentCollection.h" using namespace std; -namespace MosesChart +namespace Moses { -TrellisNode::TrellisNode(const Hypothesis *hypo) +ChartTrellisNode::ChartTrellisNode(const ChartHypothesis *hypo) :m_hypo(hypo) { - const std::vector &prevHypos = hypo->GetPrevHypos(); + const std::vector &prevHypos = hypo->GetPrevHypos(); m_edge.reserve(prevHypos.size()); for (size_t ind = 0; ind < prevHypos.size(); ++ind) { - const Hypothesis *prevHypo = prevHypos[ind]; - TrellisNode *child = new TrellisNode(prevHypo); + const ChartHypothesis *prevHypo = prevHypos[ind]; + ChartTrellisNode *child = new ChartTrellisNode(prevHypo); m_edge.push_back(child); } assert(m_hypo); } -TrellisNode::TrellisNode(const TrellisNode &origNode - , const TrellisNode &soughtNode - , const Hypothesis &replacementHypo +ChartTrellisNode::ChartTrellisNode(const ChartTrellisNode &origNode + , const ChartTrellisNode &soughtNode + , const ChartHypothesis &replacementHypo , Moses::ScoreComponentCollection &scoreChange - , const TrellisNode *&nodeChanged) + , const ChartTrellisNode *&nodeChanged) { if (&origNode.GetHypothesis() == &soughtNode.GetHypothesis()) { // this node should be replaced @@ -64,13 +64,13 @@ TrellisNode::TrellisNode(const TrellisNode &origNode assert(deltaScore <= 0.0005); // follow prev hypos back to beginning - const std::vector &prevHypos = replacementHypo.GetPrevHypos(); - vector::const_iterator iter; + const std::vector &prevHypos = replacementHypo.GetPrevHypos(); + vector::const_iterator iter; assert(m_edge.empty()); m_edge.reserve(prevHypos.size()); for (iter = prevHypos.begin(); iter != prevHypos.end(); ++iter) { - const Hypothesis *prevHypo = *iter; - TrellisNode *prevNode = new TrellisNode(prevHypo); + const ChartHypothesis *prevHypo = *iter; + ChartTrellisNode *prevNode = new ChartTrellisNode(prevHypo); m_edge.push_back(prevNode); } @@ -81,8 +81,8 @@ TrellisNode::TrellisNode(const TrellisNode &origNode assert(m_edge.empty()); m_edge.reserve(origNode.m_edge.size()); for (iter = origNode.m_edge.begin(); iter != origNode.m_edge.end(); ++iter) { - const TrellisNode &prevNode = **iter; - TrellisNode *newPrevNode = new TrellisNode(prevNode, soughtNode, replacementHypo, scoreChange, nodeChanged); + const ChartTrellisNode &prevNode = **iter; + ChartTrellisNode *newPrevNode = new ChartTrellisNode(prevNode, soughtNode, replacementHypo, scoreChange, nodeChanged); m_edge.push_back(newPrevNode); } } @@ -90,12 +90,12 @@ TrellisNode::TrellisNode(const TrellisNode &origNode assert(m_hypo); } -TrellisNode::~TrellisNode() +ChartTrellisNode::~ChartTrellisNode() { Moses::RemoveAllInColl(m_edge); } -Moses::Phrase TrellisNode::GetOutputPhrase() const +Moses::Phrase ChartTrellisNode::GetOutputPhrase() const { // exactly like same fn in hypothesis, but use trellis nodes instead of prevHypos pointer Moses::Phrase ret(Moses::Output, Moses::ARRAY_SIZE_INCR); @@ -106,7 +106,7 @@ Moses::Phrase TrellisNode::GetOutputPhrase() const if (word.IsNonTerminal()) { // non-term. fill out with prev hypo size_t nonTermInd = m_hypo->GetWordsConsumedTargetOrder(pos); - const TrellisNode &childNode = GetChild(nonTermInd); + const ChartTrellisNode &childNode = GetChild(nonTermInd); Moses::Phrase childPhrase = childNode.GetOutputPhrase(); ret.Append(childPhrase); } else { @@ -117,11 +117,11 @@ Moses::Phrase TrellisNode::GetOutputPhrase() const return ret; } -std::ostream& operator<<(std::ostream &out, const TrellisNode &node) +std::ostream& operator<<(std::ostream &out, const ChartTrellisNode &node) { out << "* " << node.GetHypothesis() << endl; - TrellisNode::NodeChildren::const_iterator iter; + ChartTrellisNode::NodeChildren::const_iterator iter; for (iter = node.GetChildren().begin(); iter != node.GetChildren().end(); ++iter) { out << **iter; } diff --git a/moses-chart/src/ChartTrellisNode.h b/moses/src/ChartTrellisNode.h similarity index 68% rename from moses-chart/src/ChartTrellisNode.h rename to moses/src/ChartTrellisNode.h index aa8814be6..b94efac39 100644 --- a/moses-chart/src/ChartTrellisNode.h +++ b/moses/src/ChartTrellisNode.h @@ -22,38 +22,33 @@ #pragma once #include -#include "../../moses/src/Phrase.h" +#include "Phrase.h" namespace Moses { class ScoreComponentCollection; -} +class ChartHypothesis; -namespace MosesChart +class ChartTrellisNode { - -class Hypothesis; - -class TrellisNode -{ - friend std::ostream& operator<<(std::ostream&, const TrellisNode&); + friend std::ostream& operator<<(std::ostream&, const ChartTrellisNode&); public: - typedef std::vector NodeChildren; + typedef std::vector NodeChildren; protected: - const Hypothesis *m_hypo; + const ChartHypothesis *m_hypo; NodeChildren m_edge; public: - TrellisNode(const Hypothesis *hypo); - TrellisNode(const TrellisNode &origNode - , const TrellisNode &soughtNode - , const Hypothesis &replacementHypo + ChartTrellisNode(const ChartHypothesis *hypo); + ChartTrellisNode(const ChartTrellisNode &origNode + , const ChartTrellisNode &soughtNode + , const ChartHypothesis &replacementHypo , Moses::ScoreComponentCollection &scoreChange - , const TrellisNode *&nodeChanged); - ~TrellisNode(); + , const ChartTrellisNode *&nodeChanged); + ~ChartTrellisNode(); - const Hypothesis &GetHypothesis() const { + const ChartHypothesis &GetHypothesis() const { return *m_hypo; } @@ -61,7 +56,7 @@ public: return m_edge; } - const TrellisNode &GetChild(size_t ind) const { + const ChartTrellisNode &GetChild(size_t ind) const { return *m_edge[ind]; } diff --git a/moses-chart/src/ChartTrellisPath.cpp b/moses/src/ChartTrellisPath.cpp similarity index 63% rename from moses-chart/src/ChartTrellisPath.cpp rename to moses/src/ChartTrellisPath.cpp index 1a90ba3ed..9648ddab0 100644 --- a/moses-chart/src/ChartTrellisPath.cpp +++ b/moses/src/ChartTrellisPath.cpp @@ -22,16 +22,16 @@ #include "ChartTrellisPath.h" #include "ChartHypothesis.h" #include "ChartTrellisPathCollection.h" -#include "../../moses/src/StaticData.h" -#include "../../moses/src/Word.h" +#include "StaticData.h" +#include "Word.h" using namespace std; -namespace MosesChart +namespace Moses { -TrellisPath::TrellisPath(const Hypothesis *hypo) - :m_finalNode(new TrellisNode(hypo)) +ChartTrellisPath::ChartTrellisPath(const ChartHypothesis *hypo) + :m_finalNode(new ChartTrellisNode(hypo)) ,m_scoreBreakdown(hypo->GetScoreBreakdown()) ,m_totalScore(hypo->GetTotalScore()) ,m_prevNodeChanged(NULL) @@ -39,14 +39,14 @@ TrellisPath::TrellisPath(const Hypothesis *hypo) { } -TrellisPath::TrellisPath(const TrellisPath &origPath - , const TrellisNode &soughtNode - , const Hypothesis &replacementHypo +ChartTrellisPath::ChartTrellisPath(const ChartTrellisPath &origPath + , const ChartTrellisNode &soughtNode + , const ChartHypothesis &replacementHypo , Moses::ScoreComponentCollection &scoreChange) :m_scoreBreakdown(origPath.GetScoreBreakdown()) ,m_prevPath(&origPath) { - m_finalNode = new TrellisNode(origPath.GetFinalNode() + m_finalNode = new ChartTrellisNode(origPath.GetFinalNode() , soughtNode , replacementHypo , scoreChange @@ -57,61 +57,61 @@ TrellisPath::TrellisPath(const TrellisPath &origPath m_totalScore = m_scoreBreakdown.GetWeightedScore(); } -TrellisPath::~TrellisPath() +ChartTrellisPath::~ChartTrellisPath() { delete m_finalNode; } -Moses::Phrase TrellisPath::GetOutputPhrase() const +Moses::Phrase ChartTrellisPath::GetOutputPhrase() const { Moses::Phrase ret = GetFinalNode().GetOutputPhrase(); return ret; } -void TrellisPath::CreateDeviantPaths(TrellisPathCollection &pathColl, const TrellisNode &soughtNode) const +void ChartTrellisPath::CreateDeviantPaths(ChartTrellisPathCollection &pathColl, const ChartTrellisNode &soughtNode) const { // copy this path but replace startHypo with its arc - const ArcList *arcList = soughtNode.GetHypothesis().GetArcList(); + const ChartArcList *arcList = soughtNode.GetHypothesis().GetArcList(); if (arcList) { - ArcList::const_iterator iterArcList; - for (iterArcList = arcList->begin(); iterArcList != arcList->end(); ++iterArcList) { + ChartArcList::const_iterator iterChartArcList; + for (iterChartArcList = arcList->begin(); iterChartArcList != arcList->end(); ++iterChartArcList) { Moses::ScoreComponentCollection scoreChange; - const Hypothesis &replacementHypo = **iterArcList; - TrellisPath *newPath = new TrellisPath(*this, soughtNode, replacementHypo, scoreChange); + const ChartHypothesis &replacementHypo = **iterChartArcList; + ChartTrellisPath *newPath = new ChartTrellisPath(*this, soughtNode, replacementHypo, scoreChange); pathColl.Add(newPath); } } // recusively create deviant paths for child nodes - const TrellisNode::NodeChildren &children = soughtNode.GetChildren(); + const ChartTrellisNode::NodeChildren &children = soughtNode.GetChildren(); - TrellisNode::NodeChildren::const_iterator iter; + ChartTrellisNode::NodeChildren::const_iterator iter; for (iter = children.begin(); iter != children.end(); ++iter) { - const TrellisNode &child = **iter; + const ChartTrellisNode &child = **iter; CreateDeviantPaths(pathColl, child); } } -void TrellisPath::CreateDeviantPaths(TrellisPathCollection &pathColl) const +void ChartTrellisPath::CreateDeviantPaths(ChartTrellisPathCollection &pathColl) const { if (m_prevNodeChanged == NULL) { // initial enumeration from a pure hypo CreateDeviantPaths(pathColl, GetFinalNode()); } else { // don't change m_prevNodeChanged, just it's children - const TrellisNode::NodeChildren &children = m_prevNodeChanged->GetChildren(); + const ChartTrellisNode::NodeChildren &children = m_prevNodeChanged->GetChildren(); - TrellisNode::NodeChildren::const_iterator iter; + ChartTrellisNode::NodeChildren::const_iterator iter; for (iter = children.begin(); iter != children.end(); ++iter) { - const TrellisNode &child = **iter; + const ChartTrellisNode &child = **iter; CreateDeviantPaths(pathColl, child); } } } -std::ostream& operator<<(std::ostream &out, const TrellisPath &path) +std::ostream& operator<<(std::ostream &out, const ChartTrellisPath &path) { out << &path << " " << path.m_prevPath << " " << path.GetOutputPhrase() << endl; diff --git a/moses-chart/src/ChartTrellisPath.h b/moses/src/ChartTrellisPath.h similarity index 66% rename from moses-chart/src/ChartTrellisPath.h rename to moses/src/ChartTrellisPath.h index 468436ec4..7c5f7e963 100644 --- a/moses-chart/src/ChartTrellisPath.h +++ b/moses/src/ChartTrellisPath.h @@ -22,43 +22,43 @@ #pragma once #include "ChartTrellisNode.h" -#include "../../moses/src/ScoreComponentCollection.h" -#include "../../moses/src/Phrase.h" +#include "ScoreComponentCollection.h" +#include "Phrase.h" -namespace MosesChart +namespace Moses { -class Hypothesis; -class TrellisPathCollection; +class ChartHypothesis; +class ChartTrellisPathCollection; -class TrellisPath +class ChartTrellisPath { - friend std::ostream& operator<<(std::ostream&, const TrellisPath&); + friend std::ostream& operator<<(std::ostream&, const ChartTrellisPath&); protected: // recursively point backwards - TrellisNode *m_finalNode; - const TrellisNode *m_prevNodeChanged; - const TrellisPath *m_prevPath; + ChartTrellisNode *m_finalNode; + const ChartTrellisNode *m_prevNodeChanged; + const ChartTrellisPath *m_prevPath; Moses::ScoreComponentCollection m_scoreBreakdown; float m_totalScore; // deviate by 1 hypo - TrellisPath(const TrellisPath &origPath - , const TrellisNode &soughtNode - , const Hypothesis &replacementHypo + ChartTrellisPath(const ChartTrellisPath &origPath + , const ChartTrellisNode &soughtNode + , const ChartHypothesis &replacementHypo , Moses::ScoreComponentCollection &scoreChange); - void CreateDeviantPaths(TrellisPathCollection &pathColl, const TrellisNode &soughtNode) const; + void CreateDeviantPaths(ChartTrellisPathCollection &pathColl, const ChartTrellisNode &soughtNode) const; - const TrellisNode &GetFinalNode() const { + const ChartTrellisNode &GetFinalNode() const { assert (m_finalNode); return *m_finalNode; } public: - TrellisPath(const Hypothesis *hypo); - ~TrellisPath(); + ChartTrellisPath(const ChartHypothesis *hypo); + ~ChartTrellisPath(); //! get score for this path throught trellis inline float GetTotalScore() const { @@ -72,7 +72,7 @@ public: return m_scoreBreakdown; } - void CreateDeviantPaths(TrellisPathCollection &pathColl) const; + void CreateDeviantPaths(ChartTrellisPathCollection &pathColl) const; }; diff --git a/moses-chart/src/ChartTrellisPathCollection.cpp b/moses/src/ChartTrellisPathCollection.cpp similarity index 87% rename from moses-chart/src/ChartTrellisPathCollection.cpp rename to moses/src/ChartTrellisPathCollection.cpp index 41368f837..648d343ec 100644 --- a/moses-chart/src/ChartTrellisPathCollection.cpp +++ b/moses/src/ChartTrellisPathCollection.cpp @@ -22,21 +22,21 @@ #include "ChartTrellisPathCollection.h" #include "ChartTrellisPath.h" -namespace MosesChart +namespace Moses { -TrellisPathCollection::~TrellisPathCollection() +ChartTrellisPathCollection::~ChartTrellisPathCollection() { // clean up Moses::RemoveAllInColl(m_collection); } -void TrellisPathCollection::Add(TrellisPath *path) +void ChartTrellisPathCollection::Add(ChartTrellisPath *path) { m_collection.insert(path); } -void TrellisPathCollection::Prune(size_t newSize) +void ChartTrellisPathCollection::Prune(size_t newSize) { size_t currSize = m_collection.size(); @@ -45,7 +45,7 @@ void TrellisPathCollection::Prune(size_t newSize) CollectionType::reverse_iterator iterRev; for (iterRev = m_collection.rbegin() ; iterRev != m_collection.rend() ; ++iterRev) { - TrellisPath *trellisPath = *iterRev; + ChartTrellisPath *trellisPath = *iterRev; delete trellisPath; currSize--; diff --git a/moses-chart/src/ChartTrellisPathCollection.h b/moses/src/ChartTrellisPathCollection.h similarity index 75% rename from moses-chart/src/ChartTrellisPathCollection.h rename to moses/src/ChartTrellisPathCollection.h index e9ce43e12..b1fbd3a65 100644 --- a/moses-chart/src/ChartTrellisPathCollection.h +++ b/moses/src/ChartTrellisPathCollection.h @@ -23,35 +23,35 @@ #include #include "ChartTrellisPath.h" -namespace MosesChart +namespace Moses { -class TrellisPath; +class ChartTrellisPath; -struct CompareTrellisPathCollection { - bool operator()(const TrellisPath* pathA, const TrellisPath* pathB) const { +struct CompareChartTrellisPathCollection { + bool operator()(const ChartTrellisPath* pathA, const ChartTrellisPath* pathB) const { return (pathA->GetTotalScore() > pathB->GetTotalScore()); } }; -class TrellisPathCollection +class ChartTrellisPathCollection { protected: - typedef std::multiset CollectionType; + typedef std::multiset CollectionType; CollectionType m_collection; public: - ~TrellisPathCollection(); + ~ChartTrellisPathCollection(); size_t GetSize() const { return m_collection.size(); } - void Add(TrellisPath *path); + void Add(ChartTrellisPath *path); void Prune(size_t newSize); - TrellisPath *pop() { - TrellisPath *top = *m_collection.begin(); + ChartTrellisPath *pop() { + ChartTrellisPath *top = *m_collection.begin(); // Detach m_collection.erase(m_collection.begin()); diff --git a/moses-chart/src/ChartTrellisPathList.cpp b/moses/src/ChartTrellisPathList.cpp similarity index 92% rename from moses-chart/src/ChartTrellisPathList.cpp rename to moses/src/ChartTrellisPathList.cpp index f7ffe9b17..c156f996e 100644 --- a/moses-chart/src/ChartTrellisPathList.cpp +++ b/moses/src/ChartTrellisPathList.cpp @@ -21,13 +21,13 @@ #include "ChartTrellisPathList.h" #include "ChartTrellisPath.h" -#include "../../moses/src/Util.h" +#include "Util.h" using namespace std; -namespace MosesChart +namespace Moses { -TrellisPathList::~TrellisPathList() +ChartTrellisPathList::~ChartTrellisPathList() { // clean up Moses::RemoveAllInColl(m_collection); diff --git a/moses-chart/src/ChartTrellisPathList.h b/moses/src/ChartTrellisPathList.h similarity index 88% rename from moses-chart/src/ChartTrellisPathList.h rename to moses/src/ChartTrellisPathList.h index 996160389..13a4bb554 100644 --- a/moses-chart/src/ChartTrellisPathList.h +++ b/moses/src/ChartTrellisPathList.h @@ -23,14 +23,14 @@ #include -namespace MosesChart +namespace Moses { -class TrellisPath; +class ChartTrellisPath; -class TrellisPathList +class ChartTrellisPathList { protected: - typedef std::vector CollType; + typedef std::vector CollType; CollType m_collection; public: @@ -54,14 +54,14 @@ public: m_collection.clear(); } - virtual ~TrellisPathList(); + virtual ~ChartTrellisPathList(); size_t GetSize() const { return m_collection.size(); } //! add a new entry into collection - void Add(TrellisPath *trellisPath) { + void Add(ChartTrellisPath *trellisPath) { m_collection.push_back(trellisPath); } }; diff --git a/moses-chart/src/Cube.cpp b/moses/src/Cube.cpp similarity index 96% rename from moses-chart/src/Cube.cpp rename to moses/src/Cube.cpp index 41462fd8b..393a2b8e7 100644 --- a/moses-chart/src/Cube.cpp +++ b/moses/src/Cube.cpp @@ -21,11 +21,11 @@ #include "Cube.h" -#include "../../moses/src/Util.h" +#include "Util.h" using namespace std; -namespace MosesChart +namespace Moses { Cube::~Cube() { diff --git a/moses-chart/src/Cube.h b/moses/src/Cube.h similarity index 99% rename from moses-chart/src/Cube.h rename to moses/src/Cube.h index 249a58392..b4e196f81 100644 --- a/moses-chart/src/Cube.h +++ b/moses/src/Cube.h @@ -29,7 +29,7 @@ #include #endif -namespace MosesChart +namespace Moses { #ifdef HAVE_BOOST diff --git a/moses/src/DotChart.cpp b/moses/src/DotChart.cpp index c76ab4206..886a82e03 100644 --- a/moses/src/DotChart.cpp +++ b/moses/src/DotChart.cpp @@ -26,10 +26,10 @@ using namespace std; namespace Moses { -ProcessedRuleColl::~ProcessedRuleColl() +DottedRuleColl::~DottedRuleColl() { #ifdef USE_BOOST_POOL - // Do nothing. ProcessedRule objects are stored in object pools owned by + // Do nothing. DottedRule objects are stored in object pools owned by // the sentence-specific ChartRuleLookupManagers. #else std::for_each(m_coll.begin(), m_coll.end(), @@ -37,7 +37,7 @@ ProcessedRuleColl::~ProcessedRuleColl() #endif } -std::ostream& operator<<(std::ostream &out, const ProcessedRule& /* rule */) +std::ostream& operator<<(std::ostream &out, const DottedRule& /* rule */) { //const PhraseDictionaryNode &node = rule.GetLastNode(); //out << node; @@ -45,11 +45,11 @@ std::ostream& operator<<(std::ostream &out, const ProcessedRule& /* rule */) return out; } -std::ostream& operator<<(std::ostream &out, const ProcessedRuleList &coll) +std::ostream& operator<<(std::ostream &out, const DottedRuleList &coll) { - ProcessedRuleList::const_iterator iter; + DottedRuleList::const_iterator iter; for (iter = coll.begin(); iter != coll.end(); ++iter) { - const ProcessedRule &rule = **iter; + const DottedRule &rule = **iter; out << rule << endl; } diff --git a/moses/src/DotChart.h b/moses/src/DotChart.h index e85bea447..61b05d791 100644 --- a/moses/src/DotChart.h +++ b/moses/src/DotChart.h @@ -28,24 +28,24 @@ namespace Moses { -class ProcessedRule +class DottedRule { - friend std::ostream& operator<<(std::ostream&, const ProcessedRule&); + friend std::ostream& operator<<(std::ostream&, const DottedRule&); protected: const PhraseDictionaryNodeSCFG &m_lastNode; const WordConsumed *m_wordsConsumed; // usually contains something, unless its the init processed rule public: // used only to init dot stack. - explicit ProcessedRule(const PhraseDictionaryNodeSCFG &lastNode) + explicit DottedRule(const PhraseDictionaryNodeSCFG &lastNode) :m_lastNode(lastNode) ,m_wordsConsumed(NULL) {} - ProcessedRule(const PhraseDictionaryNodeSCFG &lastNode, const WordConsumed *wordsConsumed) + DottedRule(const PhraseDictionaryNodeSCFG &lastNode, const WordConsumed *wordsConsumed) :m_lastNode(lastNode) ,m_wordsConsumed(wordsConsumed) {} - ~ProcessedRule() { + ~DottedRule() { #ifdef USE_BOOST_POOL // Do nothing. WordConsumed objects are stored in object pools owned by // the sentence-specific ChartRuleLookupManagers. @@ -61,18 +61,18 @@ public: } }; -typedef std::vector ProcessedRuleList; +typedef std::vector DottedRuleList; -// Collection of all ProcessedRules that share a common start point, +// Collection of all DottedRules that share a common start point, // grouped by end point. Additionally, maintains a list of all -// ProcessedRules that could be expanded further, i.e. for which the +// DottedRules that could be expanded further, i.e. for which the // corresponding PhraseDictionaryNodeSCFG is not a leaf. -class ProcessedRuleColl +class DottedRuleColl { protected: - typedef std::vector CollType; + typedef std::vector CollType; CollType m_coll; - ProcessedRuleList m_runningNodes; + DottedRuleList m_expandableDottedRuleList; public: typedef CollType::iterator iterator; @@ -91,29 +91,29 @@ public: return m_coll.end(); } - ProcessedRuleColl(size_t size) + DottedRuleColl(size_t size) : m_coll(size) {} - ~ProcessedRuleColl(); + ~DottedRuleColl(); - const ProcessedRuleList &Get(size_t pos) const { + const DottedRuleList &Get(size_t pos) const { return m_coll[pos]; } - ProcessedRuleList &Get(size_t pos) { + DottedRuleList &Get(size_t pos) { return m_coll[pos]; } - void Add(size_t pos, const ProcessedRule *processedRule) { - assert(processedRule); - m_coll[pos].push_back(processedRule); - if (!processedRule->GetLastNode().IsLeaf()) { - m_runningNodes.push_back(processedRule); + void Add(size_t pos, const DottedRule *dottedRule) { + assert(dottedRule); + m_coll[pos].push_back(dottedRule); + if (!dottedRule->GetLastNode().IsLeaf()) { + m_expandableDottedRuleList.push_back(dottedRule); } } - const ProcessedRuleList &GetRunningNodes() const { - return m_runningNodes; + const DottedRuleList &GetExpandableDottedRuleList() const { + return m_expandableDottedRuleList; } }; diff --git a/moses/src/DotChartOnDisk.cpp b/moses/src/DotChartOnDisk.cpp index 0febe7669..37bae6fec 100644 --- a/moses/src/DotChartOnDisk.cpp +++ b/moses/src/DotChartOnDisk.cpp @@ -26,15 +26,15 @@ using namespace std; namespace Moses { -ProcessedRuleStackOnDisk::ProcessedRuleStackOnDisk(size_t size) +DottedRuleStackOnDisk::DottedRuleStackOnDisk(size_t size) :m_coll(size) { for (size_t ind = 0; ind < size; ++ind) { - m_coll[ind] = new ProcessedRuleCollOnDisk(); + m_coll[ind] = new DottedRuleCollOnDisk(); } } -ProcessedRuleStackOnDisk::~ProcessedRuleStackOnDisk() +DottedRuleStackOnDisk::~DottedRuleStackOnDisk() { RemoveAllInColl(m_coll); RemoveAllInColl(m_savedNode); @@ -44,17 +44,17 @@ class SavedNodesOderer { public: bool operator()(const SavedNodeOnDisk* a, const SavedNodeOnDisk* b) const { - bool ret = a->GetProcessedRule().GetLastNode().GetCount(0) > b->GetProcessedRule().GetLastNode().GetCount(0); + bool ret = a->GetDottedRule().GetLastNode().GetCount(0) > b->GetDottedRule().GetLastNode().GetCount(0); return ret; } }; -void ProcessedRuleStackOnDisk::SortSavedNodes() +void DottedRuleStackOnDisk::SortSavedNodes() { sort(m_savedNode.begin(), m_savedNode.end(), SavedNodesOderer()); } -std::ostream& operator<<(std::ostream &out, const ProcessedRuleOnDisk & /* rule */) +std::ostream& operator<<(std::ostream &out, const DottedRuleOnDisk & /* rule */) { //const MosesBerkeleyPt::SourcePhraseNode &node = rule.GetLastNode(); //out << node; @@ -62,11 +62,11 @@ std::ostream& operator<<(std::ostream &out, const ProcessedRuleOnDisk & /* rule return out; } -std::ostream& operator<<(std::ostream &out, const ProcessedRuleCollOnDisk &coll) +std::ostream& operator<<(std::ostream &out, const DottedRuleCollOnDisk &coll) { - ProcessedRuleCollOnDisk::CollType::const_iterator iter; + DottedRuleCollOnDisk::CollType::const_iterator iter; for (iter = coll.begin(); iter != coll.end(); ++iter) { - const ProcessedRuleOnDisk &rule = **iter; + const DottedRuleOnDisk &rule = **iter; out << rule << endl; } diff --git a/moses/src/DotChartOnDisk.h b/moses/src/DotChartOnDisk.h index 9a80ef4e7..fd6148325 100644 --- a/moses/src/DotChartOnDisk.h +++ b/moses/src/DotChartOnDisk.h @@ -32,9 +32,9 @@ class PhraseNode; namespace Moses { -class ProcessedRuleOnDisk +class DottedRuleOnDisk { - friend std::ostream& operator<<(std::ostream&, const ProcessedRuleOnDisk&); + friend std::ostream& operator<<(std::ostream&, const DottedRuleOnDisk&); protected: const OnDiskPt::PhraseNode &m_lastNode; @@ -42,17 +42,17 @@ protected: mutable bool m_done; public: // used only to init dot stack. - explicit ProcessedRuleOnDisk(const OnDiskPt::PhraseNode &lastNode) + explicit DottedRuleOnDisk(const OnDiskPt::PhraseNode &lastNode) :m_lastNode(lastNode) ,m_wordsConsumed(NULL) ,m_done(false) {} - ProcessedRuleOnDisk(const OnDiskPt::PhraseNode &lastNode, const WordConsumed *wordsConsumed) + DottedRuleOnDisk(const OnDiskPt::PhraseNode &lastNode, const WordConsumed *wordsConsumed) :m_lastNode(lastNode) ,m_wordsConsumed(wordsConsumed) ,m_done(false) {} - ~ProcessedRuleOnDisk() { + ~DottedRuleOnDisk() { delete m_wordsConsumed; } const OnDiskPt::PhraseNode &GetLastNode() const { @@ -75,7 +75,7 @@ public: } /* - inline int Compare(const ProcessedRule &compare) const + inline int Compare(const DottedRule &compare) const { if (m_lastNode < compare.m_lastNode) return -1; @@ -84,19 +84,19 @@ public: return m_wordsConsumed < compare.m_wordsConsumed; } - inline bool operator<(const ProcessedRule &compare) const + inline bool operator<(const DottedRule &compare) const { return Compare(compare) < 0; } */ }; -class ProcessedRuleCollOnDisk +class DottedRuleCollOnDisk { - friend std::ostream& operator<<(std::ostream&, const ProcessedRuleCollOnDisk&); + friend std::ostream& operator<<(std::ostream&, const DottedRuleCollOnDisk&); protected: - typedef std::vector CollType; + typedef std::vector CollType; CollType m_coll; public: @@ -116,12 +116,12 @@ public: return m_coll.end(); } - const ProcessedRuleOnDisk &Get(size_t ind) const { + const DottedRuleOnDisk &Get(size_t ind) const { return *m_coll[ind]; } - void Add(const ProcessedRuleOnDisk *processedRule) { - m_coll.push_back(processedRule); + void Add(const DottedRuleOnDisk *dottedRule) { + m_coll.push_back(dottedRule); } void Delete(size_t ind) { //delete m_coll[ind]; @@ -136,31 +136,31 @@ public: class SavedNodeOnDisk { - const ProcessedRuleOnDisk *m_processedRule; + const DottedRuleOnDisk *m_dottedRule; public: - SavedNodeOnDisk(const ProcessedRuleOnDisk *processedRule) - :m_processedRule(processedRule) { - assert(m_processedRule); + SavedNodeOnDisk(const DottedRuleOnDisk *dottedRule) + :m_dottedRule(dottedRule) { + assert(m_dottedRule); } ~SavedNodeOnDisk() { - delete m_processedRule; + delete m_dottedRule; } - const ProcessedRuleOnDisk &GetProcessedRule() const { - return *m_processedRule; + const DottedRuleOnDisk &GetDottedRule() const { + return *m_dottedRule; } }; -class ProcessedRuleStackOnDisk +class DottedRuleStackOnDisk { // coll of coll of processed rules public: typedef std::vector SavedNodeColl; protected: - typedef std::vector CollType; + typedef std::vector CollType; CollType m_coll; SavedNodeColl m_savedNode; @@ -182,25 +182,25 @@ public: return m_coll.end(); } - ProcessedRuleStackOnDisk(size_t size); - ~ProcessedRuleStackOnDisk(); + DottedRuleStackOnDisk(size_t size); + ~DottedRuleStackOnDisk(); - const ProcessedRuleCollOnDisk &Get(size_t pos) const { + const DottedRuleCollOnDisk &Get(size_t pos) const { return *m_coll[pos]; } - ProcessedRuleCollOnDisk &Get(size_t pos) { + DottedRuleCollOnDisk &Get(size_t pos) { return *m_coll[pos]; } - const ProcessedRuleCollOnDisk &back() const { + const DottedRuleCollOnDisk &back() const { return *m_coll.back(); } - void Add(size_t pos, const ProcessedRuleOnDisk *processedRule) { - assert(processedRule); + void Add(size_t pos, const DottedRuleOnDisk *dottedRule) { + assert(dottedRule); - m_coll[pos]->Add(processedRule); - m_savedNode.push_back(new SavedNodeOnDisk(processedRule)); + m_coll[pos]->Add(dottedRule); + m_savedNode.push_back(new SavedNodeOnDisk(dottedRule)); } const SavedNodeColl &GetSavedNodeColl() const { diff --git a/moses/src/Makefile.am b/moses/src/Makefile.am index 43780d2b4..06e4f9aae 100644 --- a/moses/src/Makefile.am +++ b/moses/src/Makefile.am @@ -8,12 +8,23 @@ libmoses_la_HEADERS = \ BilingualDynSuffixArray.h \ BitmapContainer.h \ CellCollection.h \ + ChartCell.h \ + ChartCellCollection.h \ + ChartHypothesis.h \ + ChartHypothesisCollection.h \ + ChartManager.h \ ChartRuleLookupManager.h \ ChartRuleLookupManagerMemory.h \ ChartRuleLookupManagerOnDisk.h \ ChartTranslationOption.h \ + ChartTranslationOptionCollection.h \ ChartTranslationOptionList.h \ + ChartTrellisNode.h \ + ChartTrellisPath.h \ + ChartTrellisPathCollection.h \ + ChartTrellisPathList.h \ ConfusionNet.h \ + Cube.h \ DecodeFeature.h \ DecodeGraph.h \ DecodeStep.h \ @@ -77,6 +88,7 @@ libmoses_la_HEADERS = \ PhraseDictionaryTreeAdaptor.h \ PrefixTree.h \ PrefixTreeMap.h \ + QueueEntry.h \ ReorderingConstraint.h \ ReorderingStack.h \ ScoreComponentCollection.h \ @@ -141,11 +153,22 @@ libmoses_la_SOURCES = \ AlignmentInfo.cpp \ BilingualDynSuffixArray.cpp \ BitmapContainer.cpp \ + ChartCell.cpp \ + ChartCellCollection.cpp \ + ChartHypothesis.cpp \ + ChartHypothesisCollection.cpp \ + ChartManager.cpp \ ChartRuleLookupManagerMemory.cpp \ ChartRuleLookupManagerOnDisk.cpp \ ChartTranslationOption.cpp \ + ChartTranslationOptionCollection.cpp \ ChartTranslationOptionList.cpp \ + ChartTrellisNode.cpp \ + ChartTrellisPath.cpp \ + ChartTrellisPathCollection.cpp \ + ChartTrellisPathList.cpp \ ConfusionNet.cpp \ + Cube.cpp \ DecodeFeature.cpp \ DecodeGraph.cpp \ DecodeStep.cpp \ @@ -204,6 +227,7 @@ libmoses_la_SOURCES = \ PhraseDictionaryTree.cpp \ PhraseDictionaryTreeAdaptor.cpp \ PrefixTreeMap.cpp \ + QueueEntry.cpp \ ReorderingConstraint.cpp \ ReorderingStack.cpp \ ScoreComponentCollection.cpp \ diff --git a/moses/src/PhraseDictionaryOnDisk.h b/moses/src/PhraseDictionaryOnDisk.h index 94d292e7d..81e558c20 100644 --- a/moses/src/PhraseDictionaryOnDisk.h +++ b/moses/src/PhraseDictionaryOnDisk.h @@ -32,7 +32,7 @@ namespace Moses { class TargetPhraseCollection; -class ProcessedRuleStackOnDisk; +class DottedRuleStackOnDisk; class CellCollection; class WordPenaltyProducer; diff --git a/moses/src/PhraseDictionarySCFG.cpp b/moses/src/PhraseDictionarySCFG.cpp index 76a960338..fe9eccecb 100644 --- a/moses/src/PhraseDictionarySCFG.cpp +++ b/moses/src/PhraseDictionarySCFG.cpp @@ -144,7 +144,7 @@ bool PhraseDictionarySCFG::Load(const std::vector &input // parse source & find pt node - // head word + // constituent labels Word sourceLHS, targetLHS; // source diff --git a/moses/src/PhraseDictionarySCFG.h b/moses/src/PhraseDictionarySCFG.h index f8b1df725..639a1df78 100644 --- a/moses/src/PhraseDictionarySCFG.h +++ b/moses/src/PhraseDictionarySCFG.h @@ -32,8 +32,8 @@ namespace Moses { class ChartTranslationOptionList; -class ProcessedRuleStack; -class ProcessedRuleColl; +class DottedRuleStack; +class DottedRuleColl; /*** Implementation of a phrase table in a trie. Looking up a phrase of * length n words requires n look-ups to find the TargetPhraseCollection. diff --git a/moses-chart/src/QueueEntry.cpp b/moses/src/QueueEntry.cpp similarity index 88% rename from moses-chart/src/QueueEntry.cpp rename to moses/src/QueueEntry.cpp index 1ccdf6a94..e87df9fa9 100644 --- a/moses-chart/src/QueueEntry.cpp +++ b/moses/src/QueueEntry.cpp @@ -24,10 +24,10 @@ #include "ChartTranslationOptionCollection.h" #include "ChartCellCollection.h" #include "Cube.h" -#include "../../moses/src/WordsRange.h" -#include "../../moses/src/ChartTranslationOption.h" -#include "../../moses/src/Util.h" -#include "../../moses/src/WordConsumed.h" +#include "WordsRange.h" +#include "ChartTranslationOption.h" +#include "Util.h" +#include "WordConsumed.h" #ifdef HAVE_BOOST #include @@ -36,7 +36,7 @@ using namespace std; using namespace Moses; -namespace MosesChart +namespace Moses { // create a cube for a rule @@ -63,17 +63,14 @@ void QueueEntry::CreateChildEntry(const Moses::WordConsumed *wordsConsumed, cons // get the essential information about the non-terminal const WordsRange &childRange = wordsConsumed->GetWordsRange(); // span covered by child const ChartCell &childCell = allChartCells.Get(childRange); // list of all hypos for that span - const Word &headWord = wordsConsumed->GetSourceWord(); // target (sic!) non-terminal label + const Word &nonTerm = wordsConsumed->GetSourceWord(); // target (sic!) non-terminal label // there have to be hypothesis with the desired non-terminal // (otherwise the rule would not be considered) - assert(!childCell.GetSortedHypotheses(headWord).empty()); + assert(!childCell.GetSortedHypotheses(nonTerm).empty()); - // ??? why are we looking it up again? - const Moses::Word &nonTerm = wordsConsumed->GetSourceWord(); - assert(nonTerm.IsNonTerminal()); // create a list of hypotheses that match the non-terminal - ChildEntry childEntry(0, childCell.GetSortedHypotheses(nonTerm), nonTerm); + ChildEntry childEntry(0, childCell.GetSortedHypotheses(nonTerm)); // add them to the vector for such lists m_childEntries.push_back(childEntry); } @@ -96,7 +93,7 @@ QueueEntry::~QueueEntry() // create new QueueEntry for neighboring principle rules // (duplicate detection is handled in Cube) -void QueueEntry::CreateDeviants(Cube &cube) const +void QueueEntry::CreateNeighbors(Cube &cube) const { // loop over all child hypotheses for (size_t ind = 0; ind < m_childEntries.size(); ind++) { @@ -117,7 +114,7 @@ void QueueEntry::CalcScore() for (size_t ind = 0; ind < m_childEntries.size(); ind++) { const ChildEntry &childEntry = m_childEntries[ind]; - const Hypothesis *hypo = childEntry.GetHypothesis(); + const ChartHypothesis *hypo = childEntry.GetHypothesis(); m_combinedScore += hypo->GetTotalScore(); } } @@ -134,7 +131,7 @@ bool QueueEntry::operator<(const QueueEntry &compare) const #ifdef HAVE_BOOST std::size_t hash_value(const ChildEntry & entry) { - boost::hash hasher; + boost::hash hasher; return hasher(entry.GetHypothesis()); } diff --git a/moses-chart/src/QueueEntry.h b/moses/src/QueueEntry.h similarity index 88% rename from moses-chart/src/QueueEntry.h rename to moses/src/QueueEntry.h index e7abba67b..97cd6d64f 100644 --- a/moses-chart/src/QueueEntry.h +++ b/moses/src/QueueEntry.h @@ -26,8 +26,8 @@ #include #include #include -#include "../../moses/src/WordsRange.h" -#include "../../moses/src/Word.h" +#include "WordsRange.h" +#include "Word.h" #include "ChartHypothesis.h" namespace Moses @@ -35,11 +35,6 @@ namespace Moses class WordConsumed; class ChartTranslationOption; extern bool g_debug; -}; - -namespace MosesChart -{ - class TranslationOptionCollection; class TranslationOptionList; class ChartCell; @@ -47,7 +42,7 @@ class ChartCellCollection; class QueueEntry; class Cube; -typedef std::vector HypoList; +typedef std::vector HypoList; // wrapper around list of hypothese for a particular non-term of a trans opt class ChildEntry @@ -59,10 +54,9 @@ protected: const HypoList *m_orderedHypos; public: - ChildEntry(size_t pos, const HypoList &orderedHypos, const Moses::Word & /*headWord*/ ) + ChildEntry(size_t pos, const HypoList &orderedHypos) :m_pos(pos) ,m_orderedHypos(&orderedHypos) - //,m_headWord(headWord) {} size_t IncrementPos() { @@ -73,13 +67,10 @@ public: return m_pos + 1 < m_orderedHypos->size(); } - const Hypothesis *GetHypothesis() const { + const ChartHypothesis *GetHypothesis() const { return (*m_orderedHypos)[m_pos]; } - //const Moses::Word &GetHeadWord() const - //{ return m_headWord; } - //! transitive comparison used for adding objects into FactorCollection bool operator<(const ChildEntry &compare) const { return GetHypothesis() < compare.GetHypothesis(); @@ -120,7 +111,7 @@ public: return m_combinedScore; } - void CreateDeviants(Cube &) const; + void CreateNeighbors(Cube &) const; bool operator<(const QueueEntry &compare) const; diff --git a/moses/src/WordConsumed.h b/moses/src/WordConsumed.h index 14d6f0b4b..f76e0188c 100644 --- a/moses/src/WordConsumed.h +++ b/moses/src/WordConsumed.h @@ -33,7 +33,7 @@ class WordConsumed protected: WordsRange m_coverage; - const Word &m_sourceWord; // can be non-term headword, or term + const Word &m_sourceWord; // can be non-term or term const WordConsumed *m_prevWordsConsumed; public: WordConsumed(); // not implmented