33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
-
+
-
+
-
+
-
+
-
+
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
|
* flags “LCR” for the regex word boundaries and case sensitiveness
* [optional] option name (the rule is active only if the option defined by user or config is active)
* [optional] rule name (named rules can be disabled by user or by config)
* [optional] priority number
* a regex pattern trigger
* a list of actions
A token rules is defined by:
A token rule is defined by:
* rule name
* [optional] priority number
* one or several lists of tokens
* a list of actions (the action is active only if the option defined by user or config is active)
Token rules must be defined within a graph.
Each graph is defined within the second pass with the command:
@@@@GRAPH: graph_name|graph_code
@@@@GRAPH: graph_name|graph_code
A graph ends when another graph is defined or when is found the command:
@@@@END_GRAPH
@@@@END_GRAPH
There is no limit to the number of actions and the type of actions a rule can
launch. Each action has its own condition to be triggered.
There are several kinds of actions:
* Error warning, with a message, and optionally suggestions, and optionally an URL
* Error warning, with a message, and optionally suggestions, and optionally a URL
* Text transformation, modifying internally the checked text
* [second pass only] Disambiguation action
* Disambiguation action
* [second pass only] Tagging token
* [second pass only] Immunity rules
On the first pass, you can only write regex rules.
On the second pass, you can write regex rules and token rules. All tokens rules must be written within a graph.
## Syntax details
## REGEX RULE SYNTAX ##
### Comments
Lines beginning with `#` are comments.
### End of parsing
With the command `#END` at the beginning of a line, the parser won’t go further.
Whatever is written after will be considered as comments.
## Regex rule syntax
__LCR/option(rulename)!priority__
pattern
<<- condition ->> error_suggestions # message_error|URL
<<- condition ~>> text_rewriting
<<- condition =>> commands_for_disambiguation
...
Patterns are written with the Python syntax for regular expressions:
http://docs.python.org/library/re.html
There can be one or several actions for each rule, executed following the order they are
written.
Optional:
Optional: option, rulename, priority, condition, URL
* option
* rulename
* priority
* conditions
* URL
LCR flags means:
* L: Left boundary for the regex
* C: Case sensitiveness
* R: Right boundary for the regex
|
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
|
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
|
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
-
+
-
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
-
+
+
+
+
-
+
+
+
+
+
-
+
+
+
-
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
+
+
-
+
+
+
+
-
-
+
+
+
+
+
+
-
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
-
-
-
-
+
+
+
+
+
|
__<i]__ \b([?!.])([A-Z]+) <<- ->> \1 \2 # Missing space?
Example. Back reference in messages.
(fooo) bar <<- ->> foo # “\1” should be:
### Group positioning codes for JavaScript:
There is no way in JavaScript to know where a captured group starts and ends. To avoid misplacement, regex rules may specify group positioning codes which indicate to the grammar checker where is the position of the captured groups.
A group positioning code always begins by `@@`. If there is several codes, they are separated by a comma `,`.
Other codes:
0 1 2 3 ... n left boundary position from left
-1 -2 -2 ... -n right boundary position from right
$ extreme right boundary
w somewhere with word boundaries
* something somewhere
** something somewhere after previous group
Examples:
([A-ZÉÈÂÎ][\w-]+) [A-ZÉÈÂ]([.]) ([A-ZÉÈÂ][\w-]+) @@0,*,$
" ([?!;])" @@1
### Pattern matching
Repeating pattern matching of a single rule continues after the previous matching, so
Repeating pattern matching of a single rule continues after the previous matching, so instead of general multiword patterns, like
instead of general multiword patterns, like
(\w+) (\w+) <<- some_check(\1, \2) ->> \1, \2 # foo
use
(\w+) <<- some_check(\1, word(1)) ->> \1, # foo
## TOKEN RULES ##
### Definitions
Token rules must be defined within a graph.
### Token rules syntax
Grammalecte supports definitions to simplify the description of complex rules.
__rulename!priority__
list_of_tokens
list_of_tokens
list_of_tokens
...
<<- /option/ condition ->> suggestions|URL
<<- /option/ condition ~>> rewriting
<<- /option/ condition =>> disambiguation
<<- /option/ condition />> tagging
<<- /option/ condition !>> <immunity>
...
list_of_tokens
...
<<- action1
<<- action2
...
With token rules, for one rule name, you can define several blocks of list of tokens with different kinds of actions. Each block must be separated by an empty line.
Optional: priority, option, condition, URL
### Tokens
Tokens can be defined in several ways:
* Value (the text of the token). Examples: `word`, `<start>`, `<end>`, `,`.
* Lemma: `>lemma`.
* Regex: `~pattern`, `~pattern¬antipattern`.
* Regex on morphologies: `@pattern`, `@pattern¬antipattern`.
* Tags: `/tag`.
* Metatags: *NAME. Examples: `*WORD`, `*NUM`, `*SIGN`, etc.
* Jump over token: `<>`
Selection of tokens: `[value1|value2||>lemma|~pattern|@pattern|*META|/tag|…]`
Conditional token: `?token¿`
Conditional selection of token: `?[token1|token2|…]¿`
### Token references
Positive references are defined by a positive integer (> 0). Examples: `\1`, `\2`, `\3`, etc.
If there is at least one token set between parenthesis, these numbers refer to tokens between parenthesis, ignoring all others.
If there is no token between parenthesis, these numbers refer to tokens found in order defined by the rule triggered.
Negative references are defined by a negative integer (< 0). Examples: `\-1`, `\-2`, `\-3`, etc.
These numbers refer to the tokens beginning by the last one found by the rule triggered.
Examples:
tokens: alpha beta gamma delta epsilon
positive refs: 1 2 3 4 5
negative refs: -5 -4 -3 -2 -1
tokens: alpha (beta) gamma (delta) epsilon
positive refs: 1 2
negative refs: -5 -4 -3 -2 -1
tokens: alpha (beta) ?gamma¿ (delta) epsilon
positive refs: 1 2
negative refs: (-5/-4) (-4/-3) (-3/none) -2 -1
## CONDITIONS ##
Conditions are Python expressions, they must return a value, which will be
evaluated as boolean. You can use the usual Python syntax and libraries.
With regex rules, you can call pattern subgroups via `\1`, `\2`… `\0` is the full pattern.
Example:
these (\w+)
<<- \1 == "man" -1>> men # Man is a singular noun.
You can also apply functions to subgroups like: `\1.startswith("a")` or `\3.islower()` or `re.search("pattern", \2)`.
With token rules, you can also call each token with their reference, like `\1`, `\2`... or `\-1`, `\-2`...
Example:
foo [really|often|sometimes] bar
<<- ->> \1 \-1 # We say “foo bar”.
DEF: name pattern
### Functions for regex rules
Usage in the rules:
`word(n)`
> Catches the nth next word after the pattern (separated only by white spaces).
> Returns None if no word caught
({name}) (\w+) ->> "\1-\2" # Missing hyphen?
`word(-n)`
> Catches the nth next word before the pattern (separated only by white spaces).
> Returns None if no word caught
`textarea(regex[, neg_regex])`
### Multiple suggestions
> Checks if the full text of the checked area (paragraph or sentence) matches the regex.
`morph(n, regex[, neg_regex][, no_word=False])`
Use `|` in the replacement text to add multiple suggestions:
> Checks if all tags of the word in group n match the regex.
> If neg_regex = "*", returns True only if all morphologies match the regex.
> If there is no word at position n, returns the value of no_word.
`analyse(n, regex[, neg_regex][, no_word=False])`
Example. Foo, FOO, Bar and BAR suggestions for the input word "foo".
> Checks if all tags of the word in group n match the regex.
> If neg_regex = "*", returns True only if all morphologies match the regex.
> If there is no word at position n, returns the value of no_word.
### Functions for token rules
`value(n, values_string)`
> Analyses the value of the nth token.
> The <values_string> contains values separated by the sign `|`.
> Example: `"|foo|bar|"`
`morph(n, "regex"[, "neg_regex"][, trim_left=0][, trim_right=0])`
`analyse(n, "regex"[, "neg_regex"][, trim_left=0][, trim_right=0])`
> Same action with `morph()` and `morph0()` for regex rules.
> Parameters <trim_left> and <trim_right> removed n characters at left or the right of the token before performing an analyse.
`space_after(n, min_space[, max_space])`
> Returns True if the next token after token n is separated with at least <min_space> blank spaces and at most with <max_space> blank spaces.
`tag(n, tag)`
> Returns True if <tag> exists on taken the nth token.
`tag_before(n, tag)`
> Returns True if <tag> is found any token before the nth tag.
foo <<- ->> Foo|FOO|Bar|BAR # Did you mean:
`tag_after(n, tag)`
> Returns True if <tag> is found any token after the nth tag.
### Functions for regex and token rules
### No suggestion
`__also__`
> Returns True if the previous condition returned True.
> Example: `<<- __also__ and condition2 ->>`
You can display message without making suggestions. For this purpose,
use a single character _ in the suggestion field.
`__else__`
> Returns False if the previous condition returned False.
> Example: `<<- __else__ and condition2 ->>`
`option(option_name)`
Example. No suggestion.
> Returns True if <option_name> is activated else False
Note: the analysis is done on the preprocessed text.
foobar <<- ->> _ # Message
`after(regex[, neg_regex])`
> Checks if the text after the pattern matches the regex.
`before(regex[, neg_regex])`
> Checks if the text before the pattern matches the regex.
### Default variables
`sCountry`
> Contains the current country locale of the checked paragraph.
colour <<- sCountry == "US" ->> color # Use American English spelling.
## ACTIONS ##
There are 5 kinds of actions:
1. Suggestions. The grammar checker suggests corrections.
2. Text processor. A internal process to modify the text internally. This is used to simplify grammar checking.
* text rewriting
* text deletion
* token rewriting
* token merging
* token deletion
3. Disambiguation. Select, exclude or define morphologies of tokens.
4. Tagging. Add information on token.
5. Immunity. Prevent suggestions to be triggered.
### Positioning
Positioning is valid only for error creation and text rewriting.
Positioning is valid for suggestions, text processing, tagging and immunity.
By default, the full pattern will be underlined with blue. You can shorten the
underlined text area by specifying a back reference group of the pattern.
Instead of writing ->>, write -n>> n being the number of a back reference
group. Actually, ->> is similar to -0>>
By default, rules apply on the full text triggered. You can shorten the
effect of rules by specifying a back reference group of the pattern or token references.
Instead of writing `->>`, write `-n>>` n being the number of a back reference
group. Actually, `->>` is similar to `-0>>`.
Example:
(ying) and yang <<- -1>> yin # Did you mean:
__[s]__ (Mr.) [A-Z]\w+ <<- ~1>> Mr
|
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
|
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
|
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
+
-
-
-
-
+
-
-
+
|
With the rule B, only the first group is underlined:
ying and yang
^^^^
### Errors and suggestions
The command to suggest something is: `->>`.
#### Multiple suggestions
Use `|` in the replacement text to add multiple suggestions:
Example. Foo, FOO, Bar and BAR suggestions for the input word "foo".
foo <<- ->> Foo|FOO|Bar|BAR # Did you mean:
#### No suggestion
You can display message without making suggestions. For this purpose,
use a single character _ in the suggestion field.
Example. No suggestion.
foobar <<- ->> _ # Message
### Longer explanations with URLs
#### Longer explanations with URLs
Warning messages can contain optional URL for longer explanations.
your’s
<<- ->> yours
# Possessive pronoun:|http://en.wikipedia.org/wiki/Possessive_pronoun
#### Expressions in suggestion or replacement
Suggestions started by an equal sign are Python string expressions extended with possible back references and named definitions:
Example:
<<- ->> ='"' + \1.upper() + '"' # With uppercase letters and quotation marks
<<- ~>> =\1.upper()
### Text rewriting
**WARNING**: The replacing text must be shorter than the replaced text or have the same length. Breaking this rule will misplace following error reports.
You have to ensure yourself the rules comply with this constraint, the text processor won’t do it for you.
The command for text rewriting is: `~>>`.
Example. Replacing a string by another.
Mr. [A-Z]\w+ <<- ~>> Mister
**WARNING**: The replacing text must be shorter than the replaced text or have the
same length. Breaking this rule will misplace following error reports. You
have to ensure yourself the rules comply with this constraint, Grammalecte
won’t do it for you.
Specific commands for text rewriting:
`~>> *`
> Replace by whitespaces
`~>> @`
> Replace with arrobas, useful mostly at first pass, where it is advised to
> Replace with the at sign, useful mostly at first pass, where it is advised to check usage of punctuations and whitespaces.
> check usage of punctuations and whitespaces.
> Successions of @ are automatically removed at the beginning of the second pass.
`~>> _`
> Replace with underscores. Just a filler.
> These characters won’t be removed at the beginning of the second pass.
You can use positioning with text rewriting actions.
Mr(. [A-Z]\w+) <<- ~1>> *
You can also call Python expressions.
__[s]__ Mr. ([a-z]\w+) <<- ~1>> =\1.upper()
### Text processing
The text processor is useful to simplify texts and write simplier checking
The text processor is useful to simplify texts and write simpler checking
rules.
For example, sentences with the same grammar mistake:
These “cats” are blacks.
These cats are “blacks”.
These cats are absolutely blacks.
These stupid “cats” are all blacks.
These unknown cats are as per usual blacks.
Instead of writting complex rules or several rules to find mistakes for all possible
cases, you can use the text preprocessor to simplify the text.
Instead of writing complex rules or several rules to find mistakes for all possible cases, you can use the text preprocessor to simplify the text.
To remove the chars “”, write:
[“”] ~>> *
The * means: replace text by whitespaces.
|
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
|
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
|
-
-
+
-
-
-
+
-
+
-
+
+
-
-
+
+
+
+
-
+
-
+
-
-
+
-
+
-
+
-
-
+
+
-
+
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
+
-
-
+
-
-
-
+
-
-
-
+
-
-
-
+
-
-
-
-
-
+
-
-
-
-
+
-
+
-
-
-
+
-
-
+
-
-
-
+
-
-
+
-
-
+
-
-
-
+
-
-
-
-
+
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
+
-
-
+
-
-
-
-
-
-
-
+
-
-
-
-
+
-
-
-
+
+
-
-
-
+
+
+
|
Mister <<- ~>> Mr
(Mrs?)[.] <<- ~>> \1
### Disambiguation
When Grammalecte analyses a word with morph, before requesting the
POS tags to the dictionary, it checks if there is a stored marker for the
When the grammar checker analyses a token with `morph()`, before requesting the POS tags to the dictionary, it checks if there is a stored marker for the position of the token. If a marker is found, it uses the stored data and don’t make request to the dictionary.
position where the word is. If there is a marker, Grammalecte uses the stored
data and don’t make request to the dictionary.
The disambiguation commands store POS tags at the position of a word.
The command for disambiguation is: `=>>`. No positioning allowed.
There is 3 commands for disambiguation.
There are 4 commands for disambiguation.
`select(n, pattern)`
> stores at position n only the POS tags of the word matching the pattern.
> At reference n, select morphologies that match the pattern.
`exclude(n, pattern)`
> At reference n, exclude morphologies that match the pattern.
> stores at position n the POS tags of the word, except those matching the
pattern.
`define(n, [morph_list])`
> At reference n, set the listed morphologies (a list of strings).
`define(n, [definitions])`
`add_morph(n, [morph_list])`
> stores at position n the POS tags in definitions (a list of strings).
> At reference n, add the listed morphologies (a list of strings).
Examples:
=>> select(\1, "po:noun is:pl")
=>> exclude(\1, "po:verb")
=>> define(\1, ["po:adv"])
=>> exclude(\1, "po:verb") and define(\2, ["po:adv"]) and select(\3, "po:adv")
Note: select(), exclude() and define() ALWAYS return True.
Note: All these functions ALWAYS return True.
If select() and exclude() generate an empty list, no marker is set.
If `select()` and `exclude()` generate an empty list, nothing change.
With define, you must set a list of POS tags. Example:
With `define()` and `add_morph()`, you must set a list of POS tags. Example:
define(\1, ["po:nom is:plur", "po:adj is:sing", "po:adv"])
=>> define(\1, ["po:nom is:plur", "po:adj is:sing", "po:adv"])
=>> add_morph(\1, ["po:adv"])
### Conditions
### Tagging
Conditions are Python expressions, they must return a value, which will be
evaluated as boolean. You can use the usual Python syntax and libraries.
**Only for token rules**. Tagging can be done with the command `/>>`. You can set one or several tags at once. Use `|` as a separator.
You can call pattern subgroups via \0, \1, \2…
Example:
these (\w+)
<<- \1 == "man" -1>> men # Man is a singular noun. Use the plural form:
You can also apply functions to subgroups like:
\1.startswith("a")
\3.islower()
re.search("pattern", \2)
### Standard functions
`word(n)`
> catches the nth next word after the pattern (separated only by white spaces).
> returns None if no word catched
`word(-n)`
Example: `/>> a_tag` to set the same tag on all takens of the rule.
> catches the nth next word before the pattern (separated only by white spaces).
> returns None if no word catched
Example: `/3>> a_tag` to set the tag on the third token.
`after(regex[, neg_regex])`
Example: `/>> a_tag|another_tag` to set two tags.
> checks if the text after the pattern matches the regex.
`before(regex[, neg_regex])`
You can know if a token is tagged with eh function `tag()` and you can know if tags have been set on previous or following tokens with `tag_before()` and `tag_after()`.
> checks if the text before the pattern matches the regex.
`textarea(regex[, neg_regex])`
### Immunity
> checks if the full text of the checked area (paragraph or sentence) matches the regex.
`morph(n, regex[, neg_regex][, no_word=False])`
**Only for token rules**. A immunity rule set a flag on token(s) who are not supposed to be considered as an error. If any other rules find an error, it will be ignored. If an error has already been found, it will be removed.
> checks if all tags of the word in group n match the regex.
> if neg_regex = "*", returns True only if all morphologies match the regex.
> if there is no word at position n, returns the value of no_word.
`morph0(n, regex[, neg_regex][, no_word=False])`
Example: `!2>>` means no error can be set on the second token.
> checks if all tags of the word in group n match the regex.
> if neg_regex = "*", returns True only if all morphologies match the regex.
> if there is no word at position n, returns the value of no_word.
Example: `!>>` means all tokens will be considered as correct.
`option(option_name)`
The immunity rules are useful to create simple antipattern that will simplify writing of other rules.
> returns True if option_name is activated else False
Note: the analysis is done on the preprocessed text.
## OTHER COMMANDS ##
### Default variables
### Comments
`sCountry`
> It contains the current country locale of the checked paragraph.
Lines beginning with `#` are comments.
colour <<- sCountry == "US" ->> color # Use American English spelling.
### End of parsing
### Expressions in suggestion or replacement
With the command `#END` at the beginning of a line, the parser won’t go further.
Suggestions started by an equal sign are Python string expressions
extended with possible back references and named definitions:
Whatever is written after will be considered as comments.
Example:
<<- ->> ='"' + \1.upper() + '"' # With uppercase letters and quotation marks
<<- ~>> =\1.upper()
### Definitions
## Token rules
Grammalecte supports definitions to simplify the description of complex rules.
Token rules must be defined within a graph.
### Tokens
Tokens can be defined in several ways:
* Value (meaning the text of the token). Examples: `word`, `<start>`, `<end>`, `,`.
* Lemma: `>lemma`.
* Regex: `~pattern`, `~pattern¬antipattern`.
* Regex on morphologies: `@pattern`, `@pattern¬antipattern`.
* Tags: `/tag`.
* Metatags: *NAME. Examples: `*WORD`, `*NUM`, `*SIGN`, etc.
Selection of tokens: `[token1|token2|>lemma1|>lemma2|~pattern1|@pattern1|…]`
Definition:
Conditional token: `?token¿`
Conditional selection of token: `?[token1|token2|…]¿`
DEF: name definition
### Token references
Usage: `{name}` will be replaced by its definition
Positive references are defined by a positive integer `>= 1`. Examples: \1, \2, \3, etc.
If there is at least one token set between parenthesis, these numbers refer to tokens between parenthesis, ignoring all others.
If there is no token between parenthesis, these numbers refer to tokens found in order defined by the rule triggered.
Negative references are defined by a negative integer `<= -1`. Examples: \-1, \-2, \-3, etc.
These numbers refer to the tokens beginning by the last one found by the rule triggered.
Examples:
Example:
tokens: alpha beta gamma delta epsilon
positive refs: 1 2 3 4 5
negative refs: -5 -4 -3 -2 -1
DEF: word_3_letters \w\w\w+
tokens: alpha (beta) gamma (delta) epsilon
positive refs: 1 2
negative refs: -5 -4 -3 -2 -1
DEF: uppercase_token ~^[A-Z]+$
DEF: month_token [January|February|March|April|May|June|July|August|September|October|November|december]
tokens: alpha (beta) ?gamma¿ (delta) epsilon
positive refs: 1 2
negative refs: (-4/-5) (-3/-4) (-3/none) -2 -1
({word_3_letters}) (\w+) <<- condition ->> suggestion # message|URL
{uppercase_token} {month_token}
<<- condition ->> message # message|URL
|