mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-12-26 13:23:25 +03:00
make scfg work with factored input. Strip factors from source that are not part of phrase-table input factors
This commit is contained in:
parent
75c85acd5e
commit
b448c6285a
@ -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
|
||||
|
@ -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) {
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user