View script | License | Download documentation as: HTML or editable |
Download script | History | Other scripts by: btiffin |
[0.055] 25.615k
Documentation for: dict-scheme.rUsage document for %dict-scheme.r1. Introduction to %dict-scheme.rdict-scheme.r is a sample port scheme for the dict:// protocol hosted off of http://dict.org, and defined in RFC2229. 1.1. Credits to Jeff KreisThe original REBOL dict:// port handler was found in the dict.org resources
2. dict-scheme At a GlanceNo setup is required, just do it. >> do %dict-scheme.r 2.1. A small demo applicationFor a demo, and a few console shortcuts, right out of the library>> do read http://www.rebol.org/library/scripts/%dict-demo.r 3. DICT protocol defined URLsdict://<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 4. Using %dict-scheme.rJust 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/ 4.1. Different functions of the dict protocolThe dict protocol allows for definition lookups and spell-checker style matches. Some examples
5. Return formatsThis 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. 6. Sophisticated URLsSome of the spell-check and word lookups may require use of character symbols that can cause confusion to the builtin REBOL url parser. 6.1. Spaces in <words>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. 6.2. Block port specsThe 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. 6.3. Open portsYou can use open to access a dict port, and then use copy to read the data. insert on the port will usually have error causing consequences, but reading with copy will work fine.7. The dict protocol hostsThere are quite a few active dict protocol servers. The main list is kept at the DICT protocol Server List 8. Strategies for MatchThese 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 9. DatabasesOnce 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. 9.1. Inforead dict:///info:lat-eng will return an information summary for a database, this example being the latin-english dictionary. 9.2. Running %dict-scheme.rFrom 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 10. What you can learnAs 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. 10.1. What you can change.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. 10.2. Default DICT protocol hostThis 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. 11. What can breakQuite 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 be off-line at any given moment, but that is unlikely as of July 2007. 12. Credits
|