Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHieu Hoang <hieuhoang@gmail.com>2017-02-01 01:21:59 +0300
committerHieu Hoang <hieuhoang@gmail.com>2017-02-01 01:21:59 +0300
commita8a5b43f2dc32bd1b45006fd43989dc71e74ba0e (patch)
treee84a78fa005e29ec78076d6e525371240871122c /moses2/EstimatedScores.cpp
parent7206d592751ee9afeb1fa4753b7e19272e2585bc (diff)
move moses2 to root
Diffstat (limited to 'moses2/EstimatedScores.cpp')
-rw-r--r--moses2/EstimatedScores.cpp117
1 files changed, 117 insertions, 0 deletions
diff --git a/moses2/EstimatedScores.cpp b/moses2/EstimatedScores.cpp
new file mode 100644
index 000000000..dfe52bb2b
--- /dev/null
+++ b/moses2/EstimatedScores.cpp
@@ -0,0 +1,117 @@
+// $Id$
+// vim:tabstop=2
+
+/***********************************************************************
+ Moses - factored phrase-based language decoder
+ Copyright (C) 2006 University of Edinburgh
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ ***********************************************************************/
+
+#include <string>
+#include <iostream>
+#include "EstimatedScores.h"
+
+using namespace std;
+
+namespace Moses2
+{
+/**
+ * Calculate future score estimate for a given coverage bitmap
+ *
+ * /param bitmap coverage bitmap
+ */
+
+float EstimatedScores::CalcEstimatedScore(Bitmap const &bitmap) const
+{
+ const size_t notInGap = numeric_limits<size_t>::max();
+ size_t startGap = notInGap;
+ float estimatedScore = 0.0f;
+ for (size_t currPos = 0; currPos < bitmap.GetSize(); currPos++) {
+ // start of a new gap?
+ if (bitmap.GetValue(currPos) == false && startGap == notInGap) {
+ startGap = currPos;
+ }
+ // end of a gap?
+ else if (bitmap.GetValue(currPos) == true && startGap != notInGap) {
+ estimatedScore += GetValue(startGap, currPos - 1);
+ startGap = notInGap;
+ }
+ }
+ // coverage ending with gap?
+ if (startGap != notInGap) {
+ estimatedScore += GetValue(startGap, bitmap.GetSize() - 1);
+ }
+
+ return estimatedScore;
+}
+
+/**
+ * Calculare future score estimate for a given coverage bitmap
+ * and an additional span that is also covered. This function is used
+ * to compute future score estimates for hypotheses that we may want
+ * build, but first want to check.
+ *
+ * Note: this function is implemented a bit more complex than
+ * the basic one (w/o additional phrase) for speed reasons,
+ * which is probably overkill.
+ *
+ * /param bitmap coverage bitmap
+ * /param startPos start of the span that is added to the coverage
+ * /param endPos end of the span that is added to the coverage
+ */
+
+float EstimatedScores::CalcEstimatedScore(Bitmap const &bitmap, size_t startPos,
+ size_t endPos) const
+{
+ const size_t notInGap = numeric_limits<size_t>::max();
+ float estimatedScore = 0.0f;
+ size_t startGap = bitmap.GetFirstGapPos();
+ if (startGap == NOT_FOUND) return estimatedScore; // everything filled
+
+ // start loop at first gap
+ size_t startLoop = startGap + 1;
+ if (startPos == startGap) { // unless covered by phrase
+ startGap = notInGap;
+ startLoop = endPos + 1; // -> postpone start
+ }
+
+ size_t lastCovered = bitmap.GetLastPos();
+ if (endPos > lastCovered || lastCovered == NOT_FOUND) lastCovered = endPos;
+
+ for (size_t currPos = startLoop; currPos <= lastCovered; currPos++) {
+ // start of a new gap?
+ if (startGap == notInGap && bitmap.GetValue(currPos) == false
+ && (currPos < startPos || currPos > endPos)) {
+ startGap = currPos;
+ }
+ // end of a gap?
+ else if (startGap != notInGap
+ && (bitmap.GetValue(currPos) == true
+ || (startPos <= currPos && currPos <= endPos))) {
+ estimatedScore += GetValue(startGap, currPos - 1);
+ startGap = notInGap;
+ }
+ }
+ // coverage ending with gap?
+ if (lastCovered != bitmap.GetSize() - 1) {
+ estimatedScore += GetValue(lastCovered + 1, bitmap.GetSize() - 1);
+ }
+
+ return estimatedScore;
+}
+
+}
+