blob: fc01662ca84e26f3da32e7e13711e2a46dfcb92e [file] [log] [blame]
Nils Diewald0e6992a2015-04-14 20:13:52 +00001/**
2 * Regex object for checking the context of the hint
3 */
4define({
Nils Diewald7148c6f2015-05-04 15:07:53 +00005
6 /**
7 * Create analyzer based on regular expression.
8 */
Nils Diewald0e6992a2015-04-14 20:13:52 +00009 create : function (regex) {
10 return Object.create(this)._init(regex);
11 },
Nils Diewald7148c6f2015-05-04 15:07:53 +000012
13 // Initialize analyzer
Nils Diewald0e6992a2015-04-14 20:13:52 +000014 _init : function (regex) {
15 try {
16 this._regex = new RegExp(regex);
17 }
18 catch (e) {
19 KorAP.log(0, e);
20 return;
21 };
22 return this;
23 },
Nils Diewald7148c6f2015-05-04 15:07:53 +000024
25 /**
26 * Check a context based on the analyzer
27 * and return a valid context string.
28 */
Nils Diewald0e6992a2015-04-14 20:13:52 +000029 test : function (text) {
30 if (!this._regex.exec(text))
31 return;
32 return RegExp.$1;
33 }
34});