blob: 88404d56b5b42445a5b9656720087b2fb44e7ca8 [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 */
Akrone51eaa32020-11-10 09:35:53 +01005"use strict";
6
Nils Diewald0e6992a2015-04-14 20:13:52 +00007define(function () {
Akronff1b1f32020-10-18 11:41:29 +02008
9 const _AvailableRE =
Nils Diewald7148c6f2015-05-04 15:07:53 +000010 new RegExp("^([^\/]+?)\/([^=]+?)(?:=(spans|rels|tokens))?$");
Nils Diewald0e6992a2015-04-14 20:13:52 +000011
12 return {
Nils Diewald7148c6f2015-05-04 15:07:53 +000013 /**
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 Diewald0e6992a2015-04-14 20:13:52 +000022 create : function (foundry, layer, type) {
23 return Object.create(this)._init(foundry, layer, type);
24 },
Nils Diewald7148c6f2015-05-04 15:07:53 +000025
Akronff1b1f32020-10-18 11:41:29 +020026
Nils Diewald7148c6f2015-05-04 15:07:53 +000027 // Initialize Layer
Nils Diewald0e6992a2015-04-14 20:13:52 +000028 _init : function (foundry, layer, type) {
29 if (foundry === undefined)
Akrond67d45b2017-05-18 21:47:38 +020030 throw new Error("Missing parameters");
Akronff1b1f32020-10-18 11:41:29 +020031
32 const t = this;
Nils Diewald0e6992a2015-04-14 20:13:52 +000033
34 if (layer === undefined) {
Akrond67d45b2017-05-18 21:47:38 +020035 if (_AvailableRE.exec(foundry)) {
Akronff1b1f32020-10-18 11:41:29 +020036 t.foundry = RegExp.$1;
37 t.layer = RegExp.$2;
38 t.type = RegExp.$3;
Akrond67d45b2017-05-18 21:47:38 +020039 }
40 else {
41 throw new Error("Missing parameters");
42 };
Nils Diewald0e6992a2015-04-14 20:13:52 +000043 }
44 else {
Akronff1b1f32020-10-18 11:41:29 +020045 t.foundry = foundry;
46 t.layer = layer;
47 t.type = type;
Nils Diewald0e6992a2015-04-14 20:13:52 +000048 };
49
Akronff1b1f32020-10-18 11:41:29 +020050 if (t.type === undefined)
51 t.type = 'tokens';
Nils Diewald0e6992a2015-04-14 20:13:52 +000052
Akronff1b1f32020-10-18 11:41:29 +020053 return t;
Nils Diewald0e6992a2015-04-14 20:13:52 +000054 }
55 };
56});
57