Open madprops opened 2 years ago
I don't really want to use categories so I made a function to fetch all definitions:
# Extract definitions from result
def get_all_definitions(results):
definitions = []
if "lexicalEntries" in results[0]:
for lexical_entry in results[0]["lexicalEntries"]:
if "entries" in lexical_entry:
for entry in lexical_entry["entries"]:
if "senses" in entry:
for sense in entry["senses"]:
if "definitions" in sense:
for definition in sense["definitions"]:
definitions.append(definition)
elif "shortDefinitions" in sense:
for definition in sense["shortDefinitions"]:
definitions.append(definition)
return list(set(definitions))
Interesting -- I haven't looked at the code in a while and I just remember being really confused by the structure of the API response. How has this been working for you? Any cases where it hasn't been working?
Yeah the response is kindof confusing. I think definitions reside inside senses, every lexicalEntry has a list of senses, so I iterate through those. Sometimes I'd get some errors due to things not existing, hence all those ifs. Also some words like "clave" wouldn't show anything, at least in my version, since it only had a "shortDefinition", so I added an elif to get those if no definitions were found. What I've been doing is copying the json response, fixing it to make it pure json, and using a beautifier to check the structure.
Sounds good - looks like yours may be working better than what I have now then! If you would be so kind to make a PR, I'd to be glad to integrate your changes into the main branch.
Ah, I noticed you have a fork of this as well - I'll take a look over that then.
When testing with the word "train" I would only get verbs.