This commit is contained in:
Hieu Hoang 2013-07-18 17:00:44 +01:00
parent f81d7a446f
commit cb46bd3c00
7 changed files with 25 additions and 26 deletions

View File

@ -125,7 +125,7 @@ int Sentence::Read(std::istream& in,const std::vector<FactorType>& factorOrder)
if (staticData.GetXmlInputType() != XmlPassThrough) {
if (!ProcessAndStripXMLTags(line, xmlOptionsList, m_reorderingConstraint, xmlWalls, placeholders,
staticData.GetXmlBrackets().first, staticData.GetXmlBrackets().second)) {
staticData.GetXmlBrackets().first, staticData.GetXmlBrackets().second)) {
const string msg("Unable to parse XML in line: " + line);
TRACE_ERR(msg << endl);
throw runtime_error(msg);
@ -205,15 +205,15 @@ void Sentence::ProcessPlaceholders(const std::vector< std::pair<size_t, std::str
{
FactorType factorType = StaticData::Instance().GetPlaceholderFactor();
if (factorType == NOT_FOUND) {
return;
return;
}
for (size_t i = 0; i < placeholders.size(); ++i) {
size_t pos = placeholders[i].first;
const string &str = placeholders[i].second;
const Factor *factor = FactorCollection::Instance().AddFactor(str);
Word &word = Phrase::GetWord(pos);
word[factorType] = factor;
size_t pos = placeholders[i].first;
const string &str = placeholders[i].second;
const Factor *factor = FactorCollection::Instance().AddFactor(str);
Word &word = Phrase::GetWord(pos);
word[factorType] = factor;
}
}

View File

@ -557,10 +557,9 @@ bool StaticData::LoadData(Parameter *parameter)
}
if (m_parameter->GetParam("placeholder-factor").size() > 0) {
m_placeHolderFactor = Scan<FactorType>(m_parameter->GetParam("placeholder-factor")[0]);
}
else {
m_placeHolderFactor = NOT_FOUND;
m_placeHolderFactor = Scan<FactorType>(m_parameter->GetParam("placeholder-factor")[0]);
} else {
m_placeHolderFactor = NOT_FOUND;
}
@ -1325,7 +1324,7 @@ void StaticData::OverrideFeatures()
CHECK(keyVal.size() == 2);
VERBOSE(1, "Override " << ff.GetScoreProducerDescription() << " "
<< keyVal[0] << "=" << keyVal[1] << endl);
<< keyVal[0] << "=" << keyVal[1] << endl);
ff.SetParameter(keyVal[0], keyVal[1]);

View File

@ -770,8 +770,9 @@ public:
void OverrideFeatures();
FactorType GetPlaceholderFactor() const
{ return m_placeHolderFactor; }
FactorType GetPlaceholderFactor() const {
return m_placeHolderFactor;
}
};
}

View File

@ -85,7 +85,7 @@ public:
void Sort(bool adhereTableLimit, size_t tableLimit);
void Clear() {
RemoveAllInColl(m_collection);
RemoveAllInColl(m_collection);
}
};

View File

@ -246,9 +246,8 @@ inline std::vector<std::string> TokenizeFirstOnly(const std::string& str,
// Found a token, add it to the vector.
tokens.push_back(str.substr(0, pos));
tokens.push_back(str.substr(pos + 1, str.size() - pos - 1));
}
else {
tokens.push_back(str);
} else {
tokens.push_back(str);
}
return tokens;

View File

@ -150,7 +150,7 @@ vector<string> TokenizeXml(const string& str, const std::string& lbrackStr, cons
* \param rbrackStr xml tag's right bracket string, typically ">"
*/
bool ProcessAndStripXMLTags(string &line, vector<XmlOption*> &res, ReorderingConstraint &reorderingConstraint, vector< size_t > &walls,
std::vector< std::pair<size_t, std::string> > &placeholders,
std::vector< std::pair<size_t, std::string> > &placeholders,
const std::string& lbrackStr, const std::string& rbrackStr)
{
//parse XML markup in translation line
@ -295,12 +295,12 @@ bool ProcessAndStripXMLTags(string &line, vector<XmlOption*> &res, ReorderingCon
// name-entity placeholder
else if (tagName == "ne") {
if (startPos != (endPos - 1)) {
TRACE_ERR("ERROR: Placeholder must only span 1 word: " << line << endl);
return false;
}
string entity = ParseXmlTagAttribute(tagContent,"entity");
placeholders.push_back(std::pair<size_t, std::string>(startPos, entity));
if (startPos != (endPos - 1)) {
TRACE_ERR("ERROR: Placeholder must only span 1 word: " << line << endl);
return false;
}
string entity = ParseXmlTagAttribute(tagContent,"entity");
placeholders.push_back(std::pair<size_t, std::string>(startPos, entity));
}
// default: opening tag that specifies translation options

View File

@ -31,7 +31,7 @@ bool isXmlTag(const std::string& tag, const std::string& lbrackStr="<", const st
std::vector<std::string> TokenizeXml(const std::string& str, const std::string& lbrackStr="<", const std::string& rbrackStr=">");
bool ProcessAndStripXMLTags(std::string &line, std::vector<XmlOption*> &res, ReorderingConstraint &reorderingConstraint, std::vector< size_t > &walls,
std::vector< std::pair<size_t, std::string> > &placeholders,
std::vector< std::pair<size_t, std::string> > &placeholders,
const std::string& lbrackStr="<", const std::string& rbrackStr=">");
}