From 78728d70eadb722f81cadeeafc567ddfa2657781 Mon Sep 17 00:00:00 2001 From: evahasler Date: Tue, 27 Nov 2007 16:25:19 +0000 Subject: delete CompressedRepr() from Bitmap git-svn-id: https://mosesdecoder.svn.sourceforge.net/svnroot/mosesdecoder/branches/eva_cube_pruning/moses@1521 1f5c12ca-751b-0410-a591-d2e778427230 --- src/Hypothesis.cpp | 6 ++++-- src/Manager.cpp | 13 +++++++------ src/WordsBitmap.cpp | 23 ----------------------- src/WordsBitmap.h | 10 +++++----- 4 files changed, 16 insertions(+), 36 deletions(-) diff --git a/src/Hypothesis.cpp b/src/Hypothesis.cpp index 866768086..36a608b83 100755 --- a/src/Hypothesis.cpp +++ b/src/Hypothesis.cpp @@ -187,8 +187,10 @@ int Hypothesis::NGramCompare(const Hypothesis &compare) const // 0 = this ==compare if (m_languageModelStates < compare.m_languageModelStates) return -1; if (m_languageModelStates > compare.m_languageModelStates) return 1; - if (m_sourceCompleted.GetCompressedRepresentation() < compare.m_sourceCompleted.GetCompressedRepresentation()) return -1; - if (m_sourceCompleted.GetCompressedRepresentation() > compare.m_sourceCompleted.GetCompressedRepresentation()) return 1; + + int compareBitmap = m_sourceCompleted.Compare(compare.m_sourceCompleted); + if (compareBitmap != 0) + return compareBitmap; if (m_currSourceWordsRange.GetEndPos() < compare.m_currSourceWordsRange.GetEndPos()) return -1; if (m_currSourceWordsRange.GetEndPos() > compare.m_currSourceWordsRange.GetEndPos()) return 1; if (! StaticData::Instance().GetSourceStartPosMattersForRecombination()) return 0; diff --git a/src/Manager.cpp b/src/Manager.cpp index 18f121650..00c95c60f 100755 --- a/src/Manager.cpp +++ b/src/Manager.cpp @@ -117,7 +117,8 @@ void Manager::ProcessSentence() sourceHypoColl.CleanupArcList(); // keep already seen coverages in mind - set > seenCoverages; + //set > seenCoverages; + set< WordsBitmap > seenCoverages; // go through each hypothesis on the stack, find the set of hypothesis with same coverage and expand this set using cube pruning HypothesisStack::const_iterator iterHypo; @@ -126,12 +127,12 @@ void Manager::ProcessSentence() // take first hypothesis from stack to get coverage Hypothesis *hypothesis = *iterHypo; const WordsBitmap &wb = hypothesis->GetWordsBitmap(); - vector cov = wb.GetCompressedRepresentation(); + //vector cov = wb.GetCompressedRepresentation(); // check if coverage of current hypothesis was already seen --> if no, proceed - if( (seenCoverages.count( cov )) == 0 ) + if( (seenCoverages.count( wb )) == 0 ) { - seenCoverages.insert( cov ); + seenCoverages.insert( wb ); const set coverageSet = sourceHypoColl.GetCoverageSet( wb ); size_t j = 0; @@ -163,7 +164,7 @@ void Manager::ProcessSentence() } i++; // some logging - IFVERBOSE(2) { OutputHypoStackSize(); } + OutputHypoStackSize(); } // some more logging @@ -326,7 +327,7 @@ void Manager::CubePruning(const vector< Hypothesis*> &coverageVec, TranslationOp Hypothesis *item; // TODO: the size of the buffer could be a little bigger than top_k to allow for more possible hypotheses being found size_t extra = 0; - while( !(cand.empty()) && (buf.size() < top_k+extra) ) + while( !(cand.empty()) && (buf.size() < top_k + extra) ) { IFVERBOSE(3) { cout << "candidates: " << endl; diff --git a/src/WordsBitmap.cpp b/src/WordsBitmap.cpp index b70495552..fadf597ae 100755 --- a/src/WordsBitmap.cpp +++ b/src/WordsBitmap.cpp @@ -57,26 +57,3 @@ int WordsBitmap::GetFutureCosts(int lastPos) const } -std::vector WordsBitmap::GetCompressedRepresentation() const -{ - std::vector res(1 + (m_size >> (sizeof(int) + 3)), 0); - size_t c=0; size_t x=0; size_t ci=0; - for(size_t i=0;i swap these two lines - // x |= (size_t)m_bitmap[i]; - // x <<= 1; - x <<= 1; - x |= (size_t)m_bitmap[i]; - c++; - if (c == sizeof(int)*8) { - res[ci++] = x; x = 0; - // new - c = 0; - } - } - // rest: save current x in res - res[ci++] = x; - return res; -} - - diff --git a/src/WordsBitmap.h b/src/WordsBitmap.h index 423682108..59b3e80fe 100755 --- a/src/WordsBitmap.h +++ b/src/WordsBitmap.h @@ -149,11 +149,6 @@ public: { return m_size; } - /** represent this bitmap as 1 or more vector of integers. - * Used for exact matching of source words translated in hypothesis recombination - */ - std::vector GetCompressedRepresentation() const; - //! transitive comparison of WordsBitmap inline int Compare (const WordsBitmap &compare) const @@ -172,6 +167,11 @@ public: return std::memcmp(m_bitmap, compare.m_bitmap, thisSize); } + inline bool operator<(const WordsBitmap &compare) const + { + return Compare(compare) < 0; + } + inline size_t GetEdgeToTheLeftOf(size_t l) const { if (l == 0) return l; -- cgit v1.2.3