From 279bc261148978c4ac3e5e4e8e9ef689ca0c25ca Mon Sep 17 00:00:00 2001 From: graehl Date: Sun, 25 Jul 2010 02:52:58 +0000 Subject: cleaned up kbest, new USE_INFO_EDGE 1 logs per edge, --show_derivation (needs work; handle kbest deriv, viterbi deriv, sort hg exposing viterbi?) git-svn-id: https://ws10smt.googlecode.com/svn/trunk@405 ec762483-ff6d-05da-a07a-a48fb63a330f --- decoder/hg.h | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) (limited to 'decoder/hg.h') diff --git a/decoder/hg.h b/decoder/hg.h index b3bfd19c..34638e04 100644 --- a/decoder/hg.h +++ b/decoder/hg.h @@ -1,12 +1,24 @@ #ifndef _HG_H_ #define _HG_H_ +#define USE_INFO_EDGE 1 +#if USE_INFO_EDGE +# include +# define INFO_EDGE(e,msg) do { std::ostringstream &o=e.info_;o< #include #include "feature_vector.h" #include "small_vector.h" #include "wordid.h" +#include "tdict.h" #include "trule.h" #include "prob.h" @@ -23,6 +35,7 @@ class Hypergraph { // SmallVector is a fast, small vector implementation for sizes <= 2 typedef SmallVectorInt TailNodeVector; + typedef std::vector EdgesVector; // TODO get rid of cat_? // TODO keep cat_ and add span and/or state? :) @@ -59,8 +72,76 @@ class Hypergraph { short int j_; short int prev_i_; short int prev_j_; +#if USE_INFO_EDGE + private: + std::ostringstream info_; + public: + Edge(Edge const& o) : head_node_(o.head_node_),tail_nodes_(o.tail_nodes_),rule_(o.rule_),feature_values_(o.feature_values_),edge_prob_(o.edge_prob_),id_(o.id_),i_(o.i_),j_(o.j_),prev_i_(o.prev_i_),prev_j_(o.prev_j_), info_(o.info_.str()) { } + void operator=(Edge const& o) { + head_node_ = o.head_node_; tail_nodes_ = o.tail_nodes_; rule_ = o.rule_; feature_values_ = o.feature_values_; edge_prob_ = o.edge_prob_; id_ = o.id_; i_ = o.i_; j_ = o.j_; prev_i_ = o.prev_i_; prev_j_ = o.prev_j_; info_.str(o.info_.str()); + } + std::string info() const { return info_.str(); } +#else + std::string info() const { return std::string(); } +#endif + void show(std::ostream &o,unsigned mask=SPAN|RULE) const { + o<<'{'; + if (mask&CATEGORY) + o<GetLHS()); + if (mask&PREV_SPAN) + o<<'<'<'; + if (mask&SPAN) + o<<'<'<'; + if (mask&PROB) + o<<" p="<AsString(mask&RULE_LHS); + if (USE_INFO_EDGE) { + if (mask) o << ' '; + o<maxdepth) return; + if (indent) for(int i=0;i