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 | |
| 19 | if (value.indexOf(':') < 0) { |
| 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 | } |
| 37 | else { |
| 38 | var text = ''; |
| 39 | var v = value.split(":"); |
| 40 | var l1 = v[0]; |
| 41 | var l2 = v[1]; |
| 42 | |
| 43 | l1 += ':'; |
| 44 | |
| 45 | // Add key description |
| 46 | for (var i = 0; i < anno.length; i++) { |
| 47 | if (anno[i] && |
| 48 | anno[i][1] == l1) { |
| 49 | if (anno[i][2]) |
| 50 | text += anno[i][2]; |
| 51 | else |
| 52 | text += anno[i][0]; |
| 53 | break; |
| 54 | }; |
| 55 | }; |
| 56 | |
Akron | 369cbc4 | 2018-02-11 00:43:15 +0100 | [diff] [blame^] | 57 | // Nothing found |
Akron | f2279c4 | 2017-12-21 13:48:46 +0100 | [diff] [blame] | 58 | if (text.length === 0) |
| 59 | return; |
| 60 | |
| 61 | // Check next level |
| 62 | anno = this[foundryLayer + l1]; |
| 63 | |
Akron | 369cbc4 | 2018-02-11 00:43:15 +0100 | [diff] [blame^] | 64 | if (!anno) |
| 65 | return; |
| 66 | |
Akron | f2279c4 | 2017-12-21 13:48:46 +0100 | [diff] [blame] | 67 | l2 += ' '; |
| 68 | |
| 69 | // Add value description |
| 70 | for (var i = 0; i < anno.length; i++) { |
| 71 | if (anno[i] && |
| 72 | anno[i][1] == l2) { |
| 73 | if (anno[i][2]) |
| 74 | text += ': ' + anno[i][2]; |
| 75 | |
| 76 | return text; |
| 77 | }; |
| 78 | }; |
| 79 | }; |
| 80 | |
| 81 | return ''; |
| 82 | }; |
| 83 | |
| 84 | return ah; |
Akron | 8005599 | 2017-12-20 16:30:52 +0100 | [diff] [blame] | 85 | }); |