# Temporary inclusion of pycorenlp code for easier edits
# https://github.com/smilli/py-corenlp

import json, requests

class StanfordCoreNLP:

    def __init__(self, server_url):
        if server_url[-1] == '/':
            server_url = server_url[:-1]
        self.server_url = server_url

    def annotate(self, text, properties=None):
        assert isinstance(text, str) or isinstance(text,unicode)
        if properties is None:
            properties = {}
        else:
            assert isinstance(properties, dict)

        # Checks that the Stanford CoreNLP server is started.
        #try:
        #    requests.get(self.server_url)
        #except requests.exceptions.ConnectionError:
        #    raise Exception('Check whether you have started the CoreNLP server e.g.\n'
        #    '$ cd stanford-corenlp-full-2015-12-09/ \n'
        #    '$ java -mx4g -cp "*" edu.stanford.nlp.pipeline.StanfordCoreNLPServer')

        data = text.encode('utf8')
	print(data)
        r = requests.post(
            self.server_url, params={
                'properties': str(properties)
            }, data=data)#, headers={'Connection': 'close'})
        output = r.text
        if ('outputFormat' in properties
             and properties['outputFormat'] == 'json'):
            try:
                output = json.loads(output, encoding='utf-8', strict=False)
            except:
                print("TEXT")
                print(unicode(text))
                print("OUTPUT")
                print(unicode(output))
                raise RuntimeError("CoreNLP returned data not in JSON format")

        return output

    def tokensregex(self, text, pattern, filter):
        return self.regex('/tokensregex', text, pattern, filter)

    def semgrex(self, text, pattern, filter):
        return self.regex('/semgrex', text, pattern, filter)

    def regex(self, endpoint, text, pattern, filter):
        r = requests.get(
            self.server_url + endpoint, params={
                'pattern':  pattern,
                'filter': filter
            }, data=text)
        output = r.text
        try:
            output = json.loads(r.text)
        except:
            pass
        return output

@@ -590,17 +590,16 @@
         
-#
 try:%0A   
@@ -599,25 +599,24 @@
 ry:%0A        
-#
     requests
@@ -645,17 +645,16 @@
         
-#
 except r
@@ -693,25 +693,24 @@
 or:%0A        
-#
     raise Ex
@@ -780,25 +780,24 @@
 %5Cn'%0A        
-#
     '$ cd st
@@ -840,17 +840,16 @@
         
-#
     '$ j
@@ -956,21 +956,8 @@
 8')%0A
-%09print(data)%0A
     
@@ -1063,16 +1063,16 @@
 erties)%0A
+
         
@@ -1091,10 +1091,8 @@
 data
-)#
 , he

Undo some debug code in pycorenlp