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)
誰でも私を助けてもらえますか?