vector -> pair

This commit is contained in:
Hieu Hoang 2016-06-07 18:16:16 +01:00
parent 60b83e7963
commit 93dd29639a
2 changed files with 13 additions and 14 deletions

View File

@ -54,8 +54,8 @@ void ReorderingConstraint::SetWall( size_t pos, bool value )
void ReorderingConstraint::FinalizeWalls()
{
for(size_t z = 0; z < m_zone.size(); z++ ) {
const size_t startZone = m_zone[z][0];
const size_t endZone = m_zone[z][1];// note: wall after endZone is not local
const size_t startZone = m_zone[z].first;
const size_t endZone = m_zone[z].second;// note: wall after endZone is not local
for( size_t pos = startZone; pos < endZone; pos++ ) {
if (m_wall[ pos ]) {
m_localWall[ pos ] = z;
@ -65,8 +65,8 @@ void ReorderingConstraint::FinalizeWalls()
// enforce that local walls only apply to innermost zone
else if (m_localWall[ pos ] != NOT_A_ZONE) {
size_t assigned_z = m_localWall[ pos ];
if ((m_zone[assigned_z][0] < startZone) ||
(m_zone[assigned_z][1] > endZone)) {
if ((m_zone[assigned_z].first < startZone) ||
(m_zone[assigned_z].second > endZone)) {
m_localWall[ pos ] = z;
}
}
@ -97,9 +97,9 @@ void ReorderingConstraint::SetMonotoneAtPunctuation( const Phrase &sentence )
void ReorderingConstraint::SetZone( size_t startPos, size_t endPos )
{
VERBOSE(3,"SETTING zone " << startPos << "-" << endPos << std::endl);
std::vector< size_t > newZone;
newZone.push_back( startPos );
newZone.push_back( endPos );
std::pair<size_t,size_t> newZone;
newZone.first = startPos;
newZone.second = endPos;
m_zone.push_back( newZone );
m_active = true;
}
@ -138,8 +138,8 @@ bool ReorderingConstraint::Check( const Bitmap &bitmap, size_t startPos, size_t
// check zones
for(size_t z = 0; z < m_zone.size(); z++ ) {
const size_t startZone = m_zone[z][0];
const size_t endZone = m_zone[z][1];
const size_t startZone = m_zone[z].first;
const size_t endZone = m_zone[z].second;
// fine, if translation has not reached zone yet and phrase outside zone
if (lastPos < startZone && ( endPos < startZone || startPos > endZone ) ) {
@ -240,9 +240,8 @@ std::ostream& operator<<(std::ostream& out, const ReorderingConstraint &obj)
{
out << "Zones:";
for (size_t i = 0; i < obj.m_zone.size(); ++i) {
const std::vector< size_t > &zone1 = obj.m_zone[i];
UTIL_THROW_IF2(zone1.size() != 2, "m_zone[" << i << "] != 2");
out << zone1[0] << "-" << zone1[1] << " ";
const std::pair<size_t,size_t> &zone1 = obj.m_zone[i];
out << zone1.first << "-" << zone1.second << " ";
}
out << "Walls:";

View File

@ -51,7 +51,7 @@ protected:
size_t m_size; /**< number of words in sentence */
bool *m_wall; /**< flag for each word if it is a wall */
size_t *m_localWall; /**< flag for each word if it is a local wall */
std::vector< std::vector< size_t > > m_zone; /** zones that limit reordering */
std::vector< std::pair<size_t,size_t> > m_zone; /** zones that limit reordering */
bool m_active; /**< flag indicating, if there are any active constraints */
int m_max_distortion;
public:
@ -93,7 +93,7 @@ public:
void SetZone( size_t startPos, size_t endPos );
//! returns the vector of zones
std::vector< std::vector< size_t > > & GetZones() {
std::vector< std::pair<size_t,size_t> > & GetZones() {
return m_zone;
}