Back to LanguageTool Homepage - Privacy - Imprint

Suggesion through Java API

I am using Java to add a new rule and my code is as follows

        fakePatternTokens.add(new PatternToken("business", false, true, false));
        PatternRule rule1 = new PatternRule("id1",
                "Did you mean <match regexp_match=\"business\" regexp_replace=\"abc\"><suggestion>\\1</suggestion> </match>?",

but my output seems to be

        "from_position": 0,
        "to_position": 8,
        "message": "Did you mean <match regexp_match=\"business\" regexp_replace=\"abc\"><suggestion>business</suggestion> </match>?",
        "suggested_replacements": "business"

why is suggested replacements is not changed to ‘abc’

Seems like the <suggestion>...</suggestion> needs to be outside the <match>, not inside.

I have tried it as well. But somehow, If I do it the getSuggestedReplacements method fetch me whole tag.

I receive something like this

from getSuggestedReplacements

“from_position”: 0,
“to_position”: 8,
“message”: “Did you mean <match regexp_match=“business” regexp_replace=“abc”>business ?”,
“suggested_replacements”: "<match regexp_match=“business” regexp_replace=“abc”>business "

\1 refers to the first captured string and the first string captured by the match is the word “business”. That’s why this word is suggested, I think.