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:
authorHieu Hoang <hieuhoang@gmail.com>2013-09-19 18:33:21 +0400
committerHieu Hoang <hieuhoang@gmail.com>2013-09-19 18:33:21 +0400
commitffbfcb5577efbff5825519739464128811e9d490 (patch)
tree876f6a81f9ce93558580594ef8b0eb1b06309b5f /moses-cmd
parent98bb4fa1c72517efd64da416ecb493c9f92dc487 (diff)
placeholders work in pb decoder. God i'm bored
Diffstat (limited to 'moses-cmd')
-rw-r--r--moses-cmd/IOWrapper.cpp41
-rw-r--r--moses-cmd/IOWrapper.h5
2 files changed, 39 insertions, 7 deletions
diff --git a/moses-cmd/IOWrapper.cpp b/moses-cmd/IOWrapper.cpp
index b04257e8b..ce017ecf2 100644
--- a/moses-cmd/IOWrapper.cpp
+++ b/moses-cmd/IOWrapper.cpp
@@ -188,6 +188,25 @@ InputType*IOWrapper::GetInput(InputType* inputType)
}
}
+std::map<size_t, const Factor*> GetPlaceholders(const Hypothesis &hypo, FactorType placeholderFactor)
+{
+ const InputPath &inputPath = hypo.GetTranslationOption().GetInputPath();
+ const Phrase &inputPhrase = inputPath.GetPhrase();
+
+ std::map<size_t, const Factor*> ret;
+
+ for (size_t sourcePos = 0; sourcePos < inputPhrase.GetSize(); ++sourcePos) {
+ const Factor *factor = inputPhrase.GetFactor(sourcePos, placeholderFactor);
+ if (factor) {
+ std::set<size_t> targetPos = hypo.GetTranslationOption().GetTargetPhrase().GetAlignTerm().GetAlignmentsForSource(sourcePos);
+ CHECK(targetPos.size() == 1);
+ ret[*targetPos.begin()] = factor;
+ }
+ }
+
+ return ret;
+}
+
/***
* print surface factor only for the given phrase
*/
@@ -195,23 +214,31 @@ void OutputSurface(std::ostream &out, const Hypothesis &edge, const std::vector<
char reportSegmentation, bool reportAllFactors)
{
CHECK(outputFactorOrder.size() > 0);
- const Phrase& phrase = edge.GetCurrTargetPhrase();
+ const TargetPhrase& phrase = edge.GetCurrTargetPhrase();
bool markUnknown = StaticData::Instance().GetMarkUnknown();
if (reportAllFactors == true) {
out << phrase;
} else {
- FactorType placeholderFactor = StaticData::Instance().GetPlaceholderFactor().second;
+ FactorType placeholderFactor = StaticData::Instance().GetPlaceholderFactor().first;
+
+ std::map<size_t, const Factor*> placeholders;
+ if (placeholderFactor != NOT_FOUND) {
+ // creates map of target position -> factor for placeholders
+ placeholders = GetPlaceholders(edge, placeholderFactor);
+ }
size_t size = phrase.GetSize();
for (size_t pos = 0 ; pos < size ; pos++) {
const Factor *factor = phrase.GetFactor(pos, outputFactorOrder[0]);
- if (placeholderFactor != NOT_FOUND) {
- const Factor *origFactor = phrase.GetFactor(pos, placeholderFactor);
- if (origFactor) {
- factor = origFactor;
- }
+ if (placeholders.size()) {
+ // do placeholders
+ std::map<size_t, const Factor*>::const_iterator iter = placeholders.find(pos);
+ if (iter != placeholders.end()) {
+ factor = iter->second;
+ }
}
+
CHECK(factor);
//preface surface form with UNK if marking unknowns
diff --git a/moses-cmd/IOWrapper.h b/moses-cmd/IOWrapper.h
index 7e8ae2640..519091e67 100644
--- a/moses-cmd/IOWrapper.h
+++ b/moses-cmd/IOWrapper.h
@@ -56,6 +56,8 @@ POSSIBILITY OF SUCH DAMAGE.
namespace Moses
{
class ScoreComponentCollection;
+class Hypothesis;
+class Factor;
}
namespace MosesCmd
@@ -154,6 +156,9 @@ void OutputFeatureScores( std::ostream& out
, const Moses::FeatureFunction *ff
, std::string &lastName );
+// creates a map of target positions which should be replaced by word using placeholder
+std::map<size_t, const Moses::Factor*> GetPlaceholders(const Moses::Hypothesis &hypo, Moses::FactorType placeholderFactor);
+
}
#endif