FZF + WordNet = Dictionary
FZF + WordNet = Dictionary. FZF is a fuzzy finding command line tool. WordNet
is a dictionary structured for developers. When married together, we can get
a snappy dictionary to help us find just the right word for any occasion.
Install Required Program
Before making our new shell function, lets install the required programs.
These directions are for Max OSX with
homebrew installed. If you’re on
a different system, read the docs from the sites above to get the programs for
your operating system.
1 2 3
FZF stands for Fuzzy Finder. It is a program which enables the user to filter
a set of lines from standard in and feed those line back to standard out.
A basic example is:
find . | fzf. This presents a list of all files in the
current working directory and prompts the user for input. As you type letters, the
list will narrow, keeping only the items matching the search criteria. After
selecting an entry from the list the line or lines chosen is printed to standard
out. It provides a nifty argument
--preview which can execute a program and
display its output as an aside in the terminal. We’ll write more about FZF in the
WordNet is a large lexical database of English. Nouns, verbs, adjectives and adverbs are grouped into sets of cognitive synonyms (synsets), each expressing a distinct concept. Synsets are interlinked by means of conceptual-semantic and lexical relations. The resulting network of meaningfully related words and concepts can be navigated with the browser. WordNet is also freely and publicly available for download. WordNet’s structure makes it a useful tool for computational linguistics and natural language processing.
WordNet superficially resembles a thesaurus, in that it groups words together based on their meanings. However, there are some important distinctions. First, WordNet interlinks not just word forms—strings of letters—but specific senses of words. As a result, words that are found in close proximity to one another in the network are semantically disambiguated. Second, WordNet labels the semantic relations among words, whereas the groupings of words in a thesaurus does not follow any explicit pattern other than meaning similarity.
Using WordNet we can find information similar to what is in a dictionary and thesaurus combined.
Example output of looking up
1 2 3 4 5 6 7 8 9 10
xquartz is needed since the WordNet package also works in GUI mode. The GUI
app has a useful interface and could be more intuitive to use if you don’t mind
clicking around. The GUI app can be started with
wnb, but we’re not here for
GUI stuff. Let’s move on to making our terminal script.
The following 3 functions can be used individually and are helpful all on their own. Add these directly into your shell profile or in a separate file and source it from the profile.
fold is normally a built in command. By default it adds newlines when text
overflows the terminal, but it doesn’t do it in an easy to read fashion. The
default behavior can break in the middle of a word and assumes a terminal width
of 80 columns. Our
fold function breaks at spaces and passes the whole
terminal width to it when no other arguments are provided.
1 2 3 4 5 6 7 8
spell is the FZF portion of our script. This fuzzy matches the built in Mac
dictionary with a preview window containing the WordNet overview of the selected
1 2 3 4
dic script uses
spell to help find a word then outputs WordNet’s
1 2 3 4 5 6 7 8 9 10 11 12 13
Here’s another demo of the
Gluing programs together with
fzf --preview is fun. Let us know what other
recipes you come up with in the comments below.