我有一个关于WordNet和MIT JWI(用于访问WordNet的Java API)的非常简单的问题:我将文件读入字符串数组中,并将其分解为单词。我怎样才能得到一个单独的字符串数组,只包含使用getPOS()的名词?谢谢!什么,我已经试过Java - 使用Wordnet和JWI获取名词阵列
例子:
公共类的测试{
public static void main(String[] args) {
String sentence1 = "The cat ate the fish";
String[] s1Split = sentence1.split(" ");
String wnhome = "C:/Program Files/WordNet/2.1";
String path = wnhome + File.separator + "dict";
URL url = new URL("file", null , path);
IDictionary dict = new Dictionary(url);
dict.open();
for (int i = 0; i <s1.length; i++) {
//this is where I got confused, wanted to use something like:
//Word w = dict.getIndexWord(s1[i], ..) but I need a POS argument,
//and I can't find another suitable method
//if w.getPOS() is a noun I would add it to a separate vector
}
}
}
编辑:只是想一个又一个的 - 这将是可靠的使用类似w = dict.getIndexWord(s1[i], POS.NOUN)
,如果一个名词不存在,w将是空的?这是否值得尝试?编辑2:所以我的问题atm会是如果有任何方法我可以将一个字符串(单词)转换成一个Wordnet对象,所以我可以使用getPOS()对其?
增加了一个例子 – user573382 2012-07-05 20:55:13
这看起来不对。我认为你需要使用dict.open()的结果,对吧?迭代句子中的字符有什么用处? – ControlAltDel 2012-07-05 21:00:35
也许你想要sentence1.split(“”)? – ControlAltDel 2012-07-05 21:00:59