0

我正在努力寻找一个词是名词还是动词等

我发现 MIT Java Wordnet 接口有一个像这样的示例代码,但是当我使用它时,我得到错误,字典是抽象类,无法实例化

public void testDictionary() throws IOException {


// construct the URL to the Wordnet dictionary directory

String wnhome = System.getenv("WNHOME");

String path = wnhome + 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());

 }

我还有另一个到 wordnet 的 java 接口

danbikel的界面

但我没有得到查询的答案

WordNet wn=new WordNet("/usr/share/wordnet");
    Morphy m = new Morphy(wn);

    System.out.println(m.morphStr("search","NOUN").length);

字符串长度始终为 0,此方法的正确参数是什么?这是该方法的javadoc,我做错了什么?

public String[] morphStr(String origstr, String pos)
Tries several techniques on origstr to find possible base forms (lemmas).

Specified by:
morphStr in interface MorphyRemote
Parameters:
origstr - word or collocation, separated either by whitespace, '_' or '-', to find lemma of
pos - part of speech of origstr
Returns:
array of possible lemmas for origstr, possibly of length 0 if no lemmas could be found
4

2 回答 2

0

我个人推荐Yawni,旧 JWordNet 项目的新名称。要获取搜索词的所有词性,您将调用FileBackedDictionary.synsets(yourQueryWord),然后遍历返回Synset的 s 调用getPOS()

于 2010-10-04T19:21:11.360 回答
0

你的问题解决了吗?我之前也使用过 JWI,但不同之处在于我将 IDictionary 变量声明为静态变量......但其余的几乎相同。要获得名词,您必须使用以下方法进行迭代:

最终迭代器 itr=dict.getIndexWordIterator(POS.NOUN) While(itr.hasNext())...

于 2010-11-28T21:23:27.110 回答