Akron | c565b7c | 2021-08-18 18:54:16 +0200 | [diff] [blame] | 1 | window.KorAP = window.KorAP || {}; |
2 | |||||
Akron | f2279c4 | 2017-12-21 13:48:46 +0100 | [diff] [blame] | 3 | KorAP.annotationHelper = KorAP.annotationHelper || { '-' : [] }; |
4 | |||||
Akron | da5bd3a | 2020-10-16 17:37:49 +0200 | [diff] [blame] | 5 | "use strict"; |
6 | |||||
7 | define(["util"], function () { | ||||
Akron | f2279c4 | 2017-12-21 13:48:46 +0100 | [diff] [blame] | 8 | |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 9 | const ah = KorAP.annotationHelper; |
Akron | f2279c4 | 2017-12-21 13:48:46 +0100 | [diff] [blame] | 10 | |
Akron | da5bd3a | 2020-10-16 17:37:49 +0200 | [diff] [blame] | 11 | ah.getDesc = function (foundryLayer, value) { |
Akron | f2279c4 | 2017-12-21 13:48:46 +0100 | [diff] [blame] | 12 | |
13 | if (!foundryLayer) | ||||
14 | return; | ||||
15 | |||||
Akron | da5bd3a | 2020-10-16 17:37:49 +0200 | [diff] [blame] | 16 | let anno = this[foundryLayer]; |
Akron | f2279c4 | 2017-12-21 13:48:46 +0100 | [diff] [blame] | 17 | |
18 | if (!anno) | ||||
19 | return; | ||||
20 | |||||
Akron | 3b253d3 | 2018-07-15 10:16:06 +0200 | [diff] [blame] | 21 | if (!value.includes(':')) { |
Akron | f2279c4 | 2017-12-21 13:48:46 +0100 | [diff] [blame] | 22 | 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 | } | ||||
Akron | f2279c4 | 2017-12-21 13:48:46 +0100 | [diff] [blame] | 39 | |
Akron | da5bd3a | 2020-10-16 17:37:49 +0200 | [diff] [blame] | 40 | else { |
41 | const v = value.split(":"); | ||||
42 | let l1 = v[0] + ':'; | ||||
43 | let l2 = v[1] + ' '; | ||||
44 | let text = ''; | ||||
Akron | f2279c4 | 2017-12-21 13:48:46 +0100 | [diff] [blame] | 45 | |
46 | // Add key description | ||||
Akron | da5bd3a | 2020-10-16 17:37:49 +0200 | [diff] [blame] | 47 | for (let i = 0; i < anno.length; i++) { |
Akron | f2279c4 | 2017-12-21 13:48:46 +0100 | [diff] [blame] | 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 | |||||
Akron | 369cbc4 | 2018-02-11 00:43:15 +0100 | [diff] [blame] | 58 | // Nothing found |
Akron | f2279c4 | 2017-12-21 13:48:46 +0100 | [diff] [blame] | 59 | if (text.length === 0) |
60 | return; | ||||
61 | |||||
62 | // Check next level | ||||
63 | anno = this[foundryLayer + l1]; | ||||
64 | |||||
Akron | 369cbc4 | 2018-02-11 00:43:15 +0100 | [diff] [blame] | 65 | if (!anno) |
66 | return; | ||||
67 | |||||
Akron | f2279c4 | 2017-12-21 13:48:46 +0100 | [diff] [blame] | 68 | // Add value description |
Akron | da5bd3a | 2020-10-16 17:37:49 +0200 | [diff] [blame] | 69 | for (let i = 0; i < anno.length; i++) { |
Akron | f2279c4 | 2017-12-21 13:48:46 +0100 | [diff] [blame] | 70 | 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; | ||||
Akron | 8005599 | 2017-12-20 16:30:52 +0100 | [diff] [blame] | 84 | }); |