0
토큰 화 된 String
텍스트의 범위를 추출하고 싶습니다. 스탠포드의 CoreNLP을 사용하여, 내가 가진 :CoreNLP 토큰의 범위 추출
Properties props;
props = new Properties();
props.put("annotators", "tokenize, ssplit, pos, lemma");
this.pipeline = new StanfordCoreNLP(props);
String answerText = "This is the answer";
ArrayList<IntPair> tokenSpans = new ArrayList<IntPair>();
// create an empty Annotation with just the given text
Annotation document = new Annotation(answerText);
// run all Annotators on this text
this.pipeline.annotate(document);
// Iterate over all of the sentences
List<CoreMap> sentences = document.get(SentencesAnnotation.class);
for(CoreMap sentence: sentences) {
// Iterate over all tokens in a sentence
for (CoreLabel fullToken: sentence.get(TokensAnnotation.class)) {
IntPair span = fullToken.get(SpanAnnotation.class);
tokenSpans.add(span);
}
}
그러나, IntPairs
의 모든 null
이다. 내가 라인에서 다른 annotator
를 추가해야합니까 :
props.put("annotators", "tokenize, ssplit, pos, lemma");
원하는 출력 :
(0,3), (5,6), (8,10), (12,17)