summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xoedquery.sh47
1 files changed, 27 insertions, 20 deletions
diff --git a/oedquery.sh b/oedquery.sh
index bb85570..3e82ba8 100755
--- a/oedquery.sh
+++ b/oedquery.sh
@@ -9,7 +9,7 @@ OPTS='--silent -L -H "app_id: $appId" -H "app_key: $appKey"'
curlCount=0
_curl() {
- if [[ $curlCount -ge 20 ]]
+ if [[ $curlCount -ge 2 ]]
then
echo "cURL loop, exiting."
exit 0
@@ -97,30 +97,37 @@ _etym() {
exit 0
}
-# Return synonyms of first sense of first lexical entry
+# Return synonyms of first sense of first lexical entry (or second if no synonyms for the first)
_thes() {
_getdata
- count=0
- for json in $(echo "${result}" | jq -r '.results[].lexicalEntries[0].entries[0].senses[0].synonyms[]? | @base64'); do
- output="$output $(_jq '.text'), "
- ((count=count+1))
- # Limit output to a resonable number of synonyms
- if [[ $count -ge $maxSynonyms ]]
- then
- break
- fi
- done
-
+ # Loop to get synonyms for the first sense of a given lexical entry
+ _thesLoop () {
+ count=0
+ for json in $(echo "${result}" | jq -r '.results[].lexicalEntries['$1'].entries[0].senses[0].synonyms[]? | @base64'); do
+ output="$output $(_jq '.text'), "
+ ((count=count+1))
+ # Limit output to a resonable number of synonyms
+ if [[ $count -ge $maxSynonyms ]]
+ then
+ break
+ fi
+ done
+ }
+ # Get synonyms for first lexical entry and try the second if there aren't any
+ _thesLoop 0
if [[ -z $output ]]
then
- echo "No synonyms found."
- exit 0
- else
- # remove trailing comma
- output=$(echo $output | sed '$s/,$//')
- echo $output
- exit 0
+ _thesLoop 1
+ if [[ -z $output ]]
+ then
+ echo "No synonyms found."
+ exit 0
+ fi
fi
+ # remove trailing comma
+ output=$(echo $output | sed '$s/,$//')
+ echo $output
+ exit 0
}
# Get URL for first audio file in returned data