简体   繁体   中英

Stop StanfordCoreNLP from Connecting to StanfordCoreNLP server

Whenever I create StanfordCoreNLP for a parsing task,

StanfordCoreNLP('stanford-corenlp-full-2020-04-20', lang='en')

I get this logging

Initializing native server...
java -Xmx4g -cp "/stanford-corenlp-full-2020-04-20/*" edu.stanford.nlp.pipeline.StanfordCoreNLPServer -port 9032
Server shell PID: 11991
The server is available.
  1. Can StanfordCoreNLP work in python offline without connecting to the server?
  2. Is there a command to stop the logging to screen in stanfordCoreNLP? On applying

On applying the parser, self.nlp_src.parse(sentence) , I got another logging of the form below:

{'properties': "{'annotators': 'pos,parse', 'outputFormat': 'json'}", 'pipelineLanguage': 'en'}

  1. Is there a way to stop the above logging too?

Lastly, I got this error in the process of using the parser in the stanford coreNLP as explained above.

requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=9032): Max retries exceeded with url: /?properties=%7B%27annotators%27%3A+%27pos%2Cparse%27%2C+%27outputFormat%27%3A+%27json%27%7D&pipelineLanguage=en (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fe04121d6d0>: Failed to establish a new connection: [Errno 111] Connection refused'))

  1. What is the cause of this error? What do I do to prevent this?

Hi if you'd like to use Stanford CoreNLP in Python I'd advise using our official Python package Stanza, available here: https://stanfordnlp.github.io/stanza/

If you want to access Stanford CoreNLP in Python, Stanza will need to launch a Java server process on your local machine. This does not require connecting to the internet or any external network. The Java server process is running on your local machine and the Python process is communicating with it.

There is a detailed write up about how to launch a Java server in Python here: https://stanfordnlp.github.io/stanza/corenlp_client.html#overview

Stanza itself has part-of-speech, dependency parsing, and named entity recognition that is completely native Python and does not involve a server of any sort. More details here: https://stanfordnlp.github.io/stanza/installation_usage.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM