diff options
author | Hieu Hoang <hieu@hoang.co.uk> | 2013-07-19 18:38:13 +0400 |
---|---|---|
committer | Hieu Hoang <hieu@hoang.co.uk> | 2013-07-19 18:38:13 +0400 |
commit | b7b23dd703ca3bd6bb382092e59d89a387de7bcd (patch) | |
tree | 222047f14a8358f8e3a1225093de043e9438ba2f /moses/InputPath.cpp | |
parent | 116f1dcd41908772848ea0fee076eed28fd7566b (diff) |
starting placeholder
Diffstat (limited to 'moses/InputPath.cpp')
-rw-r--r-- | moses/InputPath.cpp | 41 |
1 files changed, 39 insertions, 2 deletions
diff --git a/moses/InputPath.cpp b/moses/InputPath.cpp index 09fed6588..9059b03bb 100644 --- a/moses/InputPath.cpp +++ b/moses/InputPath.cpp @@ -3,6 +3,9 @@ #include "TargetPhraseCollection.h" #include "StaticData.h" #include "TypeDef.h" +#include "AlignmentInfo.h" + +using namespace std; namespace Moses { @@ -60,8 +63,42 @@ void InputPath::SetTargetPhrases(const PhraseDictionary &phraseDictionary , const TargetPhraseCollection *targetPhrases , const void *ptNode) { - std::pair<const TargetPhraseCollection*, const void*> value(targetPhrases, ptNode); - m_targetPhrases[&phraseDictionary] = value; + FactorType placeholderFactor = StaticData::Instance().GetPlaceholderFactor(); + if (targetPhrases == NULL || placeholderFactor == NOT_FOUND || m_placeholders.size() == 0) { + // use all of the target phrase given + std::pair<const TargetPhraseCollection*, const void*> value(targetPhrases, ptNode); + m_targetPhrases[&phraseDictionary] = value; + } + else { + // filter out target phrases with alignments that are not 1-to-1 with placeholder + m_copiedSet.push_back(TargetPhraseCollection()); + TargetPhraseCollection &newTargetPhrases = m_copiedSet.back(); + std::pair<const TargetPhraseCollection*, const void*> value(&newTargetPhrases, ptNode); + m_targetPhrases[&phraseDictionary] = value; + + TargetPhraseCollection::const_iterator iter; + for (iter = targetPhrases->begin(); iter != targetPhrases->end(); ++iter) { + TargetPhrase *targetPhrase = *iter; + const AlignmentInfo &alignments = targetPhrase->GetAlignTerm(); + bool ok = IsCompatibleWithPlaceholders(alignments); + + if (ok) { + newTargetPhrases.Add(targetPhrase); + } + } + } +} + +bool InputPath::IsCompatibleWithPlaceholders(const AlignmentInfo &alignments) const +{ + for (size_t i = 0; i < m_placeholders.size(); ++i) { + size_t sourcePos = m_placeholders[i]; + set<size_t> targetPos = alignments.GetAlignmentsForSource(sourcePos); + if (targetPos.size() != 1) { + return false; + } + } + return true; } std::ostream& operator<<(std::ostream& out, const InputPath& obj) |