blob: f37cb7d9b8ba5e1a83ed7818afd98acace20d39c [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
19 if (value.indexOf(':') < 0) {
20 value += ' ';
21
22 // Iterate over all annotations and add the descriptions
23 // This is a classic hash-lookup-case, but we have
24 // to deal with lists ...
25 for (var i = 0; i < anno.length; i++) {
26 if (anno[i] &&
27 anno[i][1] == value) {
28 if (anno[i][2])
29 return anno[i][2];
30 else
31 return;
32 };
33 };
34
35 return;
36 }
37 else {
38 var text = '';
39 var v = value.split(":");
40 var l1 = v[0];
41 var l2 = v[1];
42
43 l1 += ':';
44
45 // Add key description
46 for (var i = 0; i < anno.length; i++) {
47 if (anno[i] &&
48 anno[i][1] == l1) {
49 if (anno[i][2])
50 text += anno[i][2];
51 else
52 text += anno[i][0];
53 break;
54 };
55 };
56
Akron369cbc42018-02-11 00:43:15 +010057 // Nothing found
Akronf2279c42017-12-21 13:48:46 +010058 if (text.length === 0)
59 return;
60
61 // Check next level
62 anno = this[foundryLayer + l1];
63
Akron369cbc42018-02-11 00:43:15 +010064 if (!anno)
65 return;
66
Akronf2279c42017-12-21 13:48:46 +010067 l2 += ' ';
68
69 // Add value description
70 for (var i = 0; i < anno.length; i++) {
71 if (anno[i] &&
72 anno[i][1] == l2) {
73 if (anno[i][2])
74 text += ': ' + anno[i][2];
75
76 return text;
77 };
78 };
79 };
80
81 return '';
82 };
83
84 return ah;
Akron80055992017-12-20 16:30:52 +010085});