Hemanth's Scribes

web

Experiments With Dictionary Server Protocol Linux | RFC 2229

Author Photo

Hemanth HM

Thumbnail

Experiments With Dictionary Server Protocol Linux | RFC 2229

There RFC 2229 defines the The Dictionary Server Protocol (DICT) is a TCP transaction based query/response protocol that allows a client to access dictionary definitions from a set of natural language dictionary databases.

The most common play with the DICT , that most people are aware is : curl -s dict://dict.org/d:word

Exploring this a more , and using few quick cli utilities i tried the below.

But with the most common method as mentioned above the negative aspect is reflected when we have a huge list of words for which you are in need of it’s meanings.

Assume that the list of words are in a file called “list” and the end of the trick you will have the meanings ins a file called “meanings”

  1. With “dict” utility , if on debian just do an apt-get install dict, then: cat list | xargs -n1 dict >> meanings

  2. Using a simple Bash script : while read word; do curl dict://dict.org/d:$word >> meanings done < list

3.With sed and curl : sed 's##dict://dict.org/d:#' list | xargs -d $'\n' curl > meanings

I hope “can’t” isn’t in your word list.Using xargs there means you DO have a loop, you just can’t see it. Also, it’s got broken parsing.If there’s a ”’“[apostrophe] in one of the words, it’ll fail. Solution : sed 's##dict://dict.org/d:#' list | tr '\n' '\0' | xargs -0 curl > meanings

It’s a bit ugly imo, but it replaces all \ns with \0s, since \0 is the only delimiter where xargs will not treat ”’” [apostrophe] specially.

You may wonder what does the ## and # signify in sed ? sed users are familiar with sed substitutions: s/pattern/replacement/ whichever character is after the s will be used as the separator. It doesn’t have to be / since the replacement contained /, it’s easier to use a different separator rather than escape each / dict:// [Ugly escape].

#javascript#linux
Author Photo

About Hemanth HM

Hemanth HM is a Sr. Machine Learning Manager at PayPal, Google Developer Expert, TC39 delegate, FOSS advocate, and community leader with a passion for programming, AI, and open-source contributions.