MIT Java WordNet Interface: Getting WordNet lexico

2019-02-11 03:55发布

问题:

I have a project where I need to get the lexical meaning of a word. I am thinking of using WordNet because it has its own lexicographer classes also called super-senses. I just downloaded MIT JWI and trying to see if this JWI does support it. The manual doesn't say anything about returning any lexical information attached to the word.

import java.io.File;
import java.io.IOException;
import java.io.ObjectInputStream.GetField;
import java.net.URL;
import edu.mit.jwi.*;
import edu.mit.jwi.item.IIndexWord;
import edu.mit.jwi.item.ILexFile;
import edu.mit.jwi.item.ISenseKey;
import edu.mit.jwi.item.IWord;
import edu.mit.jwi.item.IWordID;
import edu.mit.jwi.item.POS;

public class MITJavaWordNetInterface {

    public static void main(String[] args) throws IOException{

        //construct URL to WordNet Dictionary directory on the computer
        String wordNetDirectory = "WordNet-3.0";
        String path = wordNetDirectory + File.separator + "dict";
        URL url = new URL("file", null, path);      

        //construct the Dictionary object and open it
        IDictionary dict = new Dictionary(url);
        dict.open();

        // look up first sense of the word "dog "
        IIndexWord idxWord = dict.getIndexWord ("dog", POS.NOUN );
        IWordID wordID = idxWord.getWordIDs().get(0) ;
        IWord word = dict.getWord (wordID);         
        System.out.println("Id = " + wordID);
        System.out.println(" Lemma = " + word.getLemma());
        System.out.println(" Gloss = " + word.getSynset().getGloss());      
    }    
}

I managed to run the sample provided by MIT. Any clues or suggestions as to how I can get the lexical information on a word submitted either using MIT JWI or any other tools would be great. An example on how to call the method would also be greatly appreciated.

An example word: dog
Desired results: noun.animal

回答1:

You should be able to use the same code mentioned above and add few more lines

    IIndexWord idxWord = dict.getIndexWord("dog", POS.NOUN);
    IWordID wordID = idxWord.getWordIDs().get(0);
    IWord word = dict.getWord(wordID);
    ISynset synset = word.getSynset();
    String LexFileName = synset.getLexicalFile().getName();
    System.out.println("Lexical Name : "+ LexFileName);