diff options
author | Anoop Kunchukuttan <anoop.kunchukuttan@gmail.com> | 2020-10-04 20:13:48 +0300 |
---|---|---|
committer | Anoop Kunchukuttan <anoop.kunchukuttan@gmail.com> | 2020-10-04 20:13:48 +0300 |
commit | 2cb12decc8abcb60c84f92a9d82271782bfd6fe4 (patch) | |
tree | d22c411a5a3aea44008ae2ff67224e4b1f3a2e75 | |
parent | 95d93f8bd1be450c7713caf9584a37b9e211231f (diff) |
dynamic cast to SentenceWithCandidates (failed)
-rw-r--r-- | moses2/PhraseBased/SentenceWithCandidates.cpp | 5 | ||||
-rw-r--r-- | moses2/PhraseBased/SentenceWithCandidates.h | 4 | ||||
-rw-r--r-- | moses2/TranslationModel/MSPT/MSPT.cpp | 108 |
3 files changed, 115 insertions, 2 deletions
diff --git a/moses2/PhraseBased/SentenceWithCandidates.cpp b/moses2/PhraseBased/SentenceWithCandidates.cpp index c4115cbe8..cb96a9d92 100644 --- a/moses2/PhraseBased/SentenceWithCandidates.cpp +++ b/moses2/PhraseBased/SentenceWithCandidates.cpp @@ -70,8 +70,9 @@ SentenceWithCandidates *SentenceWithCandidates::CreateFromString(MemPool &pool, //// Parse the phrase table of the input ret->m_phraseTableString = replace_all_copy(input_parts[1],PT_LINE_DELIM,"\n"); - cerr << "Extracted Phrase Table String" << endl; - cerr << ret->m_phraseTableString << endl; + // ret->m_phraseTableString="constant phrase table"; +// cerr << "Extracted Phrase Table String: " << ret->m_phraseTableString << endl; + cerr << "Extracted Phrase Table String: " << ret->getPhraseTableString() << endl; return ret; } diff --git a/moses2/PhraseBased/SentenceWithCandidates.h b/moses2/PhraseBased/SentenceWithCandidates.h index 114ff9e67..5cc34590d 100644 --- a/moses2/PhraseBased/SentenceWithCandidates.h +++ b/moses2/PhraseBased/SentenceWithCandidates.h @@ -36,6 +36,10 @@ public: virtual ~SentenceWithCandidates() {} + std::string virtual getPhraseTableString() const{ + return m_phraseTableString; + } + private: std::string m_phraseTableString; diff --git a/moses2/TranslationModel/MSPT/MSPT.cpp b/moses2/TranslationModel/MSPT/MSPT.cpp index e7ce62a62..8bdbf46c0 100644 --- a/moses2/TranslationModel/MSPT/MSPT.cpp +++ b/moses2/TranslationModel/MSPT/MSPT.cpp @@ -19,6 +19,7 @@ #include "../../PhraseBased/InputPath.h" #include "../../PhraseBased/TargetPhraseImpl.h" #include "../../PhraseBased/TargetPhrases.h" +#include "../../PhraseBased/SentenceWithCandidates.h" #include "../../SCFG/PhraseImpl.h" #include "../../SCFG/TargetPhraseImpl.h" @@ -50,9 +51,116 @@ MSPT::~MSPT() delete m_rootSCFG; } +// void MSPT::CreatePTForInput(string phraseTableString) +// { +// FactorCollection &vocab = system.GetVocab(); +// MemPool &systemPool = system.GetSystemPool(); +// MemPool tmpSourcePool; + +// if (system.isPb) { +// m_rootPb = new PBNODE(); +// } else { +// m_rootSCFG = new SCFGNODE(); +// //cerr << "m_rootSCFG=" << m_rootSCFG << endl; +// } + +// vector<string> toks; +// size_t lineNum = 0; +// InputFileStream strme(m_path); +// string line; +// while (getline(strme, line)) { +// if (++lineNum % 1000000 == 0) { +// cerr << lineNum << " "; +// } +// toks.clear(); +// TokenizeMultiCharSeparator(toks, line, "|||"); +// UTIL_THROW_IF2(toks.size() < 3, "Wrong format"); +// //cerr << "line=" << line << endl; +// //cerr << "system.isPb=" << system.isPb << endl; + +// if (system.isPb) { +// PhraseImpl *source = PhraseImpl::CreateFromString(tmpSourcePool, vocab, system, +// toks[0]); +// //cerr << "created soure" << endl; +// TargetPhraseImpl *target = TargetPhraseImpl::CreateFromString(systemPool, *this, system, +// toks[1]); +// //cerr << "created target" << endl; +// target->GetScores().CreateFromString(toks[2], *this, system, true); +// //cerr << "created scores:" << *target << endl; + +// if (toks.size() >= 4) { +// //cerr << "alignstr=" << toks[3] << endl; +// target->SetAlignmentInfo(toks[3]); +// } + +// // properties +// if (toks.size() == 7) { +// //target->properties = (char*) system.systemPool.Allocate(toks[6].size() + 1); +// //strcpy(target->properties, toks[6].c_str()); +// } + +// system.featureFunctions.EvaluateInIsolation(systemPool, system, *source, +// *target); +// //cerr << "EvaluateInIsolation:" << *target << endl; +// m_rootPb->AddRule(m_input, *source, target); + +// //cerr << "target=" << target->Debug(system) << endl; +// } else { +// SCFG::PhraseImpl *source = SCFG::PhraseImpl::CreateFromString(tmpSourcePool, vocab, system, +// toks[0]); +// //cerr << "created source:" << *source << endl; +// SCFG::TargetPhraseImpl *target = SCFG::TargetPhraseImpl::CreateFromString(systemPool, *this, +// system, toks[1]); + +// //cerr << "created target " << *target << " source=" << *source << endl; + +// target->GetScores().CreateFromString(toks[2], *this, system, true); +// //cerr << "created scores:" << *target << endl; + +// //vector<SCORE> scores = Tokenize<SCORE>(toks[2]); +// //target->sortScore = (scores.size() >= 3) ? TransformScore(scores[2]) : 0; + +// target->SetAlignmentInfo(toks[3]); + +// // properties +// if (toks.size() == 7) { +// //target->properties = (char*) system.systemPool.Allocate(toks[6].size() + 1); +// //strcpy(target->properties, toks[6].c_str()); +// } + +// system.featureFunctions.EvaluateInIsolation(systemPool, system, *source, +// *target); +// //cerr << "EvaluateInIsolation:" << *target << endl; +// m_rootSCFG->AddRule(m_input, *source, target); +// } +// } + +// if (system.isPb) { +// m_rootPb->SortAndPrune(m_tableLimit, systemPool, system); +// //cerr << "root=" << &m_rootPb << endl; +// } else { +// m_rootSCFG->SortAndPrune(m_tableLimit, systemPool, system); +// //cerr << "root=" << &m_rootPb << endl; +// } +// /* +// BOOST_FOREACH(const PtMem::Node<Word>::Children::value_type &valPair, m_rootPb.GetChildren()) { +// const Word &word = valPair.first; +// cerr << word << " "; +// } +// cerr << endl; +// */ + +// } + void MSPT::InitializeForInput(const InputType &input) { cerr << "InitializeForInput" << endl; + + // downcast to SentenceWithCandidates + const SentenceWithCandidates& inputObj = dynamic_cast<const SentenceWithCandidates&>(input); + cerr << "Casting done." << endl; + // cerr << "PhraseTableString member: " << inputObj.getPhraseTableString() << endl; + } TargetPhrases* MSPT::Lookup(const Manager &mgr, MemPool &pool, |