diff --git a/moses/src/Hypothesis.cpp b/moses/src/Hypothesis.cpp index ee8114e37..9c3e63874 100644 --- a/moses/src/Hypothesis.cpp +++ b/moses/src/Hypothesis.cpp @@ -53,7 +53,7 @@ Hypothesis::Hypothesis(Manager& manager, InputType const& source, const TargetPh : m_prevHypo(NULL) , m_targetPhrase(emptyTarget) , m_sourcePhrase(0) - , m_sourceCompleted(source.GetSize()) + , m_sourceCompleted(source.GetSize(), manager.m_source.translated_words) , m_sourceInput(source) , m_currSourceWordsRange(NOT_FOUND, NOT_FOUND) , m_currTargetWordsRange(NOT_FOUND, NOT_FOUND) diff --git a/moses/src/InputType.h b/moses/src/InputType.h index 92f8a2297..f99bfa884 100644 --- a/moses/src/InputType.h +++ b/moses/src/InputType.h @@ -50,6 +50,9 @@ protected: public: + std::vector translated_words; + std::string translated_target; + InputType(long translationId = 0); virtual ~InputType(); diff --git a/moses/src/Manager.h b/moses/src/Manager.h index ca23b1e37..4d6aff090 100644 --- a/moses/src/Manager.h +++ b/moses/src/Manager.h @@ -81,7 +81,7 @@ class Manager void operator=(Manager const&); protected: // data - InputType const& m_source; /**< source sentence to be translated */ +// InputType const& m_source; /**< source sentence to be translated */ TranslationOptionCollection *m_transOptColl; /**< pre-computed list of translation options for the phrases in this sentence */ Search *m_search; @@ -99,6 +99,7 @@ protected: public: + InputType const& m_source; /**< source sentence to be translated */ Manager(InputType const& source, SearchAlgorithm searchAlgorithm); ~Manager(); diff --git a/moses/src/Parameter.cpp b/moses/src/Parameter.cpp index aaae471a6..254434a5c 100644 --- a/moses/src/Parameter.cpp +++ b/moses/src/Parameter.cpp @@ -41,6 +41,7 @@ Parameter::Parameter() { AddParam("beam-threshold", "b", "threshold for threshold pruning"); AddParam("config", "f", "location of the configuration file"); + AddParam("continue-partial-translation", "cpt", "TODO - write info"); AddParam("drop-unknown", "du", "drop unknown words instead of copying them"); AddParam("disable-discarding", "dd", "disable hypothesis discarding"); AddParam("factor-delimiter", "fd", "specify a different factor delimiter than the default"); diff --git a/moses/src/SearchCubePruning.cpp b/moses/src/SearchCubePruning.cpp index 2697f0952..fe07c7206 100644 --- a/moses/src/SearchCubePruning.cpp +++ b/moses/src/SearchCubePruning.cpp @@ -47,7 +47,7 @@ SearchCubePruning::SearchCubePruning(Manager& manager, const InputType &source, :Search(manager) ,m_source(source) ,m_hypoStackColl(source.GetSize() + 1) -,m_initialTargetPhrase(Output) +,m_initialTargetPhrase(Output, source.translated_target) ,m_start(clock()) ,m_transOptColl(transOptColl) { diff --git a/moses/src/SearchNormal.cpp b/moses/src/SearchNormal.cpp index eb48528f9..da6ba54a9 100644 --- a/moses/src/SearchNormal.cpp +++ b/moses/src/SearchNormal.cpp @@ -16,7 +16,7 @@ SearchNormal::SearchNormal(Manager& manager, const InputType &source, const Tran :Search(manager) ,m_source(source) ,m_hypoStackColl(source.GetSize() + 1) - ,m_initialTargetPhrase(Output) + ,m_initialTargetPhrase(Output, source.translated_target) ,m_start(clock()) ,interrupted_flag(0) ,m_transOptColl(transOptColl) diff --git a/moses/src/Sentence.cpp b/moses/src/Sentence.cpp index c24f00d26..e1f16fcff 100644 --- a/moses/src/Sentence.cpp +++ b/moses/src/Sentence.cpp @@ -49,6 +49,30 @@ int Sentence::Read(std::istream& in,const std::vector& factorOrder) if (getline(in, line, '\n').eof()) return 0; + + //get covered words + const StaticData &staticData = StaticData::Instance(); + if (staticData.ContinuePartialTranslation()){ + string prev; + string score; + int loc1 = line.find( "|||", 0 ); + int loc2 = line.find( "|||", loc1 + 3 ); + if (loc1 > -1 && loc2 > -1){ + prev = line.substr(0, loc1); + score = line.substr(loc1 + 3, loc2 - loc1 - 3); + line = line.substr(loc2 + 3); + score = Trim(score); + prev = Trim(prev); + translated_target = prev; + int len = score.size(); + translated_words.resize(len); + for (int i = 0; i < len; ++i){ + if (score.at(i) == '1') translated_words[i] = true; + else translated_words[i] = false; + } + } + } + // remove extra spaces line = Trim(line); @@ -57,7 +81,7 @@ int Sentence::Read(std::istream& in,const std::vector& factorOrder) if (meta.find("id") != meta.end()) { this->SetTranslationId(atol(meta["id"].c_str())); } // parse XML markup in translation line - const StaticData &staticData = StaticData::Instance(); + //const StaticData &staticData = StaticData::Instance(); std::vector > xmlOptionsList(0); std::vector< size_t > xmlWalls; if (staticData.GetXmlInputType() != XmlPassThrough) { diff --git a/moses/src/StaticData.cpp b/moses/src/StaticData.cpp index a1270645a..2164c5c92 100644 --- a/moses/src/StaticData.cpp +++ b/moses/src/StaticData.cpp @@ -128,6 +128,8 @@ bool StaticData::LoadData(Parameter *parameter) if (m_parameter->GetParam("factor-delimiter").size() > 0) { m_factorDelimiter = m_parameter->GetParam("factor-delimiter")[0]; } + + SetBooleanParameter( &m_continuePartialTranslation, "continue-partial-translation", false ); //word-to-word alignment SetBooleanParameter( &m_UseAlignmentInfo, "use-alignment-info", false ); diff --git a/moses/src/StaticData.h b/moses/src/StaticData.h index 3750190e4..9edc5a980 100644 --- a/moses/src/StaticData.h +++ b/moses/src/StaticData.h @@ -221,7 +221,8 @@ protected: //! load decoding steps bool LoadLexicalReorderingModel(); bool LoadGlobalLexicalModel(); - void ReduceTransOptCache() const; + void ReduceTransOptCache() const; + bool m_continuePartialTranslation; public: @@ -545,7 +546,7 @@ public: const TranslationOptionList* FindTransOptListInCache(const DecodeGraph &decodeGraph, const Phrase &sourcePhrase) const; - bool PrintAllDerivations() const { return m_printAllDerivations;} + bool PrintAllDerivations() const { return m_printAllDerivations;} const UnknownLHSList &GetUnknownLHS() const { return m_unknownLHS; } @@ -566,6 +567,7 @@ public: { return 999999; /* TODO wtf! */ } + bool ContinuePartialTranslation() const { return m_continuePartialTranslation; } }; } diff --git a/moses/src/TargetPhrase.cpp b/moses/src/TargetPhrase.cpp index 6acbe5077..94d3c360b 100644 --- a/moses/src/TargetPhrase.cpp +++ b/moses/src/TargetPhrase.cpp @@ -42,6 +42,18 @@ bool TargetPhrase::printalign=StaticData::Instance().PrintAlignmentInfo(); //bool TargetPhrase::wordalignflag; //bool TargetPhrase::printalign; +TargetPhrase::TargetPhrase(FactorDirection direction, std::string out_string) + :Phrase(direction),m_transScore(0.0), m_ngramScore(0.0), m_fullScore(0.0), m_sourcePhrase(0) +{ + + //ACAT + const StaticData &staticData = StaticData::Instance(); + CreateFromString(staticData.GetInputFactorOrder(), out_string, staticData.GetFactorDelimiter()); + wordalignflag=StaticData::Instance().UseAlignmentInfo(); + printalign=StaticData::Instance().PrintAlignmentInfo(); +} + + TargetPhrase::TargetPhrase(FactorDirection direction) :Phrase(direction) , m_transScore(0.0) diff --git a/moses/src/TargetPhrase.h b/moses/src/TargetPhrase.h index a465e2a97..f2b7d1b06 100644 --- a/moses/src/TargetPhrase.h +++ b/moses/src/TargetPhrase.h @@ -81,11 +81,7 @@ protected: public: TargetPhrase(FactorDirection direction=Output); - ~TargetPhrase() - { - delete m_debugOutput; - }; - + TargetPhrase(FactorDirection direction, std::string out_string); /** used by the unknown word handler. * Set alignment to 0 */ diff --git a/moses/src/WordsBitmap.h b/moses/src/WordsBitmap.h index e24c8bb48..4ef4970f3 100644 --- a/moses/src/WordsBitmap.h +++ b/moses/src/WordsBitmap.h @@ -55,7 +55,25 @@ protected: } } + //sets elements by vector + void Initialize(std::vector vector) + { + for (size_t pos = 0 ; pos < m_size ; pos++) + { + if (vector[pos] == true) m_bitmap[pos] = true; + else m_bitmap[pos] = false; + } + } + + public: + //! create WordsBitmap of length size and initialise with vector + WordsBitmap(size_t size, std::vector initialize_vector) + :m_size (size) + { + m_bitmap = (bool*) malloc(sizeof(bool) * size); + Initialize(initialize_vector); + } //! create WordsBitmap of length size and initialise WordsBitmap(size_t size) :m_size (size)