Back to LanguageTool Homepage - Privacy - Imprint

Suggesion through Java API


(sashank malladi) #1

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",
                language,
                fakePatternTokens,
                "desc1",
                "Did you mean <match regexp_match=\"business\" regexp_replace=\"abc\"><suggestion>\\1</suggestion> </match>?",
                "shortMsg1");

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’


(Daniel Naber) #2

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


(sashank malladi) #3

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


(sashank malladi) #4

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 "
}
]


(Oleg) #5

\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.