-
Notifications
You must be signed in to change notification settings - Fork 0
/
getsyllabification.sh
executable file
·57 lines (53 loc) · 1.68 KB
/
getsyllabification.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/bin/bash
# help
display_help() {
echo "Usage: $0 [option...] " >&2
echo
echo " -h, --help Display this help message"
echo " -d, --dictionary Specify dictionary to get syllabification. The available options are: 'ws' (for wordsmyth). The following are not working anymore: 'dc' (for dictionary.com) and 'mw' (for merriam-webster)"
echo " -i, --input-file Specify input file with list of words (one word per line)"
echo
exit 1
}
DIC='ws' #default
while [[ $# -gt 0 ]]; do
key="$1"
case "$key" in
-d|--dictionary)
shift
DIC="$1"
;;
-i|--input-file)
shift
INFILE="$1"
;;
-h | --help)
display_help # Call your function
exit 0
;;
*)
esac
# Shift after checking all the cases to get the next option
shift
done
while read line
do
SYLLABLES=""
case "$DIC" in
dc) SYLLABLES="$(curl -k -s https://www.dictionary.com/browse/$line | grep -o '<span class="pron-spell-content.*]<\/span>' | sed -e 's/<[^>]*>//g' | sed 's/[][\ ]//g')"
;;
mw) SYLLABLES="$(curl -s https://www.merriam-webster.com/dictionary/$line | grep '<span\ class="word-syllables">' | uniq | sed -e 's/[[:space:]]\+<span class="word-syllables">\(.*\)<\/span>/\1/' | sed -e 's/·​/-/g')"
;;
ws) SYLLABLES="$(curl -k -s https://www.wordsmyth.net/?ent=$line | grep '<h3\ class="headword syl">' | uniq | sed -e 's/<td class="default"><h3 class="headword syl">\(.*\)<\/h3>/\1/' | sed -e 's/·/-/g')"
;;
*) echo "Dictionary not found."
exit 0
;;
esac
if [ -z "$SYLLABLES" ]
then
echo $line
else
echo $SYLLABLES
fi
done < "${INFILE:-/dev/stdin}"