diff --git a/moses/src/Sentence.cpp b/moses/src/Sentence.cpp index 0a6a2546..1c04547d 100644 --- a/moses/src/Sentence.cpp +++ b/moses/src/Sentence.cpp @@ -98,7 +98,7 @@ int Sentence::Read(std::istream& in,const std::vector& factorOrder) // parse XML markup in translation line //const StaticData &staticData = StaticData::Instance(); - std::vector > xmlOptionsList(0); + std::vector xmlOptionsList(0); std::vector< size_t > xmlWalls; if (staticData.GetXmlInputType() != XmlPassThrough) { if (!ProcessAndStripXMLTags(line, xmlOptionsList, m_reorderingConstraint, xmlWalls )) { @@ -125,47 +125,19 @@ int Sentence::Read(std::istream& in,const std::vector& factorOrder) //iterXMLOpts will be empty for XmlIgnore //look at each column - for(std::vector >::const_iterator iterXmlOpts = xmlOptionsList.begin(); + for(std::vector::const_iterator iterXmlOpts = xmlOptionsList.begin(); iterXmlOpts != xmlOptionsList.end(); iterXmlOpts++) { - //now we are looking through one column of linked things. - //TODO: We could drop this inner loop if we didn't support linked opts. - //we could loop once, make the new TranslationOption, note its pos. in the coverageMap, - //and delete the XmlOption -JS - std::vector linkedTransOpts(0); - for(std::vector::const_iterator iterLinkedXmlOpts = (iterXmlOpts)->begin(); - iterLinkedXmlOpts != (iterXmlOpts)->end(); iterLinkedXmlOpts++) { - - //make each item into a translation option - TranslationOption *transOpt = new TranslationOption((*iterLinkedXmlOpts)->range,(*iterLinkedXmlOpts)->targetPhrase,*this); - - //store it temporarily in the linkedTransOpts vector - linkedTransOpts.push_back(transOpt); + const XmlOption *xmlOption = *iterXmlOpts; - delete (*iterLinkedXmlOpts); + TranslationOption *transOpt = new TranslationOption(xmlOption->range, xmlOption->targetPhrase, *this); + m_xmlOptionsList.push_back(transOpt); + + for(size_t j=transOpt->GetSourceWordsRange().GetStartPos();j<=transOpt->GetSourceWordsRange().GetEndPos();j++) { + m_xmlCoverageMap[j]=true; } - //now link them up and add to m_XmlOptionsList TODO: this is complicated by linked options. Drop it? -JS - for(std::vector::const_iterator iterLinkedTransOpts1 = linkedTransOpts.begin(); - iterLinkedTransOpts1 != linkedTransOpts.end(); iterLinkedTransOpts1++) { - - for(std::vector::const_iterator iterLinkedTransOpts2 = linkedTransOpts.begin(); - iterLinkedTransOpts2 != linkedTransOpts.end(); iterLinkedTransOpts2++) { - - if (iterLinkedTransOpts1 != iterLinkedTransOpts2) { - (*iterLinkedTransOpts1)->AddLinkedTransOpt(*iterLinkedTransOpts2); - } - } //inner linked opts loop - - //ok everything is linked up and initialized, add it to our list of options and mark locations in coverage map - TranslationOption *transOpt = *iterLinkedTransOpts1; - - m_xmlOptionsList.push_back(transOpt); - - for(size_t j=transOpt->GetSourceWordsRange().GetStartPos();j<=transOpt->GetSourceWordsRange().GetEndPos();j++) { - m_xmlCoverageMap[j]=true; - } - }//outer linked opts loop + delete xmlOption; } } diff --git a/moses/src/TreeInput.cpp b/moses/src/TreeInput.cpp index 14b35bf1..efc6ee91 100644 --- a/moses/src/TreeInput.cpp +++ b/moses/src/TreeInput.cpp @@ -42,9 +42,7 @@ bool TreeInput::ProcessAndStripXMLTags(string &line, std::vector vector< OpenedTag > tagStack; // stack that contains active opened tags string cleanLine; // return string (text without xml) - vector linkedOptions; size_t wordPos = 0; // position in sentence (in terms of number of words) - bool isLinked = false; const vector &outputFactorOrder = StaticData::Instance().GetOutputFactorOrder(); const string &factorDelimiter = StaticData::Instance().GetFactorDelimiter(); @@ -111,16 +109,6 @@ bool TreeInput::ProcessAndStripXMLTags(string &line, std::vector if (isOpen || isUnary) { - // special case: linked tag turns on linked flag - if (tagName == "linked") - { - if (isLinked) - { - TRACE_ERR("ERROR: second linked tag opened before first one closed: " << line << endl); - return false; - } - isLinked = true; - } // put the tag on the tag stack OpenedTag openedTag = make_pair( tagName, make_pair( wordPos, tagContent ) ); tagStack.push_back( openedTag ); diff --git a/moses/src/XmlOption.cpp b/moses/src/XmlOption.cpp index 2d08f196..a74ae1ab 100644 --- a/moses/src/XmlOption.cpp +++ b/moses/src/XmlOption.cpp @@ -149,7 +149,7 @@ vector TokenizeXml(const string& str) parse because we don't have the completed source parsed until after this function removes all the markup from it (CreateFromString in Sentence::Read). */ -bool ProcessAndStripXMLTags(string &line, vector > &res, ReorderingConstraint &reorderingConstraint, vector< size_t > &walls ) { +bool ProcessAndStripXMLTags(string &line, vector &res, ReorderingConstraint &reorderingConstraint, vector< size_t > &walls ) { //parse XML markup in translation line // no xml tag? we're done. @@ -165,9 +165,8 @@ bool ProcessAndStripXMLTags(string &line, vector > &res, Reor vector< OpenedTag > tagStack; // stack that contains active opened tags string cleanLine; // return string (text without xml) - vector linkedOptions; size_t wordPos = 0; // position in sentence (in terms of number of words) - bool isLinked = false; + const vector &outputFactorOrder = StaticData::Instance().GetOutputFactorOrder(); const string &factorDelimiter = StaticData::Instance().GetFactorDelimiter(); @@ -234,16 +233,6 @@ bool ProcessAndStripXMLTags(string &line, vector > &res, Reor if (isOpen || isUnary) { - // special case: linked tag turns on linked flag - if (tagName == "linked") - { - if (isLinked) - { - TRACE_ERR("ERROR: second linked tag opened before first one closed: " << line << endl); - return false; - } - isLinked = true; - } // put the tag on the tag stack OpenedTag openedTag = make_pair( tagName, make_pair( wordPos, tagContent ) ); tagStack.push_back( openedTag ); @@ -290,11 +279,6 @@ bool ProcessAndStripXMLTags(string &line, vector > &res, Reor } VERBOSE(3,"XML TAG " << tagName << " (" << tagContent << ") spanning " << startPos << " to " << (endPos-1) << " complete, commence processing" << endl); - // special tag: - if (tagName == "linked") - { - isLinked = false; - } // special tag: wall if (tagName == "wall") @@ -375,18 +359,7 @@ bool ProcessAndStripXMLTags(string &line, vector > &res, Reor XmlOption *option = new XmlOption(range,targetPhrase); assert(option); - if (isLinked) - { - // push all linked items as one column in our list of xmloptions - linkedOptions.push_back(option); - } - else - { - // push one-item list (not linked to anything) - vector optList(0); - optList.push_back(option); - res.push_back(optList); - } + res.push_back(option); } altTexts.clear(); altProbs.clear(); diff --git a/moses/src/XmlOption.h b/moses/src/XmlOption.h index 3ada52a5..9e7eccd3 100644 --- a/moses/src/XmlOption.h +++ b/moses/src/XmlOption.h @@ -18,9 +18,10 @@ struct XmlOption { WordsRange range; TargetPhrase targetPhrase; - std::vector linkedOptions; - XmlOption(const WordsRange &r, const TargetPhrase &tp): range(r), targetPhrase(tp), linkedOptions(0) {} + XmlOption(const WordsRange &r, const TargetPhrase &tp) + : range(r), targetPhrase(tp) + {} }; @@ -29,7 +30,7 @@ std::string TrimXml(const std::string& str) ; bool isXmlTag(const std::string& tag); std::vector TokenizeXml(const std::string& str); -bool ProcessAndStripXMLTags(std::string &line,std::vector > &res, ReorderingConstraint &reorderingConstraint, std::vector< size_t > &walls ); +bool ProcessAndStripXMLTags(std::string &line, std::vector &res, ReorderingConstraint &reorderingConstraint, std::vector< size_t > &walls ); }