parse NT correctly. Lots of debugging messages

This commit is contained in:
Hieu Hoang 2016-04-21 17:19:31 +04:00
parent 62000e0ebc
commit 4a00f1e881
10 changed files with 41 additions and 29 deletions

View File

@ -11,6 +11,8 @@
#include "../TranslationModel/PhraseTable.h"
#include "../MemPool.h"
using namespace std;
namespace Moses2
{
namespace SCFG
@ -45,6 +47,13 @@ void InputPath::AddTargetPhrase(const PhraseTable &pt,
targetPhrases[symbolBind].AddTargetPhrase(*tp);
}
void InputPath::AddActiveChartEntry(size_t ptInd, ActiveChartEntry *chartEntry)
{
cerr << "added " << range << " " << ptInd << endl;
ActiveChart &activeChart = m_activeChart[ptInd];
activeChart.entries.push_back(chartEntry);
}
}
}

View File

@ -34,8 +34,8 @@ public:
const ActiveChart &GetActiveChart(size_t ptInd) const
{ return m_activeChart[ptInd]; }
ActiveChart &GetActiveChart(size_t ptInd)
{ return m_activeChart[ptInd]; }
void AddActiveChartEntry(size_t ptInd, ActiveChartEntry *chartEntry);
void AddTargetPhrase(const PhraseTable &pt,
const SCFG::SymbolBind &symbolBind,

View File

@ -23,12 +23,9 @@ PhraseImpl *PhraseImpl::CreateFromString(MemPool &pool, FactorCollection &vocab,
for (size_t i = 0; i < size; ++i) {
SCFG::Word &word = (*ret)[i];
word.CreateFromString(vocab, system, toks[i], true);
word.CreateFromString(vocab, system, toks[i]);
}
// lhs
ret->lhs.CreateFromString(vocab, system, toks.back(), false);
return ret;
}

View File

@ -11,8 +11,6 @@ namespace SCFG
class PhraseImpl: public Phrase, public PhraseImplTemplate<SCFG::Word>
{
public:
SCFG::Word lhs;
static PhraseImpl *CreateFromString(MemPool &pool, FactorCollection &vocab,
const System &system, const std::string &str);

View File

@ -4,6 +4,8 @@
#include "TargetPhraseImpl.h"
#include "Manager.h"
using namespace std;
namespace Moses2
{
@ -20,6 +22,8 @@ StackAdd Stack::Add(SCFG::Hypothesis *hypo, Recycler<HypothesisBase*> &hypoRecyc
{
const SCFG::TargetPhraseImpl &tp = hypo->GetTargetPhrase();
const SCFG::Word &lhs = tp.lhs;
cerr << "lhs=" << lhs << endl;
HypothesisColl &coll = GetMiniStack(lhs);
StackAdd added = coll.Add(hypo);
return added;

View File

@ -34,11 +34,11 @@ TargetPhraseImpl *TargetPhraseImpl::CreateFromString(MemPool &pool,
for (size_t i = 0; i < size; ++i) {
SCFG::Word &word = (*ret)[i];
word.CreateFromString(vocab, system, toks[i], true);
word.CreateFromString(vocab, system, toks[i]);
}
// lhs
ret->lhs.CreateFromString(vocab, system, toks.back(), false);
ret->lhs.CreateFromString(vocab, system, toks.back());
//cerr << "ret=" << *ret << endl;
return ret;
}
@ -63,10 +63,14 @@ TargetPhraseImpl::~TargetPhraseImpl()
// TODO Auto-generated destructor stub
}
std::ostream& operator<<(std::ostream &out, const TargetPhraseImpl &obj)
std::ostream& operator<<(std::ostream &out, const SCFG::TargetPhraseImpl &obj)
{
out << obj.lhs << " -> " << (const Phrase&) obj
<< " SCORES:" << obj.GetScores()
out << obj.lhs << " -> ";
for (size_t i = 0; i < obj.GetSize(); ++i) {
const SCFG::Word &word = obj[i];
out << word << " ";
}
out << " SCORES:" << obj.GetScores()
<< " ALIGN:" << obj.GetAlignTerm() << " " << obj.GetAlignNonTerm();
return out;
}

View File

@ -28,7 +28,7 @@ namespace SCFG
class TargetPhraseImpl: public Moses2::TargetPhrase, public PhraseImplTemplate<SCFG::Word>
{
friend std::ostream& operator<<(std::ostream &, const TargetPhraseImpl &);
friend std::ostream& operator<<(std::ostream &, const SCFG::TargetPhraseImpl &);
public:
SCFG::Word lhs;
const AlignmentInfo* m_alignTerm, *m_alignNonTerm;
@ -89,7 +89,6 @@ public:
void SetAlignmentInfo(const std::string &alignString);
//mutable void *chartState;
protected:
};

View File

@ -14,16 +14,19 @@ namespace Moses2
{
namespace SCFG
{
void Word::CreateFromString(FactorCollection &vocab, const System &system,
const std::string &str, bool doubleNT)
void Word::CreateFromString(FactorCollection &vocab,
const System &system,
const std::string &str)
{
vector<string> toks;
if (str[0] == '[' && str[str.size() - 1] == ']') {
isNonTerminal = true;
size_t startPos = str.find("[", 1);
bool doubleNT = startPos != string::npos;
if (doubleNT) {
size_t startPos = str.find("[", 1);
assert(startPos != string::npos);
string str2 = str.substr(startPos + 1, str.size() - startPos - 2);
toks = Tokenize(str2, "|");

View File

@ -20,8 +20,9 @@ class Word: public Moses2::Word
public:
bool isNonTerminal;
void CreateFromString(FactorCollection &vocab, const System &system,
const std::string &str, bool doubleNT);
void CreateFromString(FactorCollection &vocab,
const System &system,
const std::string &str);
bool operator==(const SCFG::Word &compare) const
{

View File

@ -183,7 +183,7 @@ void PhraseTableMemory::Load(System &system)
system, toks[1]);
targetSCFG->SetAlignmentInfo(toks[3]);
target = targetSCFG;
//cerr << "created target" << endl;
cerr << "created target " << *targetSCFG << endl;
break;
default:
abort();
@ -219,10 +219,8 @@ TargetPhrases* PhraseTableMemory::Lookup(const Manager &mgr, MemPool &pool,
void PhraseTableMemory::InitActiveChart(SCFG::InputPath &path) const
{
size_t ptInd = GetPtInd();
SCFG::ActiveChart &chart = path.GetActiveChart(ptInd);
ActiveChartEntryMem *chartEntry = new ActiveChartEntryMem(NULL, false, &m_root);
chart.entries.push_back(chartEntry);
path.AddActiveChartEntry(ptInd, chartEntry);
}
void PhraseTableMemory::Lookup(MemPool &pool,
@ -246,7 +244,7 @@ void PhraseTableMemory::Lookup(MemPool &pool,
//const SCFG::InputPath *prefixPath = static_cast<const SCFG::InputPath*>(path.prefixPath);
while (prefixPath) {
const Range &prefixRange = prefixPath->range;
cerr << "prefixRange=" << prefixRange << endl;
//cerr << "prefixRange=" << prefixRange << endl;
size_t startPos = prefixRange.GetEndPos() + 1;
size_t ntSize = endPos - startPos + 1;
const SCFG::InputPath &subPhrasePath = *mgr.GetInputPaths().GetMatrix().GetValue(startPos, ntSize);
@ -272,7 +270,7 @@ void PhraseTableMemory::LookupGivenPrefixPath(const SCFG::InputPath &prefixPath,
{
size_t ptInd = GetPtInd();
cerr << "entries=" << prefixPath.GetActiveChart(ptInd).entries.size() << endl;
cerr << "prefixPath=" << prefixPath.range << " " << prefixPath.GetActiveChart(ptInd).entries.size() << endl;
BOOST_FOREACH(const SCFG::ActiveChartEntry *entry, prefixPath.GetActiveChart(ptInd).entries) {
const ActiveChartEntryMem *entryCast = static_cast<const ActiveChartEntryMem*>(entry);
@ -296,11 +294,10 @@ void PhraseTableMemory::LookupGivenNode(const Node &node,
if (nextNode) {
// new entries
SCFG::ActiveChart &chart = path.GetActiveChart(ptInd);
ActiveChartEntryMem *chartEntry = new ActiveChartEntryMem(&subPhrasePath, isNT, nextNode);
const SCFG::SymbolBind &symbolBind = chartEntry->symbolBinds;
path.AddActiveChartEntry(ptInd, chartEntry);
chart.entries.push_back(chartEntry);
const SCFG::SymbolBind &symbolBind = chartEntry->symbolBinds;
// there are some rules
AddTargetPhrasesToPath(*nextNode, symbolBind, path);