Added some code to Word.cpp to allow factor-less decoding.

Factor-less decoding currently works ONLY with suffix-array-based phrase tables.
This commit is contained in:
Ulrich Germann 2014-06-03 15:38:28 +01:00
parent ce435d22bf
commit 077f2ab51e

View File

@ -35,6 +35,15 @@ using namespace std;
namespace Moses namespace Moses
{ {
// utility function for factorless decoding
size_t
max_fax()
{
if (StaticData::Instance().GetFactorDelimiter().size())
return MAX_NUM_FACTORS;
return 1;
}
// static // static
int Word::Compare(const Word &targetWord, const Word &sourceWord) int Word::Compare(const Word &targetWord, const Word &sourceWord)
{ {
@ -43,8 +52,8 @@ int Word::Compare(const Word &targetWord, const Word &sourceWord)
} }
for (size_t factorType = 0 ; factorType < MAX_NUM_FACTORS ; factorType++) { for (size_t factorType = 0 ; factorType < MAX_NUM_FACTORS ; factorType++) {
const Factor *targetFactor = targetWord[factorType] const Factor *targetFactor = targetWord[factorType];
,*sourceFactor = sourceWord[factorType]; const Factor *sourceFactor = sourceWord[factorType];
if (targetFactor == NULL || sourceFactor == NULL) if (targetFactor == NULL || sourceFactor == NULL)
continue; continue;
@ -73,9 +82,11 @@ std::string Word::GetString(const vector<FactorType> factorType,bool endWithBlan
stringstream strme; stringstream strme;
const std::string& factorDelimiter = StaticData::Instance().GetFactorDelimiter(); const std::string& factorDelimiter = StaticData::Instance().GetFactorDelimiter();
bool firstPass = true; bool firstPass = true;
for (unsigned int i = 0 ; i < factorType.size() ; i++) { unsigned int stop = min(max_fax(),factorType.size());
for (unsigned int i = 0 ; i < stop ; i++) {
UTIL_THROW_IF2(factorType[i] >= MAX_NUM_FACTORS, UTIL_THROW_IF2(factorType[i] >= MAX_NUM_FACTORS,
"Trying to reference factor " << factorType[i] << ". Max factor is " << MAX_NUM_FACTORS); "Trying to reference factor " << factorType[i]
<< ". Max factor is " << MAX_NUM_FACTORS);
const Factor *factor = m_factorArray[factorType[i]]; const Factor *factor = m_factorArray[factorType[i]];
if (factor != NULL) { if (factor != NULL) {
@ -152,7 +163,9 @@ void Word::CreateUnknownWord(const Word &sourceWord)
m_isNonTerminal = sourceWord.IsNonTerminal(); m_isNonTerminal = sourceWord.IsNonTerminal();
for (unsigned int currFactor = 0 ; currFactor < MAX_NUM_FACTORS ; currFactor++) { // const std::string& factorDelimiter = StaticData::Instance().GetFactorDelimiter();
unsigned int stop = max_fax();
for (unsigned int currFactor = 0 ; currFactor < stop; currFactor++) {
FactorType factorType = static_cast<FactorType>(currFactor); FactorType factorType = static_cast<FactorType>(currFactor);
const Factor *sourceFactor = sourceWord[currFactor]; const Factor *sourceFactor = sourceWord[currFactor];
@ -188,10 +201,10 @@ TO_STRING_BODY(Word);
ostream& operator<<(ostream& out, const Word& word) ostream& operator<<(ostream& out, const Word& word)
{ {
stringstream strme; stringstream strme;
const std::string& factorDelimiter = StaticData::Instance().GetFactorDelimiter(); const std::string& factorDelimiter = StaticData::Instance().GetFactorDelimiter();
bool firstPass = true; bool firstPass = true;
for (unsigned int currFactor = 0 ; currFactor < MAX_NUM_FACTORS ; currFactor++) { unsigned int stop = max_fax();
for (unsigned int currFactor = 0 ; currFactor < stop; currFactor++) {
FactorType factorType = static_cast<FactorType>(currFactor); FactorType factorType = static_cast<FactorType>(currFactor);
const Factor *factor = word.GetFactor(factorType); const Factor *factor = word.GetFactor(factorType);
if (factor != NULL) { if (factor != NULL) {