00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include <string>
00024 #include <iostream>
00025 #include "SquareMatrix.h"
00026 #include "TypeDef.h"
00027 #include "Util.h"
00028
00029 using namespace std;
00030
00031 namespace Moses
00032 {
00033
00040 float SquareMatrix::CalcFutureScore( WordsBitmap const &bitmap ) const
00041 {
00042 const size_t notInGap= numeric_limits<size_t>::max();
00043 size_t startGap = notInGap;
00044 float futureScore = 0.0f;
00045 for(size_t currPos = 0 ; currPos < bitmap.GetSize() ; currPos++) {
00046
00047 if(bitmap.GetValue(currPos) == false && startGap == notInGap) {
00048 startGap = currPos;
00049 }
00050
00051 else if(bitmap.GetValue(currPos) == true && startGap != notInGap) {
00052 futureScore += GetScore(startGap, currPos - 1);
00053 startGap = notInGap;
00054 }
00055 }
00056
00057 if (startGap != notInGap) {
00058 futureScore += GetScore(startGap, bitmap.GetSize() - 1);
00059 }
00060
00061 return futureScore;
00062 }
00063
00079 float SquareMatrix::CalcFutureScore( WordsBitmap const &bitmap, size_t startPos, size_t endPos ) const
00080 {
00081 const size_t notInGap= numeric_limits<size_t>::max();
00082 float futureScore = 0.0f;
00083 size_t startGap = bitmap.GetFirstGapPos();
00084 if (startGap == NOT_FOUND) return futureScore;
00085
00086
00087 size_t startLoop = startGap+1;
00088 if (startPos == startGap) {
00089 startGap = notInGap;
00090 startLoop = endPos+1;
00091 }
00092
00093 size_t lastCovered = bitmap.GetLastPos();
00094 if (endPos > lastCovered || lastCovered == NOT_FOUND) lastCovered = endPos;
00095
00096 for(size_t currPos = startLoop; currPos <= lastCovered ; currPos++) {
00097
00098 if(startGap == notInGap && bitmap.GetValue(currPos) == false && (currPos < startPos || currPos > endPos)) {
00099 startGap = currPos;
00100 }
00101
00102 else if(startGap != notInGap && (bitmap.GetValue(currPos) == true || (startPos <= currPos && currPos <= endPos))) {
00103 futureScore += GetScore(startGap, currPos - 1);
00104 startGap = notInGap;
00105 }
00106 }
00107
00108 if (lastCovered != bitmap.GetSize() - 1) {
00109 futureScore += GetScore(lastCovered+1, bitmap.GetSize() - 1);
00110 }
00111
00112 return futureScore;
00113 }
00114
00115 TO_STRING_BODY(SquareMatrix);
00116
00117 }
00118
00119