Skip to content

Commit c57621c

Browse files
committed
update config file; update argument parser in main; update readme
Signed-off-by: Gang Ling <[email protected]>
1 parent 948acac commit c57621c

File tree

3 files changed

+28
-12
lines changed

3 files changed

+28
-12
lines changed

CONFIG.cfg

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[LTH]
2+
Path: <absolute-path-to-LTH>/lth_srl
3+
4+
[CoreNLP]
5+
Path: <absolute-path-to-CoreNLP>/stanford-corenlp-full-2016-10-31

README.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,25 @@ From Narrative Text to Formal Action Language System Descriptions
1212

1313
* **Python 3.6** Note that the version of python is *ESSENTIAL*
1414
* Download or git clone (https://github.com/gling07/Text2DRS) Text2DRS repository
15+
* If you already have LTH or Stanford core-NLP 3.7.0, you can omit related steps and edit CONFIG file directly
1516
* Download LTH (http://nlp.cs.lth.se/software/semantic-parsing-propbank-nombank-frames/)
1617
* Unzip LTH package and move the package dictionary into Text2DRS repository folder
1718
* Download Standford core-NLP **3.7.0** package (https://stanfordnlp.github.io/CoreNLP/history.html)
1819
* Unzip core-NLP package and move the package dictionary into Text2DRS repository folder
20+
* Edit CONFIG.cfg file to include system paths of LTH and core-NLP package as following:
21+
```
22+
[LTH]
23+
Path: <absolute-path-to-LTH>/lth_srl
1924
20-
* create a file named CONFIG that includes two lines specifying the place for LTH and core-NLP packages as follows
25+
[CoreNLP]
26+
Path: <absolute-path-to-CoreNLP>/stanford-corenlp-full-2016-10-31
2127
22-
lth_srl <path-to-lth-directory>/lth_srl/
23-
corenlp <path-to-corenlp-directory>/stanford-corenlp-full-2016-10-31/
24-
28+
```
2529

2630
### Parameters ###
2731

2832
* Command line to invoke the system:
29-
* python3 text2drs.py <path-to-config-file>/CONFIG <path-to-input-file-with-text>/something.txt
33+
* python3 text2drs.py <absolute-path-to-config-file>/CONFIG.cfg <absolute-path-to-input-file-with-text>/something.txt
3034

3135
For example, testFiles/paperExample.txt contains two sentences
3236
Ann went to the room.

text2drs.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import corenlp
3232
import drs2
3333
import fileGenerator
34+
import configparser
3435

3536
# lth output file
3637
output_file = None
@@ -39,13 +40,11 @@
3940

4041

4142
# The method to call and run lth tool with a input file
42-
def process_lth(file):
43+
def process_lth(file, lth_path):
4344

4445
# store text2drs tool's path
4546
text2_drs_path = os.getcwd()
4647

47-
lth_path = text2_drs_path + '/lth_srl/'
48-
4948
# switch current dictionary to lth folder
5049
os.chdir(lth_path)
5150

@@ -97,9 +96,8 @@ def process_lth(file):
9796

9897
# process input file by running corenlp through command line
9998
# output file format can be choose from text, xml, json
100-
def process_corenlp(file):
99+
def process_corenlp(file, corenlp_path):
101100
text2_drs_path = os.getcwd()
102-
corenlp_path = text2_drs_path + '/stanford-corenlp-full-2016-10-31/'
103101
os.chdir(corenlp_path)
104102
output_path = text2_drs_path + '/corenlp_Outputs/'
105103
output_format = 'xml'
@@ -116,11 +114,20 @@ def process_corenlp(file):
116114

117115

118116
def main():
117+
config = configparser.RawConfigParser()
118+
119119
parser = argparse.ArgumentParser()
120+
parser.add_argument("config", help='given full path of config file', type=str)
120121
parser.add_argument("input", help='given full path of input file', type=str)
121122
args = parser.parse_args()
123+
124+
config.read(args.config)
122125
input_file = args.input
123-
process_lth(input_file)
126+
127+
lth_path = config.get('LTH', 'Path')
128+
corenlp_path = config.get('CoreNLP', 'Path')
129+
130+
process_lth(input_file, lth_path)
124131

125132
# read lth output file and store in lth_output
126133
lth_output = None
@@ -145,7 +152,7 @@ def main():
145152
sys.stdout = orig_stdout
146153
f.close()
147154

148-
corenlp_output_path = process_corenlp(input_file)
155+
corenlp_output_path = process_corenlp(input_file, corenlp_path)
149156
corenlp_output = None
150157
try:
151158
corenlp_output = ET.parse(corenlp_output_path)

0 commit comments

Comments
 (0)