Welcome to mirror list, hosted at ThFree Co, Russian Federation.

checkplf.cpp « checkplf « contrib - github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: f8de29e8e7cdab7d20bdfaeaa734f6a3e025d99d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <iostream>

#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<double> 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;
}