forked from c-amr/camr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
parse.sh
executable file
·150 lines (139 loc) · 3.62 KB
/
parse.sh
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#!/bin/bash
datadir=data
modelname=model
iter=1
function usage {
echo "Parsing helper"
echo
echo "usage: $0 [DATADIR] [--name NAME] [--model|-m PATH] [--iter N] [--skip] [--plain] [[--input] FILE] [[--output|-o] FILE] [--] [options to amr_parsing.py...]"
echo
echo "--name NAME choose alternative model name inside DATADIR (default: model)"
echo "--iter N select model of Nth iteration (default: $iter)"
echo "--model PATH where to save model file (default: DATADIR/model-iter<i>.m.{bz2,gz})"
echo "--input FILE specify input filename to parse (default: test inside DATADIR)"
echo "--output FILE specify parsed output filename (default: test.parsed inside DATADIR)"
echo "--plain expect input file in plain format when input set explicitly (sentence per line)"
echo "--skip do not run post-process step"
echo
echo "For list of amr_parsing.py options see:"
echo "$ `dirname $0`/amr_parsing.py --help"
echo
echo "Default data/model directory: $datadir"
echo
}
for arg in $@; do
if [ "$arg" == "--help" ] || [ "$arg" == "-h" ]; then
usage
exit 0
fi
done
default_datadir=1
skip=0
plain=0
reparse=1
while [ $# -gt 0 ]; do
if [ "$1" == "--" ]; then
shift
break
elif [ "$1" == "--model" ] || [ "$1" == "-m" ]; then
shift
model="$1"
shift
elif [ "$1" == "--name" ]; then
shift
modelname="$1"
output_tag=".$1"
shift
elif [ "$1" == "--iter" ] || [ "$1" == "-i" ]; then
shift
iter=$1
shift
elif [ "$1" == "--plain" ]; then
shift
plain=1
elif [ "$1" == "--skip" ]; then
shift
skip=1
elif [ "$1" == "--no-reparse" ]; then
shift
reparse=0
elif [ "$1" == "--input" ]; then
shift
input="$1"
shift
elif [ "$1" == "--output" ] || [ "$1" == "-o" ]; then
shift
output="$1"
shift
elif [ -d "$1" ] && [ $default_datadir -eq 1 ]; then
default_datadir=0
datadir="$1"
shift
elif [ -f "$1" ] && [ "$input" == "" ]; then
input="$1"
shift
elif [ ! -d "$1" ] && [ "$input" != "" ] && [ "$output" == "" ]; then
output="$1"
shift
else
echo "unknown argument: $1"
exit 1
fi
done
if [ "$input" == "" ]; then
input="$datadir/test"
amrfmt="--amrfmt"
elif [ $plain -ne 1 ]; then
amrfmt="--amrfmt"
elif [ $plain -eq 1 ]; then
amrfmt=
fi
if [ "$output" == "" ]; then
output="$input$output_tag.parsed"
fi
if [ "$model" == "" ]; then
model="$datadir/$modelname"
# check if model file exists
if [ ! -f "$model" ]; then
if [ -f "$model.m.bz2" ]; then
model="$model.m.bz2"
elif [ -f "$model.m.gz" ]; then
model="$model.m.gz"
elif [ -f "$model-iter$iter.m.bz2" ]; then
model="$model-iter$iter.m.bz2"
elif [ -f "$model-iter$iter.m.gz" ]; then
model="$model-iter$iter.m.gz"
else
# model file not found
model=
fi
fi
fi
if [ "$model" == "" ]; then
echo "error: specify valid model"
exit 1
fi
if [ $reparse -eq 1 ] || [ ! -f "$output" ]; then
echo "Executing:"
echo "`dirname $0`/amr_parsing.py --model \"$model\" --mode parse $amrfmt \"$input\" -o \"$output\" -W $@"
echo
time `dirname $0`/amr_parsing.py --model "$model" --mode parse $amrfmt "$input" -o "$output" -W $@
if [ $? -ne 0 ]; then
echo "Error parsing"
exit 1
fi
fi
# Post-processing
if [ $skip -ne 1 ]; then
final_output="$output.final"
echo -n "Post-processing $output to $final_output ..."
`dirname $0`/postprocess.py "$output" > "$final_output" 2> /dev/null
if [ $? -eq 0 ]; then
echo "ok"
else
echo "error, to see error, try executing manually:"
echo "$ `dirname $0`/postprocess.py \"$output\" > \"$final_output\""
fi
else
cp "$output" "$final_output"
fi