I followed the instructions on the adding new rules page, Tips and Tricks - LanguageTool Wiki, but I cannot seem to get my custom rules to work.
As a simple test, I made a rule that just identifies the digit “1” and suggests to change it to “One”. I added it to an external file called my-custom-rules.xml
<rule id="ONE_DIGIT" name="one digit">
<pattern>
<marker>
<token>1</token>
</marker>
</pattern>
<message>1 should be spelled out. Like One</message>
<example correction=''><marker>1</marker></example>
<example>one</example>
</rule>
I then attempted to reference it in the grammar.xml file by placing a reference in the <DOCTYPE rules section
<!ENTITY CustomRules SYSTEM "file:///home/my-custom-rules.xml">
Then place &CustomRules after the last rule in a category section
'… </rule> &CustomRules; </category> </rules>
If I restart my server, the rule is not recognized.
Just to be sure the issue is really with the rule being in an extra file: does it work when in grammar.xml? Do you get an error when you specify a non-existing path at !ENTITY CustomRules SYSTEM?
I added the rule to the grammar.xml file, and it’s still not working. Which is odd because it’s a simple rule. This time, however, language tool does not raise any errors.
Before, I kept getting “Error: Internal Error: java.lang.RuntimeException: Could not activate rules”
Also, if I make a change and simply restart the server the error does not come up. It only gets raised after running ‘./build.sh languagetool-standalone package -DskipTests’ again.
<!DOCTYPE rules [
<!ENTITY CustomRules SYSTEM "file:///home/custom-rules.xml">
<!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 https://en.wikipedia.org/wiki/List_of_languages_by_number_of_native_speakers -->
]>
This is the end of my grammar.xml
<rule id="EUPUB_VISA" name="visa">
<pattern>
<token inflected="yes">visa</token>
</pattern>
<message>Visa is misused to render not only 'approval', but also the act of giving approval. In English, a visa is generally 'an official authorisation appended to a passport, permitting entry into and travel within a particular country or region'. It is also the name of a credit card. Alternatives: approval, endorsement, to approve, to endorse.</message>
<url>http://euenglish.webs.com/</url>
<short>EU English: visa</short>
<example type="incorrect" correction="">The centralised ex-ante <marker>visa</marker> performed by the Financial Controller, …</example>
<example type="incorrect" correction="">The Finance Section has to <marker>visa</marker> all transactions before they can be authorised.</example>
<example type="incorrect" correction="">… the ex-ante <marker>visa</marker> of the Delegation would be suspended unless…</example>
<example>The centralised ex-ante <marker>approval</marker> performed by the Financial Controller, …</example>
</rule>
&CustomRules;
</category>
This is my custom-rules.xml file.
<rule id="ONE_DIGIT" name="one digit">
<pattern>
<marker>
<token>1</token>
</marker>
</pattern>
<message>1 should be spelled out. Like One</message>
<example correction=''><marker>1</marker></example>
<example>one</example>
</rule>
Yes. This sounds like you modified the file from the source instead of the file of the build. If you just work with the ZIP, there’s no such confusion.
Okay, the grammar.xml file I am editing is located at: languagetool/languagetool-language-modules/en/src/main/resources/org/languagetool/rules/en/grammar.xml
where can I find the build files? I am working on ubuntu 16.04 through a terminal.
Everything under target is generated by Maven. I suggest either using our snapshots or, if you actually need to make code changes, to work in your IDE and only build at the very end (i.e. modify, run, test, repeat - everything in the IDE).