2014-08-29 19:24:49 +04:00
|
|
|
/*
|
|
|
|
* NonTerm.cpp
|
|
|
|
*
|
|
|
|
* Created on: 22 Feb 2014
|
|
|
|
* Author: hieu
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sstream>
|
|
|
|
#include "NonTerm.h"
|
|
|
|
#include "Word.h"
|
|
|
|
#include "ConsistentPhrase.h"
|
|
|
|
#include "Parameter.h"
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
NonTerm::NonTerm(const ConsistentPhrase &consistentPhrase,
|
2015-01-15 14:18:39 +03:00
|
|
|
const std::string &source,
|
|
|
|
const std::string &target)
|
|
|
|
:m_consistentPhrase(&consistentPhrase)
|
|
|
|
,m_source(source)
|
|
|
|
,m_target(target)
|
2014-08-29 19:24:49 +04:00
|
|
|
{
|
2015-01-15 14:18:39 +03:00
|
|
|
// TODO Auto-generated constructor stub
|
2014-08-29 19:24:49 +04:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-01-15 14:18:39 +03:00
|
|
|
NonTerm::~NonTerm()
|
|
|
|
{
|
|
|
|
// TODO Auto-generated destructor stub
|
2014-08-29 19:24:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string NonTerm::Debug() const
|
|
|
|
{
|
|
|
|
stringstream out;
|
|
|
|
out << m_source << m_target;
|
|
|
|
out << m_consistentPhrase->Debug();
|
|
|
|
return out.str();
|
|
|
|
}
|
|
|
|
|
|
|
|
void NonTerm::Output(std::ostream &out) const
|
|
|
|
{
|
|
|
|
out << m_source << m_target;
|
|
|
|
}
|
|
|
|
|
|
|
|
void NonTerm::Output(std::ostream &out, Moses::FactorDirection direction) const
|
|
|
|
{
|
2015-01-15 14:18:39 +03:00
|
|
|
out << GetLabel(direction);
|
2014-08-29 19:24:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
const std::string &NonTerm::GetLabel(Moses::FactorDirection direction) const
|
|
|
|
{
|
|
|
|
return (direction == Moses::Input) ? m_source : m_target;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool NonTerm::IsHiero(Moses::FactorDirection direction, const Parameter ¶ms) const
|
|
|
|
{
|
2015-01-15 14:18:39 +03:00
|
|
|
const std::string &label = NonTerm::GetLabel(direction);
|
|
|
|
return label == params.hieroNonTerm;
|
2014-08-29 19:24:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool NonTerm::IsHiero(const Parameter ¶ms) const
|
|
|
|
{
|
2015-01-15 14:18:39 +03:00
|
|
|
return IsHiero(Moses::Input, params) && IsHiero(Moses::Output, params);
|
2014-08-29 19:24:49 +04:00
|
|
|
}
|
2014-08-30 10:44:53 +04:00
|
|
|
|
2014-08-29 19:24:49 +04:00
|
|
|
int NonTerm::GetWidth(Moses::FactorDirection direction) const
|
2015-01-15 14:18:39 +03:00
|
|
|
{
|
|
|
|
return GetConsistentPhrase().GetWidth(direction);
|
|
|
|
}
|