APL DICT Client
for Windows
The Dictionary Server Protocol (RFC 2229) defines a standard for TCP access to lexical and informational databases in the public domain. DICT servers provide a variety of dictionary databases, such as common and specialized word definitions, language-pair translations, thesaurus, geographic places, and atomic elements, to mention a few. Although several Web/browser-based DICT clients exist (see resources at dict.org), there are advantages to using a direct TCP client, including faster operational speed, easier means for saving and utilizing results, and greater flexibility in creating custom engines or interfaces that fit within other applications. The example workspace described below demonstrates a simple DICT client developed in APL. A complete, self-installing runtime version also is available.
Previous users please note: Since Microsoft has removed the DHTML control from Windows Vista, the default display for this application has been changed to a Microsoft WebBrowser control. Vista users still can use the DHTML display if desired by installing the DHTML Editing Control for Applications Redistributable Package (x86) from Microsoft and changing the .ini configuration as discussed below.
This APL+Win workspace offers an example of a DICT client with the GUI shown below. It features essentially the same functionality as typical Web-based clients, with the following exceptions:
- Multiple DICT servers are available for connection
- DICT-protocol commands are exposed to the user/developer
- Searched words are saved in a dropdown list for the current session
- All text responses in a session can be appended to a scrollable, editable display
Runtime Users: The technical discussion below applies mostly to the development version. The runtime version operates the same way, however all the configuration options mentioned are accessible via the ini file.
To operate the example, load the workspace and execute function "RunADC" in the APL+Win session manager. Selecting a DICT server from the list automatically attempts to connect and request its database list (SHOW DB command) and strategy list (SHOW STRAT command) which are then placed in the designated combo boxes. (DICT servers not on the default list can be typed in or added to the [DICTservers] section of the ini file.) Select a DICT command from the dropdown list, select or enter any parameters required by that particular command, then click the Submit button. Text results are displayed in the response window. Coded server responses (such as "552 no match") are displayed on the status bar at the bottom of the window. The most relevant user commands are:
- DEFINE database word
- Enter a word or words to look-up; optionally select a specific database.
- Returns definitions or other information from databases where the word is found.
- MATCH database strategy word
- Enter a word or words to look-up; optionally select a specific database and/or search strategy.
- Returns names of databases where the word is found; use results to select a specific database for the DEFINE command.
- SHOW INFO database
- Retrieves information about the selected database.
While connected to a DICT server, the server dropdown list is disabled and the QUIT command must be sent before another server can be selected. If the DICT server times out and disconnects due to inactivity, the client should re-connect automatically when the next command is sent. If not, submit the "connect" command to re-connect to the same or another server. In the runtime version, the last-used DICT server, database and strategy are saved in the ini file and automatically connected the next time the program is run. To prevent this behavior, leave the server blank before closing the program, or, to disable it entirely, set AutoConnect=0 in the ini file.
The example is coded to allow use of an Edit, DHTML, RichEdit (RTF) or Microsoft WebBrowser control to display server text responses. With the DHTML, RichEdit and WebBrowser controls, responses are appended to the existing text; with the Edit control, each response replaces the previous. The default for this example is the WebBrowser control, since it can display Unicode characters (and the DHTML control will not be available in Windows Vista.) To use one of the other controls, open the function InitADC (or ini file) and change the "Display" variable assignment to 'dhtml', 'edit' or 'richedit'. Be aware that HTML character-entity codes for Unicode characters are lost when text is copied from the Microsoft DHTML or WebBrowser controls. If you want to see these codes, operate the client with the Edit or RichEdit display.
Prior to IE 7, the DHTML control would not display some Unicode characters if standard Windows fonts were used. This example is coded to use Microsoft's "Courier New" as the default font. Alternate fonts can be specified (see functions InitADC and adcHTML, or the ini file). "Gentium" is a free Unicode serif typeface available from SIL International. Another good one is the Bitstream Vera open-source font set which contains serif, sans-serif and monospace faces.
Additional notes:
- The example uses APL+Win quad-NI sockets and standard Windows GUI controls, and Microsoft's WebBrowser ActiveX objects
- The word list, up to 40 entries, is now saved to the ini file and restored with each session (previous versions did not do this.)
- Response text is not saved, but can be copied and pasted into other applications. It also can be printed directly from the WebBrowser control (access with the right-click popup menu.)
- Style attributes for displaying dictionary headwords in the DHTML or WebBrowser controls are now exposed to users in the ini file. Defaults are blue, bold, transparent background.
- As APL+Win 4 does not support Unicode, the client cannot display Unicode characters in the standard Windows GUI controls or in the Edit or RichEdit controls. However, as of version 2, the database list is presented as a dropdown box in a Microsoft WebBrowser control in order to display Unicode characters present in some database lists.
- The hard-coded CLIENT description string and command list can be changed as desired (see adcClient, InitADC and fmADC_Make) or converted to user options
- AUTH, SASLAUTH, SASLRESP, and OPTION MIME commands have not been implemented
- This client does not display Chinese characters correctly from English-Chinese dictionaries served by lividict.org. The TCP stream received for definitions does not appear to be the same as that sent to lividict's browser client and appears to contain invalid UTF-8 byte-sequences for Chinese characters.
- It is not advisable to submit the request DEFINE "00-database-info" for database "[any]" to lividict.org. They return about a 9MB response which, if it doesn't crash APL+Win, may freeze your system.
- As of this writing (17 Oct 2006) the built-in dict-server list includes all the servers reported at DICT protocol server list. For unknown reasons dict.aioe.org has not responded to this client since June 2006 and has been removed from my list; vocabulary.aioe.org responded once today but not since. However, this client contains a time-out feature so you shouldn't get stuck trying to access non-responding servers. The server list can be edited via the ini file as noted above.
With some modifications, the techniques demonstrated in this example should be adaptable for APL applications where online access to dictionary information would be useful.