Akron | f2279c4 | 2017-12-21 13:48:46 +0100 | [diff] [blame] | 1 | window.KorAP = window.KorAP || {}; |
| 2 | KorAP.annotationHelper = KorAP.annotationHelper || { '-' : [] }; |
| 3 | |
Akron | 8005599 | 2017-12-20 16:30:52 +0100 | [diff] [blame] | 4 | define(function () { |
Akron | f2279c4 | 2017-12-21 13:48:46 +0100 | [diff] [blame] | 5 | |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame^] | 6 | const ah = KorAP.annotationHelper; |
Akron | f2279c4 | 2017-12-21 13:48:46 +0100 | [diff] [blame] | 7 | |
| 8 | ah["getDesc"] = function (foundryLayer, value) { |
| 9 | |
| 10 | if (!foundryLayer) |
| 11 | return; |
| 12 | |
| 13 | var anno = this[foundryLayer]; |
| 14 | |
| 15 | if (!anno) |
| 16 | return; |
| 17 | |
| 18 | if (value.indexOf(':') < 0) { |
| 19 | value += ' '; |
| 20 | |
| 21 | // Iterate over all annotations and add the descriptions |
| 22 | // This is a classic hash-lookup-case, but we have |
| 23 | // to deal with lists ... |
| 24 | for (var i = 0; i < anno.length; i++) { |
| 25 | if (anno[i] && |
| 26 | anno[i][1] == value) { |
| 27 | if (anno[i][2]) |
| 28 | return anno[i][2]; |
| 29 | else |
| 30 | return; |
| 31 | }; |
| 32 | }; |
| 33 | |
| 34 | return; |
| 35 | } |
| 36 | else { |
| 37 | var text = ''; |
| 38 | var v = value.split(":"); |
| 39 | var l1 = v[0]; |
| 40 | var l2 = v[1]; |
| 41 | |
| 42 | l1 += ':'; |
| 43 | |
| 44 | // Add key description |
| 45 | for (var i = 0; i < anno.length; i++) { |
| 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 | |
| 56 | // Nothinmg found |
| 57 | if (text.length === 0) |
| 58 | return; |
| 59 | |
| 60 | // Check next level |
| 61 | anno = this[foundryLayer + l1]; |
| 62 | |
| 63 | l2 += ' '; |
| 64 | |
| 65 | // Add value description |
| 66 | for (var i = 0; i < anno.length; i++) { |
| 67 | if (anno[i] && |
| 68 | anno[i][1] == l2) { |
| 69 | if (anno[i][2]) |
| 70 | text += ': ' + anno[i][2]; |
| 71 | |
| 72 | return text; |
| 73 | }; |
| 74 | }; |
| 75 | }; |
| 76 | |
| 77 | return ''; |
| 78 | }; |
| 79 | |
| 80 | return ah; |
Akron | 8005599 | 2017-12-20 16:30:52 +0100 | [diff] [blame] | 81 | }); |