Skip to content

Commit

Permalink
get rid of linked trans opt
Browse files Browse the repository at this point in the history
git-svn-id: https://mosesdecoder.svn.sourceforge.net/svnroot/mosesdecoder/trunk@3863 1f5c12ca-751b-0410-a591-d2e778427230
  • Loading branch information
hieuhoang1972 committed Feb 2, 2011
1 parent ddc8087 commit c0cdeb4
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 82 deletions.
46 changes: 9 additions & 37 deletions moses/src/Sentence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ int Sentence::Read(std::istream& in,const std::vector<FactorType>& factorOrder)

// parse XML markup in translation line
//const StaticData &staticData = StaticData::Instance();
std::vector<std::vector<XmlOption*> > xmlOptionsList(0);
std::vector<XmlOption*> xmlOptionsList(0);
std::vector< size_t > xmlWalls;
if (staticData.GetXmlInputType() != XmlPassThrough) {
if (!ProcessAndStripXMLTags(line, xmlOptionsList, m_reorderingConstraint, xmlWalls )) {
Expand All @@ -125,47 +125,19 @@ int Sentence::Read(std::istream& in,const std::vector<FactorType>& factorOrder)

//iterXMLOpts will be empty for XmlIgnore
//look at each column
for(std::vector<std::vector<XmlOption*> >::const_iterator iterXmlOpts = xmlOptionsList.begin();
for(std::vector<XmlOption*>::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<TranslationOption*> linkedTransOpts(0);
for(std::vector<XmlOption*>::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<TranslationOption *>::const_iterator iterLinkedTransOpts1 = linkedTransOpts.begin();
iterLinkedTransOpts1 != linkedTransOpts.end(); iterLinkedTransOpts1++) {

for(std::vector<TranslationOption *>::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;
}

}
Expand Down
12 changes: 0 additions & 12 deletions moses/src/TreeInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ bool TreeInput::ProcessAndStripXMLTags(string &line, std::vector<XMLParseOutput>
vector< OpenedTag > tagStack; // stack that contains active opened tags

string cleanLine; // return string (text without xml)
vector<XmlOption*> linkedOptions;
size_t wordPos = 0; // position in sentence (in terms of number of words)
bool isLinked = false;
const vector<FactorType> &outputFactorOrder = StaticData::Instance().GetOutputFactorOrder();
const string &factorDelimiter = StaticData::Instance().GetFactorDelimiter();

Expand Down Expand Up @@ -111,16 +109,6 @@ bool TreeInput::ProcessAndStripXMLTags(string &line, std::vector<XMLParseOutput>

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 );
Expand Down
33 changes: 3 additions & 30 deletions moses/src/XmlOption.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ vector<string> 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<vector<XmlOption*> > &res, ReorderingConstraint &reorderingConstraint, vector< size_t > &walls ) {
bool ProcessAndStripXMLTags(string &line, vector<XmlOption*> &res, ReorderingConstraint &reorderingConstraint, vector< size_t > &walls ) {
//parse XML markup in translation line

// no xml tag? we're done.
Expand All @@ -165,9 +165,8 @@ bool ProcessAndStripXMLTags(string &line, vector<vector<XmlOption*> > &res, Reor
vector< OpenedTag > tagStack; // stack that contains active opened tags

string cleanLine; // return string (text without xml)
vector<XmlOption*> linkedOptions;
size_t wordPos = 0; // position in sentence (in terms of number of words)
bool isLinked = false;

const vector<FactorType> &outputFactorOrder = StaticData::Instance().GetOutputFactorOrder();
const string &factorDelimiter = StaticData::Instance().GetFactorDelimiter();

Expand Down Expand Up @@ -234,16 +233,6 @@ bool ProcessAndStripXMLTags(string &line, vector<vector<XmlOption*> > &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 );
Expand Down Expand Up @@ -290,11 +279,6 @@ bool ProcessAndStripXMLTags(string &line, vector<vector<XmlOption*> > &res, Reor
}

VERBOSE(3,"XML TAG " << tagName << " (" << tagContent << ") spanning " << startPos << " to " << (endPos-1) << " complete, commence processing" << endl);
// special tag: <linked>
if (tagName == "linked")
{
isLinked = false;
}

// special tag: wall
if (tagName == "wall")
Expand Down Expand Up @@ -375,18 +359,7 @@ bool ProcessAndStripXMLTags(string &line, vector<vector<XmlOption*> > &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<XmlOption*> optList(0);
optList.push_back(option);
res.push_back(optList);
}
res.push_back(option);
}
altTexts.clear();
altProbs.clear();
Expand Down
7 changes: 4 additions & 3 deletions moses/src/XmlOption.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ struct XmlOption {

WordsRange range;
TargetPhrase targetPhrase;
std::vector<XmlOption*> 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)
{}

};

Expand All @@ -29,7 +30,7 @@ std::string TrimXml(const std::string& str) ;
bool isXmlTag(const std::string& tag);
std::vector<std::string> TokenizeXml(const std::string& str);

bool ProcessAndStripXMLTags(std::string &line,std::vector<std::vector<XmlOption*> > &res, ReorderingConstraint &reorderingConstraint, std::vector< size_t > &walls );
bool ProcessAndStripXMLTags(std::string &line, std::vector<XmlOption*> &res, ReorderingConstraint &reorderingConstraint, std::vector< size_t > &walls );

}

Expand Down

0 comments on commit c0cdeb4

Please sign in to comment.