How to extend LanguageTool with custom grammar rules via API?

Hello

I am working on integrating LanguageTool into a small writing application and want to add a few domain-specific grammar rules. :slightly_smiling_face:Using the HTTP API works fine for standard checks but I couldn’t figure out how to extend it with my own grammar or style rules. :innocent:

The documentation mentions XML-based rules and Java-based development but I am not sure how these custom rules can be exposed when using the HTTP server mode. :upside_down_face:

Is there a way to load or register new rules directly with the HTTP API setup, or do I need to modify and build LanguageTool from source in Java every time I want to add a custom grammar rule? :thinking:

Ideally; I would like a workflow where I can keep the server running & just add new rules dynamically without restarting or recompiling the whole tool. :slightly_smiling_face: Checked LanguageTool API documentation guide related to this and found it quite informative. I also saw an example where someone connected LanguageTool with a ChatGPT Agent to enhance text suggestions; which made me wonder if a similar approach could be used for injecting custom grammar rules via the API. :thinking:

If anyone has experience with this; I would really appreciate some guidance. A clear example of how to create a custom grammar rule & make it available through the HTTP API would be very useful for developers like me who want to extend LanguageTool for specialized use cases. :innocent:

Thank you !! :slightly_smiling_face:

Is there a way to load or register new rules directly with the HTTP API setup

No, you’ll need to add XML rules to the grammar.xml file and re-start the LT server to make sure they become active. For Java rules, you’ll need to add the Java code and recompile LT.

How to write XML rules is documented here.

You can also put grammar rules and disambiguation rules in an external file (Tips and Tricks | dev.languagetool.org).

For an example of grammar rules that are in an external file, refer to https://www.simplified-english.co.uk/grammar-projectterms.xml. (Some postags are not standard LT postags. They are postags that I added in a customized disambiguation file, and that file is not publicly available.)