Akron | f2279c4 | 2017-12-21 13:48:46 +0100 | [diff] [blame] | 1 | window.KorAP = window.KorAP || {}; |
| 2 | KorAP.annotationHelper = KorAP.annotationHelper || { '-' : [] }; |
| 3 | |
Akron | 369cbc4 | 2018-02-11 00:43:15 +0100 | [diff] [blame] | 4 | define([], function () { |
| 5 | "use strict"; |
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 | |
| 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 | |
Akron | 3b253d3 | 2018-07-15 10:16:06 +0200 | [diff] [blame] | 19 | // if (value.indexOf(':') < 0) { |
| 20 | if (!value.includes(':')) { |
Akron | f2279c4 | 2017-12-21 13:48:46 +0100 | [diff] [blame] | 21 | value += ' '; |
| 22 | |
| 23 | // Iterate over all annotations and add the descriptions |
| 24 | // This is a classic hash-lookup-case, but we have |
| 25 | // to deal with lists ... |
| 26 | for (var i = 0; i < anno.length; i++) { |
| 27 | if (anno[i] && |
| 28 | anno[i][1] == value) { |
| 29 | if (anno[i][2]) |
| 30 | return anno[i][2]; |
| 31 | else |
| 32 | return; |
| 33 | }; |
| 34 | }; |
| 35 | |
| 36 | return; |
| 37 | } |
| 38 | else { |
| 39 | var text = ''; |
| 40 | var v = value.split(":"); |
| 41 | var l1 = v[0]; |
| 42 | var l2 = v[1]; |
| 43 | |
| 44 | l1 += ':'; |
| 45 | |
| 46 | // Add key description |
| 47 | for (var i = 0; i < anno.length; i++) { |
| 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 | l2 += ' '; |
| 69 | |
| 70 | // Add value description |
| 71 | for (var i = 0; i < anno.length; i++) { |
| 72 | if (anno[i] && |
| 73 | anno[i][1] == l2) { |
| 74 | if (anno[i][2]) |
| 75 | text += ': ' + anno[i][2]; |
| 76 | |
| 77 | return text; |
| 78 | }; |
| 79 | }; |
| 80 | }; |
| 81 | |
| 82 | return ''; |
| 83 | }; |
| 84 | |
| 85 | return ah; |
Akron | 8005599 | 2017-12-20 16:30:52 +0100 | [diff] [blame] | 86 | }); |