나는 생물 의학 텍스트를 토큰 화하려고하므로 http://nlp.stanford.edu/software/eventparser.shtml을 사용하기로 결정했습니다. 내가 원하는대로 RunBioNLPTokenizer라는 독립 실행 형 프로그램을 사용했습니다.BioNLP 스탠포드 - 토큰 화
이제 Stanford 라이브러리를 사용하는 자체 프로그램을 만들고 싶습니다. 그래서 아래에서 설명하는 RunBioNLPTokenizer에서 코드를 읽었습니다.
package edu.stanford.nlp.ie.machinereading.domains.bionlp;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.util.Collection;
import java.util.List;
import java.util.Properties;
import edu.stanford.nlp.ie.machinereading.GenericDataSetReader;
import edu.stanford.nlp.ie.machinereading.msteventextractor.DataSet;
import edu.stanford.nlp.ie.machinereading.msteventextractor.EpigeneticsDataSet;
import edu.stanford.nlp.ie.machinereading.msteventextractor.GENIA11DataSet;
import edu.stanford.nlp.ie.machinereading.msteventextractor.InfectiousDiseasesDataSet;
import edu.stanford.nlp.io.IOUtils;
import edu.stanford.nlp.ling.CoreLabel;
import edu.stanford.nlp.util.StringUtils;
/**
* Standalone program to run our BioNLP tokenizer and save its output
*/
public class RunBioNLPTokenizer extends GenericDataSetReader {
public static void main(String[] args) throws IOException {
Properties props = StringUtils.argsToProperties(args);
String basePath = props.getProperty("base.directory", "/u/nlp/data/bioNLP/2011/originals/");
DataSet dataset = new GENIA11DataSet();
dataset.getFilesystemInformation().setTokenizer("stanford");
runTokenizerForDirectory(dataset, basePath + "genia/training");
runTokenizerForDirectory(dataset, basePath + "genia/development");
runTokenizerForDirectory(dataset, basePath + "genia/testing");
dataset = new EpigeneticsDataSet();
dataset.getFilesystemInformation().setTokenizer("stanford");
runTokenizerForDirectory(dataset, basePath + "epi/training");
runTokenizerForDirectory(dataset, basePath + "epi/development");
runTokenizerForDirectory(dataset, basePath + "epi/testing");
dataset = new InfectiousDiseasesDataSet();
dataset.getFilesystemInformation().setTokenizer("stanford");
runTokenizerForDirectory(dataset, basePath + "infect/training");
runTokenizerForDirectory(dataset, basePath + "infect/development");
runTokenizerForDirectory(dataset, basePath + "infect/testing");
}
private static void runTokenizerForDirectory(DataSet dataset, String path) throws IOException {
System.out.println("Input directory: " + path);
BioNLPFormatReader reader = new BioNLPFormatReader();
for (File rawFile : reader.getRawFiles(path)) {
System.out.println("Input filename: " + rawFile.getName());
String rawText = IOUtils.slurpFile(rawFile);
String docId = rawFile.getName().replace("." + BioNLPFormatReader.TEXT_EXTENSION, "");
String parentPath = rawFile.getParent();
runTokenizer(dataset.getFilesystemInformation().getTokenizedFilename(parentPath, docId), rawText);
}
}
private static void runTokenizer(String tokenizedFilename, String text) {
System.out.println("Tokenized filename: " + tokenizedFilename);
Collection<String> sentences = BioNLPFormatReader.splitSentences(text);
PrintStream os = null;
try {
os = new PrintStream(new FileOutputStream(tokenizedFilename));
} catch (IOException e) {
System.err.println("ERROR: cannot save online tokenization to " + tokenizedFilename);
e.printStackTrace();
System.exit(1);
}
for (String sentence : sentences) {
BioNLPFormatReader.BioNLPTokenizer tokenizer = new BioNLPFormatReader.BioNLPTokenizer(sentence);
List<CoreLabel> tokens = tokenizer.tokenize();
for (CoreLabel l : tokens) {
os.print(l.word() + " ");
}
os.println();
}
os.close();
}
}
아래 코드를 작성했습니다. 텍스트를 문장으로 나눠서 작성했지만 BioNLPTokenizer를 RunBioNLPTokenizer에서 사용되는대로 사용할 수는 없습니다. Uncompilable 소스 코드 - edu.stanford.nlp.ie.machinereading.domains.bionlp.BioNLPFormatReader.BioNLPTokenizer :
public static void main(String[] args) throws Exception {
// TODO code application logic here
Collection<String> c =BioNLPFormatReader.splitSentences("..");
for (String sentence : c) {
System.out.println(sentence);
BioNLPFormatReader.BioNLPTokenizer x = BioNLPFormatReader.BioNLPTokenizer(sentence);
}
}
나는 스레드에서 "주요"java.lang.RuntimeException가를이 오류
예외를했다
내 질문에 대한 답변입니다. RunBioNLPTokenizer를 사용하지 않고 Stanford 라이브러리에 따라 생물 의학 문장을 어떻게 토큰화할 수 있습니까?
답장을 보내 주셔서 감사합니다. 나는 문제를 해결했다 (나는 생각한다). BioNLPFormatReader를 확장하기 위해 클래스를 만들었습니다. 이것은 나를 위해 일했다. 이미 베타 버전이라고 읽었습니다. 라이브러리에 생물 의학 텍스트를위한 토크 나이저가 있습니까? –
당신이 해결 방법을 발견했음을 기쁘게 생각합니다. 나는 Mihai와 나 자신이 더 이상 스탠포드에 있지 않기 때문에 아마 "베타"보다는 "대부분 유지가되지 않는다"라고 말할 것입니다. 어느 도서관을 언급하고 있습니까? – dmcc
음, 스탠포드 CoreNLP 라이브러리를 의미합니다. 하지만 생물 의학에서 토큰 화에 대해 알고 있다면, 감사하겠습니다. 사전에 감사드립니다. –