NAME

lexicon - dict client

SYNOPSIS

include "bufio.m";
include "lexicon.m";
lexicon := load Lexicon Lexicon->PATH;

open:   fn(addr: string): (ref Lex, string);
fopen:  fn(fd: ref Sys->FD): (ref Lex, string);

Lex: adt {
	lexicons:       fn(l: self ref Lex): (list of (string, string), string);
	strategies:     fn(l: self ref Lex): (list of (string, string), string);
	serverinfo:     fn(l: self ref Lex): (string, string);
	lexiconinfo:    fn(l: self ref Lex, lexicon: string):
				(string, string);
	match:          fn(l: self ref Lex, word, lexicon, strategy: string):
				(list of (string, string), string);
	define:         fn(l: self ref Lex, word, lexicon: string):
				(list of (string, string, string, string), string);
	setdebug:       fn(l: self ref Lex, debug: int);
};

DESCRIPTION

Lex represents a connection to a dict server. The dict protocol is specified in rfc2229. Open dials addr and performs the dict handshake. Fopen uses fd as connection and performs the dict handshake on it. Both functions return a tuple (ref Lex, err) with err non-nil when an error occurred. Once connected, the lex provides the following routines, they all have tuples of the form (results, err) with err non-nil in case of an error.

lex.lexicons()
Return list of lexicons available at the server. Each tuple is of the form (short name, descriptive name).
lex.strategies()
Return list of strategies available at the server. Each tuple is of the form (short name, descriptive name).
lex.serverinfo()
Return information about the server.
lex.lexiconinfo(lexicon)
Return information about lexicon.
lex.match(name",lexicon,strategy)
Find words in lexicon that match word using strategy. Each tuple in the result is of the form (lexicon, word).
lex.define(word",lexicon)
Retrieve definition for word in lexicon . Each tuple in the result is of the form (word, lexicon name, lexicon description, definition).
lex.setdebug(debug)
Set debugging to debug. ``0'' suppresses all debug information, ``1'' prints all protocol messages to standard error.

For match and define special values for lexicon are recognized (by the dict server): ``!'' for querying all databases until a match has been found, and ``*'' for querying all databases and continuing even when matches have been found.

SOURCE

/appl/lib/lexicon.b

SEE ALSO

hdict(1)

``A Dictionary Server Protocol'', rfc2229.

CAVEATS

Many `features' from the specification are unsupported. These include authentication, MIME responses, dict URL's, command pipelining and extensions.

BUGS

Support for automatically reconnecting is missing.
The error codes returned by the dict server are not parsed other than to determine whether the operation was successful. However, the error messages returned by the functions contain the full error response from the server.

LEXICON(2 ) Rev:  Wed Oct 31 21:58:07 GMT 2007