【发布时间】:2014-07-21 10:48:29
【问题描述】:
我需要提取以下单词之后的所有单词,直到句子 (/[Ee]ach+/) ([tag:NN]+|[tag:NNS]+) (/has+/|/have+/) 结束,但我在第 13 行遇到错误,下面是我的代码:
1 String file="Each campus has one club. Each programme has a unique code, title, level and duration.";
2 Properties props = new Properties();
3 props.put("annotators", "tokenize, ssplit, pos, lemma, ner, parse, dcoref");
4 StanfordCoreNLP pipeline = new StanfordCoreNLP(props);
5 Annotation document = new Annotation(file);
6 pipeline.annotate(document);
7 List<CoreLabel> tokens = new ArrayList<CoreLabel>();
8 List<CoreMap> sentences = document.get(CoreAnnotations.SentencesAnnotation.class);
9 for(CoreMap sentence: sentences)
10 {
11 for (CoreLabel token: sentence.get(CoreAnnotations.TokensAnnotation.class))
12 tokens.add(token);
13 TokenSequencePattern pattern = TokenSequencePattern.compile("(/[Ee]ach+/) ([tag:NN]+|[tag:NNS]+) (/has+/|/have+/) [A-Z]");
14 TokenSequenceMatcher matcher = pattern.getMatcher(tokens);
15 while( matcher.find()){
16 JOptionPane.showMessageDialog(rootPane, matcher.group());
17 String matched = matcher.group();
18 }
19 tokens.removeAll(tokens);
20 }
【问题讨论】:
-
预期输出是什么?
-
预期的输出是。第一句话“每个校区都有一个俱乐部”,第二句话“每个项目都有唯一的代码、名称、级别和持续时间”。
标签: java regex stanford-nlp