Can't seem to get the 1st and most popular definition for every word, only some words. Javascript

So I am creating a simple dictionary google chrome extension. Simply, you enter a word, and then it get's the definition by accessing Oxford API. I would get the response and then retrieve the definition by

However, I realized through trials that it would not grab the first/most popular definition. Some words it would retrieve the first entry definition for that word (great!). However, for others it would not retrieve one at all or it would retrieve a weird definition that is not usually meant with that word.

So I am asking how to access the BEST/FIRST entry for each word every time. The way I am accessing the definition is not working as expected for some words.



  • SimoneSimone Administrator admin

    Hi @reddismycolor, welcome!
    I'm sorry I could not acknowledge your question yesterday - I was ill.

    But I'm on it now, I'm contacting my colleagues from the technical team to get back to you asap.
    So help is on the way, bear with us!

  • vantipinvantipin Member

    Hi @reddismycolor some "senses" don't have definition records. Sometimes the only definition in entry is positioned "senses" -> "subsenses" -> "definition"

    I would advise using more sophisticated logic to access definition. Looping through "senses" would do. And just in case there is no definition - you should have checks in place.

  • AmosDuveenAmosDuveen Member, Administrator, Moderator admin
    edited March 2017

    Hi @reddismycolor,

    Further to what @vantipin said, it is worth mentioning that some entries do not have definition field because the meaning of the word is instead contained within a cross-reference field e.g. sense 6 of 'term' (see here).

  • @vantipin thanks for the response. how would i go about this then? I am relatively new to JS and APIs so. response.results[0].lexicalEntries[0].entries[0].senses[0].definitions[0] has been working pretty well. I got the first definition for many, but then I search up something stupid like "dawg" and it returns an error become definitions[0] is undefined, even though there is an entry for it. Is there a way to get it to work for EVERY word? How come the internal structure for the responses isn't the same for every word?

    Thanks a lot for the help!

  • SimoneSimone Administrator admin

    Hi @reddismycolor, let me get in touch with the technical team again for you, bear with me!

  • vantipinvantipin Member
    edited April 2017

    Hi @reddismycolor,

    You'll need a simple loop to go through all the options for entries, senses.
    You can easily find how to do this online.

    Before accessing the value you should check it's not null

    Use "break" to stop looping as soon as you found the definition

  • AmosDuveenAmosDuveen Member, Administrator, Moderator admin

    Hi @reddismycolor,

    Following up again on the issue, you still need to check for cross-references, which are tagged differently to standard definitions. To use the example you quoted, "dawg", a standard entry call produces the output below (note that the cross reference content replaces the definition):

    { "metadata": { "provider": "Oxford University Press" }, "results": [ { "id": "dawg", "language": "en", "lexicalEntries": [ { "entries": [ { "grammaticalFeatures": [ { "text": "Singular", "type": "Number" } ], "homographNumber": "000", "senses": [ { "crossReferenceMarkers": [ "non-standard spelling of dog, used especially to represent American speech" ], "crossReferences": [ { "id": "dog", "text": "dog", "type": "variant spelling" } ], "id": "m_en_gbus0252470.008" } ] } ], "language": "en", "lexicalCategory": "Noun", "pronunciations": [ { "audioFile": "", "phoneticNotation": "IPA", "phoneticSpelling": "dɔːɡ" } ], "text": "dawg" } ], "type": "headword", "word": "dawg" } ] }

  • joughtredjoughtred Member, Administrator, Moderator admin

    You might also like to know that, in general, the lower the homograph number (for example, '001'), the more common the definition. I hope this helps, @reddismycolor!

Sign In or Register to comment.