MSPT works

This commit is contained in:
Hieu Hoang 2020-10-05 12:47:13 -07:00
parent b8ae6d58af
commit 83dd5fb7ff
3 changed files with 25 additions and 28 deletions

View File

@ -38,10 +38,10 @@ SentenceWithCandidates *SentenceWithCandidates::CreateFromString(MemPool &pool,
input_parts.push_back(copy_range<std::string>(*It));
}
cerr << "Number of subparts: " << input_parts.size() << endl;
//cerr << "Number of subparts: " << input_parts.size() << endl;
if (input_parts.size() ==2 ) {
cerr << "correct number of parts" << endl ;
//cerr << "correct number of parts" << endl ;
} else {
// TODO: how to handle wrong input format
cerr << "INCORRECT number of parts" << endl ;
@ -50,8 +50,8 @@ SentenceWithCandidates *SentenceWithCandidates::CreateFromString(MemPool &pool,
trim(input_parts[0]);
trim(input_parts[1]);
cerr << "Input String: " << input_parts[0] << endl ;
cerr << "Phrase Table: " << input_parts[1] << endl ;
//cerr << "Input String: " << input_parts[0] << endl ;
//cerr << "Phrase Table: " << input_parts[1] << endl ;
///// Process the text part of the input
const string partstr = input_parts[0];
@ -72,7 +72,7 @@ SentenceWithCandidates *SentenceWithCandidates::CreateFromString(MemPool &pool,
ret->m_phraseTableString = replace_all_copy(input_parts[1],PT_LINE_DELIM,"\n");
// ret->m_phraseTableString="constant phrase table";
// cerr << "Extracted Phrase Table String: " << ret->m_phraseTableString << endl;
cerr << "Extracted Phrase Table String: " << ret->getPhraseTableString() << endl;
//cerr << "Extracted Phrase Table String: " << ret->getPhraseTableString() << endl;
return ret;
}
@ -80,17 +80,17 @@ SentenceWithCandidates *SentenceWithCandidates::CreateFromString(MemPool &pool,
SentenceWithCandidates::SentenceWithCandidates(MemPool &pool, size_t size)
:Sentence(pool, size)
{
cerr << "SentenceWithCandidates::SentenceWithCandidates" << endl;
//cerr << "SentenceWithCandidates::SentenceWithCandidates" << endl;
}
SentenceWithCandidates::~SentenceWithCandidates()
{
cerr << "SentenceWithCandidates::~SentenceWithCandidates" << endl;
//cerr << "SentenceWithCandidates::~SentenceWithCandidates" << endl;
}
std::string SentenceWithCandidates::Debug(const System &system) const
{
cerr << "SentenceWithCandidates::Debug" << endl;
return "SentenceWithCandidates::Debug";
}
} /* namespace Moses2 */

View File

@ -30,6 +30,7 @@
#include "../../SCFG/Manager.h"
#include "../../PhraseBased/SentenceWithCandidates.h"
#include "../../PhraseBased/Manager.h"
using namespace std;
@ -55,7 +56,7 @@ MSPT::~MSPT()
void MSPT::CreatePTForInput(const System &system, string phraseTableString)
{
cerr << "In CreatePTForInput" << endl << flush;
//cerr << "In CreatePTForInput" << endl << flush;
FactorCollection &vocab = system.GetVocab();
MemPool &systemPool = system.GetSystemPool();
@ -105,7 +106,7 @@ void MSPT::CreatePTForInput(const System &system, string phraseTableString)
system.featureFunctions.EvaluateInIsolation(systemPool, system, *source,
*target);
//cerr << "EvaluateInIsolation:" << *target << endl;
//cerr << "EvaluateInIsolation:" << target->Debug(system) << endl;
m_rootPb->AddRule(m_input, *source, target);
//cerr << "target=" << target->Debug(system) << endl;
@ -158,27 +159,29 @@ void MSPT::CreatePTForInput(const System &system, string phraseTableString)
void MSPT::InitializeForInput(const System &system, const InputType &input)
{
cerr << "InitializeForInput MSPT" << endl;
cerr << input.Debug(system) << endl << flush;
cerr << "HH1" << endl << flush;
//cerr << "InitializeForInput MSPT" << endl;
//cerr << input.Debug(system) << endl;
//cerr << "HH1" << endl << flush;
// downcast to SentenceWithCandidates
//const SentenceWithCandidates &inputObj = static_cast<const SentenceWithCandidates&>(input);
const SentenceWithCandidates &inputObj = dynamic_cast<const SentenceWithCandidates&>(input);
cerr << "Casting done." << endl << flush;
cerr << "PhraseTableString member: " << inputObj.getPhraseTableString() << endl;
cerr << "Hardcoding sample PhraseTableString" << endl << flush;
string phraseTableString="a ||| x ||| 0.4 $$$ a ||| y ||| 0.6 $$$ b ||| y ||| 0.1 $$$ b ||| z ||| 0.9";
CreatePTForInput(system,phraseTableString);
const SentenceWithCandidates &inputObj = static_cast<const SentenceWithCandidates&>(input);
//const SentenceWithCandidates &inputObj = dynamic_cast<const SentenceWithCandidates&>(input);
//cerr << "Casting done." << endl << flush;
//cerr << "PhraseTableString member: " << inputObj.getPhraseTableString() << endl << flush;
//cerr << "HH2" << endl << flush;
CreatePTForInput(system, inputObj.getPhraseTableString());
//cerr << "HH3" << endl << flush;
}
TargetPhrases* MSPT::Lookup(const Manager &mgr, MemPool &pool,
InputPath &inputPath) const
{
//cerr << "MSPT::Lookup inputPath:" << inputPath.Debug(mgr.system) << endl;
const SubPhrase<Moses2::Word> &phrase = inputPath.subPhrase;
TargetPhrases *tps = m_rootPb->Find(m_input, phrase);
//cerr << "MSPT::Lookup tps:" << tps->Debug(mgr.system) << endl;
//cerr << "MSPT::Lookup done" << endl;
return tps;
}

View File

@ -80,13 +80,7 @@ void PhraseTable::Lookup(const Manager &mgr, InputPathsBase &inputPaths) const
if (SatisfyBackoff(mgr, *path)) {
TargetPhrases *tpsPtr = Lookup(mgr, mgr.GetPool(), *path);
/*
cerr << "tpsPtr=" << tpsPtr << " ";
if (tps.get()) {
cerr << tps.get()->GetSize();
}
cerr << endl;
*/
//cerr << "tpsPtr=" << tpsPtr << endl;
path->AddTargetPhrases(*this, tpsPtr);
}