Back to LanguageTool Homepage - Privacy - Imprint

Declaration of long regexp in Grammar.xml

Since ‘spelled’ abbreviations like cd and dvd are treated in a special way, which has an impact on multiple rules, I would like to declare them in one spot, to be reused in grammar.xml in multiple rules.
Is that possible?
Can I use the same construction as in ‘weekdays’?
I just did, and it worked.

Yes, I use same construction for Russian rules in grammar.xml.

From English grammar.xml:

<!DOCTYPE rules [
    <!ENTITY weekdays "Monday|Wednesday|T(ue|hur)sday|Friday|S(atur|un)day">
    <!ENTITY abbrevWeekdays "Mon?|Tue?|Wed?|Thu?|Fri?|Sat?|Sun?">
    <!ENTITY months "January|February|March|April|May|Ju(ne|ly)|August|September|October|November|December">
    <!ENTITY abbrevMonths "Jan|Feb|Mar|Apr|Ju[ln]|Aug|Sept?|Oct|Nov|Dec">
    <!ENTITY languages "Akan|Amharic|Arabic|Assamese|Awadhi|Azerbaijani|Balochi|Bangla|Belarusian|Bengali|Bhojpuri|Burmese|Cantonese|Cebuano|Chewa|Chhattisgarhi|Chittagonian|Czech|Deccan|Dhundhari|Dutch|English|Filipino|French|Fula|Gaelic|German|Greek|Gujarati|Hakka|Haryanvi|Hausa|Hiligaynon|Hindi|Hmong|Hunanese|Hungarian|Igbo|Ilocano|Ilonggo|Indonesian|Italian|Ja[pv]anese|Jin|Kannada|Kazakh|Khmer|Kinyarwanda|Kirundi|Konkani|Korean|Kurdish|Madurese|Magahi|Maithili|Malagasy|Malay(alam)?|Malaysian|Mandarin|Marathi|Marwari|Mossi|Nepali|Odia|Oriya|Oromo|Pashto|Persian|Polish|Portuguese|Punjabi|Quechua|Romanian|Russian|Saraiki|Serbo-Croatian|Shona|Sindhi|Sinhalese|Somali|Spanish|Sundanese|Swedish|Sylheti|Tagalog|Tamil|Telugu|Thai|Turk(ish|men)|Ukrainian|Urdu|Uyghur|Uzbek|Vietnamese|Visayan|Wu|Xhosa|Xiang|Yoruba|Yue|Zhuang|Zulu"><!-- Most are from -->

If you want to use the entity regular expression in a rule, use &entity_name;


<rule id="MISSING_COMMA_AFTER_WEEKDAY" name="Missing comma after weekday">
            <token regexp="yes">&weekdays;</token>
        <token regexp="yes">&months;</token>
        <token regexp="yes">[0123]?[0-9]</token>
    <message>Commas set off the month in a weekday-month-day date: <suggestion>\1,</suggestion>.</message>
    <short>Missing comma</short>
    <example correction="Friday,">We will meet <marker>Friday</marker> July 15.</example>
    <example>He was born on Friday, August 12, 2016.</example>

Long regular expressions may be quite slow. Alternative way is to have an abbreviation tag in your POS tag dictionary and then use this postag in the rules. It would be much faster but you need to update the dictionary.

It is an option. But it is mis-use of the postag, since it is no postag. It would be a kind of word-flag, an option I duscussed with Daniel, but I was the only one so far whishing it.