00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #pragma once
00021 #ifndef HOLE_H_INCLUDED_
00022 #define HOLE_H_INCLUDED_
00023
00024 #include <cassert>
00025 #include <list>
00026 #include <string>
00027 #include <vector>
00028
00029 namespace MosesTraining
00030 {
00031
00032 class Hole
00033 {
00034 protected:
00035 std::vector<int> m_start, m_end, m_pos;
00036 std::vector<std::string> m_label;
00037
00038 public:
00039 Hole()
00040 : m_start(2)
00041 , m_end(2)
00042 , m_pos(2)
00043 , m_label(2) {
00044 }
00045
00046 Hole(const Hole ©)
00047 : m_start(copy.m_start)
00048 , m_end(copy.m_end)
00049 , m_pos(copy.m_pos)
00050 , m_label(copy.m_label) {
00051 }
00052
00053 Hole(int startS, int endS, int startT, int endT)
00054 : m_start(2)
00055 , m_end(2)
00056 , m_pos(2)
00057 , m_label(2) {
00058 m_start[0] = startS;
00059 m_end[0] = endS;
00060 m_start[1] = startT;
00061 m_end[1] = endT;
00062 }
00063
00064 int GetStart(size_t direction) const {
00065 return m_start[direction];
00066 }
00067
00068 int GetEnd(size_t direction) const {
00069 return m_end[direction];
00070 }
00071
00072 int GetSize(size_t direction) const {
00073 return m_end[direction] - m_start[direction] + 1;
00074 }
00075
00076 void SetPos(int pos, size_t direction) {
00077 m_pos[direction] = pos;
00078 }
00079
00080 int GetPos(size_t direction) const {
00081 return m_pos[direction];
00082 }
00083
00084 void SetLabel(const std::string &label, size_t direction) {
00085 m_label[direction] = label;
00086 }
00087
00088 const std::string &GetLabel(size_t direction) const {
00089 return m_label[direction];
00090 }
00091
00092 bool Overlap(const Hole &otherHole, size_t direction) const {
00093 return ! ( otherHole.GetEnd(direction) < GetStart(direction) ||
00094 otherHole.GetStart(direction) > GetEnd(direction) );
00095 }
00096
00097 bool Neighbor(const Hole &otherHole, size_t direction) const {
00098 return ( otherHole.GetEnd(direction)+1 == GetStart(direction) ||
00099 otherHole.GetStart(direction) == GetEnd(direction)+1 );
00100 }
00101 };
00102
00103 typedef std::list<Hole> HoleList;
00104
00105 class HoleSourceOrderer
00106 {
00107 public:
00108 bool operator()(const Hole* holeA, const Hole* holeB) const {
00109 assert(holeA->GetStart(0) != holeB->GetStart(0));
00110 return holeA->GetStart(0) < holeB->GetStart(0);
00111 }
00112 };
00113
00114 }
00115
00116 #endif