Grammar check

General TRichView support forum. Please post your questions here
Post Reply
Extorian
Posts: 24
Joined: Wed Dec 28, 2011 3:52 pm

Grammar check

Post 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
Sergey Tkachenko
Site Admin
Posts: 17566
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Do you know any grammar checker that could be used if TRichView implements API for using it?
Extorian
Posts: 24
Joined: Wed Dec 28, 2011 3:52 pm

Post 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.
Sergey Tkachenko
Site Admin
Posts: 17566
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Is it really useful for "check as you type" grammar checking?
Extorian
Posts: 24
Joined: Wed Dec 28, 2011 3:52 pm

Post 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"
Sergey Tkachenko
Site Admin
Posts: 17566
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post 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.
Extorian
Posts: 24
Joined: Wed Dec 28, 2011 3:52 pm

Post 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
Sergey Tkachenko
Site Admin
Posts: 17566
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post 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).
Extorian
Posts: 24
Joined: Wed Dec 28, 2011 3:52 pm

Post by Extorian »

Thank you :)
batbot113
Posts: 1
Joined: Tue Dec 11, 2012 2:12 pm

Post by batbot113 »

I think http://proofreadbot.com/ is the best solution for your grammar checking in the same way.
Extorian
Posts: 24
Joined: Wed Dec 28, 2011 3:52 pm

Post by Extorian »

Interesting service. But proofreadbot is commercial with no api. Afterthedeadline is open source and free. And they have a web api.
Post Reply