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

PhraseLengthFeature.cpp « src « moses - github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ece3b09237e22dbb83a09a07b44e4e937a7d2590 (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
#include <sstream>
#include "PhraseLengthFeature.h"
#include "Hypothesis.h"
#include "ScoreComponentCollection.h"

namespace Moses {

using namespace std;

void PhraseLengthFeature::Evaluate(const TargetPhrase& targetPhrase,
                                   ScoreComponentCollection* accumulator) const
{
  // get length of source and target phrase
  size_t sourceLength = targetPhrase.GetSourcePhrase().GetSize();
  size_t targetLength = targetPhrase.GetSize();

  // create feature names
  stringstream nameSource;
  nameSource << "s" << sourceLength;

  stringstream nameTarget;
  nameTarget << "t" << targetLength;

  stringstream nameBoth;
  nameBoth << sourceLength << "," << targetLength;

  // increase feature counts
  accumulator->PlusEquals(this,nameSource.str(),1);
  accumulator->PlusEquals(this,nameTarget.str(),1);
  accumulator->PlusEquals(this,nameBoth.str(),1);

  //cerr << nameSource.str() << " " << nameTarget.str() << " " << nameBoth.str() << endl;
}

}