--json context size

Hello.

How can i get the whole analyzed sentence in --json “context”:{“text”: …} output? My idea was to change
private static int DEFAULT_CONTEXT_SIZE, but i don’t know how to get matched sentence length.

1 Like

I think this is not so easy, at least without re-running the sentence splitter process. But it’s a good idea to also include the complete sentence in the API response. I think our internal data structures would need to be modified for that, i.e. the RuleMatch constructor would need to get the matching sentence.

1 Like

Is there a way to change the “context” text yet?

Instead of the way it is now (…letters-in-a-broken-word and then ending with another ellipsis…), I would prefer if LT returned the entire sentence starting from SENT_START all the way to SENT_END. Is that a possibility?

Sorry, this hasn’t been implemented yet.

What exactly are you trying to accomplish? There may be an alternative way to go around it.

Here is the code that i use to get analyzed sentences. You need to change 3 files from source code.
In …\languagetool-master\languagetool-core\src\main\java\org\languagetool
JLanguageTool.java (40.2 KB)
In …\languagetool-master\languagetool-core\src\main\java\org\languagetool\rules
RuleMatch.java (10.3 KB)
and in …\languagetool-master\languagetool-core\src\main\java\org\languagetool\tools
RuleMatchesAsJsonSerializer.java (6.8 KB)

After recompiling languagetool, in json output to every match there will be “sentence” field with “text” (whole sentence), “before” (text before error) and so on…

Note that some rules are text level so they don’t have exact analyzed sentence, but i extract some text before and after error.

1 Like

Hello KnowZero,
I would like to capture each sentence that a user (student) submits containing an error in order to show that sentence to the user later for review.

Thank you BebraiPuola,
I will see what I can do with your suggestions.

Hello BebraiPuola,
My programmer has used your three files with the latest snapshot of LT, but we are still not getting the full context length of the sentence containing an error.

Furthermore, those three patches are generating lots of errors in other files in the LT 3.9 SNAPSHOT. Is there some other change that we should make to LT to get this solution to work?

Could you let us know which line numbers we should change in the code to return the full sentence in the error context text? We are stuck at the moment, and you seem to be the best person to ask.

Best wishes,
Nick

Hi, sorry I didn’t mention that those files were for LT 3.7 version. I attach new files, which I have tested with LT 3.9 snapshot. Also in these files I marked the places where I change the code like: /*START … /*END.

RuleMatchesAsJsonSerializer.java (7.7 KB)
JLanguageTool.java (45.1 KB)
RuleMatch.java (10.7 KB)

Let me know if these work for you.

1 Like

Hi @BebraiPuola,

Thanks for the update.
Latest java files are working fine with 3.9-SNAPSHOT version.
But my only concern is that if the text length is too long and the user doesn’t want to get the full sentence with the response for performance issue or don’t want to review the full sentence.

Is it possible to pass an optional boolean parameter with the request to determine the response?
Like:
Response for the url http://host:port/v2/check?fullSentence=true&text=your+text should return response with full sentence and
default request without the fullSentence parameter should return how it was before(without full sentence).

Hi, you can try to create optional parameter like in …server/TextChecker.java and then create JLanguageTool instance with that parameter. Of course you will need to edit JLanguageTool class to be able receive another parameter, and then you need to add checking of that parameter in every method which was modified to get full sentences.

It is just my thoughts of how to do it, but i don’t know if that will work

Good luck