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

CountNonTerms.cpp « FF « moses - github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: f49aecfc82d93083862ef549b71f64cd1e25e4e1 (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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include "CountNonTerms.h"
#include "moses/Util.h"
#include "moses/TargetPhrase.h"
#include "moses/StaticData.h"

using namespace std;

namespace Moses
{
CountNonTerms::CountNonTerms(const std::string &line)
  :StatelessFeatureFunction(line,true)
  ,m_all(true)
  ,m_sourceSyntax(false)
  ,m_targetSyntax(false)
{
  ReadParameters();
}

void CountNonTerms::EvaluateInIsolation(const Phrase &sourcePhrase
                                        , const TargetPhrase &targetPhrase
                                        , ScoreComponentCollection &scoreBreakdown
                                        , ScoreComponentCollection &estimatedScores) const
{
  const StaticData &staticData = StaticData::Instance();

  vector<float> scores(m_numScoreComponents, 0);
  size_t indScore = 0;

  if (m_all) {
    for (size_t i = 0; i < targetPhrase.GetSize(); ++i) {
      const Word &word = targetPhrase.GetWord(i);
      if (word.IsNonTerminal()) {
        ++scores[indScore];
      }
    }
    ++indScore;
  }

  if (m_targetSyntax) {
    for (size_t i = 0; i < targetPhrase.GetSize(); ++i) {
      const Word &word = targetPhrase.GetWord(i);
      if (word.IsNonTerminal() && word != staticData.GetOutputDefaultNonTerminal()) {
        ++scores[indScore];
      }
    }
    ++indScore;
  }

  if (m_sourceSyntax) {
    for (size_t i = 0; i < sourcePhrase.GetSize(); ++i) {
      const Word &word = sourcePhrase.GetWord(i);
      if (word.IsNonTerminal() && word != staticData.GetInputDefaultNonTerminal()) {
        ++scores[indScore];
      }
    }
    ++indScore;
  }

  scoreBreakdown.PlusEquals(this, scores);
}

void CountNonTerms::SetParameter(const std::string& key, const std::string& value)
{
  if (key == "all") {
    m_all = Scan<bool>(value);
  } else if (key == "source-syntax") {
    m_sourceSyntax = Scan<bool>(value);
  } else if (key == "target-syntax") {
    m_targetSyntax = Scan<bool>(value);
  } else {
    StatelessFeatureFunction::SetParameter(key, value);
  }
}


}