从 wordnet 获取名词和动词

发布于 2024-09-25 21:38:40 字数 1545 浏览 5 评论 0原文

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

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

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

I'm struggling to find whether a word is noun or verb etc

I found the MIT Java Wordnet Interface
there was a sample code like this, but when i use this i get error that Dictionary is abstract class and cannot be instantiated

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

 }

i also got another java interface to wordnet

danbikel's interface

but i dont get answer for the query

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

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

Always the string length is 0, what is the correct arguments for this method? here is the javadoc of the method, what am i doing wrong?

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

ぽ尐不点ル 2024-10-02 21:38:40

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

I personally recommend Yawni, the new name for the old JWordNet project. To get all the parts-of-speech for a search word, you would call FileBackedDictionary.synsets(yourQueryWord), then iterate through the returned Synsets calling getPOS().

温折酒 2024-10-02 21:38:40

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

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

Have you solved your problem? I also used JWI before but the difference is that I declare my IDictionary variable as an static... but the rest it is almost the same. To get the nouns you have to iterate using:

final Iterator
itr=dict.getIndexWordIterator(POS.NOUN)
While(itr.hasNext())...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文