From 93dd29639a0e336eeca5cd50258b70c6fdf9cc89 Mon Sep 17 00:00:00 2001 From: Hieu Hoang Date: Tue, 7 Jun 2016 18:16:16 +0100 Subject: [PATCH] vector -> pair --- moses/ReorderingConstraint.cpp | 23 +++++++++++------------ moses/ReorderingConstraint.h | 4 ++-- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/moses/ReorderingConstraint.cpp b/moses/ReorderingConstraint.cpp index 5f98bd893..d868f5c29 100644 --- a/moses/ReorderingConstraint.cpp +++ b/moses/ReorderingConstraint.cpp @@ -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 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 &zone1 = obj.m_zone[i]; + out << zone1.first << "-" << zone1.second << " "; } out << "Walls:"; diff --git a/moses/ReorderingConstraint.h b/moses/ReorderingConstraint.h index 33046fc99..047382076 100644 --- a/moses/ReorderingConstraint.h +++ b/moses/ReorderingConstraint.h @@ -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 > 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 > & GetZones() { return m_zone; }