Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I parallelize check spelling using Delphi?

I've got a sort of spell checker written in Delphi. It analyzes the text sentence by sentence. It encolors wrong items according to some rules after parsing each sentence. The user is able to interrupt this process, which is important. How can I parallelize this process in general using some 3rd party Delphi libraries? In the current state I've got on the fly sentence coloration after check. Thus the user sees the progress.

like image 845
ilya Avatar asked Jun 15 '12 06:06

ilya


1 Answers

The algorithm would be as such:

  • Create multiple workers.
  • Create a spell-checker in each worker.
  • Grab the text and split it into work units (word or sentences). Each work unit must be accompanied with the location in original text.
  • Send work units to workers. Good approach is to send data into common queue from which workers are taking work units. Queue must either support multiple readers or you must use locking to access it.
  • Each worker takes a work unit, runs a spell-check and returns the result (together with the location in the original text) to the owner.
    • The simplest way to return a result is to send a message to the main thread.
    • Alternatively, you can write results into a result queue (which must either use locking or support multiple writers) and application can then poll those results (either from a timer or from the OnIdle handler).

How the multiple spell-checkers will access the dictionary is another problem. You can load a copy of the dictionary in each worker or you can protect access to the dictionary with a lock (but that would slow things down). If you are lucky, dictionary is thread-safe for reading and you can do simultaneous queries without locking.

Appropriate OmniThreadLibrary abstraction for the problem would be either a ParallelTask or a BackgroundWorker.

like image 160
gabr Avatar answered Oct 20 '22 00:10

gabr