【问题标题】:getting nouns and verbs from wordnet从 wordnet 中获取名词和动词
【发布时间】:2010-10-04 17:57:03
【问题描述】:

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

我找到了 MIT Java Wordnet 接口 有一个这样的示例代码,但是当我使用它时,我得到了 Dictionary 是抽象类并且无法实例化的错误

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

 }

我还有另一个 java 接口到 wordnet

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

【问题讨论】:

    标签: java nlp wordnet


    【解决方案1】:

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

    【讨论】:

    【解决方案2】:

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

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

    【讨论】:

    • 是的,我找到了问题..这是由于不正确的导入..有 2 个 Dictionary 类,一个在 java.util 中,另一个在 wordnet 包中,问题是导入不匹配
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多