#include <WordsBitmap.h>
Public Member Functions | |
WordsBitmap (size_t size, const std::vector< bool > &initializer) | |
Create WordsBitmap of length size, and initialise with vector. | |
WordsBitmap (size_t size) | |
Create WordsBitmap of length size and initialise. | |
WordsBitmap (const WordsBitmap ©) | |
Deep copy. | |
size_t | GetNumWordsCovered () const |
Count of words translated. | |
size_t | GetFirstGapPos () const |
position of 1st word not yet translated, or NOT_FOUND if everything already translated | |
size_t | GetLastGapPos () const |
position of last word not yet translated, or NOT_FOUND if everything already translated | |
size_t | GetLastPos () const |
position of last translated word | |
bool | IsAdjacent (size_t startPos, size_t endPos) const |
bool | GetValue (size_t pos) const |
whether a word has been translated at a particular position | |
void | SetValue (size_t pos, bool value) |
set value at a particular position | |
void | SetValue (size_t startPos, size_t endPos, bool value) |
set value between 2 positions, inclusive | |
void | SetValue (WordsRange const &range, bool val) |
bool | IsComplete () const |
whether every word has been translated | |
bool | Overlap (const WordsRange &compare) const |
whether the wordrange overlaps with any translated word in this bitmap | |
size_t | GetSize () const |
number of elements | |
size_t | GetEdgeToTheLeftOf (size_t l) const |
size_t | GetEdgeToTheRightOf (size_t r) const |
WordsBitmapID | GetID () const |
converts bitmap into an integer ID: it consists of two parts: the first 16 bit are the pattern between the first gap and the last word-1, the second 16 bit are the number of filled positions. enforces a sentence length limit of 65535 and a max distortion of 16 | |
WordsBitmapID | GetIDPlus (size_t startPos, size_t endPos) const |
converts bitmap into an integer ID, with an additional span covered | |
size_t | hash () const |
bool | operator== (const WordsBitmap &other) const |
bool | operator!= (const WordsBitmap &other) const |
TO_STRING () | |
Friends | |
std::ostream & | operator<< (std::ostream &out, const WordsBitmap &wordsBitmap) |
Implemented using a vector of char, which is usually the same representation for the elements that a C array of bool would use. A vector of bool, or a Boost dynamic_bitset, could be much more efficient in theory. Unfortunately algorithms like std::find() are not optimized for vector<bool> on gcc or clang, and dynamic_bitset lacks all the optimized search operations we want. Only benchmarking will tell what works best. Perhaps dynamic_bitset could still be a dramatic improvement, if we flip the meaning of the bits around so we can use its find_first() and find_next() for the most common searches.
Definition at line 50 of file WordsBitmap.h.
Moses::WordsBitmap::WordsBitmap | ( | size_t | size, | |
const std::vector< bool > & | initializer | |||
) | [inline] |
Create WordsBitmap of length size, and initialise with vector.
Definition at line 85 of file WordsBitmap.h.
References NOT_FOUND.
Moses::WordsBitmap::WordsBitmap | ( | size_t | size | ) | [inline] |
Moses::WordsBitmap::WordsBitmap | ( | const WordsBitmap & | copy | ) | [inline] |
size_t Moses::WordsBitmap::GetEdgeToTheLeftOf | ( | size_t | l | ) | const [inline] |
Definition at line 186 of file WordsBitmap.h.
Referenced by Moses::SearchNormal::ProcessOneHypothesis().
size_t Moses::WordsBitmap::GetEdgeToTheRightOf | ( | size_t | r | ) | const [inline] |
Definition at line 194 of file WordsBitmap.h.
Referenced by Moses::SearchNormal::ProcessOneHypothesis().
size_t Moses::WordsBitmap::GetFirstGapPos | ( | ) | const [inline] |
position of 1st word not yet translated, or NOT_FOUND if everything already translated
Definition at line 116 of file WordsBitmap.h.
Referenced by BOOST_AUTO_TEST_CASE(), Moses::SquareMatrix::CalcFutureScore2(), Moses::ReorderingConstraint::Check(), Moses::SearchCubePruning::CheckDistortion(), Moses::DistortionScoreProducer::EvaluateWhenApplied(), GetID(), GetIDPlus(), IsAdjacent(), Moses::HypothesisScoreOrdererWithDistortion::operator()(), and Moses::SearchNormal::ProcessOneHypothesis().
WordsBitmapID Moses::WordsBitmap::GetID | ( | ) | const [inline] |
converts bitmap into an integer ID: it consists of two parts: the first 16 bit are the pattern between the first gap and the last word-1, the second 16 bit are the number of filled positions. enforces a sentence length limit of 65535 and a max distortion of 16
Definition at line 204 of file WordsBitmap.h.
References end, GetFirstGapPos(), GetLastPos(), GetValue(), and NOT_FOUND.
Referenced by Moses::HypothesisStackNormal::Add(), Moses::HypothesisStackNormal::GetWorstScoreForBitmap(), and Moses::HypothesisStackNormal::PruneToSize().
WordsBitmapID Moses::WordsBitmap::GetIDPlus | ( | size_t | startPos, | |
size_t | endPos | |||
) | const [inline] |
converts bitmap into an integer ID, with an additional span covered
Definition at line 222 of file WordsBitmap.h.
References end, GetFirstGapPos(), GetLastPos(), GetValue(), and NOT_FOUND.
Referenced by Moses::SearchNormal::ExpandHypothesis().
size_t Moses::WordsBitmap::GetLastGapPos | ( | ) | const [inline] |
position of last word not yet translated, or NOT_FOUND if everything already translated
Definition at line 122 of file WordsBitmap.h.
References NOT_FOUND.
Referenced by BOOST_AUTO_TEST_CASE(), and IsAdjacent().
size_t Moses::WordsBitmap::GetLastPos | ( | ) | const [inline] |
position of last translated word
Definition at line 134 of file WordsBitmap.h.
References NOT_FOUND.
Referenced by BOOST_AUTO_TEST_CASE(), Moses::SquareMatrix::CalcFutureScore2(), Moses::ReorderingConstraint::Check(), GetID(), and GetIDPlus().
size_t Moses::WordsBitmap::GetNumWordsCovered | ( | ) | const [inline] |
Count of words translated.
Definition at line 111 of file WordsBitmap.h.
References count.
Referenced by Moses::SentenceStats::AddRecombination(), Moses::ascendingCoverageCmp(), Moses::BackwardsEdge::BackwardsEdge(), BOOST_AUTO_TEST_CASE(), Moses::calcNgramExpectations(), Moses::SearchCubePruning::CreateForwardTodos(), Moses::BleuScoreFeature::EvaluateWhenApplied(), Moses::SearchNormal::ExpandHypothesis(), IsAdjacent(), IsComplete(), Moses::Manager::OutputSearchGraphAsHypergraph(), and Moses::OutputSearchNode().
size_t Moses::WordsBitmap::GetSize | ( | ) | const [inline] |
number of elements
Definition at line 182 of file WordsBitmap.h.
Referenced by BOOST_AUTO_TEST_CASE(), Moses::SquareMatrix::CalcFutureScore(), Moses::SquareMatrix::CalcFutureScore2(), Moses::BleuScoreFeature::EvaluateWhenApplied(), and IsComplete().
bool Moses::WordsBitmap::GetValue | ( | size_t | pos | ) | const [inline] |
whether a word has been translated at a particular position
Definition at line 147 of file WordsBitmap.h.
Referenced by BOOST_AUTO_TEST_CASE(), Moses::SquareMatrix::CalcFutureScore(), Moses::SquareMatrix::CalcFutureScore2(), Moses::ReorderingConstraint::Check(), Moses::SearchCubePruning::CreateForwardTodos(), GetID(), GetIDPlus(), Moses::IsMonotonicStep(), Moses::IsSwap(), Moses::operator<<(), and Moses::SearchNormal::ProcessOneHypothesis().
size_t Moses::WordsBitmap::hash | ( | ) | const |
Definition at line 39 of file WordsBitmap.cpp.
References Moses::hash_value().
Referenced by Moses::Hypothesis::hash().
bool Moses::WordsBitmap::IsAdjacent | ( | size_t | startPos, | |
size_t | endPos | |||
) | const |
Definition at line 30 of file WordsBitmap.cpp.
References GetFirstGapPos(), GetLastGapPos(), and GetNumWordsCovered().
bool Moses::WordsBitmap::IsComplete | ( | ) | const [inline] |
whether every word has been translated
Definition at line 170 of file WordsBitmap.h.
References GetNumWordsCovered(), and GetSize().
Referenced by Moses::calcNgramExpectations(), Moses::TargetNgramFeature::EvaluateWhenApplied(), Moses::TargetBigramFeature::EvaluateWhenApplied(), and Moses::Hypothesis::IsSourceCompleted().
bool Moses::WordsBitmap::operator!= | ( | const WordsBitmap & | other | ) | const [inline] |
Definition at line 247 of file WordsBitmap.h.
bool Moses::WordsBitmap::operator== | ( | const WordsBitmap & | other | ) | const |
Definition at line 45 of file WordsBitmap.cpp.
bool Moses::WordsBitmap::Overlap | ( | const WordsRange & | compare | ) | const [inline] |
whether the wordrange overlaps with any translated word in this bitmap
Definition at line 174 of file WordsBitmap.h.
References Moses::WordsRange::GetEndPos(), and Moses::WordsRange::GetStartPos().
Referenced by Moses::TranslationOption::Overlap(), and Moses::SearchNormal::ProcessOneHypothesis().
void Moses::WordsBitmap::SetValue | ( | WordsRange const & | range, | |
bool | val | |||
) | [inline] |
Definition at line 165 of file WordsBitmap.h.
References Moses::WordsRange::GetEndPos(), Moses::WordsRange::GetStartPos(), and SetValue().
void Moses::WordsBitmap::SetValue | ( | size_t | startPos, | |
size_t | endPos, | |||
bool | value | |||
) | [inline] |
void Moses::WordsBitmap::SetValue | ( | size_t | pos, | |
bool | value | |||
) | [inline] |
set value at a particular position
Definition at line 151 of file WordsBitmap.h.
Referenced by BOOST_AUTO_TEST_CASE(), Moses::SearchCubePruning::CreateForwardTodos(), Moses::OpSequenceModel::EvaluateWhenApplied(), Moses::HReorderingForwardState::Expand(), Moses::HReorderingForwardState::HReorderingForwardState(), and SetValue().
Moses::WordsBitmap::TO_STRING | ( | ) |
std::ostream& operator<< | ( | std::ostream & | out, | |
const WordsBitmap & | wordsBitmap | |||
) | [friend] |
Definition at line 51 of file WordsBitmap.cpp.