mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-09-11 11:25:40 +03:00
prefix subphrase optimization done for in-memory pt. Need to delete objects also
This commit is contained in:
parent
934e24718e
commit
f0dc30f25a
@ -138,19 +138,14 @@ void PhraseDictionaryMemory::SetTargetPhraseFromPtMatrix(const std::vector<Input
|
||||
{
|
||||
// UTIL_THROW(util::Exception, "SetTargetPhraseFromPtMatrix() not implemented");
|
||||
for (size_t i = 0; i < phraseDictionaryQueue.size(); ++i) {
|
||||
bool doIt = true;
|
||||
InputLatticeNode &node = *phraseDictionaryQueue[i];
|
||||
const Phrase &phrase = node.GetPhrase();
|
||||
const InputLatticeNode *prevNode = node.GetPrevNode();
|
||||
|
||||
const PhraseDictionaryNodeMemory *prevPtNode;
|
||||
const PhraseDictionaryNodeMemory *prevPtNode = NULL;
|
||||
|
||||
if (prevNode) {
|
||||
prevPtNode = static_cast<const PhraseDictionaryNodeMemory*>(prevNode->GetPtNode(*this));
|
||||
|
||||
if (prevPtNode == NULL) {
|
||||
doIt = false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Starting subphrase.
|
||||
@ -158,8 +153,10 @@ void PhraseDictionaryMemory::SetTargetPhraseFromPtMatrix(const std::vector<Input
|
||||
prevPtNode = &GetRootNode();
|
||||
}
|
||||
|
||||
if (doIt) {
|
||||
const Word &lastWord = phrase.GetWord(phrase.GetSize() - 1);
|
||||
if (prevPtNode) {
|
||||
Word lastWord = phrase.GetWord(phrase.GetSize() - 1);
|
||||
lastWord.OnlyTheseFactors(m_inputFactors);
|
||||
|
||||
const PhraseDictionaryNodeMemory *ptNode = prevPtNode->GetChild(lastWord);
|
||||
if (ptNode) {
|
||||
const TargetPhraseCollection *targetPhrases = ptNode->GetTargetPhraseCollection();
|
||||
|
@ -24,6 +24,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
#include "memory.h"
|
||||
#include "Word.h"
|
||||
#include "TypeDef.h"
|
||||
#include "FactorTypeSet.h"
|
||||
#include "StaticData.h" // needed to determine the FactorDelimiter
|
||||
#include "util/exception.hh"
|
||||
#include "util/tokenize_piece.hh"
|
||||
@ -127,6 +128,15 @@ void Word::CreateUnknownWord(const Word &sourceWord)
|
||||
m_isNonTerminal = sourceWord.IsNonTerminal();
|
||||
}
|
||||
|
||||
void Word::OnlyTheseFactors(const FactorMask &factors)
|
||||
{
|
||||
for (unsigned int currFactor = 0 ; currFactor < MAX_NUM_FACTORS ; currFactor++) {
|
||||
if (!factors[currFactor]) {
|
||||
SetFactor(currFactor, NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TO_STRING_BODY(Word);
|
||||
|
||||
// friend
|
||||
|
@ -38,6 +38,7 @@ namespace Moses
|
||||
{
|
||||
|
||||
class Phrase;
|
||||
class FactorMask;
|
||||
|
||||
/** Represent a word (terminal or non-term)
|
||||
* Wrapper around hold a set of factors for a single word
|
||||
@ -150,6 +151,8 @@ public:
|
||||
|
||||
void CreateUnknownWord(const Word &sourceWord);
|
||||
|
||||
void OnlyTheseFactors(const FactorMask &factors);
|
||||
|
||||
inline size_t hash() const {
|
||||
return util::MurmurHashNative(m_factorArray, MAX_NUM_FACTORS*sizeof(Factor*), m_isNonTerminal);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user