使用JWNL获取与WordNet中的动词相关的所有名词

时间:2013-06-24 12:23:33

标签: java nlp wordnet

我正在使用JWNL(1.4.1 rc2)。给定一个动词,我需要找到“相关”的名词。例如,给定动词:bear我想要名词birth

我可以通过WordNet在线界面看到这一点: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。如何在JWNL中完成。

1 个答案:

答案 0 :(得分:1)

您可以对每个单词的含义使用Synset,然后在每个Synset中打印出单词,如下所示:

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()+")");
    }
}

这会得到你:

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])

但那是所有动词,因为我们正在查找动词。如果你想获得名词(如在Web版本中所见),你应该做一些进一步的步骤。

它被称为" morphosemantic" ally相关词,在this file中定义,如Wordnet website中所述。您可以使用该文件上可用的映射创建自己的代码来提取与形态相关的单词。

由于这是一个超出标准WordNet发行版的附加文件,遗憾的是我认为这不是在JWNL中实现的,所以如果你可以创建一个简单的代码来获得映射,那么它可能是最好的。首先,您可以使用任何电子表格程序(如Excel)将xls文件转换为CSV文件。然后你需要获得那种感觉的感知键。不幸的是,JWNL(1.4.1 rc2)没有简单的方法来获取感知键。但是,它包含在JWNL(1.4 rc3)中,这是类getSenseKey(lemma)中的方法Synset。因此,假设您升级到JWNL 1.4_rc3,您可以执行以下操作:

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

,当birth%1:28:00::的感觉2中的单词为birth%1:22:00::时,将返回由birth%1:11:00::birthbear组成的Arraylist关键熊%2:29:01 ::,导致出生;&#34;我的妻子昨天有双胞胎!&#34;),感觉关键出生%2:29:00 ::,可以使用下面的JWNL 1.4 rc3在输出中看到:

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::)

我从GrepCode

获得了非常好的资源