blob: 256ee766534c9850db810e96b2cc7a34c6b9a87e [file] [log] [blame]
Akronf2279c42017-12-21 13:48:46 +01001window.KorAP = window.KorAP || {};
2KorAP.annotationHelper = KorAP.annotationHelper || { '-' : [] };
3
Akron369cbc42018-02-11 00:43:15 +01004define([], function () {
5 "use strict";
Akronf2279c42017-12-21 13:48:46 +01006
Akron0b489ad2018-02-02 16:49:32 +01007 const ah = KorAP.annotationHelper;
Akronf2279c42017-12-21 13:48:46 +01008
9 ah["getDesc"] = function (foundryLayer, value) {
10
11 if (!foundryLayer)
12 return;
13
14 var anno = this[foundryLayer];
15
16 if (!anno)
17 return;
18
Akron3b253d32018-07-15 10:16:06 +020019 // if (value.indexOf(':') < 0) {
20 if (!value.includes(':')) {
Akronf2279c42017-12-21 13:48:46 +010021 value += ' ';
22
23 // Iterate over all annotations and add the descriptions
24 // This is a classic hash-lookup-case, but we have
25 // to deal with lists ...
26 for (var i = 0; i < anno.length; i++) {
27 if (anno[i] &&
28 anno[i][1] == value) {
29 if (anno[i][2])
30 return anno[i][2];
31 else
32 return;
33 };
34 };
35
36 return;
37 }
38 else {
39 var text = '';
40 var v = value.split(":");
41 var l1 = v[0];
42 var l2 = v[1];
43
44 l1 += ':';
45
46 // Add key description
47 for (var i = 0; i < anno.length; i++) {
48 if (anno[i] &&
49 anno[i][1] == l1) {
50 if (anno[i][2])
51 text += anno[i][2];
52 else
53 text += anno[i][0];
54 break;
55 };
56 };
57
Akron369cbc42018-02-11 00:43:15 +010058 // Nothing found
Akronf2279c42017-12-21 13:48:46 +010059 if (text.length === 0)
60 return;
61
62 // Check next level
63 anno = this[foundryLayer + l1];
64
Akron369cbc42018-02-11 00:43:15 +010065 if (!anno)
66 return;
67
Akronf2279c42017-12-21 13:48:46 +010068 l2 += ' ';
69
70 // Add value description
71 for (var i = 0; i < anno.length; i++) {
72 if (anno[i] &&
73 anno[i][1] == l2) {
74 if (anno[i][2])
75 text += ': ' + anno[i][2];
76
77 return text;
78 };
79 };
80 };
81
82 return '';
83 };
84
85 return ah;
Akron80055992017-12-20 16:30:52 +010086});