make scfg work with factored input. Strip factors from source that are not part of phrase-table input factors

This commit is contained in:
Hieu Hoang 2013-04-26 12:20:49 +01:00
parent 75c85acd5e
commit b448c6285a
5 changed files with 20 additions and 4 deletions

View File

@ -342,6 +342,17 @@ void Phrase::FinalizeMemPool()
{
}
void Phrase::OnlyTheseFactors(const FactorMask &factors)
{
for (unsigned int currFactor = 0 ; currFactor < MAX_NUM_FACTORS ; currFactor++) {
if (!factors[currFactor]) {
for (size_t pos = 0; pos < GetSize(); ++pos) {
SetFactor(pos, currFactor, NULL);
}
}
}
}
TO_STRING_BODY(Phrase);
// friend

View File

@ -39,6 +39,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
namespace Moses
{
class FactorMask;
/** Representation of a phrase, ie. a contiguous number of words.
* Wrapper for vector of words
@ -166,6 +167,9 @@ public:
{
return Compare(compare) == 0;
}
void OnlyTheseFactors(const FactorMask &factors);
};
inline size_t hash_value(const Phrase& phrase) {

View File

@ -85,7 +85,9 @@ PhraseDictionary::PhraseDictionary(const std::string &description, const std::st
const TargetPhraseCollection *PhraseDictionary::
GetTargetPhraseCollection(InputType const& src,WordsRange const& range) const
{
return GetTargetPhraseCollection(src.GetSubString(range));
Phrase phrase = src.GetSubString(range);
phrase.OnlyTheseFactors(m_inputFactors);
return GetTargetPhraseCollection(phrase);
}
}

View File

@ -113,6 +113,8 @@ void TranslationOption::CalcScore(const TranslationSystem* system)
// future score
m_futureScore = retFullScore - ngramScore + oovScore
+ m_scoreBreakdown.GetWeightedScore();
cerr << *this << endl;
}
TO_STRING_BODY(TranslationOption);

View File

@ -266,17 +266,14 @@ void TranslationOptionCollection::ProcessOneUnknownWord(const Word &sourceWord,s
targetPhrase.SetScore(unknownWordPenaltyProducer, unknownScore);
targetPhrase.SetScore(staticData.GetWordPenaltyProducer(), wordPenaltyScore);
cerr << targetPhrase << endl;
if (inputScores != NULL) {
targetPhrase.SetScore(m_system,*inputScores);
}
cerr << targetPhrase << endl;
transOpt = new TranslationOption(WordsRange(sourcePos, sourcePos + length - 1), targetPhrase, m_source
, StaticData::Instance().GetUnknownWordPenaltyProducer());
transOpt->CalcScore(m_system);
cerr << *transOpt << endl;
Add(transOpt);