mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-12-25 12:52:29 +03:00
InputLatticeNode to InputPath
This commit is contained in:
parent
ecef376aed
commit
29b895a97a
@ -2,7 +2,7 @@
|
||||
|
||||
namespace Moses
|
||||
{
|
||||
const TargetPhraseCollection *InputLatticeNode::GetTargetPhrases(const PhraseDictionary &phraseDictionary) const
|
||||
const TargetPhraseCollection *InputPath::GetTargetPhrases(const PhraseDictionary &phraseDictionary) const
|
||||
{
|
||||
std::map<const PhraseDictionary*, std::pair<const TargetPhraseCollection*, const void*> >::const_iterator iter;
|
||||
iter = m_targetPhrases.find(&phraseDictionary);
|
||||
@ -12,7 +12,7 @@ const TargetPhraseCollection *InputLatticeNode::GetTargetPhrases(const PhraseDic
|
||||
return iter->second.first;
|
||||
}
|
||||
|
||||
const void *InputLatticeNode::GetPtNode(const PhraseDictionary &phraseDictionary) const
|
||||
const void *InputPath::GetPtNode(const PhraseDictionary &phraseDictionary) const
|
||||
{
|
||||
std::map<const PhraseDictionary*, std::pair<const TargetPhraseCollection*, const void*> >::const_iterator iter;
|
||||
iter = m_targetPhrases.find(&phraseDictionary);
|
||||
@ -22,7 +22,7 @@ const void *InputLatticeNode::GetPtNode(const PhraseDictionary &phraseDictionary
|
||||
return iter->second.second;
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& out, const InputLatticeNode& obj)
|
||||
std::ostream& operator<<(std::ostream& out, const InputPath& obj)
|
||||
{
|
||||
out << &obj << " " << obj.GetWordsRange() << " " << obj.GetPrevNode() << " " << obj.GetPhrase();
|
||||
|
||||
|
@ -14,26 +14,26 @@ class TargetPhraseCollection;
|
||||
/** Each node contains
|
||||
1. substring used to searching the phrase table
|
||||
2. the source range it covers
|
||||
3. a list of InputLatticeNode that it is a prefix of
|
||||
3. a list of InputPath that it is a prefix of
|
||||
This is for both sentence input, and confusion network/lattices
|
||||
*/
|
||||
class InputLatticeNode
|
||||
class InputPath
|
||||
{
|
||||
friend std::ostream& operator<<(std::ostream& out, const InputLatticeNode &obj);
|
||||
friend std::ostream& operator<<(std::ostream& out, const InputPath &obj);
|
||||
|
||||
protected:
|
||||
const InputLatticeNode *m_prevNode;
|
||||
const InputPath *m_prevNode;
|
||||
Phrase m_phrase;
|
||||
WordsRange m_range;
|
||||
std::map<const PhraseDictionary*, std::pair<const TargetPhraseCollection*, const void*> > m_targetPhrases;
|
||||
|
||||
public:
|
||||
explicit InputLatticeNode()
|
||||
explicit InputPath()
|
||||
: m_prevNode(NULL)
|
||||
, m_range(NOT_FOUND, NOT_FOUND) {
|
||||
}
|
||||
|
||||
InputLatticeNode(const Phrase &phrase, const WordsRange &range, const InputLatticeNode *prevNode)
|
||||
InputPath(const Phrase &phrase, const WordsRange &range, const InputPath *prevNode)
|
||||
:m_prevNode(prevNode)
|
||||
,m_phrase(phrase)
|
||||
,m_range(range) {
|
||||
@ -45,7 +45,7 @@ public:
|
||||
const WordsRange &GetWordsRange() const {
|
||||
return m_range;
|
||||
}
|
||||
const InputLatticeNode *GetPrevNode() const {
|
||||
const InputPath *GetPrevNode() const {
|
||||
return m_prevNode;
|
||||
}
|
||||
|
||||
|
@ -69,11 +69,11 @@ void PhraseDictionary::SetFeaturesToApply()
|
||||
}
|
||||
}
|
||||
|
||||
void PhraseDictionary::SetTargetPhraseFromPtMatrix(const std::vector<InputLatticeNode*> &phraseDictionaryQueue) const
|
||||
void PhraseDictionary::SetTargetPhraseFromPtMatrix(const std::vector<InputPath*> &phraseDictionaryQueue) const
|
||||
{
|
||||
// UTIL_THROW(util::Exception, "SetTargetPhraseFromPtMatrix() not implemented");
|
||||
for (size_t i = 0; i < phraseDictionaryQueue.size(); ++i) {
|
||||
InputLatticeNode &node = *phraseDictionaryQueue[i];
|
||||
InputPath &node = *phraseDictionaryQueue[i];
|
||||
|
||||
const Phrase &phrase = node.GetPhrase();
|
||||
const TargetPhraseCollection *targetPhrases = this->GetTargetPhraseCollection(phrase);
|
||||
|
@ -47,7 +47,7 @@ class InputType;
|
||||
class WordsRange;
|
||||
class ChartCellCollectionBase;
|
||||
class ChartRuleLookupManager;
|
||||
class InputLatticeNode;
|
||||
class InputPath;
|
||||
|
||||
/**
|
||||
* Abstract base class for phrase dictionaries (tables).
|
||||
@ -94,7 +94,7 @@ public:
|
||||
|
||||
void SetParameter(const std::string& key, const std::string& value);
|
||||
|
||||
virtual void SetTargetPhraseFromPtMatrix(const std::vector<InputLatticeNode*> &phraseDictionaryQueue) const;
|
||||
virtual void SetTargetPhraseFromPtMatrix(const std::vector<InputPath*> &phraseDictionaryQueue) const;
|
||||
|
||||
protected:
|
||||
size_t m_tableLimit;
|
||||
|
@ -134,13 +134,13 @@ void PhraseDictionaryMemory::SortAndPrune()
|
||||
}
|
||||
}
|
||||
|
||||
void PhraseDictionaryMemory::SetTargetPhraseFromPtMatrix(const std::vector<InputLatticeNode*> &phraseDictionaryQueue) const
|
||||
void PhraseDictionaryMemory::SetTargetPhraseFromPtMatrix(const std::vector<InputPath*> &phraseDictionaryQueue) const
|
||||
{
|
||||
// UTIL_THROW(util::Exception, "SetTargetPhraseFromPtMatrix() not implemented");
|
||||
for (size_t i = 0; i < phraseDictionaryQueue.size(); ++i) {
|
||||
InputLatticeNode &node = *phraseDictionaryQueue[i];
|
||||
InputPath &node = *phraseDictionaryQueue[i];
|
||||
const Phrase &phrase = node.GetPhrase();
|
||||
const InputLatticeNode *prevNode = node.GetPrevNode();
|
||||
const InputPath *prevNode = node.GetPrevNode();
|
||||
|
||||
const PhraseDictionaryNodeMemory *prevPtNode = NULL;
|
||||
|
||||
|
@ -53,7 +53,7 @@ public:
|
||||
const InputType &,
|
||||
const ChartCellCollectionBase &);
|
||||
|
||||
void SetTargetPhraseFromPtMatrix(const std::vector<InputLatticeNode*> &phraseDictionaryQueue) const;
|
||||
void SetTargetPhraseFromPtMatrix(const std::vector<InputPath*> &phraseDictionaryQueue) const;
|
||||
|
||||
TO_STRING();
|
||||
|
||||
|
@ -98,14 +98,14 @@ void PhraseDictionaryOnDisk::InitializeForInput(InputType const& source)
|
||||
m_implementation.reset(obj);
|
||||
}
|
||||
|
||||
void PhraseDictionaryOnDisk::SetTargetPhraseFromPtMatrix(const std::vector<InputLatticeNode*> &phraseDictionaryQueue) const
|
||||
void PhraseDictionaryOnDisk::SetTargetPhraseFromPtMatrix(const std::vector<InputPath*> &phraseDictionaryQueue) const
|
||||
{
|
||||
OnDiskPt::OnDiskWrapper &wrapper = const_cast<OnDiskPt::OnDiskWrapper&>(GetImplementation());
|
||||
|
||||
for (size_t i = 0; i < phraseDictionaryQueue.size(); ++i) {
|
||||
InputLatticeNode &node = *phraseDictionaryQueue[i];
|
||||
InputPath &node = *phraseDictionaryQueue[i];
|
||||
const Phrase &phrase = node.GetPhrase();
|
||||
const InputLatticeNode *prevNode = node.GetPrevNode();
|
||||
const InputPath *prevNode = node.GetPrevNode();
|
||||
|
||||
const OnDiskPt::PhraseNode *prevPtNode = NULL;
|
||||
|
||||
|
@ -40,7 +40,7 @@ namespace Moses
|
||||
{
|
||||
class TargetPhraseCollection;
|
||||
class DottedRuleStackOnDisk;
|
||||
class InputLatticeNode;
|
||||
class InputPath;
|
||||
|
||||
/** Implementation of on-disk phrase table for hierarchical/syntax model.
|
||||
*/
|
||||
@ -77,7 +77,7 @@ public:
|
||||
const ChartCellCollectionBase &);
|
||||
|
||||
virtual void InitializeForInput(InputType const& source);
|
||||
void SetTargetPhraseFromPtMatrix(const std::vector<InputLatticeNode*> &phraseDictionaryQueue) const;
|
||||
void SetTargetPhraseFromPtMatrix(const std::vector<InputPath*> &phraseDictionaryQueue) const;
|
||||
|
||||
};
|
||||
|
||||
|
@ -43,7 +43,7 @@ class FactorMask;
|
||||
class Word;
|
||||
class DecodeGraph;
|
||||
class PhraseDictionary;
|
||||
class InputLatticeNode;
|
||||
class InputPath;
|
||||
|
||||
/** Contains all phrase translations applicable to current input type (a sentence or confusion network).
|
||||
* A key insight into efficient decoding is that various input
|
||||
@ -69,7 +69,7 @@ protected:
|
||||
const size_t m_maxNoTransOptPerCoverage; /*< maximum number of translation options per input span */
|
||||
const float m_translationOptionThreshold; /*< threshold for translation options with regard to best option for input span */
|
||||
std::vector<Phrase*> m_unksrcs;
|
||||
std::vector<InputLatticeNode*> m_phraseDictionaryQueue;
|
||||
std::vector<InputPath*> m_phraseDictionaryQueue;
|
||||
|
||||
TranslationOptionCollection(InputType const& src, size_t maxNoTransOptPerCoverage,
|
||||
float translationOptionThreshold);
|
||||
|
@ -40,17 +40,17 @@ TranslationOptionCollectionText::TranslationOptionCollectionText(Sentence const
|
||||
for (size_t phaseSize = 1; phaseSize <= size; ++phaseSize) {
|
||||
for (size_t startPos = 0; startPos < size - phaseSize + 1; ++startPos) {
|
||||
size_t endPos = startPos + phaseSize -1;
|
||||
std::vector<InputLatticeNode*> &vec = m_targetPhrasesfromPt[startPos];
|
||||
std::vector<InputPath*> &vec = m_targetPhrasesfromPt[startPos];
|
||||
|
||||
Phrase subphrase(input.GetSubString(WordsRange(startPos, endPos)));
|
||||
WordsRange range(startPos, endPos);
|
||||
|
||||
if (range.GetNumWordsCovered() == 1) {
|
||||
InputLatticeNode *node = new InputLatticeNode(subphrase, range, NULL);
|
||||
InputPath *node = new InputPath(subphrase, range, NULL);
|
||||
vec.push_back(node);
|
||||
} else {
|
||||
const InputLatticeNode &prevNode = GetInputLatticeNode(startPos, endPos - 1);
|
||||
InputLatticeNode *node = new InputLatticeNode(subphrase, range, &prevNode);
|
||||
const InputPath &prevNode = GetInputPath(startPos, endPos - 1);
|
||||
InputPath *node = new InputPath(subphrase, range, &prevNode);
|
||||
vec.push_back(node);
|
||||
}
|
||||
}
|
||||
@ -60,7 +60,7 @@ TranslationOptionCollectionText::TranslationOptionCollectionText(Sentence const
|
||||
for (size_t startPos = 0; startPos < size - phaseSize + 1; ++startPos) {
|
||||
size_t endPos = startPos + phaseSize -1;
|
||||
//cerr << startPos << "-" << endPos << "=" << GetPhrase(startPos, endPos) << endl;
|
||||
InputLatticeNode &node = GetInputLatticeNode(startPos, endPos);
|
||||
InputPath &node = GetInputPath(startPos, endPos);
|
||||
m_phraseDictionaryQueue.push_back(&node);
|
||||
}
|
||||
}
|
||||
@ -102,7 +102,7 @@ void TranslationOptionCollectionText::CreateXmlOptionsForRange(size_t startPosit
|
||||
|
||||
};
|
||||
|
||||
InputLatticeNode &TranslationOptionCollectionText::GetInputLatticeNode(size_t startPos, size_t endPos)
|
||||
InputPath &TranslationOptionCollectionText::GetInputPath(size_t startPos, size_t endPos)
|
||||
{
|
||||
size_t offset = endPos - startPos;
|
||||
CHECK(offset < m_targetPhrasesfromPt[startPos].size());
|
||||
@ -130,7 +130,7 @@ void TranslationOptionCollectionText::CreateTranslationOptionsForRange(
|
||||
, bool adhereTableLimit
|
||||
, size_t graphInd)
|
||||
{
|
||||
InputLatticeNode &inputLatticeNode = GetInputLatticeNode(startPos, endPos);
|
||||
InputPath &InputPath = GetInputPath(startPos, endPos);
|
||||
|
||||
if ((StaticData::Instance().GetXmlInputType() != XmlExclusive) || !HasXmlOptionsOverlappingRange(startPos,endPos)) {
|
||||
Phrase *sourcePhrase = NULL; // can't initialise with substring, in case it's confusion network
|
||||
@ -164,7 +164,7 @@ void TranslationOptionCollectionText::CreateTranslationOptionsForRange(
|
||||
const DecodeStep &decodeStep = **iterStep;
|
||||
|
||||
const PhraseDictionary &phraseDictionary = *decodeStep.GetPhraseDictionaryFeature();
|
||||
const TargetPhraseCollection *targetPhrases = inputLatticeNode.GetTargetPhrases(phraseDictionary);
|
||||
const TargetPhraseCollection *targetPhrases = InputPath.GetTargetPhrases(phraseDictionary);
|
||||
|
||||
static_cast<const DecodeStepTranslation&>(decodeStep).ProcessInitialTranslation
|
||||
(m_source, *oldPtoc
|
||||
@ -187,7 +187,7 @@ void TranslationOptionCollectionText::CreateTranslationOptionsForRange(
|
||||
|
||||
if (const DecodeStepTranslation *translateStep = dynamic_cast<const DecodeStepTranslation*>(decodeStep) ) {
|
||||
const PhraseDictionary &phraseDictionary = *translateStep->GetPhraseDictionaryFeature();
|
||||
const TargetPhraseCollection *targetPhrases = inputLatticeNode.GetTargetPhrases(phraseDictionary);
|
||||
const TargetPhraseCollection *targetPhrases = InputPath.GetTargetPhrases(phraseDictionary);
|
||||
translateStep->Process(inputPartialTranslOpt
|
||||
, *decodeStep
|
||||
, *newPtoc
|
||||
|
@ -38,12 +38,12 @@ class Sentence;
|
||||
class TranslationOptionCollectionText : public TranslationOptionCollection
|
||||
{
|
||||
public:
|
||||
typedef std::vector< std::vector<InputLatticeNode*> > TargetPhraseMatrix;
|
||||
typedef std::vector< std::vector<InputPath*> > TargetPhraseMatrix;
|
||||
|
||||
protected:
|
||||
TargetPhraseMatrix m_targetPhrasesfromPt; /*< contains translation options */
|
||||
|
||||
InputLatticeNode &GetInputLatticeNode(size_t startPos, size_t endPos);
|
||||
InputPath &GetInputPath(size_t startPos, size_t endPos);
|
||||
|
||||
public:
|
||||
void ProcessUnknownWord(size_t sourcePos);
|
||||
|
Loading…
Reference in New Issue
Block a user