Stanford CoreNLP

1. direct call


a jar package wrapper in python

2. Server

CoreNLP Server

Run Server

# Set up your classpath. For example, to add all jars in the current directory tree:
export CLASSPATH="`find . -name '*.jar'`"

# Run the server
java -mx4g -cp "*" edu.stanford.nlp.pipeline.StanfordCoreNLPServer [port=9000]

# send post data & get parameter to the server
wget --post-data 'the quick brown fox jumped over the lazy dog' 'localhost:9000/?properties={"tokenize.whitespace": "true", "annotators": "tokenize,ssplit,pos", "outputFormat": "json"}' -O -

# Run with Chinese
java -cp "*" -Xmx8g edu.stanford.nlp.pipeline.StanfordCoreNLPServer -serverProperties -port 19000

# request
wget --post-data '我爱北京天安门' 'localhost:19000/?properties={"outputFormat":"json"}' -O -

Kill Server



wget "localhost:9000/shutdown?key=`cat /tmp/corenlp.shutdown`" -O -

python talking with server install lib:

pip install pycorenlp

how to use:

from pycorenlp import StanfordCoreNLP

if __name__ == '__main__':
    nlp = StanfordCoreNLP('http://localhost:9000')
    text = (
        'Pusheen and Smitha walked along the beach. Pusheen wanted to surf,'
        'but fell off the surfboard.')
    output = nlp.annotate(text, properties={
        'annotators': 'tokenize,ssplit,pos,depparse,parse',
        'outputFormat': 'json'
    output = nlp.tokensregex(text, pattern='/Pusheen|Smitha/', filter=False)
    output = nlp.semgrex(text, pattern='{tag: VBD}', filter=False)

3. demo

NLTK (python)

source: (python)