Skip to content

Instantly share code, notes, and snippets.

@charneykaye
Last active August 25, 2016 21:17
Show Gist options
  • Save charneykaye/ff0a1321412e4d79d4937b527752363f to your computer and use it in GitHub Desktop.
Save charneykaye/ff0a1321412e4d79d4937b527752363f to your computer and use it in GitHub Desktop.
Clean Thesaurus Lookup with Multi-word Intersection
#!/usr/bin/env bash
#
# Clean Thesaurus Lookup with Multi-word Intersection
#
# Author: Charney Kaye <charney.io>
#
# Requires *nix packages:
# dict dictd dict-moby-thesurus
#
# prefix to temporary saved text files
Saved=tmp/thx-
# arguments
if [ "$#" -eq 1 ]; then
LOOKUP=1
Word1=$1
elif [ "$#" -eq 2 ]; then
LOOKUP=2
Word1=$1
Word2=$2
elif [ "$#" -eq 3 ]; then
LOOKUP=3
Word1=$1
Word2=$2
Word3=$3
else
echo "Currently only supports lookups between 1 and 3 words."
exit 1
fi
#
function ThesaurusLookup() {
dict -d moby-thesaurus ${1} | tail -n +6 | sed -e 's/,/\n/g' | sed -e 's/^\s*//g' | sed '/^$/d' | sort
}
# lookups
if [ ${LOOKUP} -eq 1 ]; then
ThesaurusLookup ${Word1} | tee ${Saved}${Word1}
elif [ ${LOOKUP} -eq 2 ]; then
ThesaurusLookup ${Word1} > ${Saved}${Word1}
ThesaurusLookup ${Word2} > ${Saved}${Word2}
comm -1 -2 ${Saved}${Word1} ${Saved}${Word2}
elif [ ${LOOKUP} -eq 3 ]; then
ThesaurusLookup ${Word1} > ${Saved}${Word1}
ThesaurusLookup ${Word2} > ${Saved}${Word2}
ThesaurusLookup ${Word3} > ${Saved}${Word3}
comm -1 -2 ${Saved}${Word1} ${Saved}${Word2} > ${Saved}${Word1}-${Word2}
comm -1 -2 ${Saved}${Word1}-${Word2} ${Saved}${Word3}
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment