blob: 80d73328259f8a75c577e6d24c0935597e228c48 [file] [log] [blame]
Akronc565b7c2021-08-18 18:54:16 +02001window.KorAP = window.KorAP || {};
2
Akronf2279c42017-12-21 13:48:46 +01003KorAP.annotationHelper = KorAP.annotationHelper || { '-' : [] };
4
Akronda5bd3a2020-10-16 17:37:49 +02005"use strict";
6
7define(["util"], function () {
Akronf2279c42017-12-21 13:48:46 +01008
Akron0b489ad2018-02-02 16:49:32 +01009 const ah = KorAP.annotationHelper;
Akronf2279c42017-12-21 13:48:46 +010010
Akronda5bd3a2020-10-16 17:37:49 +020011 ah.getDesc = function (foundryLayer, value) {
Akronf2279c42017-12-21 13:48:46 +010012
13 if (!foundryLayer)
14 return;
15
Akronda5bd3a2020-10-16 17:37:49 +020016 let anno = this[foundryLayer];
Akronf2279c42017-12-21 13:48:46 +010017
18 if (!anno)
19 return;
20
Akron3b253d32018-07-15 10:16:06 +020021 if (!value.includes(':')) {
Akronf2279c42017-12-21 13:48:46 +010022 value += ' ';
23
24 // Iterate over all annotations and add the descriptions
25 // This is a classic hash-lookup-case, but we have
26 // to deal with lists ...
27 for (var i = 0; i < anno.length; i++) {
28 if (anno[i] &&
29 anno[i][1] == value) {
30 if (anno[i][2])
31 return anno[i][2];
32 else
33 return;
34 };
35 };
36
37 return;
38 }
Akronf2279c42017-12-21 13:48:46 +010039
Akronda5bd3a2020-10-16 17:37:49 +020040 else {
41 const v = value.split(":");
42 let l1 = v[0] + ':';
43 let l2 = v[1] + ' ';
44 let text = '';
Akronf2279c42017-12-21 13:48:46 +010045
46 // Add key description
Akronda5bd3a2020-10-16 17:37:49 +020047 for (let i = 0; i < anno.length; i++) {
Akronf2279c42017-12-21 13:48:46 +010048 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 // Add value description
Akronda5bd3a2020-10-16 17:37:49 +020069 for (let i = 0; i < anno.length; i++) {
Akronf2279c42017-12-21 13:48:46 +010070 if (anno[i] &&
71 anno[i][1] == l2) {
72 if (anno[i][2])
73 text += ': ' + anno[i][2];
74
75 return text;
76 };
77 };
78 };
79
80 return '';
81 };
82
83 return ah;
Akron80055992017-12-20 16:30:52 +010084});