2017-03-18 3 views

답변

1

와 CoreNLP 3.7.0을 사용하고 당신은 단지 대신이 방법을 사용해야합니다

Counter<List<IN>> classifyKBest(List<IN> doc, Class<? extends CoreAnnotation<String>> answerField, int k) 

그것은 점수로 돌아 시퀀스의 매핑을 반환됩니다.

List<List<IN>> sorted = Counters.toSortedList(kBest); 

나는 당신이하려는 정확히 잘 모르겠지만, 일반적으로 IN는 CoreLabel는 다음 코드 줄로

당신은 순서의 정렬 된 목록에 그 카운터를 해제 할 수 있습니다. 여기서 핵심은 문자열을 IN의 목록으로 변환하는 것입니다. 이것은 CoreLabel이어야하지만, 나는 당신이 작업하고있는 AbstractSequenceClassifier의 전체 세부 사항을 모른다.

당신이 문장에 당신의 순서 분류를 실행하려면 먼저 파이프 라인을 토큰 화 수 있으며, 귀하의 예제에서 당신은 K를 얻을하려는 경우 다음 예를 들어 classifyKBest(...)

에 토큰의 목록을 통과 - 가장 유명한 엔티티 태그 :

// set up pipeline 
Properties props = new Properties(); 
props.setProperty("annotators", "tokenize"); 
StanfordCoreNLP tokenizerPipeline = new StanfordCoreNLP(props); 

// get list of tokens for example sentence 
String exampleSentence = "..."; 
// wrap sentence in an Annotation object 
Annotation annotation = new Annotation(exampleSentence); 
// tokenize sentence 
tokenizerPipeline.annotate(annotation); 
// get the list of tokens 
List<CoreLabel> tokens = annotation.get(CoreAnnotations.TokensAnnotation.class); 

//... 
// classifier should be an AbstractSequenceClassifier 

// get the k best sequences from your abstract sequence classifier 
Counter<List<CoreLabel>> kBestSequences = classifier.classifyKBest(tokens,CoreAnnotations.NamedEntityTagAnnotation.class, 10) 
// sort the k-best examples 
List<List<CoreLabel>> sortedKBest = Counters.toSortedList(kBestSequences); 
// example: getting the second best list 
List<CoreLabel> secondBest = sortedKBest.get(1); 
// example: print out the tags for the second best list 
System.out.println(secondBest.stream().map(token->token.get(CoreAnnotations.NamedEntityTagAnnotation.class)).collect(Collectors.joining(" "))); 
// example print out the score for the second best list 
System.out.println(kBestSequences.getCount(secondBest)); 

더 많은 질문이 있으면 알려 주시면 도와 드리겠습니다.

+0

감사합니다. 그 점은 [ "주석은 주석 자의 결과를 보유하는 데이터 구조입니다] (http://stanfordnlp.github.io/CoreNLP/api.html)는 주석이 입력을 유지할 수 있다고 생각하게 만듭니다 "결과"라는 용어 때문에 - 아래의 예가 그 결과를 보여줍니다. –