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