Search code examples
c++cwordnet

WordNet SynSet ptrlist from findtheinfo_ds() only goes one level


I'm trying to call the WordNet C API from my C++ application, and it works, but not as expected. Here's my code:

int search (char* term)
{
    results.clear();

    SynsetPtr synsets = findtheinfo_ds(term, NOUN, HYPERPTR, ALLSENSES);
    SynsetPtr currentSynset = synsets;

    // Loop all senses
    while (currentSynset != nullptr)
    {
        SynsetPtr next = currentSynset;

        // Iterate up hierarchy for each sense.
        while (next != nullptr)
        {
            String words;

            for (int i = 0; i != next->wcount; ++i)
            {
                String nextWord = next->words[i];
                nextWord = nextWord.replaceCharacter('_', ' ');

                words += String(nextWord);
                if (i != (next->wcount - 1)) words += ", ";
            }

            results.add (words + " - " + String(next->defn));

            next = next->ptrlist;
        }

        currentSynset = currentSynset->nextss;
    }

    free_syns(synsets);

    return results.size();
}

My program correctly outputs the definition of each of the senses, but for each sense, it only outputs the ONE hypernym directly above my search term in the hierarchy, it doesn't go all the way up the tree to 'entity'. In other words, the second SynsetPtr->ptrlist is always NULL, even when I can see from the WordNet CLI that there are many levels up.

Am I missing something? Am I calling findtheinfo_ds() incorrectly?


Solution

  • findtheinfo_ds() only returns one node. To work your way through the tree you have to call findtheinfo_ds() for each connection it finds. I found this page which shows a gdb interactive session on the returned data structure, which I think you will find useful.

    Also take a look at the traceptrs_ds() function, which sounds like it might be designed for what you are trying to do.