summaryrefslogtreecommitdiff
path: root/decoder/viterbi.cc
diff options
context:
space:
mode:
authorChris Dyer <cdyer@cab.ark.cs.cmu.edu>2012-06-19 00:05:18 -0400
committerChris Dyer <cdyer@cab.ark.cs.cmu.edu>2012-06-19 00:05:18 -0400
commit5975dcaa50adb5ce7a05b83583b8f9ddc45f3f0a (patch)
tree2bc2eb4e17576e0726d7a2fa7f20eac9061c311d /decoder/viterbi.cc
parent78cc819168b2a550e52e9cac06dbbed41a3b04b2 (diff)
parentee1520c5095ea8648617a3658b20eedfd4dd2007 (diff)
Merge branch 'master' of https://github.com/pks/cdec-dtrain
Diffstat (limited to 'decoder/viterbi.cc')
-rw-r--r--decoder/viterbi.cc12
1 files changed, 11 insertions, 1 deletions
diff --git a/decoder/viterbi.cc b/decoder/viterbi.cc
index 9d19914b..1b9c6665 100644
--- a/decoder/viterbi.cc
+++ b/decoder/viterbi.cc
@@ -5,11 +5,12 @@
#include <vector>
#include "hg.h"
+
//#define DEBUG_VITERBI_SORT
using namespace std;
-std::string viterbi_stats(Hypergraph const& hg, std::string const& name, bool estring, bool etree,bool show_derivation)
+std::string viterbi_stats(Hypergraph const& hg, std::string const& name, bool estring, bool etree,bool show_derivation, bool extract_rules, boost::shared_ptr<WriteFile> extract_file)
{
ostringstream o;
o << hg.stats(name);
@@ -22,6 +23,9 @@ std::string viterbi_stats(Hypergraph const& hg, std::string const& name, bool es
if (etree) {
o<<name<<" tree: "<<ViterbiETree(hg)<<endl;
}
+ if (extract_rules) {
+ ViterbiRules(hg, extract_file->stream());
+ }
if (show_derivation) {
o<<name<<" derivation: ";
o << hg.show_viterbi_tree(false); // last item should be goal (or at least depend on prev items). TODO: this doesn't actually reorder the nodes in hg.
@@ -36,6 +40,12 @@ std::string viterbi_stats(Hypergraph const& hg, std::string const& name, bool es
return o.str();
}
+void ViterbiRules(const Hypergraph& hg, ostream* o) {
+ vector<Hypergraph::Edge const*> edges;
+ Viterbi<ViterbiPathTraversal>(hg, &edges);
+ for (unsigned i = 0; i < edges.size(); i++)
+ (*o) << edges[i]->rule_->AsString(true) << endl;
+}
string ViterbiETree(const Hypergraph& hg) {
vector<WordID> tmp;