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

hierarchical-segmentation.js « web « ems « scripts - github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: fad5a16d45112259746513d8f9b9fe2d09cbfa99 (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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
var nodeIn = [];
var nodeOut = [];
var nodeChildren = [];
var max_depth = [];
var span_count_in = [];
var span_count_out = [];
var current_depth = -1;

function alignIn( sentence, word, depth ) {
  var id, i;
  if (current_depth < depth) {
    current_depth = depth;
  }
  else { return; }

  id = 0;
  for(i=1;i<nodeIn[sentence].size();i++ ) {
    if (nodeIn[sentence][i].start <= word && word <= nodeIn[sentence][i].end && nodeIn[sentence][i].depth <= depth) {
      id = i;
    }
  }

  highlightNode( sentence, id );
}

function alignOut( sentence, word, depth ) {
  var id, i;
  if (current_depth < depth) {
    current_depth = depth;
  }
  else { return; }
  id = 0;
  for(i=1;i<nodeOut[sentence].size();i++ ) {
    if (nodeOut[sentence][i].start <= word && word <= nodeOut[sentence][i].end && nodeOut[sentence][i].depth <= depth) {
      id = i;
    }
  }

  highlightNode( sentence, id );
}

function unAlign( sentence ) {
  if (current_depth == -1) { return; }
  current_depth = -1;
  lowlightAllNodes( sentence );
}

function highlightNode( sentence, id ) {
  var i;
  lowlightAllNodes( sentence );
  highlightSingleNode( sentence, id, 'yellow' );
  for(i=0; i<nodeChildren[sentence][id].size(); i++) {
    var childId = nodeChildren[sentence][id][i];
    var j;
    highlightSingleNode( sentence, childId, '#ffffa0');
    for(j=0; j<nodeChildren[sentence][childId].size(); j++) {
      highlightSingleNode( sentence, nodeChildren[sentence][childId][j], '#ffffe0');
    }
  }
}

function highlightSingleNode( sentence, id, color ) {
  var i, j;
  for(i=nodeIn[sentence][id].start;i<=nodeIn[sentence][id].end;i++) {
    for(j=nodeIn[sentence][id].depth;j<=max_depth[sentence];j++) {
      var item = "in-" + sentence + "-" + i + "-" + j;
      if ($(item) != null) {
        $(item).setStyle({ backgroundColor: color, borderColor: 'red' });
      }
    }
  }
  //$("debug").innerHTML = "highlight: "+id+", of "+nodeOut[sentence].size()+"<br>";
  for(i=nodeOut[sentence][id].start;i<=nodeOut[sentence][id].end;i++) {
    for(j=nodeOut[sentence][id].depth;j<=max_depth[sentence];j++) {
      var item = "out-" + sentence + "-" + i + "-" + j;
      //$("debug").innerHTML += item;
      if ($(item) != null) {
        $(item).setStyle({ backgroundColor: color, borderColor: 'red' });
      }
    }
  }
}

function lowlightAllNodes( sentence ) {
  var i, j;
  for(i=0;i<span_count_in[sentence];i++) {
    for(j=0;j<=max_depth[sentence];j++) {
      var item = "in-" + sentence + "-" + i + "-" + j;
      if ($(item) != null) {
        $(item).setStyle({ backgroundColor: 'white', borderColor: 'black' });
      }
    }
  }
  for(i=0;i<span_count_out[sentence];i++) {
    for(j=0;j<=max_depth[sentence];j++) {
      var item = "out-" + sentence + "-" + i + "-" + j;
      if ($(item) != null) {
        $(item).setStyle({ backgroundColor: 'white', borderColor: 'black' });
      }
    }
  }
}