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

RuleScope.cpp « FF « moses - github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 5f38a59aef13ee9f74b9805881651bc750a9e817 (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
#include "RuleScope.h"
#include "moses/StaticData.h"
#include "moses/Word.h"

namespace Moses
{
RuleScope::RuleScope(const std::string &line)
  :StatelessFeatureFunction(1, line)
  ,m_sourceSyntax(true)
{
}

bool IsAmbiguous(const Word &word, bool sourceSyntax)
{
  const Word &inputDefaultNonTerminal = StaticData::Instance().GetInputDefaultNonTerminal();
  return word.IsNonTerminal() && (!sourceSyntax || word == inputDefaultNonTerminal);
}

void RuleScope::EvaluateInIsolation(const Phrase &source
                                    , const TargetPhrase &targetPhrase
                                    , ScoreComponentCollection &scoreBreakdown
                                    , ScoreComponentCollection &estimatedFutureScore) const
{
  // adjacent non-term count as 1 ammbiguity, rather than 2 as in rule scope
  // source can't be empty, right?
  float score = 0;

  int count = 0;
  for (size_t i = 0; i < source.GetSize() - 0; ++i) {
    const Word &word = source.GetWord(i);
    bool ambiguous = IsAmbiguous(word, m_sourceSyntax);
    if (ambiguous) {
      ++count;
    } else {
      if (count > 0) {
        score += count;
      }
      count = -1;
    }
  }

  // 1st & last always adjacent to ambiguity
  ++count;
  if (count > 0) {
    score += count;
  }

  scoreBreakdown.PlusEquals(this, score);
}

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

}