blob: b4b59f8e32f3d467c1f8b7a71eede85fcf75bd7e (
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
|
#include "Rule.h"
#include "Node.h"
#include "Subgraph.h"
namespace MosesTraining
{
namespace Syntax
{
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 Syntax
} // namespace MosesTraining
|