麻省理工学院Java WordNet接口:线程" main" edu.mit.jwi.data.IHasLifecycle $ ObjectClosedException

时间:2015-01-27 20:33:36

标签: java eclipse jwi

我在Eclipse中使用JWI来访问Mac上的WordNet。我跟着这个例子:

package tutorial;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import edu.mit.jwi.*;
import edu.mit.jwi.item.IIndexWord;
import edu.mit.jwi.item.IWord;
import edu.mit.jwi.item.IWordID;
import edu.mit.jwi.item.POS;

public class ExampleWordnet {

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

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


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

但我无法运行它。总有错误:

Exception in thread "main" edu.mit.jwi.data.IHasLifecycle$ObjectClosedException
at edu.mit.jwi.CachingDictionary.checkOpen(CachingDictionary.java:111)
at edu.mit.jwi.CachingDictionary.getIndexWord(CachingDictionary.java:172)
at tutorial.ExampleWordnet.main(ExampleWordnet.java:28)

有人可以帮帮我吗?

0 个答案:

没有答案