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
path: root/moses/FF
diff options
context:
space:
mode:
authorHieu Hoang <hieuhoang@gmail.com>2015-10-13 18:24:22 +0300
committerHieu Hoang <hieuhoang@gmail.com>2015-10-13 18:24:22 +0300
commit0dd07cda0b79ac9bdc0499e4a908655d58ddab98 (patch)
treeb0df9ac64de29c0cb8cf2ebf7986ead327e0b58a /moses/FF
parent4ea806a159d92e86fd6b3670ca59da3ec69e8713 (diff)
new FF state API for more FF
Diffstat (limited to 'moses/FF')
-rw-r--r--moses/FF/FFState.h2
-rw-r--r--moses/FF/InternalTree.h2
-rw-r--r--moses/FF/LexicalReordering/LexicalReorderingState.cpp6
-rw-r--r--moses/FF/OSM-Feature/osmHyp.cpp22
-rw-r--r--moses/FF/OSM-Feature/osmHyp.h5
-rw-r--r--moses/FF/SkeletonStatefulFF.h7
-rw-r--r--moses/FF/TargetNgramFeature.cpp31
-rw-r--r--moses/FF/TargetNgramFeature.h10
8 files changed, 64 insertions, 21 deletions
diff --git a/moses/FF/FFState.h b/moses/FF/FFState.h
index 740e90cdc..931532755 100644
--- a/moses/FF/FFState.h
+++ b/moses/FF/FFState.h
@@ -36,7 +36,7 @@ public:
virtual bool operator==(const FFState& other) const
{
- UTIL_THROW2("TODO:Haven't figure this out yet");
+ return true;
}
};
diff --git a/moses/FF/InternalTree.h b/moses/FF/InternalTree.h
index 2a02ab159..cab6951b2 100644
--- a/moses/FF/InternalTree.h
+++ b/moses/FF/InternalTree.h
@@ -150,7 +150,7 @@ public:
}
virtual bool operator==(const FFState& other) const
{
- UTIL_THROW2("TODO:Haven't figure this out yet");
+ return true;
}
};
diff --git a/moses/FF/LexicalReordering/LexicalReorderingState.cpp b/moses/FF/LexicalReordering/LexicalReorderingState.cpp
index 6e6ecaf46..a3683b2b7 100644
--- a/moses/FF/LexicalReordering/LexicalReorderingState.cpp
+++ b/moses/FF/LexicalReordering/LexicalReorderingState.cpp
@@ -344,10 +344,10 @@ bool PhraseBasedReorderingState::operator==(const FFState& o) const
{
if (&o == this) return true;
- const PhraseBasedReorderingState* other = static_cast<const PhraseBasedReorderingState*>(&o);
- if (m_prevRange == other->m_prevRange) {
+ const PhraseBasedReorderingState &other = static_cast<const PhraseBasedReorderingState&>(o);
+ if (m_prevRange == other.m_prevRange) {
if (m_direction == LRModel::Forward) {
- int compareScore = ComparePrevScores(other->m_prevOption);
+ int compareScore = ComparePrevScores(other.m_prevOption);
return compareScore == 0;
} else {
return true;
diff --git a/moses/FF/OSM-Feature/osmHyp.cpp b/moses/FF/OSM-Feature/osmHyp.cpp
index c21257c26..e8913bafb 100644
--- a/moses/FF/OSM-Feature/osmHyp.cpp
+++ b/moses/FF/OSM-Feature/osmHyp.cpp
@@ -41,9 +41,29 @@ int osmState::Compare(const FFState& otherBase) const
size_t osmState::hash() const
{
- UTIL_THROW2("TODO:Haven't figure this out yet");
+ size_t ret = j;
+
+ boost::hash_combine(ret, E);
+ boost::hash_combine(ret, gap);
+ boost::hash_combine(ret, lmState.length);
+
+ return ret;
}
+bool osmState::operator==(const FFState& otherBase) const
+{
+ const osmState &other = static_cast<const osmState&>(otherBase);
+ if (j != other.j)
+ return false;
+ if (E != other.E)
+ return false;
+ if (gap != other.gap)
+ return false;
+ if (lmState.length != other.lmState.length)
+ return false;
+
+ return true;
+}
std::string osmState :: getName() const
{
diff --git a/moses/FF/OSM-Feature/osmHyp.h b/moses/FF/OSM-Feature/osmHyp.h
index 66d2d3bcc..d64cac019 100644
--- a/moses/FF/OSM-Feature/osmHyp.h
+++ b/moses/FF/OSM-Feature/osmHyp.h
@@ -18,10 +18,7 @@ public:
osmState(const lm::ngram::State & val);
int Compare(const FFState& other) const;
virtual size_t hash() const;
- virtual bool operator==(const FFState& other) const
- {
- UTIL_THROW2("TODO:Haven't figure this out yet");
- }
+ virtual bool operator==(const FFState& other) const;
void saveState(int jVal, int eVal, std::map <int , std::string> & gapVal);
int getJ()const {
diff --git a/moses/FF/SkeletonStatefulFF.h b/moses/FF/SkeletonStatefulFF.h
index 448dde3d8..d51172b32 100644
--- a/moses/FF/SkeletonStatefulFF.h
+++ b/moses/FF/SkeletonStatefulFF.h
@@ -18,11 +18,12 @@ public:
int Compare(const FFState& other) const;
virtual size_t hash() const {
- return (size_t) m_targetLen;
+ return (size_t) m_targetLen;
}
- virtual bool operator==(const FFState& other) const
+ virtual bool operator==(const FFState& o) const
{
- UTIL_THROW2("TODO:Haven't figure this out yet");
+ const SkeletonState& other = static_cast<const SkeletonState&>(o);
+ return m_targetLen == other.m_targetLen;
}
};
diff --git a/moses/FF/TargetNgramFeature.cpp b/moses/FF/TargetNgramFeature.cpp
index 8414e1bc2..f39a388ef 100644
--- a/moses/FF/TargetNgramFeature.cpp
+++ b/moses/FF/TargetNgramFeature.cpp
@@ -37,6 +37,37 @@ int TargetNgramState::Compare(const FFState& other) const
}
}
+size_t TargetNgramState::hash() const
+{
+ std::size_t ret = boost::hash_range(m_words.begin(), m_words.end());
+ return ret;
+}
+bool TargetNgramState::operator==(const FFState& other) const
+{
+ const TargetNgramState& rhs = dynamic_cast<const TargetNgramState&>(other);
+ int result;
+ if (m_words.size() == rhs.m_words.size()) {
+ for (size_t i = 0; i < m_words.size(); ++i) {
+ result = Word::Compare(m_words[i],rhs.m_words[i]);
+ if (result != 0) return false;
+ }
+ return true;
+ } else if (m_words.size() < rhs.m_words.size()) {
+ for (size_t i = 0; i < m_words.size(); ++i) {
+ result = Word::Compare(m_words[i],rhs.m_words[i]);
+ if (result != 0) return false;
+ }
+ return true;
+ } else {
+ for (size_t i = 0; i < rhs.m_words.size(); ++i) {
+ result = Word::Compare(m_words[i],rhs.m_words[i]);
+ if (result != 0) return false;
+ }
+ return true;
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////
TargetNgramFeature::TargetNgramFeature(const std::string &line)
:StatefulFeatureFunction(0, line)
{
diff --git a/moses/FF/TargetNgramFeature.h b/moses/FF/TargetNgramFeature.h
index 5d241376d..865d0a2f7 100644
--- a/moses/FF/TargetNgramFeature.h
+++ b/moses/FF/TargetNgramFeature.h
@@ -25,14 +25,8 @@ public:
}
virtual int Compare(const FFState& other) const;
- size_t hash() const
- {
- UTIL_THROW2("TODO:Haven't figure this out yet");
- }
- virtual bool operator==(const FFState& other) const
- {
- UTIL_THROW2("TODO:Haven't figure this out yet");
- }
+ size_t hash() const;
+ virtual bool operator==(const FFState& other) const;
private:
std::vector<Word> m_words;