Skip to content

Commit

Permalink
Merge branch 'dev' of github.com:stanfordnlp/stanza into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
AngledLuffa committed Apr 16, 2020
2 parents e50eb21 + 1ee2e62 commit 4341e4b
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
4 changes: 2 additions & 2 deletions doc/CoreNLP.proto
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ message Document {
repeated Mention mentionsForCoref = 14;
optional bool hasCorefMentionAnnotation = 15;
optional bool hasCorefAnnotation = 16;
repeated uint32 corefMentionToEntityMentionMappings = 17;
repeated uint32 entityMentionToCorefMentionMappings = 18;
repeated int32 corefMentionToEntityMentionMappings = 17;
repeated int32 entityMentionToCorefMentionMappings = 18;

extensions 100 to 255;
}
Expand Down
6 changes: 3 additions & 3 deletions stanza/protobuf/CoreNLP_pb2.py

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions stanza/server/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Client for accessing Stanford CoreNLP in Python
"""

import atexit
import contextlib
import io
import os
Expand Down Expand Up @@ -88,6 +89,13 @@ class PermanentlyFailedException(Exception):
pass


def clean_props_file(props_file):
# check if there is a temp server props file to remove and remove it
if props_file:
if (os.path.isfile(props_file) and
SERVER_PROPS_TMP_FILE_PATTERN.match(os.path.basename(props_file))):
os.remove(props_file)

class RobustService(object):
""" Service that resuscitates itself if it is not available. """
CHECK_ALIVE_TIMEOUT = 120
Expand Down Expand Up @@ -344,22 +352,14 @@ def _setup_default_server_props(self, properties, annotators, output_format):
client_side_properties['outputFormat'] = output_format
# write client side props to a tmp file which will be erased at end
self.server_props_file['path'] = write_corenlp_props(client_side_properties)
atexit.register(clean_props_file, self.server_props_file['path'])
self.server_props_file['is_temp'] = True
# record server start up info
self.server_start_info['client_side'] = True
self.server_start_info['props'] = client_side_properties
self.server_start_info['props_file'] = self.server_props_file['path']
self.server_start_info['preload_annotators'] = client_side_properties['annotators']

def __exit__(self, exc_type, exc_value, traceback):
# check if there is a temp server props file to remove and remove it
if self.server_props_file['is_temp']:
if os.path.isfile(self.server_props_file['path']) and \
SERVER_PROPS_TMP_FILE_PATTERN.match(os.path.basename(self.server_props_file['path'])):
os.remove(self.server_props_file['path'])
# run base class __exit__
super(CoreNLPClient, self).__exit__(exc_type, exc_value, traceback)

def _request(self, buf, properties, **kwargs):
"""
Send a request to the CoreNLP server.
Expand Down
2 changes: 1 addition & 1 deletion tests/test_protobuf.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def doc_pb():


def test_parse_protobuf(doc_pb):
assert doc_pb.ByteSize() == 4239
assert doc_pb.ByteSize() == 4709


def test_write_protobuf(doc_pb):
Expand Down

0 comments on commit 4341e4b

Please sign in to comment.