[JAVA] Lassen Sie uns Stanford CoreNLP Server für Windows einrichten (kürzeste Anleitung)

CoreNLP Server

Eine detaillierte Beschreibung von CoreNLP Server finden Sie unten. Muster werden ebenfalls veröffentlicht.

CoreNLP Server - CoreNLP https://stanfordnlp.github.io/CoreNLP/corenlp-server.html

herunterladen

Es stehen verschiedene Download-Methoden zur Verfügung. Am einfachsten ist es jedoch, die Datei über die unten stehende URL herunterzuladen. http://nlp.stanford.edu/software/stanford-corenlp-latest.zip

Extrahieren Sie die heruntergeladene ZIP-Datei.

Ab Oktober 2020 werden die folgenden Ordner erweitert.

stanford-corenlp-4.1.0

Verschieben Sie den Ordner in den folgenden Pfad. Bitte ändern Sie es nach Ihren Wünschen.

C:\usr\local\stanford-corenlp-4.1.0

Lauf

Wechseln Sie an der Eingabeaufforderung zu C: \ usr \ local \ stanford-corenlp-4.1.0 und führen Sie den Java-Befehl aus.

C:\>cd C:\usr\local\stanford-corenlp-4.1.0
C:\usr\local\stanford-corenlp-4.1.0>java -mx4g -cp "*" edu.stanford.nlp.pipeline.StanfordCoreNLPServer -port 9000 -timeout 15000
[main] INFO CoreNLP - --- StanfordCoreNLPServer#main() called ---
[main] INFO CoreNLP - Server default properties:
                        (Note: unspecified annotator properties are English defaults)
                        inputFormat = text
                        outputFormat = json
                        prettyPrint = false
[main] INFO CoreNLP - Threads: 8
[main] INFO CoreNLP - Starting server...
[main] INFO CoreNLP - StanfordCoreNLPServer listening at /0:0:0:0:0:0:0:0:9000

Client erstellen

pom.xml

<!-- https://mvnrepository.com/artifact/edu.stanford.nlp/stanford-corenlp -->
<dependency>
	<groupId>edu.stanford.nlp</groupId>
	<artifactId>stanford-corenlp</artifactId>
	<version>4.0.0</version>
	<scope>provided</scope>
</dependency>

package nlp4j.stanford;

import java.util.List;
import java.util.Properties;

import edu.stanford.nlp.ling.CoreAnnotations.LemmaAnnotation;
import edu.stanford.nlp.ling.CoreAnnotations.PartOfSpeechAnnotation;
import edu.stanford.nlp.ling.CoreAnnotations.TextAnnotation;
import edu.stanford.nlp.ling.CoreAnnotations.TokensAnnotation;
import edu.stanford.nlp.ling.CoreLabel;
import edu.stanford.nlp.pipeline.Annotation;
import edu.stanford.nlp.pipeline.StanfordCoreNLPClient;

public class StanfordClientSample1 {

	public static void main(String[] args) throws Exception {

		// creates a StanfordCoreNLP object with POS tagging, lemmatization
		Properties props = new Properties();
		props.setProperty("annotators", "tokenize, ssplit, pos, lemma");

		StanfordCoreNLPClient pipeline = new StanfordCoreNLPClient(props, "http://localhost", 9000, 2);

		// read some text in the text variable
		String text = "This is sample text for NLP.";

		// create an empty Annotation just with the given text
		Annotation document = new Annotation(text);

		// run all Annotators on this text
		pipeline.annotate(document);

		{
			List<CoreLabel> labels = document.get(TokensAnnotation.class);
			// for each labels
			for (CoreLabel label : labels) { //
				String str = label.get(TextAnnotation.class);
				String lex = label.get(LemmaAnnotation.class);
				String pos = label.get(PartOfSpeechAnnotation.class);
				int begin = label.beginPosition();
				int end = label.endPosition();

				System.err.println("str=" + str + ",lex=" + lex + ",pos=" + pos + ",begin=" + begin + ",end=" + end);

			} // for each labels
		}

	}

}

Ausführungsergebnis

str=This,lex=this,pos=DT,begin=0,end=4
str=is,lex=be,pos=VBZ,begin=5,end=7
str=sample,lex=sample,pos=NN,begin=8,end=14
str=text,lex=text,pos=NN,begin=15,end=19
str=for,lex=for,pos=IN,begin=20,end=23
str=NLP,lex=nlp,pos=NN,begin=24,end=27
str=.,lex=.,pos=.,begin=27,end=28

Zusammenfassung

Das Starten von Stanford NLP in Java dauert lange, aber die Verwendung von Core NLP Server beschleunigt den zweiten und nachfolgenden Aufruf erheblich. Es wird empfohlen, da es einfach ist, den Server einzurichten, sobald Sie sich daran gewöhnt haben.

das ist alles

Recommended Posts

Lassen Sie uns Stanford CoreNLP Server für Windows einrichten (kürzeste Anleitung)
Richten Sie den Metabasisdienst unter Windows Server 2012 ein
[Hinweis] So starten Sie den mit Docker-Compose eingerichteten Windows-Container neu
[Ubuntu] Richten Sie einen Nukkit-Server ein
Versuchen Sie eine syntaktische Analyse englischer Sätze mit Stanford CoreNLP