Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUlrich Germann <ugermann@inf.ed.ac.uk>2014-06-03 18:38:28 +0400
committerUlrich Germann <ugermann@inf.ed.ac.uk>2014-06-03 18:38:28 +0400
commit077f2ab51e81fbe4469c7c6b9d6246e245f7e498 (patch)
tree5befb73fdb062e413e20c364d08b1a95ea798017 /moses/Word.cpp
parentce435d22bfdf0407931ac62c3853975192417cba (diff)
Added some code to Word.cpp to allow factor-less decoding.
Factor-less decoding currently works ONLY with suffix-array-based phrase tables.
Diffstat (limited to 'moses/Word.cpp')
-rw-r--r--moses/Word.cpp29
1 files changed, 21 insertions, 8 deletions
diff --git a/moses/Word.cpp b/moses/Word.cpp
index 800d0bb33..04cbdb6a7 100644
--- a/moses/Word.cpp
+++ b/moses/Word.cpp
@@ -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) {