2012-12-23 51 views
-1

從給定下面的代碼:: 我想提取關係作爲如何檢索包含特殊字符的句子中的單詞?

 
amod delhi 
nsubj capital delhi 
.....etc 

[amod(delhi-2, -1), nsubj(capital-5, delhi-2), cop(capital-5, is-3), 
det(capital-5, the-4), root(ROOT-0, capital-5), prep_of(capital-5, 
india-7)] 
+0

你是否真的投入的樣子嗎? – fge

回答

0

如果輸入看上去真是這樣,那麼你可以使用這個

Pattern p = Pattern.compile("(\\w+)\\((\\w*)-\\d+,\\s(\\w*)-\\d+\\)"); 
//groups      1  2    3 
String data = "[amod(delhi-2, -1), nsubj(capital-5, delhi-2), " + 
     "cop(capital-5, is-3), det(capital-5, the-4), root(ROOT-0, " + 
     "capital-5), prep_of(capital-5, india-7)]"; 
Matcher m = p.matcher(data); 
while (m.find()) 
    System.out.println(m.group(1) + " " + m.group(2) + " " + m.group(3)); 
相關問題