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