이 절에서는 nlp가 무엇인지, 왜 개발자가 그것을 사용하고 싶어하는지에 대한 개요를 제공합니다.
또한 nlp 내의 큰 주제를 언급하고 관련 주제에 링크해야합니다. nlp에 대한 문서는 새로운 것이므로 관련 주제의 초기 버전을 만들어야 할 수도 있습니다.
Stanford CoreNLP 는 많은 핵심 NLP 작업을 지원하는 널리 사용되는 Natural Language Processing 툴킷입니다.
프로그램을 다운로드하고 설치하려면 릴리스 패키지를 다운로드하고 클래스 경로에 필요한 *.jar
파일을 포함 시키거나 Maven 중심의 종속성을 추가하십시오. 자세한 내용 은 다운로드 페이지 를 참조하십시오. 예 :
curl http://nlp.stanford.edu/software/stanford-corenlp-full-2015-12-09.zip -o corenlp.zip
unzip corenlp.zip
cd corenlp
export CLASSPATH="$CLASSPATH:`pwd`/*
CoreNLP 도구를 실행하는 방법으로는 (1) 기본 완벽하게 사용자 정의 가능한 API 사용 , (2) Simple CoreNLP API 사용 또는 (3) CoreNLP 서버 사용 중 지원되는 세 가지 방법이 있습니다. 각각에 대한 간단한 사용 예가 아래에 나와 있습니다. 동기를 부여하는 유스 케이스로서,이 예제는 문장의 구문 분석을 예측하는 것입니다.
CoreNLP API
public class CoreNLPDemo { public static void main(String[] args) { // 1. Set up a CoreNLP pipeline. This should be done once per type of annotation, // as it's fairly slow to initialize. // creates a StanfordCoreNLP object, with POS tagging, lemmatization, NER, parsing, and coreference resolution Properties props = new Properties(); props.setProperty("annotators", "tokenize, ssplit, parse"); StanfordCoreNLP pipeline = new StanfordCoreNLP(props); // 2. Run the pipeline on some text. // read some text in the text variable String text = "the quick brown fox jumped over the lazy dog"; // Add your text here! // create an empty Annotation just with the given text Annotation document = new Annotation(text); // run all Annotators on this text pipeline.annotate(document); // 3. Read off the result // Get the list of sentences in the document List<CoreMap> sentences = document.get(CoreAnnotations.SentencesAnnotation.class); for (CoreMap sentence : sentences) { // Get the parse tree for each sentence Tree parseTree = sentence.get(TreeAnnotations.TreeAnnotation.class); // Do something interesting with the parse tree! System.out.println(parseTree); } } }
간단한 CoreNLP
public class CoreNLPDemo { public static void main(String[] args) { String text = "The quick brown fox jumped over the lazy dog"); // your text here! Document document = new Document(text); // implicitly runs tokenizer for (Sentence sentence : document.sentences()) { Tree parseTree = sentence.parse(); // implicitly runs parser // Do something with your parse tree! System.out.println(parseTree); } } }
CoreNLP 서버
다음을 사용하여 서버를 시작하십시오 (클래스 경로를 적절히 설정하십시오).
java -mx4g -cp "*" edu.stanford.nlp.pipeline.StanfordCoreNLPServer [port] [timeout]
주어진 애노 테이터 세트에 대해 JSON 형식의 출력을 가져 와서 표준 출력으로 출력합니다.
wget --post-data 'The quick brown fox jumped over the lazy dog.' 'localhost:9000/?properties={"annotators":"tokenize,ssplit,parse","outputFormat":"json"}' -O -
구문 분석 트리를 JSON에서 가져 오려면 JSON을 sentences[i].parse
로 이동하면됩니다.