blob: ce6ef434968cd3cc8c52841ec5eca1c24c7100fd [file] [log] [blame]
Akronf2279c42017-12-21 13:48:46 +01001KorAP.annotationHelper = KorAP.annotationHelper || { '-' : [] };
2
Akronda5bd3a2020-10-16 17:37:49 +02003"use strict";
4
5define(["util"], function () {
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
Akronda5bd3a2020-10-16 17:37:49 +02009 ah.getDesc = function (foundryLayer, value) {
Akronf2279c42017-12-21 13:48:46 +010010
11 if (!foundryLayer)
12 return;
13
Akronda5bd3a2020-10-16 17:37:49 +020014 let anno = this[foundryLayer];
Akronf2279c42017-12-21 13:48:46 +010015
16 if (!anno)
17 return;
18
Akron3b253d32018-07-15 10:16:06 +020019 if (!value.includes(':')) {
Akronf2279c42017-12-21 13:48:46 +010020 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 }
Akronf2279c42017-12-21 13:48:46 +010037
Akronda5bd3a2020-10-16 17:37:49 +020038 else {
39 const v = value.split(":");
40 let l1 = v[0] + ':';
41 let l2 = v[1] + ' ';
42 let text = '';
Akronf2279c42017-12-21 13:48:46 +010043
44 // Add key description
Akronda5bd3a2020-10-16 17:37:49 +020045 for (let i = 0; i < anno.length; i++) {
Akronf2279c42017-12-21 13:48:46 +010046 if (anno[i] &&
47 anno[i][1] == l1) {
48 if (anno[i][2])
49 text += anno[i][2];
50 else
51 text += anno[i][0];
52 break;
53 };
54 };
55
Akron369cbc42018-02-11 00:43:15 +010056 // Nothing found
Akronf2279c42017-12-21 13:48:46 +010057 if (text.length === 0)
58 return;
59
60 // Check next level
61 anno = this[foundryLayer + l1];
62
Akron369cbc42018-02-11 00:43:15 +010063 if (!anno)
64 return;
65
Akronf2279c42017-12-21 13:48:46 +010066 // Add value description
Akronda5bd3a2020-10-16 17:37:49 +020067 for (let i = 0; i < anno.length; i++) {
Akronf2279c42017-12-21 13:48:46 +010068 if (anno[i] &&
69 anno[i][1] == l2) {
70 if (anno[i][2])
71 text += ': ' + anno[i][2];
72
73 return text;
74 };
75 };
76 };
77
78 return '';
79 };
80
81 return ah;
Akron80055992017-12-20 16:30:52 +010082});