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

Rule.cpp « extract-ghkm « phrase-extract - github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: da6b2ff232a4470b0c5989af4d64130d746aca3d (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
#include "Rule.h"

#include "Node.h"
#include "Subgraph.h"

namespace Moses
{
namespace GHKM
{

int Rule::Scope(const std::vector<Symbol> &symbols)
{
  int scope = 0;
  bool predIsNonTerm = false;
  if (symbols[0].GetType() == NonTerminal) {
    ++scope;
    predIsNonTerm = true;
  }
  for (std::size_t i = 1; i < symbols.size(); ++i) {
    bool isNonTerm = symbols[i].GetType() == NonTerminal;
    if (isNonTerm && predIsNonTerm) {
      ++scope;
    }
    predIsNonTerm = isNonTerm;
  }
  if (predIsNonTerm) {
    ++scope;
  }
  return scope;
}

bool Rule::PartitionOrderComp(const Node *a, const Node *b)
{
  const Span &aSpan = a->GetSpan();
  const Span &bSpan = b->GetSpan();
  assert(!aSpan.empty() && !bSpan.empty());
  return *(aSpan.begin()) < *(bSpan.begin());
}

}  // namespace GHKM
}  // namespace Moses