mosesdecoder/moses2/InputType.cpp

93 lines
2.2 KiB
C++
Raw Normal View History

/*
* InputType.cpp
*
* Created on: 14 Dec 2015
* Author: hieu
*/
2016-01-18 18:00:49 +03:00
#include "InputType.h"
2016-06-21 17:37:31 +03:00
#include "System.h"
2016-03-31 23:00:16 +03:00
namespace Moses2
{
2016-06-21 14:35:16 +03:00
//////////////////////////////////////////////////////////////////////////////
2016-06-22 00:54:34 +03:00
InputType::XMLOption::XMLOption(MemPool &pool, const std::string &nodeName, size_t vStartPos)
2017-02-01 03:27:14 +03:00
:startPos(vStartPos)
,prob(0)
,m_entity(NULL)
2016-06-22 01:53:50 +03:00
{
2017-02-01 03:27:14 +03:00
m_nodeName = pool.Allocate<char>(nodeName.size() + 1);
strcpy(m_nodeName, nodeName.c_str());
2016-06-22 01:53:50 +03:00
}
2016-06-22 00:54:34 +03:00
void InputType::XMLOption::SetTranslation(MemPool &pool, const std::string &val)
{
2017-02-01 03:27:14 +03:00
m_translation = pool.Allocate<char>(val.size() + 1);
strcpy(m_translation, val.c_str());
2016-06-22 00:54:34 +03:00
}
2016-06-21 14:35:16 +03:00
2016-08-26 20:35:30 +03:00
void InputType::XMLOption::SetEntity(MemPool &pool, const std::string &val)
2016-06-21 14:35:16 +03:00
{
2017-02-01 03:27:14 +03:00
m_entity = pool.Allocate<char>(val.size() + 1);
strcpy(m_entity, val.c_str());
2016-08-26 20:35:30 +03:00
}
std::string InputType::XMLOption::Debug(const System &system) const
{
std::stringstream out;
2016-06-21 14:35:16 +03:00
out << "[" << startPos << "," << phraseSize << "]="
2017-02-01 03:27:14 +03:00
<< m_nodeName << ","
<< m_translation << ","
<< prob;
2016-08-26 20:35:30 +03:00
if (m_entity) {
2017-02-01 03:27:14 +03:00
out << "," << m_entity;
2016-08-26 20:35:30 +03:00
}
return out.str();
2016-06-21 14:35:16 +03:00
}
//////////////////////////////////////////////////////////////////////////////
InputType::InputType(MemPool &pool)
2017-02-01 03:27:14 +03:00
:m_reorderingConstraint(pool)
,m_xmlOptions(pool)
,m_xmlCoverageMap(pool)
2016-06-07 19:57:33 +03:00
{
}
2016-03-31 23:00:16 +03:00
InputType::~InputType()
{
// TODO Auto-generated destructor stub
}
2016-06-21 17:37:31 +03:00
void InputType::Init(const System &system, size_t size, int max_distortion)
2016-06-07 14:03:03 +03:00
{
m_reorderingConstraint.InitializeWalls(size, max_distortion);
2016-06-21 17:37:31 +03:00
if (system.options.input.xml_policy != XmlPassThrough) {
2017-02-01 03:27:14 +03:00
m_xmlCoverageMap.assign(size, false);
2016-06-21 17:37:31 +03:00
}
2016-06-07 14:03:03 +03:00
}
2016-06-21 17:37:31 +03:00
void InputType::AddXMLOption(const System &system, const XMLOption *xmlOption)
2016-06-21 17:24:58 +03:00
{
2017-02-01 03:27:14 +03:00
m_xmlOptions.push_back(xmlOption);
2016-06-21 17:37:31 +03:00
if (system.options.input.xml_policy != XmlPassThrough) {
2017-02-01 03:27:14 +03:00
for(size_t j = xmlOption->startPos; j < xmlOption->startPos + xmlOption->phraseSize; ++j) {
m_xmlCoverageMap[j]=true;
}
2016-06-21 17:37:31 +03:00
}
}
bool InputType::XmlOverlap(size_t startPos, size_t endPos) const
{
for (size_t pos = startPos; pos <= endPos ; pos++) {
if (pos < m_xmlCoverageMap.size() && m_xmlCoverageMap[pos]) {
return true;
}
}
return false;
2016-06-21 17:24:58 +03:00
}
} /* namespace Moses2 */