我需要在此特定句子中提取'NN'後面的單詞嗎?從文本中提取特定單詞
(ROOT (SBARQ [26.015] (WHNP [1.500] (WP [1.051] What)) (SQ[23.912] (VBZ[2.669]'s)
(NP [19.076] (PRP$ [3.816] your) (NN [9.843] thought))) (. [0.002] ?)))
所以,當我分析這個..使用正則表達式,我需要提取只有兩個字「想」出來。
我該怎麼做?
我的代碼:
String pattern = "\NN \[[0-9]+(?:\.[0-9])?\] (.)\)";
Pattern r = Pattern.compile(pattern);
Matcher m = r.matcher(st); while(m.find()) {System.out.println(m.group());}
output: (NN [9.843] thought))) (. [0.002] ?)))
但我只想要'想'
答:
明白了:-)感謝的人。
String pattern = "NN \\[.*] (\\w+)";
Pattern r = Pattern.compile(pattern);
Matcher m = r.matcher(st);
while(m.find())
{System.out.println(m.group(1));}
輸出:認爲
我試了兩個..似乎沒有工作。 – madCode 2011-03-27 08:50:39
嘿,感謝您的鏈接,它很棒。 – madCode 2011-03-27 09:29:26