get ready for SCFG

This commit is contained in:
Hieu Hoang 2016-04-15 16:38:01 +04:00
parent 9fa9636937
commit b7467dc551
12 changed files with 55 additions and 4 deletions

View File

@ -33,6 +33,11 @@ public:
}
virtual const Word& operator[](size_t pos) const = 0;
virtual size_t GetSize() const = 0;
virtual const Word& Front() const
{ return (*this)[0]; }
virtual const Word& Back() const
{ return (*this)[GetSize() - 1]; }
virtual size_t hash() const;
virtual bool operator==(const Phrase &compare) const;
virtual bool operator!=(const Phrase &compare) const

View File

@ -23,6 +23,9 @@ InputPath::InputPath(MemPool &pool, const SubPhrase &subPhrase,
ActiveChart &memAddr = m_activeChart[i];
ActiveChart *obj = new (&memAddr) ActiveChart();
}
targetPhrases = pool.Allocate<const TargetPhrases*>(numPt);
Init<const TargetPhrases*>(targetPhrases, numPt, NULL);
}
InputPath::~InputPath()

View File

@ -38,6 +38,8 @@ class InputPath: public InputPathBase
{
friend std::ostream& operator<<(std::ostream &, const InputPath &);
public:
const TargetPhrases** targetPhrases;
InputPath(MemPool &pool, const SubPhrase &subPhrase, const Range &range,
size_t numPt, const InputPath *prefixPath);
virtual ~InputPath();

View File

@ -55,7 +55,7 @@ void Manager::Decode()
for (int endPos = startPos + 1; endPos < size + 1; ++endPos) {
SubPhrase sub = m_input->GetSubPhrase(startPos, endPos - startPos);
cerr << "sub=" << sub << endl;
Decode(startPos, endPos);
}
}
}
@ -63,7 +63,7 @@ void Manager::Decode()
void Manager::InitActiveChart(size_t pos)
{
InputPath &path = static_cast<InputPath&>(*m_inputPaths.GetMatrix().GetValue(pos, 0));
InputPath &path = *m_inputPaths.GetMatrix().GetValue(pos, 0);
cerr << "pos=" << pos << " path=" << path << endl;
size_t numPt = system.mappings.size();
cerr << "numPt=" << numPt << endl;
@ -74,7 +74,19 @@ void Manager::InitActiveChart(size_t pos)
pt.InitActiveChart(path);
cerr << "FINISHED InitActiveChart" << endl;
}
}
void Manager::Decode(size_t startPos, size_t endPos)
{
InputPath &path = *m_inputPaths.GetMatrix().GetValue(startPos, endPos - startPos);
size_t numPt = system.mappings.size();
cerr << "numPt=" << numPt << endl;
for (size_t i = 0; i < numPt; ++i) {
const PhraseTable &pt = *system.mappings[i];
pt.Lookup(path);
}
}
}

View File

@ -37,6 +37,7 @@ protected:
InputPaths m_inputPaths;
void InitActiveChart(size_t pos);
void Decode(size_t startPos, size_t endPos);
};
}

View File

@ -24,8 +24,7 @@ class PhraseTable;
namespace SCFG
{
class TargetPhraseImpl: public Moses2::TargetPhrase, public PhraseImplTemplate<
SCFG::Word>
class TargetPhraseImpl: public Moses2::TargetPhrase, public PhraseImplTemplate<SCFG::Word>
{
friend std::ostream& operator<<(std::ostream &, const TargetPhraseImpl &);
public:

View File

@ -91,10 +91,16 @@ void PhraseTable::CleanUpAfterSentenceProcessing()
{
}
// scfg
void PhraseTable::InitActiveChart(SCFG::InputPath &path) const
{
UTIL_THROW2("Not implemented");
}
void PhraseTable::Lookup(SCFG::InputPath &path) const
{
UTIL_THROW2("Not implemented");
}
}

View File

@ -55,6 +55,7 @@ public:
// scfg
virtual void InitActiveChart(SCFG::InputPath &path) const;
virtual void Lookup(SCFG::InputPath &path) const;
protected:
std::string m_path;

View File

@ -202,5 +202,16 @@ void PhraseTableMemory::InitActiveChart(SCFG::InputPath &path) const
chart.entries.push_back(chartEntry);
}
void PhraseTableMemory::Lookup(SCFG::InputPath &path) const
{
// terminal
const Word &lastWord = path.subPhrase.Back();
cerr << "PhraseTableMemory lastWord=" << lastWord << endl;
const SCFG::InputPath &prefixPath = static_cast<const SCFG::InputPath &>(*path.prefixPath);
}
}

View File

@ -46,6 +46,7 @@ public:
InputPathBase &inputPath) const;
virtual void InitActiveChart(SCFG::InputPath &path) const;
void Lookup(SCFG::InputPath &path) const;
protected:
Node m_root;

View File

@ -11,6 +11,9 @@
#include "../PhraseBased/Manager.h"
#include "../PhraseBased/TargetPhraseImpl.h"
#include "../PhraseBased/InputPath.h"
#include "../SCFG/InputPath.h"
using namespace std;
namespace Moses2
{
@ -103,5 +106,11 @@ void UnknownWordPenalty::InitActiveChart(SCFG::InputPath &path) const
{
}
void UnknownWordPenalty::Lookup(SCFG::InputPath &path) const
{
// terminal
const Word &lastWord = path.subPhrase.Back();
cerr << "UnknownWordPenalty lastWord=" << lastWord << endl;
}
}

View File

@ -28,6 +28,7 @@ public:
SCORE *estimatedScore) const;
virtual void InitActiveChart(SCFG::InputPath &path) const;
void Lookup(SCFG::InputPath &path) const;
};