Regex 如何使用TokenSequencePattern

Regex 如何使用TokenSequencePattern,regex,stanford-nlp,Regex,Stanford Nlp,我刚刚开始使用CoreNLP的TokenSequencePattern,但我无法使用简单的匹配。我所要做的就是从输入文本中匹配一个标记。下面的代码执行时没有错误,但与任何内容都不匹配。但是,如果将匹配表达式更改为[],则它将匹配这两个句子 Properties props = new Properties(); props.put("annotators", "tokenize, ssplit, parse"); StanfordCoreNLP pipeline =

我刚刚开始使用CoreNLP的TokenSequencePattern,但我无法使用简单的匹配。我所要做的就是从输入文本中匹配一个标记。下面的代码执行时没有错误,但与任何内容都不匹配。但是,如果将匹配表达式更改为[],则它将匹配这两个句子

     Properties props = new Properties();
     props.put("annotators", "tokenize, ssplit, parse");
     StanfordCoreNLP pipeline = new StanfordCoreNLP(props);
     Annotation document = new Annotation("This is sent 1. And here is sent 2");
     pipeline.annotate(document);
     List<CoreMap> sentences = document.get(CoreAnnotations.SentencesAnnotation.class);

     Env env = TokenSequencePattern.getNewEnv();
     env.setDefaultStringMatchFlags(NodePattern.CASE_INSENSITIVE);
     env.setDefaultStringPatternFlags(Pattern.CASE_INSENSITIVE);

     TokenSequencePattern pattern = TokenSequencePattern.compile(env,"[ { word:\"sent\" } ]");
     TokenSequenceMatcher matcher = pattern.getMatcher(sentences);

     while ( matcher.find() ) {
        System.out.println( matcher.group() );
    }
Properties=newproperties();
props.put(“注释器”、“标记化、ssplit、解析”);
StanfordCoreNLP管道=新的StanfordCoreNLP(道具);
注释文档=新注释(“此为发送1,此处为发送2”);
管道注释(文件);
列出句子=document.get(coreanotations.SentencesAnnotation.class);
Env Env=TokenSequencePattern.getNewEnv();
env.setDefaultStringMatchFlags(NodePattern.CASE_不区分大小写);
env.setDefaultStringPatternFlags(模式不区分大小写);
TokenSequencePattern=TokenSequencePattern.compile(env,“[{word:\”sent\“}]”);
TokenSequenceMatcher matcher=pattern.getMatcher(句子);
while(matcher.find()){
System.out.println(matcher.group());
}
谢谢大家!

列出令牌=
List<CoreLabel> tokens = 
document.get(CoreAnnotations.TokensAnnotation.class);
TokenSequencePattern pattern= TokenSequencePattern.compile("[ { 
word:\"sent\" } ]");
TokenSequenceMatcher matcher = pattern.getMatcher(tokens);
while (matcher.find())
{
String matchedString = matcher.group();
List<CoreMap> matchedTokens = matcher.groupNodes();
System.out.println(matchedString + " " + matchedTokens);
}
get(coreanotations.TokensAnnotation.class); TokenSequencePattern=TokenSequencePattern.compile(“[{ 字:\“已发送\“}]”; TokenSequenceMatcher matcher=pattern.getMatcher(令牌); while(matcher.find()) { String matchedString=matcher.group(); List matchedTokens=matcher.groupNodes(); System.out.println(matchedString+“”+matchedTokens); }
即使代码是正确的,写一些文字解释为什么这是答案总是有帮助的。