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: b4eb206cea785911d6557227c6abcca7eca210d9 (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
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 ) {
	if (current_depth < depth) {
		current_depth = depth;
	}
	else { return; }
	
	var id = 0;
	for(var 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 ) {
	if (current_depth < depth) {
		current_depth = depth;
	}
	else { return; }
	var id = 0;
	for(var 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 ) {
	lowlightAllNodes( sentence );
	highlightSingleNode( sentence, id, 'yellow' );
	for(var i=0; i<nodeChildren[sentence][id].size(); i++) {
		var childId = nodeChildren[sentence][id][i];
		highlightSingleNode( sentence, childId, '#ffffa0');
		for(var j=0; j<nodeChildren[sentence][childId].size(); j++) {
			highlightSingleNode( sentence, nodeChildren[sentence][childId][j], '#ffffe0');
		}
	}
}

function highlightSingleNode( sentence, id, color ) {
	for(var i=nodeIn[sentence][id].start;i<=nodeIn[sentence][id].end;i++) {
		for(var 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(var i=nodeOut[sentence][id].start;i<=nodeOut[sentence][id].end;i++) {
		for(var 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 ) {
	for(var i=0;i<span_count_in[sentence];i++) {
		for(var j=0;j<=max_depth[sentence];j++) {
			var item = "in-" + sentence + "-" + i + "-" + j;
			if ($(item) != null) {
				$(item).setStyle({ backgroundColor: 'white', borderColor: 'black' });			
			}
		}
	}	
	for(var i=0;i<span_count_out[sentence];i++) {
		for(var j=0;j<=max_depth[sentence];j++) {
			var item = "out-" + sentence + "-" + i + "-" + j;
			if ($(item) != null) {
				$(item).setStyle({ backgroundColor: 'white', borderColor: 'black' });			
			}
		}
	}	
}