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:
authorPhil Williams <philip.williams@mac.com>2015-10-26 18:57:07 +0300
committerPhil Williams <philip.williams@mac.com>2015-10-26 18:57:07 +0300
commit8a41bad9aad708390cbdafffdf2834d37b4c2b9e (patch)
tree813b8b1631a87cf7481b632676d2c84bc3f459ab /moses/Syntax
parent1b09fe5a7229d656c044cc5f96513a73ea01f583 (diff)
Separate SVertexRecombination{EqualityPred,Hasher} classes
Diffstat (limited to 'moses/Syntax')
-rw-r--r--moses/Syntax/F2S/Manager-inl.h7
-rw-r--r--moses/Syntax/S2T/Manager-inl.h7
-rw-r--r--moses/Syntax/SVertex.cpp29
-rw-r--r--moses/Syntax/SVertex.h6
-rw-r--r--moses/Syntax/SVertexRecombinationEqualityPred.h27
-rw-r--r--moses/Syntax/SVertexRecombinationHasher.h26
-rw-r--r--moses/Syntax/SVertexRecombinationOrderer.h27
-rw-r--r--moses/Syntax/T2S/Manager-inl.h7
8 files changed, 70 insertions, 66 deletions
diff --git a/moses/Syntax/F2S/Manager-inl.h b/moses/Syntax/F2S/Manager-inl.h
index 19446c5cd..db4d2858e 100644
--- a/moses/Syntax/F2S/Manager-inl.h
+++ b/moses/Syntax/F2S/Manager-inl.h
@@ -11,7 +11,8 @@
#include "moses/Syntax/RuleTableFF.h"
#include "moses/Syntax/SHyperedgeBundle.h"
#include "moses/Syntax/SVertex.h"
-#include "moses/Syntax/SVertexRecombinationOrderer.h"
+#include "moses/Syntax/SVertexRecombinationEqualityPred.h"
+#include "moses/Syntax/SVertexRecombinationHasher.h"
#include "moses/Syntax/SymbolEqualityPred.h"
#include "moses/Syntax/SymbolHasher.h"
#include "moses/Syntax/T2S/InputTree.h"
@@ -285,7 +286,9 @@ void Manager<RuleMatcher>::RecombineAndSort(
// head pointers are updated to point to the vertex instances in the map and
// any 'duplicate' vertices are deleted.
// TODO Set?
- typedef boost::unordered_map<SVertex *, SVertex *, SVertexRecombinationUnordered, SVertexRecombinationUnordered> Map;
+ typedef boost::unordered_map<SVertex *, SVertex *,
+ SVertexRecombinationHasher,
+ SVertexRecombinationEqualityPred> Map;
Map map;
for (std::vector<SHyperedge*>::const_iterator p = buffer.begin();
p != buffer.end(); ++p) {
diff --git a/moses/Syntax/S2T/Manager-inl.h b/moses/Syntax/S2T/Manager-inl.h
index 0dff7b846..57a52703b 100644
--- a/moses/Syntax/S2T/Manager-inl.h
+++ b/moses/Syntax/S2T/Manager-inl.h
@@ -13,7 +13,8 @@
#include "moses/Syntax/RuleTableFF.h"
#include "moses/Syntax/SHyperedgeBundle.h"
#include "moses/Syntax/SVertex.h"
-#include "moses/Syntax/SVertexRecombinationOrderer.h"
+#include "moses/Syntax/SVertexRecombinationEqualityPred.h"
+#include "moses/Syntax/SVertexRecombinationHasher.h"
#include "moses/Syntax/SymbolEqualityPred.h"
#include "moses/Syntax/SymbolHasher.h"
@@ -349,7 +350,9 @@ void Manager<Parser>::RecombineAndSort(const std::vector<SHyperedge*> &buffer,
// head pointers are updated to point to the vertex instances in the map and
// any 'duplicate' vertices are deleted.
// TODO Set?
- typedef boost::unordered_map<SVertex *, SVertex *, SVertexRecombinationUnordered, SVertexRecombinationUnordered> Map;
+ typedef boost::unordered_map<SVertex *, SVertex *,
+ SVertexRecombinationHasher,
+ SVertexRecombinationEqualityPred> Map;
Map map;
for (std::vector<SHyperedge*>::const_iterator p = buffer.begin();
p != buffer.end(); ++p) {
diff --git a/moses/Syntax/SVertex.cpp b/moses/Syntax/SVertex.cpp
index cd4c1c666..b55f97fe6 100644
--- a/moses/Syntax/SVertex.cpp
+++ b/moses/Syntax/SVertex.cpp
@@ -1,5 +1,7 @@
#include "SVertex.h"
+
#include "moses/FF/FFState.h"
+
#include "SHyperedge.h"
namespace Moses
@@ -22,32 +24,5 @@ SVertex::~SVertex()
}
}
-size_t SVertex::hash() const
-{
- size_t seed;
-
- // states
- for (size_t i = 0; i < states.size(); ++i) {
- const FFState *state = states[i];
- size_t hash = state->hash();
- boost::hash_combine(seed, hash);
- }
- return seed;
-
-}
-
-bool SVertex::operator==(const SVertex& other) const
-{
- // states
- for (size_t i = 0; i < states.size(); ++i) {
- const FFState &thisState = *states[i];
- const FFState &otherState = *other.states[i];
- if (thisState != otherState) {
- return false;
- }
- }
- return true;
-}
-
} // Syntax
} // Moses
diff --git a/moses/Syntax/SVertex.h b/moses/Syntax/SVertex.h
index 9a5392d30..047b98742 100644
--- a/moses/Syntax/SVertex.h
+++ b/moses/Syntax/SVertex.h
@@ -1,7 +1,6 @@
#pragma once
#include <vector>
-#include <stddef.h>
namespace Moses
{
@@ -25,11 +24,6 @@ struct SVertex {
std::vector<SHyperedge*> recombined;
const PVertex *pvertex;
std::vector<FFState*> states;
-
- // for unordered_set in stack
- size_t hash() const;
- bool operator==(const SVertex& other) const;
-
};
} // Syntax
diff --git a/moses/Syntax/SVertexRecombinationEqualityPred.h b/moses/Syntax/SVertexRecombinationEqualityPred.h
new file mode 100644
index 000000000..3461e4fa2
--- /dev/null
+++ b/moses/Syntax/SVertexRecombinationEqualityPred.h
@@ -0,0 +1,27 @@
+#pragma once
+
+#include "moses/FF/FFState.h"
+
+#include "SVertex.h"
+
+namespace Moses
+{
+namespace Syntax
+{
+
+class SVertexRecombinationEqualityPred
+{
+ public:
+ bool operator()(const SVertex *v1, const SVertex *v2) const {
+ assert(v1->states.size() == v2->states.size());
+ for (std::size_t i = 0; i < v1->states.size(); ++i) {
+ if (*(v1->states[i]) != *(v2->states[i])) {
+ return false;
+ }
+ }
+ return true;
+ }
+};
+
+} // Syntax
+} // Moses
diff --git a/moses/Syntax/SVertexRecombinationHasher.h b/moses/Syntax/SVertexRecombinationHasher.h
new file mode 100644
index 000000000..e0cbc06ba
--- /dev/null
+++ b/moses/Syntax/SVertexRecombinationHasher.h
@@ -0,0 +1,26 @@
+#pragma once
+
+#include "moses/FF/FFState.h"
+
+#include "SVertex.h"
+
+namespace Moses
+{
+namespace Syntax
+{
+
+class SVertexRecombinationHasher
+{
+ public:
+ std::size_t operator()(const SVertex *v) const {
+ std::size_t seed = 0;
+ for (std::vector<FFState*>::const_iterator p = v->states.begin();
+ p != v->states.end(); ++p) {
+ boost::hash_combine(seed, (*p)->hash());
+ }
+ return seed;
+ }
+};
+
+} // Syntax
+} // Moses
diff --git a/moses/Syntax/SVertexRecombinationOrderer.h b/moses/Syntax/SVertexRecombinationOrderer.h
deleted file mode 100644
index a91a3b125..000000000
--- a/moses/Syntax/SVertexRecombinationOrderer.h
+++ /dev/null
@@ -1,27 +0,0 @@
-#pragma once
-
-#include "moses/FF/FFState.h"
-
-#include "SVertex.h"
-
-namespace Moses
-{
-namespace Syntax
-{
-
-
-class SVertexRecombinationUnordered
-{
-public:
- size_t operator()(const SVertex* hypo) const {
- return hypo->hash();
- }
-
- bool operator()(const SVertex* hypoA, const SVertex* hypoB) const {
- return (*hypoA) == (*hypoB);
- }
-
-};
-
-} // Syntax
-} // Moses
diff --git a/moses/Syntax/T2S/Manager-inl.h b/moses/Syntax/T2S/Manager-inl.h
index 46d8b7177..e9d6cd82d 100644
--- a/moses/Syntax/T2S/Manager-inl.h
+++ b/moses/Syntax/T2S/Manager-inl.h
@@ -11,7 +11,8 @@
#include "moses/Syntax/RuleTableFF.h"
#include "moses/Syntax/SHyperedgeBundle.h"
#include "moses/Syntax/SVertex.h"
-#include "moses/Syntax/SVertexRecombinationOrderer.h"
+#include "moses/Syntax/SVertexRecombinationEqualityPred.h"
+#include "moses/Syntax/SVertexRecombinationHasher.h"
#include "moses/Syntax/SymbolEqualityPred.h"
#include "moses/Syntax/SymbolHasher.h"
@@ -245,7 +246,9 @@ void Manager<RuleMatcher>::RecombineAndSort(
// head pointers are updated to point to the vertex instances in the map and
// any 'duplicate' vertices are deleted.
// TODO Set?
- typedef boost::unordered_map<SVertex *, SVertex *, SVertexRecombinationUnordered, SVertexRecombinationUnordered> Map;
+ typedef boost::unordered_map<SVertex *, SVertex *,
+ SVertexRecombinationHasher,
+ SVertexRecombinationEqualityPred> Map;
Map map;
for (std::vector<SHyperedge*>::const_iterator p = buffer.begin();
p != buffer.end(); ++p) {