diff --git a/moses-cmd/src/Makefile.am b/moses-cmd/src/Makefile.am index 27f70b5b0..350b4fafd 100644 --- a/moses-cmd/src/Makefile.am +++ b/moses-cmd/src/Makefile.am @@ -1,7 +1,10 @@ -bin_PROGRAMS = moses lmbrgrid +bin_PROGRAMS = moses lmbrgrid checkplf AM_CPPFLAGS = -W -Wall -ffor-scope -D_FILE_OFFSET_BITS=64 -D_LARGE_FILES -DUSE_HYPO_POOL -I$(top_srcdir)/moses/src $(BOOST_CPPFLAGS) +checkplf_SOURCES = checkplf.cpp +checkplf_LDADD = $(top_builddir)/moses/src/libmoses.la + moses_SOURCES = Main.cpp mbr.cpp IOWrapper.cpp TranslationAnalysis.cpp LatticeMBR.cpp ThreadPool.cpp moses_LDADD = $(top_builddir)/moses/src/libmoses.la $(BOOST_LDFLAGS) $(BOOST_THREAD_LIB) -L$(top_srcdir)/OnDiskPt/src -lOnDiskPt diff --git a/moses-cmd/src/checkplf.cpp b/moses-cmd/src/checkplf.cpp new file mode 100644 index 000000000..703e34a21 --- /dev/null +++ b/moses-cmd/src/checkplf.cpp @@ -0,0 +1,61 @@ +#include + +#include "PCNTools.h" + +using namespace std; + +int main() { + cerr << "Reading PLF from STDIN...\n"; + string line; + int lc = 0; + double num_paths = 0; + double num_nodes = 0; + double num_edges = 0; + while(cin) { + getline(cin,line); + if (line.empty()) continue; + ++lc; + PCN::CN plf = PCN::parsePCN(line); + vector alphas(plf.size() + 1, 0.0); + num_nodes += plf.size(); + alphas[0] = 1.0; + for (unsigned node = 0; node < plf.size(); ++node) { + const PCN::CNCol& edges = plf[node]; + const double alpha = alphas[node]; + if (alpha < 1.0) { + cerr << "Line " << lc << ": unreachable node at column position " << (node+1) << endl; + return 1; + } + num_edges += edges.size(); + for (unsigned j = 0; j < edges.size(); ++j) { + const PCN::CNAlt& edge = edges[j]; + size_t head = edge.second + node; + const string& label = edge.first.first; + if (head <= node) { + cerr << "Line " << lc << ": cycle detected at column position " << (node+1) << ", edge label = '" << label << "'" << endl; + return 1; + } + if (head >= alphas.size()) { + cerr << "Line " << lc << ": edge goes beyond goal node at column position " << (node+1) << ", edge label = '" << label << "'" << endl; + cerr << " Goal node expected at position " << alphas.size() << ", but edge references a node at position " << head << endl; + return 1; + } + alphas[head] += alpha; + } + } + if (alphas.back() < 1.0) { + cerr << "Line " << lc << ": there appears to be no path to the goal" << endl; + return 1; + } + num_paths += alphas.back(); + } + cerr << "PLF format appears to be correct.\nSTATISTICS:\n"; + cerr << " Number of lattices: " << lc << endl; + cerr << " Total number of nodes: " << num_nodes << endl; + cerr << " Total number of edges: " << num_edges << endl; + cerr << " Average density: " << (num_edges / num_nodes) << " edges/node\n"; + cerr << " Total number of paths: " << num_paths << endl; + cerr << " Average number of paths: " << (num_paths / lc) << endl; + return 0; +} +