Documention for: dict-scheme.r Created by: btiffin on: 18-Jul-2007 Last updated by: btiffin on: 18-Jul-2007 Format: text/editable Downloaded on: 30-Apr-2025 [h1 Usage document for %dict-scheme.r [contents [numbering-on [h2 Introduction to %dict-scheme.r [p dict-scheme.r is a sample port scheme for the dict:// protocol hosted off of http://dict.org, and defined in RFC2229. [h3 Credits to Jeff Kreis [p The original REBOL dict:// port handler was found in the [link ftp://ftp.dict.org/pub/dict/contrib/dict.rebol "dict.org resources" [table/att/border="1px"/att/cellpadding="4px" [row [cell **scheme** [cell A REBOL term for a port protocol [row [cell **protocol** [cell A set of formal rules describing how to transmit data especially across a network [row [cell **port** [cell A REBOL I/O interface to external series table] [h2 dict-scheme At a Glance [p No setup is required, just **do** it. [asis >> do %dict-scheme.r asis] [h3 A small demo application For a demo, and a few console shortcuts, right out of the library [asis >> do read http://www.rebol.org/library/scripts/%dict-demo.r asis] [h2 DICT protocol defined URLs [asis dict://<user>;<auth>@<host>:<port>/d:<word>:<database> dict://<user>;<auth>@<host>:<port>/m:<word>:<database>:<strat> asis] [p The REBOL **dict** scheme will allow for [asis dict:///<word> asis] [p as a shortcut to the default host, and port and the default action is /define: (alias for /d:) and [asis dict:// asis] [p to read the databases included with the default host. [p This port handlers extends the /d: and /m: to include [list [li /match:word:database:strat [li /define:word:database [li /help: [li /strat: [li /server [li /info:database [li /status: list] [p without the terminating colons, the words will be treated as default definition lookups [h2 Using %dict-scheme.r [p Just as simply and easily as other REBOL network interfaces, you can [asis >> print read dict:// asis] [p 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/ [h3 Different functions of the dict protocol [p The **dict** protocol allows for **definition** lookups and spell-checker style **match**es. [p Some examples [table/att/border="1px"/att/cellpadding="4px" [row [cell read dict:/// [cell Returns the default list of databases from the default host, all.dict.org [row [cell read dict:///server: [cell Returns a server summary of the default host. Note the three slashes [row [cell read dict://vocabulary.aioe.org/server: [cell Returns server summary of another dict protocol host, a very complete one [row [cell read dict://dict.org/d:protocol:foldoc [cell Will read the definition of "protocol" from the Free On-Line Dictionary Of Computing [row [cell read dict://dict.org/match:japan:soundex [cell Does a soundex spell-checker match for ""japan"". match: is an extension alias for m: [row [cell read dict:///strat: [cell Returns a list of match strategies, ""exact"" being the usual default. [row [cell read dict:///define:Canada:world95 [cell Returns the complete entry for Canada from the CIA Book of World Facts, 1995 edition table] [h2 Return formats [p 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 [asis [[{First def}][{Second def}]] asis] [p being a block of blocks holding the strings. [h2 Sophisticated URLs [p Some of the spell-check and word lookups may require use of character symbols that can cause confusion to the builtin REBOL url parser. [h3 Spaces in <words> [p 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. [p Some Regular Expression characters will also cause confusion for URLs. Luckily REBOL allows a port to be opened using a control block. [h3 Block port specs [p The REBOL **dict** scheme can be accessed using the standard REBOL block spec for ports. [asis read [scheme: 'dict target: {define:'caveat emptor':bouvier}] asis] [p will allow you to lookup definitions for words with spaces, and [asis read [scheme: 'dict host: ""vocabulary.aieo.org"" target: {match:[a|b|c]$:gcide:re}] asis] [p will allow you to take full advantage of the **re** strategy when doing word matches. [h3 Open ports You 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. [h2 The dict protocol hosts [p There are quite a few active **dict** protocol servers. The main list is kept at the [link http://luetzschena-stahmeln.de/dictd/index.php "DICT protocol Server List" [h2 Strategies for Match [p These are subject to change and may be different for each host, but all.dict.org supports [list [li exact "Match headwords exactly" [li prefix "Match prefixes" [li substring "Match substring occurring anywhere in a headword" [li suffix "Match suffixes" [li re "POSIX 1003.2 (modern) regular expressions" [li regexp "Old (basic) regular expressions" [li soundex "Match using SOUNDEX algorithm" [li lev "Match headwords within Levenshtein distance one" [li word "Match separate words within headwords" list] [p Using "." as a strategy allows the host to pick the best [h2 Databases [p Once again, subject to change, but all.dict.org has access to [list [li gcide "The Collaborative International Dictionary of English v.0.48" [li wn "WordNet (r) 2.0" [li moby-thes "Moby Thesaurus II by Grady Ward, 1.0" [li elements "Elements database 20001107" [li vera "Virtual Entity of Relevant Acronyms (Version 1.9, June 2002)" [li jargon "Jargon File (4.3.1, 29 Jun 2001)" [li foldoc "The Free On-line Dictionary of Computing (27 SEP 03)" [li easton "Easton's 1897 Bible Dictionary" [li hitchcock "Hitchcock's Bible Names Dictionary (late 1800's)" [li bouvier "Bouvier's Law Dictionary, Revised 6th Ed (1856)" [li devils "THE DEVIL'S DICTIONARY ((C)1911 Released April 15 1993)" [li world02 "CIA World Factbook 2002" [li gazetteer "U.S. Gazetteer (1990)" [li gaz-county "U.S. Gazetteer Counties (2000)" [li gaz-place "U.S. Gazetteer Places (2000)" [li gaz-zip "U.S. Gazetteer Zip Code Tabulation Areas (2000)" [li --exit-- "Stop default search here." [li afr-deu "Africaan-German Freedict dictionary" [li afr-eng "Africaan-English Freedict Dictionary" [li ara-eng "English-Arabic Freedict Dictionary" [li cro-eng "Croatian-English Freedict Dictionary" [li cze-eng "Czech-English Freedict dictionary" [li dan-eng "Danish-English Freedict dictionary" [li deu-eng "German-English Freedict dictionary" [li deu-fra "German-French Freedict dictionary" [li deu-ita "German-Italian Freedict dictionary" [li deu-nld "German-Nederland Freedict dictionary" [li deu-por "German-Portugese Freedict dictionary" [li eng-afr "English-Africaan Freedict Dictionary" [li eng-ara "English-Arabic FreeDict Dictionary" [li eng-cro "English-Croatian Freedict Dictionary" [li eng-cze "English-Czech fdicts/FreeDict Dictionary" [li eng-deu "English-German Freedict dictionary" [li eng-fra "English-French Freedict Dictionary" [li eng-hin "English-Hindi Freedict Dictionary" [li eng-hun "English-Hungarian Freedict Dictionary" [li eng-iri "English-Irish Freedict dictionary" [li eng-ita "English-Italian Freedict dictionary" [li eng-lat "English-Latin Freedict dictionary" [li eng-nld "English-Netherlands Freedict dictionary" [li eng-por "English-Portugese Freedict dictionary" [li eng-rom "English-Romanian FreeDict dictionary" [li eng-rus "English-Russian Freedict dictionary" [li eng-spa "English-Spanish Freedict dictionary" [li eng-swa "English-Swahili xFried/FreeDict Dictionary" [li eng-swe "English-Swedish Freedict dictionary" [li eng-tur "English-Turkish FreeDict Dictionary" [li eng-wel "English-Welsh Freedict dictionary" [li fra-deu "French-German Freedict dictionary" [li fra-eng "French-English Freedict dictionary" [li fra-nld "French-Nederlands Freedict dictionary" [li hin-eng "English-Hindi Freedict Dictionary [reverse index]" [li hun-eng "Hungarian-English FreeDict Dictionary" [li iri-eng "Irish-English Freedict dictionary" [li ita-deu "Italian-German Freedict dictionary" [li jpn-deu "Japanese-German Freedict dictionary" [li kha-deu "Khasi-German FreeDict Dictionary" [li lat-deu "Latin-German Freedict dictionary" [li lat-eng "Latin-English Freedict dictionary" [li nld-deu "Nederlands-German Freedict dictionary" [li nld-eng "Nederlands-English Freedict dictionary" [li nld-fra "Nederlands-French Freedict dictionary" [li por-deu "Portugese-German Freedict dictionary" [li por-eng "Portugese-English Freedict dictionary" [li sco-deu "Scottish-German Freedict dictionary" [li scr-eng "Serbo-Croat-English Freedict dictionary" [li slo-eng "Slovenian-English Freedict dictionary" [li spa-eng "Spanish-English Freedict dictionary" [li swa-eng "Swahili-English xFried/FreeDict Dictionary" [li swe-eng "Swedish-English Freedict dictionary" [li tur-deu "Turkish-German Freedict dictionary" [li tur-eng "Turkish-English Freedict dictionary" [li english "English Monolingual Dictionaries" [li trans "Translating Dictionaries" [li all "All Dictionaries (English-Only and Translating)" [li web1913 "Webster's Revised Unabridged Dictionary (1913)" [li world95 "The CIA World Factbook (1995)" list] [p 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. [h3 Info [p read dict:///info:lat-eng will return an information summary for a database, this example being the latin-english dictionary. [h3 Running %dict-scheme.r [p From the library with: [asis/style/font-size:75% >> do http://www.rebol.org/cgi-bin/cgiwrap/rebol/download-a-script.r?script-name=dict-scheme.r asis] or locally with: [asis >> do %dict-scheme.r asis] or from the REBOL/View sandbox with [asis >> do-thru http://www.rebol.org/library/scripts/dict-scheme.r asis] [h2 What you can learn [p 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. [p 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. [h3 What you can change. [p 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. [p 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. [h3 Default DICT protocol host [p 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. [h2 What can break [p 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. [p No guarantees on availability, and these servers may be off-line at any given moment, but that is unlikely as of July 2007. [h2 Credits [table/att/border="1px"/att/cellpadding="4px" [row [cell %dict-scheme.r [cell Author: Brian Tiffin [row [cell %dict.rebol [cell Author: Jeff Kreis table] [list [li The rebol.org Library Team [li Usage document by Brian Tiffin, Library Team Apprentice, [date list]