Spellchecking API

General

With the Spellchecking API you can spell-check mass data using a service which can be performed in the background (e.g. as a server job). The SpellCheckService supports spell-checking of the plain texts as well as EntityItems. Depending on the input for the spell-checking you get also a corresponding result with the objects with the incorrect words. The SpellCheckService is placed in PIM Core so it can be used on the server as well as on the client, in PIM Desktop as well as in PIM Web. The service delegates all requests to the corresponding RequestHandler on the server, so the spell-checking itself will be always performed server-side. See also the architecture picture below.

Architecture

images/download/attachments/47908177/SpellCheckService_Architecture.png

The SpellCheckService uses the RequestHandler to spell-check the input data on the PIM Server. The RequestHandler again uses for each object to spell-check the already existed SpellngService (which is also used from the UI to spell-check a text from the text field "on the fly" when editing). So the SpellCheckService uses the same Dictionaries as the spell-checking process in the UI.

Usage

Plain texts

The simplest usage of the SpellCheckService is to the spell-check one or many plain texts:

String[] textsToCheck = { "Text1", "Text2", "Text3" };
SpellCheckService spellCheckService = SpellCheckComponent.getSpellCheckService();
TextSpellCheckServiceResult result = spellCheckService.check( progressMonitor, ThreadLocale.getDefault(),
textsToCheck );

As result you receive an instance of type TextSpellCheckServiceResult. It provides methods to determine whether every single text is spelled correctly. You can also get the ResultDetails for each incorrect text which contains all incorrect words of the text (including the start and the end index of each incorrect word relative to the whole text).

EntityItems

For more advanced usage there are methods to spell-check values of specific fields of one or many EntityItems:

EntityProxy[] entityProxies = new EntityProxy[] { article1, article2, article3 };
EntityItemList itemList = new ArrayEntityItemList( articleEntity, entityProxies );
FieldPath[] fieldPaths = getFieldPathForSpellChecking();
SpellCheckService spellCheckService = SpellCheckComponent.getSpellCheckService();
RevisionToken revisionToken = RevisionContext.getInstance()
.getRevisionToken();
EntityItemSpellCheckServiceResult result = spellCheckService.check( progressMonitor, revisionToken,
ThreadLocale.getDefault(), itemList, fieldPaths );

NOTE: the FieldPaths using for the spell-checking should be full-qualified and contain the current revision, otherwsie the spell-checking can not be performed properly.

As result you receive an instance of type EntityItemSpellCheckServiceResult. It provides methods to get all entityItems which contain incorrect texts. You can also get for each item and for each fieldPath the corresponding ResultDetails which contains all incorrct words (including the start and the end index of each incorrect word relative to the whole text).

SpellCheckServiceJob

If you want to run the spell-checking process as a server job, use the corresponding SpellCheckServiceJob instead of using the SpellCheckService directly:

RevisionToken revisionToken = RevisionContext.getInstance()
.getRevisionToken();
SpellCheckServiceParam param = new SpellCheckServiceParam( null, revisionToken, itemList, fieldPaths );
Serializable2DomPersistableAdapter serverJobParam = new Serializable2DomPersistableAdapter( param );
ServerJobScheduler.getInstance()
.schedule( "SpellCheckService", serverJobParam, null, null, null );

The result of the spell-checking process you can see in the corresponding process overview category "Spellcheck". All items with incorrect words will be listed in the ploblemLog of the corresponding server job.

REST API

The SpellCheckService can be also used via REST Service API. Currently only one REST support for the spell-checking is implemented: spell-checking of the plain text. So you can send a POST request using specific URL including the text which should be spell-checked as a request body:

images/download/attachments/47908177/spell_check_rest_example.png

As result you get a HTML string which contains the input text including the highlighting HTML-tags around the incorrect words.

For the future also other REST support for the spell-checking is proposed. Fill free to inform the PIM dev team which kind of REST API for the spell-checking would be useful.

Examples

As examples of the usage of the SpellCheckService there are two UI commands which are contributed for several views and can be performed from the user to spell-check corresponding entity items.

Both examples can be found in the SDK examples: sdk\examples\customizing\com.heiler.ppm.customizing.spelling.ui

Spellcheck items

images/download/attachments/47908177/spellcheck_api_example_1.png

The command handler for this menu contribution uses the SpellCheckService directly and let spell-check the short and long descriptions of all selected items. The result will be shown as a ProblemLog-Dialog.

Spellcheck catalog

images/download/attachments/47908177/spellcheck_api_example_2.png

The command handler for this menu contribution performs a server job - SpellCheckServiceJob - and let spell-check the short and long descriptions of all items from the selected catalog. The result can be viewed in the process overview.