00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "HoleCollection.h"
00021
00022 #include <algorithm>
00023
00024 namespace MosesTraining
00025 {
00026
00027 void HoleCollection::SortSourceHoles()
00028 {
00029 assert(m_sortedSourceHoles.size() == 0);
00030
00031
00032 HoleList::iterator iter;
00033 for (iter = m_holes.begin(); iter != m_holes.end(); ++iter) {
00034 Hole &currHole = *iter;
00035 m_sortedSourceHoles.push_back(&currHole);
00036 }
00037
00038
00039 std::sort(m_sortedSourceHoles.begin(), m_sortedSourceHoles.end(), HoleSourceOrderer());
00040 }
00041
00042 void HoleCollection::Add(int startT, int endT, int startS, int endS)
00043 {
00044 Hole hole(startS, endS, startT, endT);
00045 m_scope.push_back(Scope(hole));
00046 m_sourceHoleStartPoints.push_back(startS);
00047 m_sourceHoleEndPoints.push_back(endS);
00048 m_holes.push_back(hole);
00049 m_sortedSourceHoles.clear();
00050 }
00051
00052 void HoleCollection::RemoveLast()
00053 {
00054 m_scope.pop_back();
00055 m_sourceHoleStartPoints.pop_back();
00056 m_sourceHoleEndPoints.pop_back();
00057 m_holes.pop_back();
00058 m_sortedSourceHoles.clear();
00059 }
00060
00061 int HoleCollection::Scope(const Hole &proposedHole) const
00062 {
00063 const int holeStart = proposedHole.GetStart(0);
00064 const int holeEnd = proposedHole.GetEnd(0);
00065 int scope = m_scope.back();
00066 if (holeStart == m_sourcePhraseStart.back() ||
00067 find(m_sourceHoleEndPoints.begin(), m_sourceHoleEndPoints.end(), holeStart-1) != m_sourceHoleEndPoints.end()) {
00068 ++scope;
00069 }
00070 if (holeEnd == m_sourcePhraseEnd.back() ||
00071 find(m_sourceHoleStartPoints.begin(), m_sourceHoleStartPoints.end(), holeEnd-1) != m_sourceHoleStartPoints.end()) {
00072 ++scope;
00073 }
00074 return scope;
00075 }
00076
00077 }