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

pruneGeneration.cpp « misc - github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 8207e287f65906ed2792d4c52f20ec3ba7f07898 (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
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <cassert>
#include <algorithm>
#include <functional>
#include "pruneGeneration.h"

using namespace std;

int main(int argc, char **argv)
{
  cerr << "Starting" << endl;
  int limit = atoi(argv[1]);

  vector<Rec> records;
  string prevInWord;
  string line;
  while (getline(cin, line)) {
    vector<string> toks;
    Tokenize(toks, line);
    assert(toks.size() == 4);

    if (prevInWord != toks[0]) {
      Output(limit, records);
      records.clear();
    }

    // add new record
    float prob = atof(toks[2].c_str());
    records.push_back(Rec(prob, line));

    prevInWord = toks[0];
  }

  // last
  Output(limit, records);
  records.clear();

  cerr << "Finished" << endl;
}

void Output(int limit, vector<Rec> &records)
{
  std::sort(records.rbegin(), records.rend());

  for (size_t i = 0; i < limit && i < records.size(); ++i) {
    const Rec &rec = records[i];
    cout << rec.line << endl;
  }
}