我有一個關於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