Word definition being returned as XML by Wordnik.

35 views
Skip to first unread message

Dean Kitson

unread,
Sep 10, 2024, 3:33:46 AM9/10/24
to Wordnik API
I am testing to see if a word and corresponding word type (e.g. noun, verb, etc) exist by sending a request to Wordnik for a definition. My code is working but get a definition if the word and word type exist in XML format. Is there a way of getting a definition as a text string?

Erin McKean

unread,
Sep 10, 2024, 10:36:56 AM9/10/24
to wordn...@googlegroups.com
Hi Dean! Could you share what call you're using, exactly?

Thanks!

Erin
---------------------
Erin McKean
Wordnik
@emc...@xoxo.zone/@wor...@wordnik.social
Wordnik is a 501(c)3 nonprofit organization
The Wordnik mission: every English word, available to everyone, everywhere

On Tue, Sep 10, 2024 at 12:33 AM 'Dean Kitson' via Wordnik API <wordn...@googlegroups.com> wrote:
I am testing to see if a word and corresponding word type (e.g. noun, verb, etc) exist by sending a request to Wordnik for a definition. My code is working but get a definition if the word and word type exist in XML format. Is there a way of getting a definition as a text string?

--
You received this message because you are subscribed to the Google Groups "Wordnik API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wordnik-api...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/wordnik-api/0701993a-b37f-44b1-ac98-feb390f9eeben%40googlegroups.com.

Dean Kitson

unread,
Sep 10, 2024, 9:17:46 PM9/10/24
to wordn...@googlegroups.com
Hi Erin,

Below is a copy of the method in Python that I am using to get a definition of a word of a word type (noun, verb, etc).


def lookUpWord(word, wordType):

    apiUrl = 'http://api.wordnik.com/v4'
#apiKey = 'YOUR API KEY HERE'
    apiKey = '5z2ema7aq0lqbekymzc6kuky2d9wzugfvetbl2dzrajok86a3'

    client = swagger.ApiClient(apiKey, apiUrl)

    wordApi = WordApi.WordApi(client)

#    word = input("Word to look up: ")
#    pOSpeech = input("Part of speech: ")

    definitions = wordApi.getDefinitions(word,
                                     partOfSpeech=wordType,
                                     sourceDictionaries='wiktionary',
                                     limit=3)
   
    return definitions[0].text


It works but the definition is in XML format, whereas I am wanting a text string.


Best Regards,

Dean Kitson.

--
You received this message because you are subscribed to a topic in the Google Groups "Wordnik API" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/wordnik-api/R-lq1hMxtd8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to wordnik-api...@googlegroups.com.

To view this discussion on the web visit

Erin McKean

unread,
Sep 10, 2024, 11:51:46 PM9/10/24
to wordn...@googlegroups.com
Hi Dean, unfortunately it looks like you shared your live API key with this large group -- I've reset your key and you can find your new key on your API Dashboard (log in to your Wordnik user page and there will be a link to your dashboard on that page).

When I ran your with the word 'cat' and partOfSpeech noun I got "A <xref>catamaran</xref>." Is that the kind of output you're seeing?

Some of the definitions (especially from Wiktionary) do have some tags in them (mostly <xref>), but they are not in XML format. Unfortunately we do not have a feature that will strip these tags for you at this time. I recommend using regular expressions (or better yet, a library such as Beautiful Soup) to remove these tags.

Thank you for using Wordnik!

Yours,

Erin

Reply all
Reply to author
Forward
0 new messages