저는 Stanford CoreNLP 툴킷을 처음 접했으며 뉴스 텍스트에서 상호 참조를 해결하는 프로젝트에 사용하려고합니다. Stanford CoreNLP 공동 참조 시스템을 사용하기 위해 일반적으로 토큰 화, 문장 분할, 품사 태깅, lemmarization, 명명 된 엔티티 인식 및 구문 분석이 필요한 파이프 라인을 생성합니다. 예를 들면 :
Properties props = new Properties();
props.setProperty("annotators", "tokenize, ssplit, pos, lemma, ner, parse, dcoref");
StanfordCoreNLP pipeline = new StanfordCoreNLP(props);
// read some text in the text variable
String text = "As competition heats up in Spain's crowded bank market, Banco Exterior de Espana is seeking to shed its image of a state-owned bank and move into new activities.";
// create an empty Annotation just with the given text
Annotation document = new Annotation(text);
// run all Annotators on this text
pipeline.annotate(document);
그러면 다음과 같이 문장 주석을 쉽게 얻을 수 있습니다.
List<CoreMap> sentences = document.get(SentencesAnnotation.class);
그러나 전처리를 위해 다른 도구를 사용하고 있으며 독립형 상호 참조 확인 시스템이 필요합니다. 토큰을 만들고 트리 주석을 구문 분석하고 주석으로 설정하는 것은 매우 쉽습니다.
// create new annotation
Annotation annotation = new Annotation();
// create token annotations for each sentence from the input file
List<CoreLabel> tokens = new ArrayList<>();
for(int tokenCount = 0; tokenCount < parsedSentence.size(); tokenCount++) {
ArrayList<String> parsedLine = parsedSentence.get(tokenCount);
String word = parsedLine.get(1);
String lemma = parsedLine.get(2);
String posTag = parsedLine.get(3);
String namedEntity = parsedLine.get(4);
String partOfParseTree = parsedLine.get(6);
CoreLabel token = new CoreLabel();
token.setWord(word);
token.setWord(lemma);
token.setTag(posTag);
token.setNER(namedEntity);
tokens.add(token);
}
// set tokens annotations to annotation
annotation.set(TokensAnnotation.class, tokens);
// set parse tree annotations to annotation
Tree stanfordParseTree = Tree.valueOf(inputParseTree);
annotation.set(TreeAnnotation.class, stanfordParseTree);
그러나 문장 주석을 만드는 것은 매우 까다 롭습니다. 내 지식으로는 자세히 설명 할 문서가 없기 때문입니다. 문장 주석에 대한 데이터 구조를 만들고 주석으로 설정할 수 있습니다.
List<CoreMap> sentences = new ArrayList<CoreMap>();
annotation.set(SentencesAnnotation.class, sentences);
그렇게 어려울 수는 없지만 토큰 주석에서 문장 주석을 만드는 방법, 즉 ArrayList를 실제 문장 주석으로 채우는 방법에 대한 문서는 없습니다.
어떤 아이디어?
Btw, 처리 도구에서 제공하는 토큰 및 구문 분석 트리 주석을 사용하고 StanfordCoreNLP 파이프 라인에서 제공하는 문장 주석 만 사용하고 StanfordCoreNLP 독립 실행 형 상호 참조 해결 시스템을 적용하면 올바른 결과를 얻고 있습니다. 따라서 완전한 독립형 상호 참조 해결 시스템에서 누락 된 유일한 부분은 토큰 주석에서 문장 주석을 생성하는 기능입니다.
이미 토큰 화 된 문장 목록이있는 경우 문서를 설정 하는 인수가 있는 Annotation
생성자 가 있습니다 List<CoreMap> sentences
.
각 문장에 대해 CoreMap
다음과 같이 개체 를 만들고자합니다 . (또한 각 문장과 토큰 객체에 각각 문장과 토큰 인덱스를 추가했습니다.)
int sentenceIdx = 1;
List<CoreMap> sentences = new ArrayList<CoreMap>();
for (parsedSentence : parsedSentences) {
CoreMap sentence = new CoreLabel();
List<CoreLabel> tokens = new ArrayList<>();
for(int tokenCount = 0; tokenCount < parsedSentence.size(); tokenCount++) {
ArrayList<String> parsedLine = parsedSentence.get(tokenCount);
String word = parsedLine.get(1);
String lemma = parsedLine.get(2);
String posTag = parsedLine.get(3);
String namedEntity = parsedLine.get(4);
String partOfParseTree = parsedLine.get(6);
CoreLabel token = new CoreLabel();
token.setWord(word);
token.setLemma(lemma);
token.setTag(posTag);
token.setNER(namedEntity);
token.setIndex(tokenCount + 1);
tokens.add(token);
}
// set tokens annotations and id of sentence
sentence.set(TokensAnnotation.class, tokens);
sentence.set(SentenceIndexAnnotation.class, sentenceIdx++);
// set parse tree annotations to annotation
Tree stanfordParseTree = Tree.valueOf(inputParseTree);
sentence.set(TreeAnnotation.class, stanfordParseTree);
// add sentence to list of sentences
sentences.add(sentence);
}
그런 다음 목록으로 Annotation
인스턴스를 만들 수 있습니다 sentences
.
Annotation annotation = new Annotation(sentences);
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다