summaryrefslogtreecommitdiff
path: root/decoder
diff options
context:
space:
mode:
Diffstat (limited to 'decoder')
-rw-r--r--decoder/Makefile.am1
-rw-r--r--decoder/exp_semiring.h71
-rw-r--r--decoder/hg.h17
3 files changed, 16 insertions, 73 deletions
diff --git a/decoder/Makefile.am b/decoder/Makefile.am
index c41cd7f9..7481192b 100644
--- a/decoder/Makefile.am
+++ b/decoder/Makefile.am
@@ -37,7 +37,6 @@ libcdec_a_SOURCES = \
csplit.h \
decoder.h \
earley_composer.h \
- exp_semiring.h \
factored_lexicon_helper.h \
ff.h \
ff_basic.h \
diff --git a/decoder/exp_semiring.h b/decoder/exp_semiring.h
deleted file mode 100644
index 2a9034bb..00000000
--- a/decoder/exp_semiring.h
+++ /dev/null
@@ -1,71 +0,0 @@
-#ifndef _EXP_SEMIRING_H_
-#define _EXP_SEMIRING_H_
-
-#include <iostream>
-
-// this file implements the first-order expectation semiring described
-// in Li & Eisner (EMNLP 2009)
-
-// requirements:
-// RType * RType ==> RType
-// PType * PType ==> PType
-// RType * PType ==> RType
-// good examples:
-// PType scalar, RType vector
-// BAD examples:
-// PType vector, RType scalar
-template <class PType, class RType>
-struct PRPair {
- PRPair() : p(), r() {}
- // Inside algorithm requires that T(0) and T(1)
- // return the 0 and 1 values of the semiring
- explicit PRPair(double x) : p(x), r() {}
- PRPair(const PType& p, const RType& r) : p(p), r(r) {}
- PRPair& operator+=(const PRPair& o) {
- p += o.p;
- r += o.r;
- return *this;
- }
- PRPair& operator*=(const PRPair& o) {
- r = (o.r * p) + (o.p * r);
- p *= o.p;
- return *this;
- }
- PType p;
- RType r;
-};
-
-template <class P, class R>
-std::ostream& operator<<(std::ostream& o, const PRPair<P,R>& x) {
- return o << '<' << x.p << ", " << x.r << '>';
-}
-
-template <class P, class R>
-const PRPair<P,R> operator+(const PRPair<P,R>& a, const PRPair<P,R>& b) {
- PRPair<P,R> result = a;
- result += b;
- return result;
-}
-
-template <class P, class R>
-const PRPair<P,R> operator*(const PRPair<P,R>& a, const PRPair<P,R>& b) {
- PRPair<P,R> result = a;
- result *= b;
- return result;
-}
-
-template <class P, class PWeightFunction, class R, class RWeightFunction>
-struct PRWeightFunction {
- explicit PRWeightFunction(const PWeightFunction& pwf = PWeightFunction(),
- const RWeightFunction& rwf = RWeightFunction()) :
- pweight(pwf), rweight(rwf) {}
- PRPair<P,R> operator()(const HG::Edge& e) const {
- const P p = pweight(e);
- const R r = rweight(e);
- return PRPair<P,R>(p, r * p);
- }
- const PWeightFunction pweight;
- const RWeightFunction rweight;
-};
-
-#endif
diff --git a/decoder/hg.h b/decoder/hg.h
index 3d8cd9bc..343b99cf 100644
--- a/decoder/hg.h
+++ b/decoder/hg.h
@@ -25,6 +25,7 @@
#include "tdict.h"
#include "trule.h"
#include "prob.h"
+#include "exp_semiring.h"
#include "indices_after.h"
#include "nt_span.h"
@@ -527,7 +528,21 @@ struct EdgeFeaturesAndProbWeightFunction {
struct TransitionCountWeightFunction {
typedef double Weight;
- inline double operator()(const HG::Edge& e) const { (void)e; return 1.0; }
+ inline double operator()(const HG::Edge&) const { return 1.0; }
+};
+
+template <class P, class PWeightFunction, class R, class RWeightFunction>
+struct PRWeightFunction {
+ explicit PRWeightFunction(const PWeightFunction& pwf = PWeightFunction(),
+ const RWeightFunction& rwf = RWeightFunction()) :
+ pweight(pwf), rweight(rwf) {}
+ PRPair<P,R> operator()(const HG::Edge& e) const {
+ const P p = pweight(e);
+ const R r = rweight(e);
+ return PRPair<P,R>(p, r * p);
+ }
+ const PWeightFunction pweight;
+ const RWeightFunction rweight;
};
#endif