Page 1 of 1

Grammar check

Posted: Mon Oct 22, 2012 6:09 pm
by Extorian
Hi,

Is it possible to highlight more than 1 word using the OnSpellingCheck event? When grammar checking sometimes more than 1 word needs to be highlighted. We like the way the OnSpellingCheck is implemented and its perfect for spell check. Just wondering if a similar way can be done for grammar checking.

For example
"to be" phrase is passive voice and occurrences of the phrase would need to be highlighted both words "to" and "be" together.

Thanks and kind regards,

Extorian

Posted: Tue Oct 23, 2012 10:52 am
by Sergey Tkachenko
Do you know any grammar checker that could be used if TRichView implements API for using it?

Posted: Tue Oct 23, 2012 5:59 pm
by Extorian
We evaluated a few grammar checkers both offline and online before deciding on using the online free afterthedeadline service.

Among those we evaluated include Link grammar parser used by AbiWord, LanguageTool used by OpenOffice and Graviax. Some of these are merely parsers which you have to provide the rules and explanation, others like the languagetool are java apps or services which isn't really suitable for our purpose. Perhaps other readers here might have better luck with them.

We are thinking of wrapping afterthedeadline web api to work with our app. We can develop a vcl component that wraps the service and can collaborate to create a compatible api to integrate with TrichView/ScaleRichview. Let me know you thoughts.

Posted: Wed Oct 24, 2012 11:51 am
by Sergey Tkachenko
Is it really useful for "check as you type" grammar checking?

Posted: Wed Oct 24, 2012 4:38 pm
by Extorian
Yes, it can do it. Typically if you have "check as you type" enabled then, the app has to send to the service only when a sentence is complete. So it would check the sentence and return the results. This can be handled in a separate thread for seamless operation.

If you are doing a whole document check, we can send the whole document to the service and return the results as one block.

For example for sentence

He is to be here here.

The grammar check results would be in the following form.

Possibly an array.

Error phrase, error type, suggested replacement, url for more details
"to be", "passive voice", none,www. ...
"here here", "duplicate word","here", www. ...

In the above case, trichview would need to highlight all occurrences of "to be" and "here here" in the document. When the user right clicks, on popup can fill with the corresponding error type and suggestions after detecting the right clicked error phrase through a form of "GetCurrentMisspelling"

Posted: Wed Oct 24, 2012 5:03 pm
by Sergey Tkachenko
Does it return the position of an error in the string?

I am afraid we could not implement a grammar checking right now, we have too many half-completed projects. I can return to this problem only in the next year.

Performing a grammar checking on a click (similarly to their demo on the site) is very simple, but a background thread requires a considerable amount of work.

Posted: Wed Oct 24, 2012 6:06 pm
by Extorian
No unfortunately it does not return the position. Only the phrase.

Could you tell how to implement a simple grammar check on right click similar to their demo? With some code if you can? Mostly how to underline a phrase (in green) and how to detect on right click if it is on a bad phrase. We will try to carry on from there.

Thanks

Posted: Sun Oct 28, 2012 7:08 pm
by Sergey Tkachenko
I can give you an example as a starting point:
http://www.trichview.com/support/files/rectmarks.zip

This example uses the same mechanism as used for live-spelling underlines to mark some substrings. This example draws rectangles around the strings, but you can change them to underlines.

This unit contains the function
MarkSubstring(rv: TCustomRichView; const s: String; Color: TColor);
It marks all occurrences of s, it's just what you need.

I suggest to use RVGetTextRange(rv, 0, RVGetTextLength(rv)) (functions from RVLinear unit) to get a text string for checking.

(This solution is ok for small documents. However, it would be much more efficient to check paragraph by paragraph. You will need functions returning text in the paragraph, and a modification of MarkSubstring working only in this paragraph).

Posted: Sat Nov 03, 2012 4:47 pm
by Extorian
Thank you :)

Posted: Tue Dec 11, 2012 2:51 pm
by batbot113
I think http://proofreadbot.com/ is the best solution for your grammar checking in the same way.

Posted: Tue Dec 11, 2012 4:46 pm
by Extorian
Interesting service. But proofreadbot is commercial with no api. Afterthedeadline is open source and free. And they have a web api.