从下面给出的代码:: 我希望将关系提取为
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 :(得分: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));