-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathstanford.py
73 lines (57 loc) · 2.02 KB
/
stanford.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# Script for running StanfordCoreNLP
# Copyright (C) 2017 Yanjun Gao
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Aug 6, 2017
# Step 0, move this file to stanford-corenlp folder
# mode: 1: peer summries; 2: wise_crowd_summaries, 3:test_summaries
# Usage: python stanford.py mode
import os
import sys
import glob
#from lib_preprocessing import *
path_ = sys.argv[1]
mode = sys.argv[2]
pyrEval = sys.argv[3]
# Clean Summary before XML dump
for fname in glob.iglob(path_ + '/*'):
f = open(fname, 'r')
lines = f.readlines()
f.close()
clean = []
for line in lines:
line = line.replace("'", '').replace('`', '')
# if '.' in line:
# ind = line.index('.')
# if len(line) == ind + 1:
# pass
# elif line[ind + 1] != ' ':
# line[ind] = ' '
clean.append(line)
with open(fname, 'w') as f:
for line in clean:
f.write(line)
f.close()
for filename in glob.glob(os.path.join(path_, '')):
print "current filename", filename
print mode
if int(mode) == 1:
outpath = pyrEval + "/Preprocess/peer_summaries"
elif int(mode) == 2:
outpath = pyrEval + "/Preprocess/wise_crowd_summaries"
#elif int(mode) == 3:
#outpath = pyrEval + "/Preprocess/test_summaries"
else:
print "Option doesn't exist!!!"
if outpath:
print outpath
command2 = "java -cp '*' edu.stanford.nlp.pipeline.StanfordCoreNLP -annotators tokenize,ssplit,pos,parse,depparse -file "+filename+" -outputDirectory "+outpath
os.system(command2)