| Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 1 | /** | 
| Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 2 | * Object representing information | 
| 3 | * about a match's layer annotation. | ||||
| Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 4 | */ | 
| Akron | e51eaa3 | 2020-11-10 09:35:53 +0100 | [diff] [blame] | 5 | "use strict"; | 
| 6 | |||||
| Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 7 | define(function () { | 
| Akron | ff1b1f3 | 2020-10-18 11:41:29 +0200 | [diff] [blame] | 8 | |
| 9 | const _AvailableRE = | ||||
| Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 10 | new RegExp("^([^\/]+?)\/([^=]+?)(?:=(spans|rels|tokens))?$"); | 
| Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 11 | |
| 12 | return { | ||||
| Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 13 | /** | 
| 14 | * Create new match information | ||||
| 15 | * object for one layer. | ||||
| 16 | * | ||||
| 17 | * Alternatively pass a string as | ||||
| 18 | * <tt>base/s=span</tt> | ||||
| 19 | * | ||||
| 20 | * @param foundry | ||||
| 21 | */ | ||||
| Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 22 | create : function (foundry, layer, type) { | 
| 23 | return Object.create(this)._init(foundry, layer, type); | ||||
| 24 | }, | ||||
| Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 25 | |
| Akron | ff1b1f3 | 2020-10-18 11:41:29 +0200 | [diff] [blame] | 26 | |
| Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 27 | // Initialize Layer | 
| Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 28 | _init : function (foundry, layer, type) { | 
| 29 | if (foundry === undefined) | ||||
| Akron | d67d45b | 2017-05-18 21:47:38 +0200 | [diff] [blame] | 30 | throw new Error("Missing parameters"); | 
| Akron | ff1b1f3 | 2020-10-18 11:41:29 +0200 | [diff] [blame] | 31 | |
| 32 | const t = this; | ||||
| Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 33 | |
| 34 | if (layer === undefined) { | ||||
| Akron | d67d45b | 2017-05-18 21:47:38 +0200 | [diff] [blame] | 35 | if (_AvailableRE.exec(foundry)) { | 
| Akron | ff1b1f3 | 2020-10-18 11:41:29 +0200 | [diff] [blame] | 36 | t.foundry = RegExp.$1; | 
| 37 | t.layer = RegExp.$2; | ||||
| 38 | t.type = RegExp.$3; | ||||
| Akron | d67d45b | 2017-05-18 21:47:38 +0200 | [diff] [blame] | 39 | } | 
| 40 | else { | ||||
| 41 | throw new Error("Missing parameters"); | ||||
| 42 | }; | ||||
| Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 43 | } | 
| 44 | else { | ||||
| Akron | ff1b1f3 | 2020-10-18 11:41:29 +0200 | [diff] [blame] | 45 | t.foundry = foundry; | 
| 46 | t.layer = layer; | ||||
| 47 | t.type = type; | ||||
| Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 48 | }; | 
| 49 | |||||
| Akron | ff1b1f3 | 2020-10-18 11:41:29 +0200 | [diff] [blame] | 50 | if (t.type === undefined) | 
| 51 | t.type = 'tokens'; | ||||
| Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 52 | |
| Akron | ff1b1f3 | 2020-10-18 11:41:29 +0200 | [diff] [blame] | 53 | return t; | 
| Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 54 | } | 
| 55 | }; | ||||
| 56 | }); | ||||
| 57 | |||||