简体   繁体   English

连接到专用服务器-CoreNLP

[英]Connect to Dedicated Server - CoreNLP

I am looking for the python code required to connect to a local instantiation of the Stanford CoreNLP Server. 我正在寻找连接到Stanford CoreNLP服务器的本地实例所需的python代码。

I have successfully connected and communicated with Stanford's server where you need to enter the following into the command line prompt: 我已经成功连接了斯坦福大学的服务器并与之通信,您需要在命令行提示符下输入以下内容:

java -mx4g -cp "*" edu.stanford.nlp.pipeline.StanfordCoreNLPServer -port 9000 -timeout 15000

and have nlp = StanfordCoreNLP('http://localhost:9000') in your python code. 并在您的python代码中包含nlp = StanfordCoreNLP('http://localhost:9000')

I now have a local CoreNLP server operating on CentOS 6. I use the terminal prompt: sudo service corenlp start and get the system response CoreNLP server started. 我现在有一个在CentOS 6上运行的本地CoreNLP服务器。我使用终端提示符: sudo service corenlp startsudo service corenlp start系统响应CoreNLP server started. Which I assume means my local instantiation of the CoreNLP server is listening for any requests. 我认为这意味着我在CoreNLP服务器的本地实例正在侦听任何请求。 I now need to know how to communicate with my local server. 现在,我需要知道如何与本地服务器通信。

Can anyone enlighten me on what I need to replace nlp = StanfordCoreNLP('http://localhost:9000') with in order to be able to talk to my local CoreNLP Server? 谁能启发我我需要替换nlp = StanfordCoreNLP('http://localhost:9000')以便能够与我的本地CoreNLP服务器通信?

You should use the Stanford NLP group's Python library stanza : 您应该使用Stanford NLP小组的Python库stanza

https://github.com/stanfordnlp/stanza https://github.com/stanfordnlp/stanza

Hopefully over the next month there will be better documentation and support for starting and stopping the server in Python. 希望在下个月将有更好的文档和对使用Python启动和停止服务器的支持。

As noted above by @StanfordNLPHelp, stanza can be imported and used with the following code: 如上面@StanfordNLPHelp所述, stanza可以导入并与以下代码一起使用:

from stanza.nlp.corenlp import CoreNLPClient
client = CoreNLPClient(server='http://localhost:9000', default_annotators=['ssplit', 'tokenize', 'lemma', 'pos', 'ner'])
annotated = client.annotate('This is an example document. Here is a second sentence')

This code acts in a similar manner to that of this line of code, which should look familiar if you have been connecting to Stanford's server nlp = StanfordCoreNLP('http://localhost:9000') . 这段代码的行为类似于此代码行的行为,如果您已连接到Stanford的服务器nlp = StanfordCoreNLP('http://localhost:9000') ,则应该看起来很熟悉。

My Problem was that I could not connect to the dedicated server that resides on my local CentOS based operating system. 我的问题是我无法连接到基于本地CentOS的操作系统上的专用服务器。

The Solution to my problem was that I was missing the 'middleman'. 解决我的问题的方法是我错过了“中间人”。 By that I mean I was missing the part of the process where I connected to my dedicated server. 我的意思是说我缺少连接到专用服务器的过程部分。 I had the dedicated server properly set up and running, and I had the Python code that would reach out to the server BUT I did NOT have the "pipeline" open to my dedicated server. 我已经正确设置并运行了专用服务器,并且我拥有可以连接到服务器的Python代码,但我没有向专用服务器打开“管道”。

To do this I just needed to follow these simple steps: 为此,我只需要遵循以下简单步骤:

  1. Download CoreNLP 3.7.0 to Downloads folder. 将CoreNLP 3.7.0下载到Downloads文件夹。

    a. 一种。 unzip folder. 解压缩文件夹。 Note which location you extracted to 注意您提取到的位置

  2. Disconnect from the Internet!! 断开互联网连接!!

  3. Enter the following into the terminal window: 在终端窗口中输入以下内容:

    a. 一种。 cd ~/stanford-corenlp-full-2016-10-31 (<--wherever you stored this file) cd〜/ stanford-corenlp-full-2016-10-31(<-无论您存储此文件的位置)

    b. java -mx4g -cp "*" edu.stanford.nlp.pipeline.StanfordCoreNLPServer -port 80 -timeout 15000 java -mx4g -cp“ *” edu.stanford.nlp.pipeline.StanfordCoreNLPServer-端口80-超时15000

  4. Run Python code. 运行Python代码。

*Note that I disconnected from the internet. *请注意,我已断开与互联网的连接。 If you do not do this the java command will not connect to your local server but Stanford's. 如果您不这样做,那么java命令将不会连接到您本地的服务器,而是斯坦福的。

Summary: When using Stanford CoreNLP there are three components that you need (1) Appropriate line of code in Python script to call out to the server. 简介:使用Stanford CoreNLP时,需要三个组件(1)用Python脚本中的相应代码行调用服务器。 Two options presented above (2) A functioning server. 上面介绍的两个选项(2)运行中的服务器。 The two options I am aware of include Stanford's own server, or a dedicate server you have on your local system. 我知道的两个选项包括斯坦福大学自己的服务器,或本地系统上的专用服务器。 and (3) the CoreNLp software that opens the pipeline from your system to the server. (3)CoreNLp软件,用于打开从系统到服务器的管道。 Number three is where I was getting caught up. 第三是我被赶上的地方。

*I am interested to know if there is a way to connect to my local server without disconnecting the internet. *我很想知道是否可以在不断开互联网的情况下连接到本地服务器。 It seems that if the internet is enabled the code will default to Stanford's instanciation of the server. 似乎,如果启用了Internet,则该代码将默认为斯坦福对服务器的实例化。 Is it possible to overwrite this default? 是否可以覆盖此默认值? Feel free to comment below with input on this side bar. 您可以在下面的边栏上随意输入评论。

EDIT: I do not believe that the above information is correct. 编辑:我不认为上述信息是正确的。 According to Stanford CoreNLP's Server page , "Stanford CoreNLP ships with a built-in server, which requires only the CoreNLP dependencies." 根据Stanford CoreNLP的“服务器”页面 ,“ Stanford CoreNLP附带了一个内置服务器,它只需要CoreNLP依赖项。” I believe that my solution above was only using this "built-in" server not my local dedicated server. 我相信上面的解决方案仅使用此“内置”服务器,而不使用本地专用服务器。 I am still investigating this issue. 我仍在调查此问题。 I will edit as more information is uncovered. 随着更多信息的发现,我将进行编辑。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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