| Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 1 | /** | 
|  | 2 | * Regex object for checking the context of the hint | 
|  | 3 | */ | 
| Akron | da5bd3a | 2020-10-16 17:37:49 +0200 | [diff] [blame] | 4 | "use strict"; | 
|  | 5 |  | 
| Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 6 | define({ | 
| Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 7 |  | 
|  | 8 | /** | 
|  | 9 | * Create analyzer based on regular expression. | 
|  | 10 | */ | 
| Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 11 | create : function (regex) { | 
|  | 12 | return Object.create(this)._init(regex); | 
|  | 13 | }, | 
| Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 14 |  | 
|  | 15 | // Initialize analyzer | 
| Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 16 | _init : function (regex) { | 
|  | 17 | try { | 
|  | 18 | this._regex = new RegExp(regex); | 
|  | 19 | } | 
|  | 20 | catch (e) { | 
|  | 21 | KorAP.log(0, e); | 
|  | 22 | return; | 
|  | 23 | }; | 
|  | 24 | return this; | 
|  | 25 | }, | 
| Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 26 |  | 
|  | 27 | /** | 
|  | 28 | * Check a context based on the analyzer | 
|  | 29 | * and return a valid context string. | 
|  | 30 | */ | 
| Nils Diewald | 0e6992a | 2015-04-14 20:13:52 +0000 | [diff] [blame] | 31 | test : function (text) { | 
|  | 32 | if (!this._regex.exec(text)) | 
|  | 33 | return; | 
|  | 34 | return RegExp.$1; | 
|  | 35 | } | 
|  | 36 | }); |