mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-12-26 05:14:36 +03:00
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:
parent
ce435d22bf
commit
077f2ab51e
@ -34,6 +34,15 @@ using namespace std;
|
||||
|
||||
namespace Moses
|
||||
{
|
||||
|
||||
// utility function for factorless decoding
|
||||
size_t
|
||||
max_fax()
|
||||
{
|
||||
if (StaticData::Instance().GetFactorDelimiter().size())
|
||||
return MAX_NUM_FACTORS;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// static
|
||||
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++) {
|
||||
const Factor *targetFactor = targetWord[factorType]
|
||||
,*sourceFactor = sourceWord[factorType];
|
||||
const Factor *targetFactor = targetWord[factorType];
|
||||
const Factor *sourceFactor = sourceWord[factorType];
|
||||
|
||||
if (targetFactor == NULL || sourceFactor == NULL)
|
||||
continue;
|
||||
@ -73,9 +82,11 @@ std::string Word::GetString(const vector<FactorType> factorType,bool endWithBlan
|
||||
stringstream strme;
|
||||
const std::string& factorDelimiter = StaticData::Instance().GetFactorDelimiter();
|
||||
bool firstPass = true;
|
||||
for (unsigned int i = 0 ; i < factorType.size() ; i++) {
|
||||
UTIL_THROW_IF2(factorType[i] >= MAX_NUM_FACTORS,
|
||||
"Trying to reference factor " << factorType[i] << ". Max factor is " << MAX_NUM_FACTORS);
|
||||
unsigned int stop = min(max_fax(),factorType.size());
|
||||
for (unsigned int i = 0 ; i < stop ; i++) {
|
||||
UTIL_THROW_IF2(factorType[i] >= MAX_NUM_FACTORS,
|
||||
"Trying to reference factor " << factorType[i]
|
||||
<< ". Max factor is " << MAX_NUM_FACTORS);
|
||||
|
||||
const Factor *factor = m_factorArray[factorType[i]];
|
||||
if (factor != NULL) {
|
||||
@ -152,7 +163,9 @@ void Word::CreateUnknownWord(const Word &sourceWord)
|
||||
|
||||
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);
|
||||
|
||||
const Factor *sourceFactor = sourceWord[currFactor];
|
||||
@ -188,10 +201,10 @@ TO_STRING_BODY(Word);
|
||||
ostream& operator<<(ostream& out, const Word& word)
|
||||
{
|
||||
stringstream strme;
|
||||
|
||||
const std::string& factorDelimiter = StaticData::Instance().GetFactorDelimiter();
|
||||
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);
|
||||
const Factor *factor = word.GetFactor(factorType);
|
||||
if (factor != NULL) {
|
||||
|
Loading…
Reference in New Issue
Block a user