00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef moses_ReorderingConstraint_h
00025 #define moses_ReorderingConstraint_h
00026
00027
00028 #include <limits>
00029 #include <vector>
00030 #include <iostream>
00031 #include <cstring>
00032 #include <cmath>
00033 #include "TypeDef.h"
00034 #include "Word.h"
00035 #include "Phrase.h"
00036
00037 namespace Moses
00038 {
00039
00040 class InputType;
00041 class Bitmap;
00042
00043 #define NOT_A_ZONE 999999999
00044
00046 class ReorderingConstraint
00047 {
00048 friend std::ostream& operator<<(std::ostream& out, const ReorderingConstraint &obj);
00049 protected:
00050
00051 size_t m_size;
00052 bool *m_wall;
00053 size_t *m_localWall;
00054 std::vector< std::pair<size_t,size_t> > m_zone;
00055 bool m_active;
00056 int m_max_distortion;
00057 public:
00058
00060 ReorderingConstraint(int max_distortion)
00061 : m_wall(NULL)
00062 , m_localWall(NULL)
00063 , m_active(false)
00064 , m_max_distortion(max_distortion)
00065 {}
00066
00068 ~ReorderingConstraint() {
00069 if (m_wall != NULL) free(m_wall);
00070 if (m_localWall != NULL) free(m_localWall);
00071 }
00072
00074 void InitializeWalls(size_t size);
00075
00077 void FinalizeWalls();
00078
00080 void SetWall( size_t pos, bool value );
00081
00083 bool GetWall(size_t pos) const {
00084 return m_wall[pos];
00085 }
00086
00088 bool GetLocalWall(size_t pos, size_t zone ) const {
00089 return (m_localWall[pos] == zone);
00090 }
00091
00093 void SetZone( size_t startPos, size_t endPos );
00094
00096 std::vector< std::pair<size_t,size_t> > & GetZones() {
00097 return m_zone;
00098 }
00099
00101 void SetMonotoneAtPunctuation( const Phrase & sentence );
00102
00104 bool Check( const Bitmap &bitmap, size_t start, size_t end ) const;
00105
00107 bool IsActive() const {
00108 return m_active;
00109 }
00110 };
00111
00112 }
00113 #endif