summaryrefslogtreecommitdiff
path: root/decoder
diff options
context:
space:
mode:
authorChris Dyer <redpony@gmail.com>2014-04-25 23:45:32 -0400
committerChris Dyer <redpony@gmail.com>2014-04-25 23:45:32 -0400
commit1400adb9f5e8ebf8ea1658d658893f0731b6fc22 (patch)
treea6d9ff65a7cca2b4326640a2fc2929e3a3063e0a /decoder
parent94d515b00d66d9ea18758b951c1ce4789f3875b0 (diff)
check for non-rescorable hypergraphs
Diffstat (limited to 'decoder')
-rw-r--r--decoder/decoder.cc5
-rw-r--r--decoder/hg.cc7
-rw-r--r--decoder/hg.h4
3 files changed, 16 insertions, 0 deletions
diff --git a/decoder/decoder.cc b/decoder/decoder.cc
index 354ea2d9..41f36822 100644
--- a/decoder/decoder.cc
+++ b/decoder/decoder.cc
@@ -755,6 +755,11 @@ bool DecoderImpl::Decode(const string& input, DecoderObserver* o) {
if (!SILENT) cerr << " *** NODES NOT UNIQUELY IDENTIFIED ***\n";
}
+ if (!forest.ArePreGoalEdgesArity1()) {
+ cerr << "Pre-goal edges are not arity-1. The decoder requires this.\n";
+ abort();
+ }
+
const bool show_tree_structure=conf.count("show_tree_structure");
if (!SILENT) forest_stats(forest," Init. forest",show_tree_structure,oracle.show_derivation);
if (conf.count("show_expected_length")) {
diff --git a/decoder/hg.cc b/decoder/hg.cc
index e456fa7c..46543b01 100644
--- a/decoder/hg.cc
+++ b/decoder/hg.cc
@@ -28,6 +28,13 @@ bool Hypergraph::AreNodesUniquelyIdentified() const {
return true;
}
+bool Hypergraph::ArePreGoalEdgesArity1() const {
+ auto& n = nodes_.back();
+ for (auto eid : n.in_edges_)
+ if (edges_[eid].Arity() != 1) return false;
+ return true;
+}
+
Hypergraph::Edge const* Hypergraph::ViterbiSortInEdges() {
NodeProbs nv;
ComputeNodeViterbi(&nv);
diff --git a/decoder/hg.h b/decoder/hg.h
index 43fb275b..4ed27d87 100644
--- a/decoder/hg.h
+++ b/decoder/hg.h
@@ -268,6 +268,10 @@ public:
// if all node states are unique, return true
bool AreNodesUniquelyIdentified() const;
+ // the feature function interface assumes that pre-goal edges are
+ // arity 1 (this simplifies the "final transition" feature computation)
+ bool ArePreGoalEdgesArity1() const;
+
// reserves space in the nodes vector to prevent memory locations
// from changing
void ReserveNodes(size_t n, size_t e = 0) {