Skip to content

Commit 84eed35

Browse files
committed
Added support windows
made file paths OS neutral and changed jars to *
1 parent e1d7c56 commit 84eed35

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

corenlp/corenlp.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,14 @@ def init_corenlp_command(corenlp_path, memory, properties):
105105
"joda-time.jar",
106106
"jollyday.jar"
107107
]
108+
109+
jars = ["*"]
108110

109111
java_path = "java"
110112
classname = "edu.stanford.nlp.pipeline.StanfordCoreNLP"
111113
# include the properties file, so you can change defaults
112114
# but any changes in output format will break parse_parser_results()
113-
current_dir_pr = os.path.dirname(os.path.abspath(__file__)) + "/" + properties
115+
current_dir_pr = os.path.join(os.path.dirname(os.path.abspath(__file__)), properties)
114116
if os.path.exists(properties):
115117
props = "-props %s" % (properties.replace(" ", "\\ "))
116118
elif os.path.exists(current_dir_pr):
@@ -119,9 +121,9 @@ def init_corenlp_command(corenlp_path, memory, properties):
119121
raise Exception("Error! Cannot locate: %s" % properties)
120122

121123
# add and check classpaths
122-
jars = [corenlp_path + "/" + jar for jar in jars]
124+
jars = [os.path.join(corenlp_path,jar) for jar in jars]
123125
for jar in jars:
124-
if not os.path.exists(jar):
126+
if not os.path.exists(jar) and not "*" in jar:
125127
raise Exception("Error! Cannot locate: %s" % jar)
126128

127129
# add memory limit on JVM
@@ -278,7 +280,7 @@ def parse_xml_output(input_dir, corenlp_path=DIRECTORY, memory="3g", raw_output=
278280

279281
#we get a list of the cleaned files that we want to parse:
280282

281-
files = [input_dir + '/' + f for f in os.listdir(input_dir) if f.endswith(".txt")]
283+
files = [os.path.join(input_dir , f) for f in os.listdir(input_dir) if f.endswith(".txt")]
282284

283285
#creating the file list of files to parse
284286

@@ -296,7 +298,7 @@ def parse_xml_output(input_dir, corenlp_path=DIRECTORY, memory="3g", raw_output=
296298
# result = []
297299
try:
298300
for output_file in os.listdir(xml_dir):
299-
with open(xml_dir + '/' + output_file, 'r') as xml:
301+
with open(os.path.join(xml_dir + output_file), 'r') as xml:
300302
# parsed = xml.read()
301303
file_name = re.sub('.xml$', '', os.path.basename(output_file))
302304
# result.append(parse_parser_xml_results(xml.read(), file_name,
@@ -358,7 +360,12 @@ def __init__(self, corenlp_path=DIRECTORY, memory="3g", properties='default.prop
358360
self._spawn_corenlp()
359361

360362
def close(self, force=True):
361-
self.corenlp.terminate(force)
363+
global use_winpexpect
364+
if use_winpexpect:
365+
self.corenlp.terminate()
366+
else:
367+
self.corenlp.terminate(force)
368+
362369

363370
def isalive(self):
364371
return self.corenlp.isalive()

0 commit comments

Comments
 (0)