Check existence of English infinitives efficiently

Hello there,
I use the API for research purposes. I have to one-time check, if 96’288 infinitives exist in the English lexicon. Most of them (approximately 80 %) will not exist in the English lexicon. The infinitives are in fact German verb stems. I use the lemma endpoint and python.
According to several tutorials in this forum I decided to use the status code to check if a word_id exists or not.
I would like to hear from you if the following approach is the most recommended and efficient way of doing this.
Consider this: The API receives status code 200 for 'hoer' although it's not a verb. this is true for other word_id's that exist in other lexical categories. How can I handle this?

#!/usr/bin/env python
# coding: utf-8

# This script checks if input list inf_sql_string exist as verbs in English part of lemma endpoint of the Oxford English Dictionary (OED). The output is 'FALSE' for non-existing words and input=output if the word exists. 

import requests
import json

#input
inf_sql_string = ['zeig', 'frag', 'koenn', 'hoer']

#define function for looking up input in OED API
def LookupInOED(lookup_lemma):
    url = url_consistent + 'lemmas/'  + language + '/'  + lookup_lemma.lower() + '?lexicalCategory=' + 'verb' 
    r = requests.get(url, headers = {'app_id' : app_id, 'app_key' : app_key})
    status_code = r.status_code
    if status_code == 200:
        result_lemma = lookup_lemma
    else:
        result_lemma = 'FALSE'
    return result_lemma

# consistent informations for API of OED (put your credentials here)
app_id = ' '
app_key = ' '
language = 'en'

url_consistent = 'https://od-api.oxforddictionaries.com:443/api/v2/'

# process with OED API
for lemma in inf_sql_string:
    result_lemma = LookupInOED(lemma) # look up in OED
    print(result_lemma)

Comments

  • TaisFukushimaTaisFukushima Member, Administrator, Moderator admin

    Hello @vizzerdrix

    I've forwarded your question to my colleagues in the technical team so hopefully myself or one of them should be able to get back to you - bear with us!

  • TaisFukushimaTaisFukushima Member, Administrator, Moderator admin
    edited October 24

    Hello @vizzerdrix2

    Thank you for contacting us, and please accept my apologies for the slowness of this response.

    I’ve forwarded your case to my colleague in the technical team and they said that your approach is very sensible and is absolutely right. Although, we have identified the misleading behaviour in the API we would suggest an extra check when the API returns a 200:

    # !/usr/bin/env python
    # coding: utf-8
    
    # This script checks if input list inf_sql_string exist as verbs in English part of lemma endpoint of
    # the Oxford Dictionary of English(ODE). The output is 'FALSE' for non-existing words and input=output if the word exists.
    
    import requests
    import json
    
    # input
    inf_sql_string = ['zeig', 'frag', 'koenn', 'hoer', 'window']
    
    
    # define function for looking up input in OD API
    def LookupInOED(lookup_lemma):
        url = url_consistent + 'lemmas/' + language + '/' + lookup_lemma.lower() + '?lexicalCategory=' + 'verb'
        r = requests.get(url, headers={'app_id': app_id, 'app_key': app_key})
        status_code = r.status_code
        body = r.json()
        if status_code == 200:
            if not body.get('results', []):
                result_lemma = 'False'
            else:
                result_lemma = lookup_lemma
        else:
           result_lemma = 'FALSE'
    
        return result_lemma
    
    
    # consistent informations for OD-API (put your credentials here)
    app_id = '’
    app_key = ‘’
    language = 'en'
    
    url_consistent = 'https://od-api.oxforddictionaries.com:443/api/v2/'
    
    # process with OD-API
    for lemma in inf_sql_string:
        result_lemma = LookupInOED(lemma)  # look up in OD of English
        print(result_lemma)
    

    Thank you for flagging this up to us.

    We also have noticed that in the Forum discussion when you showed the code you have added OED-API. We would kindly inform that the Oxford English Dictionary (OED) is actually a different dictionary dataset to the English dictionary included in our Oxford Dictionaries API (the OED is a historical record of English, while the Oxford Dictionaries API contains our current English dictionary datasets). So you will see in this example that my colleagues changed the comments to name the API as OD-API and to refer at the dictionary as ODE not as OED.

    We hope it helped

Sign In or Register to comment.