def send_request(request, response_type, java_main): """ Use subprocess to run the Semgrex processor on the given request Returns the protobuf response """ pipe = subprocess.run(["java", "-cp", resolve_classpath(), java_main], input=request.SerializeToString(), stdout=subprocess.PIPE) response = response_type() response.ParseFromString(pipe.stdout) return response
def test_external_server_legacy_start_server(): """ Test starting up an external server and accessing with a client with start_server=False """ corenlp_home = client.resolve_classpath(None) start_cmd = f'java -Xmx5g -cp "{corenlp_home}" edu.stanford.nlp.pipeline.StanfordCoreNLPServer -port 9001 ' \ f'-timeout 60000 -server_id stanza_external_server -serverProperties {SERVER_TEST_PROPS}' start_cmd = start_cmd and shlex.split(start_cmd) external_server_process = subprocess.Popen(start_cmd) with corenlp.CoreNLPClient(start_server=False, endpoint="http://localhost:9001") as external_server_client: ann = external_server_client.annotate(TEXT, annotators='tokenize,ssplit,pos', output_format='text') assert external_server_process external_server_process.terminate() external_server_process.wait(5) assert ann.strip() == EN_GOLD
def __init__(self, classpath, build_response, java_main): self.classpath = resolve_classpath(classpath) self.build_response = build_response self.java_main = java_main