2008-06-11 14:52:57 +04:00
|
|
|
// $Id$
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
Moses - factored phrase-based language decoder
|
|
|
|
Copyright (C) 2006 University of Edinburgh
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Lesser General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
License along with this library; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
***********************************************************************/
|
|
|
|
|
2010-02-24 14:15:44 +03:00
|
|
|
#ifndef moses_WordsRange_h
|
|
|
|
#define moses_WordsRange_h
|
2008-06-11 14:52:57 +04:00
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include "TypeDef.h"
|
|
|
|
#include "Util.h"
|
|
|
|
|
2012-07-18 01:45:23 +04:00
|
|
|
#ifdef WIN32
|
|
|
|
#undef max
|
|
|
|
#endif
|
|
|
|
|
2008-10-09 03:51:26 +04:00
|
|
|
namespace Moses
|
|
|
|
{
|
|
|
|
|
2008-06-11 14:52:57 +04:00
|
|
|
/***
|
|
|
|
* Efficient version of WordsBitmap for contiguous ranges
|
|
|
|
*/
|
|
|
|
class WordsRange
|
|
|
|
{
|
2011-02-24 16:14:42 +03:00
|
|
|
friend std::ostream& operator << (std::ostream& out, const WordsRange& range);
|
2008-06-11 14:52:57 +04:00
|
|
|
|
2011-02-24 16:14:42 +03:00
|
|
|
size_t m_startPos, m_endPos;
|
2008-06-11 14:52:57 +04:00
|
|
|
public:
|
2011-02-24 16:14:42 +03:00
|
|
|
inline WordsRange(size_t startPos, size_t endPos) : m_startPos(startPos), m_endPos(endPos) {}
|
|
|
|
inline WordsRange(const WordsRange ©)
|
|
|
|
: m_startPos(copy.GetStartPos())
|
2013-06-10 21:11:55 +04:00
|
|
|
, m_endPos(copy.GetEndPos()) {
|
|
|
|
}
|
2011-02-24 16:14:42 +03:00
|
|
|
|
|
|
|
inline size_t GetStartPos() const {
|
|
|
|
return m_startPos;
|
|
|
|
}
|
|
|
|
inline size_t GetEndPos() const {
|
|
|
|
return m_endPos;
|
|
|
|
}
|
|
|
|
|
|
|
|
//! count of words translated
|
|
|
|
inline size_t GetNumWordsCovered() const {
|
|
|
|
return (m_startPos == NOT_FOUND) ? 0 : m_endPos - m_startPos + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
//! transitive comparison
|
|
|
|
inline bool operator<(const WordsRange& x) const {
|
|
|
|
return (m_startPos<x.m_startPos
|
|
|
|
|| (m_startPos==x.m_startPos && m_endPos<x.m_endPos));
|
|
|
|
}
|
|
|
|
|
|
|
|
// equality operator
|
|
|
|
inline bool operator==(const WordsRange& x) const {
|
|
|
|
return (m_startPos==x.m_startPos && m_endPos==x.m_endPos);
|
|
|
|
}
|
|
|
|
// Whether two word ranges overlap or not
|
|
|
|
inline bool Overlap(const WordsRange& x) const {
|
|
|
|
|
|
|
|
if ( x.m_endPos < m_startPos || x.m_startPos > m_endPos) return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline size_t GetNumWordsBetween(const WordsRange& x) const {
|
2011-11-18 16:07:41 +04:00
|
|
|
CHECK(!Overlap(x));
|
2011-02-24 16:14:42 +03:00
|
|
|
|
|
|
|
if (x.m_endPos < m_startPos) {
|
2012-06-21 19:41:05 +04:00
|
|
|
return m_startPos - x.m_endPos - 1;
|
2011-02-24 16:14:42 +03:00
|
|
|
}
|
|
|
|
|
2012-06-21 19:41:05 +04:00
|
|
|
return x.m_startPos - m_endPos - 1;
|
2011-02-24 16:14:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TO_STRING();
|
2008-06-11 14:52:57 +04:00
|
|
|
};
|
|
|
|
|
2008-10-09 03:51:26 +04:00
|
|
|
|
|
|
|
}
|
2010-02-24 14:15:44 +03:00
|
|
|
#endif
|