dict-scheme.r is a sample port scheme for the dict:// protocol hosted off of http://dict.org, and defined in RFC2229.
dict-demo.r is a how-to and sample of usage for the dict protocol.
The original REBOL dict:// port handler was found in the dict.org resources
scheme | A REBOL term for a port protocol |
protocol | A set of formal rules describing how to transmit data especially across a network |
port | A REBOL I/O interface to external series |
No setup is required, just do it. Use one of the following
>> do %dict-demo.r or >> do-thru http://www.rebol.org/library/scripts/dict-demo.r or >> do read http://www.rebol.org/library/scripts/dict-demo.r or >>do http://www.rebol.org/cgi-bin/cgiwrap/rebol/download-a-script.r?script-name=dict-demo.r
For quick and easy access to rebol.org scripts, I have the following in my %user.r file.
rebol.org: http://www.rebol.org/library/scripts
When I want execute one of the stand-alone scripts I can use
>> do-thru rebol.org/dict-demo.r Script: "using dict protocol from dict.org" (17-Jul-2007) Script: "dict protocol from dict.org" (17-Jul-2007) dict protocol loaded You can now try: demo, def, thes, spell, soundex, regexp, trans, cia For demo and how-to...not thoroughly tested, maybe untrue >>
or for a version of REBOL that does not have to do-thru function
>> do read rebol.org/dict-demo.r connecting to: www.rebol.org connecting to: www.rebol.org dict protocol loaded You can now try: demo, def, thes, spell, soundex, regexp, trans, cia For demo and how-to...not thoroughly tested, maybe untrue >>
Nice and short and sweet. And for REBOL/View, it will rarely have to go to the Internet to get the code. It will usually be cached on the local disk. If there may have been an update to the rebol.org code, just use do-thru/update.
PLUS, if the script is one that needed modification for proper functioning, and you make a copy of those edits into the local sandbox (not the originals, too great a risk of overwrite) the do-thru rebol.org/script will pick up the local edit copy and hum away.
dorg: func [script] [ do to url! rejoin [ "http://www.rebol.org/cgi-bin/cgiwrap/rebol/download-a-script.r?script-name=" script ] ]
in your %user.r and then
>> dorg %dict-demo.r
will make me happy as I scan the library and see that people are enjoying the demo. You don't have to name the function dorg, it could be do-library or xyzzy if you are so inclined. Note: Anyone that doesn't know about xyzzy, has to check out ADVENT, if for nothing less than a history lesson.
End of side-trip, back to DICT.
The DICT demo, is just that, a demo. Don't expect the spell or thes functions to be world-class production ready functions. They will break in weird and wonderful ways, are not optimized or error checked in anyway what-so-ever. Only samples of what can be done. Having mentioned that disclaimer, the sample functions are pretty handy little command line tools.
demo | a simple point and click demo for REBOL/View or a blast of output for REBOL/Core |
def | fetches a definition |
thes | does a thesaurus database lookup |
spell | a quick and dirty spell-checker type word match options list |
soundex | word match using soundex |
regexp | word match using regular expressions, more common to GNU/Linux users, see man 7 regex |
endsinvowels | lookup up all the words in the database the end with four vowels |
trans | translate the word from whatever to whatever. Scans all the translation databases |
cia | lookup up the country in the CIA World FactBook 1995 edition |
The demo words work, but not well. More for fun and how-to than anything. These are just starting points for what a full-fledged DICT client could be in REBOL. You need to look at the code to get the most of this demo.
A lot of the rest of this material is also in the %dict-scheme.r usage document
dict://<user>;<auth>@<host>:<port>/d:<word>:<database> dict://<user>;<auth>@<host>:<port>/m:<word>:<database>:<strat>
The REBOL dict scheme will allow for
dict:///<word>
as a shortcut to the default host, and port and the default action is /define: (alias for /d:) and
dict://
to read the databases included with the default host.
This port handlers extends the /d: and /m: to include
without the terminating colons, the words will be treated as default definition lookups
Just as simply and easily as other REBOL network interfaces, you can
>> print read dict://
The dict:// is the scheme, and the %demo-scheme.r file includes a default host of all.dict.org . So that it is really print read dict://all.dict.org/
The dict protocol allows for definition lookups and spell-checker style matches.
Some examples
read dict:/// | Returns the default list of databases from the default host, all.dict.org |
read dict:///server: | Returns a server summary of the default host. Note the three slashes |
read dict://vocabulary.aioe.org/server: | Returns server summary of another dict protocol host, a very complete one |
read dict://dict.org/d:protocol:foldoc | Will read the definition of protocol from the Free On-Line Dictionary Of Computing |
read dict://dict.org/match:japan:soundex | Does a soundex spell-checker match for japan . match: is an extension alias for m: |
read dict:///strat: | Returns a list of match strategies, "exact" being the usual default. |
read dict:///define:Canada:world95 | Returns the complete entry for Canada from the CIA Book of World Facts, 1995 edition |
This port handler returns a block! for results. For all queries other than define, the block will contain a single string!. For /d: queries, the results will be one inner block! for each definition. So read dict://dict.org/define:test will return a block structure of
[{First def}][{Second def}]
being a block of blocks holding the strings.
Some of the spell-check and word lookups may require use of character symbols that can cause confusion to the builtin REBOL url parser.
RFC2229 allows for double-quote and single-quotes for surroundind spaces. REBOL will not allow a URL to contain " double-quotes. Use ' single-quotes instead.
Some Regular Expression characters will also cause confusion for URLs. Luckily REBOL allows a port to be opened using a control block.
The REBOL dict scheme can be accessed using the standard REBOL block spec for ports.
read [scheme: 'dict target: {define:'caveat emptor':bouvier}]
will allow you to lookup definitions for words with spaces, and
read [scheme: 'dict host: "vocabulary.aieo.org" target: {match:[a|b|c]$:gcide:re}]
will allow you to take full advantage of the re strategy when doing word matches.
There are quite a few active dict protocol servers. The main list is kept at the DICT protocol Server List
These are subject to change and may be different for each host, but all.dict.org supports
Using "." as a strategy allows the host to pick the best
Once again, subject to change, but all.dict.org has access to
In the full url you can specify one database or use "!" to allow the server to choice a best path, or "*" to force the server to use all the databases.
read dict:///info:lat-eng will return an information summary for a database, this example being the latin-english dictionary.
From the library with:
>> do http://www.rebol.org/cgi-bin/cgiwrap/rebol/download-a-script.r?script-name=dict-scheme.ror locally with:
>> do %dict-scheme.ror from the REBOL/View sandbox with
>> do-thru http://www.rebol.org/library/scripts/dict-scheme.r
As of July 2007, writing REBOL R2 port schemes is a little bit technically arcane. More documentation is promised, but the release of REBOL R3 may change the entire landscape so unless you are very curious, wait for the R3 documentation and the easier to manage port schemes.
One note. If you look at Jeff's original dict.rebol code, he used system/standard/port-flags/direct, and redefined the Root-Protocol read handler. This version uses system/standard/port-flags/pass-thru and defines the copy function for the handler. This version allows for a more REBOL standard way of accessing a dict:// port.
Currently this scheme does not implement authentication. If you need access to a proprietary dictionary, you may need to change this handler to support those features of the protocol.
The scheme could be changed to throw less errors by adding response handlers for status codes like "420", but it's sometimes better to let a high level error handler do its thing instead.
This may be something to change depending on expected use. The current default of "all.dict.org" is a DNS round-robin of dict?.us.dict.org, and will try different primary servers for each request. But there are some other servers that you may wish to make the default. See the list mentioned above for the options, and perhaps a search of dict protocol on the Internet could highlight others.
Quite a few things could break here. Errors are left to be thrown on response codes that are not (but could be) recognized. An application that relies on this scheme will need judicious use of error? try and attempt blocks.
No guarantees on availability, and these servers may de off-line at any given moment, but that is unlikely as of July 2007.
%dict-demo.r | Author: Brian Tiffin |
%dict-scheme.r | Author: Brian Tiffin |
%dict-rebol.r | Author: Jeff Kreis |