-1

从下面给出的代码:: 我想提取关系为

阿莫德德里
新德里首都德里
.....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,
印度-7)]
4

1 回答 1

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));
于 2012-12-23T18:00:12.070 回答