Search code examples
javanlpwordnet

Getting all nouns related to a verb in WordNet using JWNL


I am using JWNL (1.4.1 rc2). Given a verb, I need to find "related" nouns. For example, given the verb: bear I want the noun birth.

I can see this through the WordNet online interface: http://wordnetweb.princeton.edu/perl/webwn?o2=&o0=1&o8=1&o1=1&o7=&o5=&o9=&o6=&o3=&o4=&s=bear&i=8&h=000100000000000000000#c. How would this be done in JWNL.


Solution

  • You can use the Synset for each sense of the word, then print out the word in each Synset, as follows:

    IndexWord indexWord = proc.lookupBaseForm(POS.VERB,"bear");
    int senseNum = 0;
    for(Synset synset: indexWord.getSenses()){
        senseNum++;
        System.out.println("For sense: " + senseNum + " (" + synset.getGloss()+")");
        Word[] words = synset.getWords();
        for(Word word: words){
            System.out.println("\t"+word.getLemma()+"("+word.getPOS()+")");
        }
    }
    

    which will get you this:

    For sense: 1 (have; "bear a resemblance"; "bear a signature")
        bear([POS: verb])
    For sense: 2 (cause to be born; "My wife had twins yesterday!")
        give_birth([POS: verb])
        deliver([POS: verb])
        bear([POS: verb])
        birth([POS: verb])
        have([POS: verb])
    For sense: 3 (put up with something or somebody unpleasant; "I cannot bear his constant criticism"; "The new secretary had to endure a lot of unprofessional remarks"; "he learned to tolerate the heat"; "She stuck out two years in a miserable marriage")
        digest([POS: verb])
        endure([POS: verb])
        stick_out([POS: verb])
        stomach([POS: verb])
        bear([POS: verb])
        stand([POS: verb])
        tolerate([POS: verb])
        support([POS: verb])
        brook([POS: verb])
        abide([POS: verb])
        suffer([POS: verb])
        put_up([POS: verb])
    For sense: 4 (move while holding up or supporting; "Bear gifts"; "bear a heavy load"; "bear news"; "bearing orders")
        bear([POS: verb])
    For sense: 5 (bring forth, "The apple tree bore delicious apples this year"; "The unidentified plant bore gorgeous flowers")
        bear([POS: verb])
        turn_out([POS: verb])
    For sense: 6 (take on as one's own the expenses or debts of another person; "I'll accept the charges"; "She agreed to bear the responsibility")
        bear([POS: verb])
        take_over([POS: verb])
        accept([POS: verb])
        assume([POS: verb])
    For sense: 7 (contain or hold; have within; "The jar carries wine"; "The canteen holds fresh water"; "This can contains water")
        hold([POS: verb])
        bear([POS: verb])
        carry([POS: verb])
        contain([POS: verb])
    For sense: 8 (bring in; "interest-bearing accounts"; "How much does this savings certificate pay annually?")
        yield([POS: verb])
        pay([POS: verb])
        bear([POS: verb])
    For sense: 9 (have on one's person; "He wore a red ribbon"; "bear a scar")
        wear([POS: verb])
        bear([POS: verb])
    For sense: 10 (behave in a certain manner; "She carried herself well"; "he bore himself with dignity"; "They conducted themselves well during these difficult times")
        behave([POS: verb])
        acquit([POS: verb])
        bear([POS: verb])
        deport([POS: verb])
        conduct([POS: verb])
        comport([POS: verb])
        carry([POS: verb])
    For sense: 11 (have rightfully; of rights, titles, and offices; "She bears the title of Duchess"; "He held the governorship for almost a decade")
        bear([POS: verb])
        hold([POS: verb])
    For sense: 12 (support or hold in a certain manner; "She holds her head high"; "He carried himself upright")
        hold([POS: verb])
        carry([POS: verb])
        bear([POS: verb])
    For sense: 13 (be pregnant with; "She is bearing his child"; "The are expecting another child in January"; "I am carrying his child")
        have_a_bun_in_the_oven([POS: verb])
        bear([POS: verb])
        carry([POS: verb])
        gestate([POS: verb])
        expect([POS: verb])
    

    But that's all verb, since we are looking up verbs. If you want to get noun (as seen in the Web version), you should do some further steps.

    It's called "morphosemantic"ally related words, which is defined in this file, as stated in Wordnet website. You can create your own code to extract morphosemantically related words by using the mapping available on that file.

    Since this is an additional file beyond standard WordNet distribution, regretfully I believe this is not implemented in JWNL, so probably it's best if you can just create a simple code to get the mapping. First, you can convert the xls file into CSV file using any spreadsheet program such as Excel. Then you'll need to get the sense key of that sense. Unfortunately, JWNL (1.4.1 rc2) has no simple method to get the sense key. However, it's included in JWNL (1.4 rc3), which is the method getSenseKey(lemma) in the class Synset. So, assuming you upgrade to JWNL 1.4_rc3, you can do:

    HashMap<String,ArrayList<String>> relatedWords = loadMorphosemanticFile();
    ...
    relatedWords.get(word.getSynset().getSenseKey(word.getLemma()))
    

    which will return an Arraylist consisting of: birth%1:28:00::, birth%1:22:00::, and birth%1:11:00:: when the word is birth in the sense 2 of bear (sense key bear%2:29:01::, cause to be born; "My wife had twins yesterday!"), which has the sense key birth%2:29:00::, as can be seen in the output using JWNL 1.4 rc3 below:

    For sense: bear%2:29:01:: (cause to be born; "My wife had twins yesterday!")
        give_birth (give_birth%2:29:00::)
        deliver (deliver%2:29:01::)
        bear (bear%2:29:01::)
        birth (birth%2:29:00::)
        have (have%2:29:00::)
    

    I got this very good resources from GrepCode