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:
authorbhaddow <barry.haddow@gmail.com>2011-09-20 14:23:38 +0400
committerbhaddow <barry.haddow@gmail.com>2011-09-20 14:23:38 +0400
commit5b7c5ebdb50c84a05afef1f479049d82be668b8e (patch)
treeb89ff733bf9aad1e9890af270558db4951b9f6f0 /moses-cmd
parent2dd9e4cc7c3b8ba549376483c80bab551bc9bff5 (diff)
parenta064f799e06e8ee6fdb5f8d579e297b645ea97d8 (diff)
Merge branch 'master' into miramerge
Conflicts: moses-chart-cmd/src/Main.cpp moses-cmd/src/IOWrapper.cpp moses-cmd/src/Main.cpp moses/src/DummyScoreProducers.cpp moses/src/DummyScoreProducers.h moses/src/GenerationDictionary.cpp moses/src/GenerationDictionary.h moses/src/GlobalLexicalModel.h moses/src/LMList.h moses/src/LanguageModel.cpp moses/src/LanguageModel.h moses/src/LanguageModelImplementation.h moses/src/LanguageModelKen.h moses/src/LanguageModelMultiFactor.cpp moses/src/LanguageModelMultiFactor.h moses/src/LanguageModelSingleFactor.cpp moses/src/LanguageModelSingleFactor.h moses/src/LexicalReordering.h moses/src/PhraseDictionary.cpp moses/src/PhraseDictionary.h moses/src/ScoreIndexManager.cpp moses/src/ScoreProducer.h moses/src/StaticData.cpp moses/src/StaticData.h moses/src/TranslationSystem.cpp
Diffstat (limited to 'moses-cmd')
-rw-r--r--moses-cmd/src/IOWrapper.cpp128
-rw-r--r--moses-cmd/src/Main.cpp1
2 files changed, 62 insertions, 67 deletions
diff --git a/moses-cmd/src/IOWrapper.cpp b/moses-cmd/src/IOWrapper.cpp
index f3c73caf8..30e98558e 100644
--- a/moses-cmd/src/IOWrapper.cpp
+++ b/moses-cmd/src/IOWrapper.cpp
@@ -207,22 +207,40 @@ void OutputSurface(std::ostream &out, const Phrase &phrase, const std::vector<Fa
}
}
-void OutputAlignment(OutputCollector* collector, size_t lineNo , const vector<const Hypothesis *> &edges)
+void OutputAlignment(ostream &out, const AlignmentInfo &ai, size_t sourceOffset, size_t targetOffset)
+{
+ typedef std::vector< const std::pair<size_t,size_t>* > AlignVec;
+ AlignVec alignments = ai.GetSortedAlignments();
+
+ AlignVec::const_iterator it;
+ for (it = alignments.begin(); it != alignments.end(); ++it) {
+ const std::pair<size_t,size_t> &alignment = **it;
+ out << alignment.first + sourceOffset << "-" << alignment.second + targetOffset << " ";
+ }
+
+}
+
+void OutputAlignment(ostream &out, const vector<const Hypothesis *> &edges)
{
- ostringstream out;
size_t targetOffset = 0;
for (int currEdge = (int)edges.size() - 1 ; currEdge >= 0 ; currEdge--) {
const Hypothesis &edge = *edges[currEdge];
const TargetPhrase &tp = edge.GetCurrTargetPhrase();
size_t sourceOffset = edge.GetCurrSourceWordsRange().GetStartPos();
- AlignmentInfo::const_iterator it;
- for (it = tp.GetAlignmentInfo().begin(); it != tp.GetAlignmentInfo().end(); ++it) {
- out << it->first + sourceOffset << "-" << it->second + targetOffset << " ";
- }
+
+ OutputAlignment(out, tp.GetAlignmentInfo(), sourceOffset, targetOffset);
+
targetOffset += tp.GetSize();
}
out << std::endl;
+}
+
+void OutputAlignment(OutputCollector* collector, size_t lineNo , const vector<const Hypothesis *> &edges)
+{
+ ostringstream out;
+ OutputAlignment(out, edges);
+
collector->Write(lineNo,out.str());
}
@@ -364,68 +382,45 @@ void OutputNBest(std::ostream& out, const Moses::TrellisPathList &nBestList, con
// print scores with feature names
OutputAllFeatureScores( out, system, path );
+ string lastName;
// translation components
- if (StaticData::Instance().GetInputType()==SentenceInput) {
- // translation components for text input
- vector<PhraseDictionaryFeature*> pds = system->GetPhraseDictionaries();
- if (pds.size() > 0) {
- if (labeledOutput)
- out << " tm:";
- vector<PhraseDictionaryFeature*>::iterator iter;
- for (iter = pds.begin(); iter != pds.end(); ++iter) {
- vector<float> scores = path.GetScoreBreakdown().GetScoresForProducer(*iter);
- for (size_t j = 0; j<scores.size(); ++j)
- out << " " << scores[j];
- }
- }
- } else {
- // translation components for Confusion Network input
- // first translation component has GetNumInputScores() scores from the input Confusion Network
- // at the beginning of the vector
- vector<PhraseDictionaryFeature*> pds = system->GetPhraseDictionaries();
- if (pds.size() > 0) {
- vector<PhraseDictionaryFeature*>::iterator iter;
-
- iter = pds.begin();
- vector<float> scores = path.GetScoreBreakdown().GetScoresForProducer(*iter);
-
- size_t pd_numinputscore = (*iter)->GetNumInputScores();
-
- if (pd_numinputscore) {
-
- if (labeledOutput)
- out << " I:";
-
- for (size_t j = 0; j < pd_numinputscore; ++j)
- out << " " << scores[j];
- }
-
-
- for (iter = pds.begin() ; iter != pds.end(); ++iter) {
- vector<float> scores = path.GetScoreBreakdown().GetScoresForProducer(*iter);
-
- size_t pd_numinputscore = (*iter)->GetNumInputScores();
-
- if (iter == pds.begin() && labeledOutput)
- out << " tm:";
- for (size_t j = pd_numinputscore; j < scores.size() ; ++j)
- out << " " << scores[j];
- }
+ const vector<PhraseDictionaryFeature*>& pds = system->GetPhraseDictionaries();
+ if (pds.size() > 0) {
+
+ for( size_t i=0; i<pds.size(); i++ ) {
+ size_t pd_numinputscore = pds[i]->GetNumInputScores();
+ vector<float> scores = path.GetScoreBreakdown().GetScoresForProducer( pds[i] );
+ for (size_t j = 0; j<scores.size(); ++j){
+
+ if (labeledOutput && (i == 0) ){
+ if ((j == 0) || (j == pd_numinputscore)){
+ lastName = pds[i]->GetScoreProducerWeightShortName(j);
+ out << " " << lastName << ":";
+ }
+ }
+ out << " " << scores[j];
+ }
}
}
// generation
- const vector<GenerationDictionary*> gds = system->GetGenerationDictionaries();
+ const vector<GenerationDictionary*>& gds = system->GetGenerationDictionaries();
if (gds.size() > 0) {
- if (labeledOutput)
- out << " g: ";
- vector<GenerationDictionary*>::const_iterator iter;
- for (iter = gds.begin(); iter != gds.end(); ++iter) {
- vector<float> scores = path.GetScoreBreakdown().GetScoresForProducer(*iter);
- for (size_t j = 0; j<scores.size(); j++) {
- out << scores[j] << " ";
- }
+
+ for( size_t i=0; i<gds.size(); i++ ) {
+ size_t pd_numinputscore = gds[i]->GetNumInputScores();
+ vector<float> scores = path.GetScoreBreakdown().GetScoresForProducer( gds[i] );
+ for (size_t j = 0; j<scores.size(); ++j){
+
+ if (labeledOutput && (i == 0) ){
+ if ((j == 0) || (j == pd_numinputscore)){
+ lastName = gds[i]->GetScoreProducerWeightShortName(j);
+ out << " " << lastName << ":";
+ }
+ }
+ out << " " << scores[j];
+ }
}
}
@@ -451,18 +446,17 @@ void OutputNBest(std::ostream& out, const Moses::TrellisPathList &nBestList, con
}
if (includeWordAlignment) {
- out << " |||";
+ out << " ||| ";
for (int currEdge = (int)edges.size() - 2 ; currEdge >= 0 ; currEdge--) {
const Hypothesis &edge = *edges[currEdge];
const WordsRange &sourceRange = edge.GetCurrSourceWordsRange();
WordsRange targetRange = path.GetTargetWordsRange(edge);
const int sourceOffset = sourceRange.GetStartPos();
const int targetOffset = targetRange.GetStartPos();
- const AlignmentInfo AI = edge.GetCurrTargetPhrase().GetAlignmentInfo();
- AlignmentInfo::const_iterator iter;
- for (iter = AI.begin(); iter != AI.end(); ++iter) {
- out << " " << iter->first+sourceOffset << "-" << iter->second+targetOffset;
- }
+ const AlignmentInfo &ai = edge.GetCurrTargetPhrase().GetAlignmentInfo();
+
+ OutputAlignment(out, ai, sourceOffset, targetOffset);
+
}
}
diff --git a/moses-cmd/src/Main.cpp b/moses-cmd/src/Main.cpp
index a49e872b9..e8949ddb9 100644
--- a/moses-cmd/src/Main.cpp
+++ b/moses-cmd/src/Main.cpp
@@ -341,6 +341,7 @@ int main(int argc, char** argv)
exit(1);
}
+
// create threadpool, if using multi-threaded decoding
// note: multi-threading is done on sentence-level,
// each thread translates one sentence