Skip to content

Instantly share code, notes, and snippets.

@ddrscott
Created May 12, 2017 19:24
Show Gist options
  • Save ddrscott/bb53c3805c327fccee5ad38de9669840 to your computer and use it in GitHub Desktop.
Save ddrscott/bb53c3805c327fccee5ad38de9669840 to your computer and use it in GitHub Desktop.
Wrapper scripts around the excellent WordNet CLI tools.

WordNet

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.

TL;DR - Dictionary and thesaurus for engineers

Installation

# install dependency
brew cask install xquartz
 
# install the CLI
brew install wordnet

Utilization

# See the options
wn    
 
# Lookup a word overview
wn cool -over

# > Overview of noun cool
# > 
# > The noun cool has 2 senses (no senses from tagged texts)
# > 
# > 1. cool -- (the quality of being at a refreshingly low temperature; "the cool
# > of early morning")
# > 2. aplomb, assuredness, cool, poise, sang-froid -- (great coolness and
# > composure under strain; "keep your cool")
# > ...

Helper Shell Functions

Install wn-helpers.sh in your shell to get some useful shortcuts.

Requires FZF for fuzzy finding brew install fzf

# fuzzy find spelling of a word
spell

# fuzzy find definition of word in WordNet dictionary
dic

# I know the word, just lookup the definition
dic cool

# fuzzy find the synonymn of a word
syn

# I know the word, just get me similar words
syn cool
# Default `fold` to screen width and break at spaces
function fold {
if [ $# -eq 0 ]; then
/usr/bin/fold -w $COLUMNS -s
else
/usr/bin/fold $*
fi
}
# Use `fzf` against system dictionary
function spell {
cat /usr/share/dict/words | fzf
}
# Lookup definition of word using `wn $1 -over`.
# If $1 is not provided, we'll use the `spell` command to pick a word.
#
# Requires:
# brew install wordnet
# brew install fzf
function dic {
if [ $# -eq 0 ]; then
wn `spell` -over | fold
else
wn $1 -over | fold
fi
}
# Lookup synonym of word using `wn $1 -synsn - synsa`.
# If $1 is not provided, we'll use the `spell` command to pick a word.
#
# Requires:
# brew install wordnet
# brew install fzf
function syn {
if [ $# -eq 0 ]; then
wn `spell` -synsn -synsa | fold
else
wn $1 -synsn -synsa | fold
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment