从 wordnet 获取名词和动词
我正在努力寻找一个单词是名词还是动词等
我找到了 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我个人推荐 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 returnedSynset
s callinggetPOS()
.你的问题解决了吗?我之前也使用过 JWI,但不同之处在于我将 IDictionary 变量声明为静态...但其余部分几乎相同。要获取名词,您必须使用以下方法进行迭代:
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: