Back to LanguageTool Homepage - Privacy - Imprint

[SOLVED] Check spelling and grammar for the content of an XML file


(vers) #1

Hi,

I'd like to use LanguageTool to check the spelling and grammar for the text contained in an XML file, adjusting error positions so they refer to the original text including markup.

Example 1:



<text>A sentences</text>

Example 2:



<text><bold>A</bold> sentences</text>

For "Example 1" I've managed to do this by calling the method check(String) of the class org.languagetool.JLanguageTool

But for "Example 2" this didn't work (no errors were detected). I suppose the reason is that "A" is nested inside the "" element.

Which is the best way to analyze a text (containing markup) with LanguageTool adjusting error positions so they refer to the original text including markup?

Thanks in advance.


(Daniel Naber) #2

You can use https://languagetool.org/development/api/org/languagetool/markup/AnnotatedTextBuilder.html to get an AnnotatedText object which can then be checked. Markup will be ignored.


(vers) #3

Thanks! That's exactly what I was looking for.