blob: 8d282864a55d02975ab095eb4b784773b66425de [file] [log] [blame]
Nils Diewald0e6992a2015-04-14 20:13:52 +00001/**
Nils Diewald7148c6f2015-05-04 15:07:53 +00002 * Object representing information
3 * about a match's layer annotation.
Nils Diewald0e6992a2015-04-14 20:13:52 +00004 */
5define(function () {
Akronff1b1f32020-10-18 11:41:29 +02006 "use strict";
7
8 const _AvailableRE =
Nils Diewald7148c6f2015-05-04 15:07:53 +00009 new RegExp("^([^\/]+?)\/([^=]+?)(?:=(spans|rels|tokens))?$");
Nils Diewald0e6992a2015-04-14 20:13:52 +000010
11 return {
Nils Diewald7148c6f2015-05-04 15:07:53 +000012 /**
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 Diewald0e6992a2015-04-14 20:13:52 +000021 create : function (foundry, layer, type) {
22 return Object.create(this)._init(foundry, layer, type);
23 },
Nils Diewald7148c6f2015-05-04 15:07:53 +000024
Akronff1b1f32020-10-18 11:41:29 +020025
Nils Diewald7148c6f2015-05-04 15:07:53 +000026 // Initialize Layer
Nils Diewald0e6992a2015-04-14 20:13:52 +000027 _init : function (foundry, layer, type) {
28 if (foundry === undefined)
Akrond67d45b2017-05-18 21:47:38 +020029 throw new Error("Missing parameters");
Akronff1b1f32020-10-18 11:41:29 +020030
31 const t = this;
Nils Diewald0e6992a2015-04-14 20:13:52 +000032
33 if (layer === undefined) {
Akrond67d45b2017-05-18 21:47:38 +020034 if (_AvailableRE.exec(foundry)) {
Akronff1b1f32020-10-18 11:41:29 +020035 t.foundry = RegExp.$1;
36 t.layer = RegExp.$2;
37 t.type = RegExp.$3;
Akrond67d45b2017-05-18 21:47:38 +020038 }
39 else {
40 throw new Error("Missing parameters");
41 };
Nils Diewald0e6992a2015-04-14 20:13:52 +000042 }
43 else {
Akronff1b1f32020-10-18 11:41:29 +020044 t.foundry = foundry;
45 t.layer = layer;
46 t.type = type;
Nils Diewald0e6992a2015-04-14 20:13:52 +000047 };
48
Akronff1b1f32020-10-18 11:41:29 +020049 if (t.type === undefined)
50 t.type = 'tokens';
Nils Diewald0e6992a2015-04-14 20:13:52 +000051
Akronff1b1f32020-10-18 11:41:29 +020052 return t;
Nils Diewald0e6992a2015-04-14 20:13:52 +000053 }
54 };
55});
56