File size: 1,862 Bytes
158b61b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include "RuleTableWriter.h"

#include <cassert>
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <iterator>
#include <string>
#include <sstream>
#include <vector>

#include "util/string_piece.hh"
#include "util/tokenize_piece.hh"

#include "InputFileStream.h"
#include "LexicalTable.h"
#include "OutputFileStream.h"
#include "Options.h"
#include "RuleGroup.h"

namespace MosesTraining
{
namespace Syntax
{
namespace ScoreStsg
{

void RuleTableWriter::WriteLine(const TokenizedRuleHalf &source,
                                const TokenizedRuleHalf &target,
                                const std::string &bestAlignment,
                                double lexScore, double treeScore, int count,
                                int totalCount, int distinctCount)
{
  if (m_options.inverse) {
    WriteRuleHalf(target);
    m_out << " ||| ";
    WriteRuleHalf(source);
  } else {
    WriteRuleHalf(source);
    m_out << " ||| ";
    WriteRuleHalf(target);
  }

  m_out << " |||" << bestAlignment << "||| ";

  if (!m_options.noLex) {
    m_out << MaybeLog(lexScore);
  }

  if (m_options.treeScore && !m_options.inverse) {
    m_out << " " << MaybeLog(treeScore);
  }

  m_out << " ||| " << totalCount << " " << count;
  if (m_options.kneserNey) {
    m_out << " " << distinctCount;
  }
  m_out << " |||";
  m_out << std::endl;
}

void RuleTableWriter::WriteRuleHalf(const TokenizedRuleHalf &half)
{
  if (half.IsTree()) {
    m_out << half.string;
    return;
  }

  for (std::vector<RuleSymbol>::const_iterator p = half.frontierSymbols.begin();
       p != half.frontierSymbols.end(); ++p) {
    if (p->isNonTerminal) {
      m_out << "[" << p->value << "][" << p->value << "] ";
    } else {
      m_out << p->value << " ";
    }
  }
  m_out << "[X]";
}

}  // namespace ScoreStsg
}  // namespace Syntax
}  // namespace MosesTraining