Try to set up Stanford CoreNLP Server for Windows (shortest guide)

CoreNLP Server

A detailed description of CoreNLP Server can be found below. Samples are also posted.

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

download

There are several download methods available, but the easiest is to download the file from the URL below. http://nlp.stanford.edu/software/stanford-corenlp-latest.zip

Extract the downloaded ZIP file.

As of October 2020, the following folders will be expanded.

stanford-corenlp-4.1.0

Move the folder to the following path. Please change it to your liking.

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

Run

At the command prompt, go to C: \ usr \ local \ stanford-corenlp-4.1.0 and run the Java command.

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

Creating a client

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
		}

	}

}

Execution result

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

Summary

Starting Stanford NLP in Java takes a long time to load, but using Core NLP Server makes the second and subsequent calls much faster. It is recommended because it is easy to set up the server once you get used to it.

that's all

Recommended Posts

Try to set up Stanford CoreNLP Server for Windows (shortest guide)
Set up Metabase service on Windows Server 2012
Steps to set up a VNC server on CentOS 8.3
[Note] How to restart the Windows container set up with docker-compose
[Ubuntu] Set up a Nukkit server
Try parsing English with Stanford CoreNLP