From 23b16f6589da76f6313c315b5895becb77685c00 Mon Sep 17 00:00:00 2001 From: graehl Date: Tue, 6 Jul 2010 22:06:22 +0000 Subject: Boolean semiring git-svn-id: https://ws10smt.googlecode.com/svn/trunk@166 ec762483-ff6d-05da-a07a-a48fb63a330f --- decoder/inside_outside.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'decoder') diff --git a/decoder/inside_outside.h b/decoder/inside_outside.h index 3c7518f2..9f7ce526 100644 --- a/decoder/inside_outside.h +++ b/decoder/inside_outside.h @@ -5,6 +5,23 @@ #include #include "hg.h" +// semiring for Inside/Outside +struct Boolean { + bool x; + Boolean() : x() { } + Boolean(bool i) : x(i) { } + operator bool() const { return x; } + // normally you'd use the logical (short circuit) || && operators, but bool really is guaranteed to be 0 or 1 numerically. + void operator+=(Boolean o) { x|=o.x; } + friend inline Boolean operator +(Boolean a,Boolean b) { + return Boolean(a.x|b.x); + } + void operator*=(Boolean o) { x&=o.x; } + friend inline Boolean operator *(Boolean a,Boolean b) { + return Boolean(a.x&b.x); + } +}; + // run the inside algorithm and return the inside score // if result is non-NULL, result will contain the inside // score for each node -- cgit v1.2.3