forked from synalp/NER
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ester2SNER.sh
executable file
·200 lines (186 loc) · 6.35 KB
/
ester2SNER.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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
#!/bin/bash
JCP="bin:lib/jsafran.jar:lib/mallet.jar:lib/mallet-deps.jar:lib/trove.jar:lib/org.annolab.tt4j-1.0.12.jar:build/classes::lib/anna.jar"
#allens="pers fonc org loc prod time amount"
allens="pers org loc prod"
#allens="pn"
# debug
dest2="/home/rojasbar/development/contnomina/corpus/ESTER2ftp/package_scoring_ESTER2-v1.7/information_extraction_task"
export PATH=$PATH:$dest2/tools
if [ "1" == "0" ]; then
echo "conversion du train en .xml"
mkdir train
for i in /home/rojasbar/development/contnomina/corpus/ESTER2ftp/EN/train/trs_train_EN_v1.1/*.trs
#for i in /home/rojasbar/development/contnomina/corpus/ESTER2ftp/EN/test/*.trs
do
j=`echo $i | sed 's,/, ,g;s,trs$,,g' | awk '{print $NF}'`"xml"
echo "convert train to xml "$i" "$j
echo $i > tmp.trsl
java -cp "$JCP" ester2.ESTER2EN -trs2xml tmp.trsl
mv output.xml oo2.xml
java -cp "$JCP" jsafran.ponctuation.UttSegmenter oo2.xml
mv -f output.xml /tmp/
pushd .
java -cp "$JCP" jsafran.JSafran -retag /tmp/output.xml
mv -f output_treetagged.xml /tmp/
popd
mv /tmp/output_treetagged.xml train/$j
done
fi
if [ "1" == "0" ]; then
echo "conversion du dev en .xml"
mkdir dev
for i in /home/rojasbar/development/contnomina/corpus/ESTER2ftp/EN/dev/*.trs
#for i in /home/rojasbar/development/contnomina/corpus/ESTER2ftp/EN/test/*.trs
do
j=`echo $i | sed 's,/, ,g;s,trs$,,g' | awk '{print $NF}'`"xml"
echo "convert dev to xml "$i" "$j
echo $i > tmp.trsl
java -cp "$JCP" ester2.ESTER2EN -trs2xml tmp.trsl
mv output.xml oo2.xml
java -cp "$JCP" jsafran.ponctuation.UttSegmenter oo2.xml
mv -f output.xml /tmp/
pushd .
java -cp "$JCP" jsafran.JSafran -retag /tmp/output.xml
mv -f output_treetagged.xml /tmp/
popd
mv /tmp/output_treetagged.xml dev/$j
done
fi
#NO PARSING
if [ "1" == "0" ]; then
echo "parsing du train et du test"
#cp -f ../jsafran/mate.mods.FTBfull ./mate.mods
cp -f ../jsafran/mate.mods.ETB ./mate.mods
#mkdir train
for i in `cat esterTrainALL.xmll`
do
java -Xmx20g -cp "$JCP" jsafran.MateParser -parse $i
mv output.xml $i
done
for i in `cat esterTestALL.xmll`
do
java -Xmx20g -cp "$JCP" jsafran.MateParser -parse $i
mv output.xml $i
done
fi
if [ "1" == "0" ]; then
echo "create training files for CRF"
#ls parser/*_mate.xml > train.xmll
#echo "no syntax"
ls train/*.xml > train.xmll
for i in $allens
do
echo $i
# merge toutes les ENs qui commencent par $i en un seul fichier groups.$i.tab.crf
# laisse le champs syntaxique vide
java -Xmx1g -cp "$JCP" ester2.ESTER2EN -saveNER train.xmll $i
cp -f groups.$i.tab.crf groups.$i.tab.crf.train
done
fi
if [ "1" == "0" ]; then
echo "train CRF"
for en in $allens
#unk
do
sed 's,trainFile=synfeats0.tab,trainFile=groups.'$en'.tab.crf.train,g' syn.props > tmp.props
java -Xmx20g -cp ../stanfordNLP/stanford-ner-2014-01-04/stanford-ner-2014-01-04.jar edu.stanford.nlp.ie.crf.CRFClassifier -prop tmp.props
mv kiki.mods en.$en.mods
done
fi
###############################################################
if [ "1" == "0" ]; then
echo "create the graphs.xml files from the gold test TRS"
rm -rf test
mkdir test
touch test/trs2xml.list
for i in /home/rojasbar/development/contnomina/corpus/ESTER2ftp/EN/test/*.trs
do
j=`echo $i | sed 's,/, ,g;s,\.trs$,,g' | awk '{print $NF}'`
echo $i" "$j".xml"
echo $i > tmp.trsl
java -cp "$JCP" ester2.ESTER2EN -trs2xml tmp.trsl
grep -v -e '^<group> ' output.xml > oo2.xml
java -cp "$JCP" jsafran.ponctuation.UttSegmenter oo2.xml
mv -f output.xml /tmp/
pushd .
cd ../jsafran
java -cp "$JCP" jsafran.JSafran -retag /tmp/output.xml
mv -f output_treetagged.xml /tmp/
popd
mv /tmp/output_treetagged.xml test/$j".xml"
echo $i" test/"$j".xml" >> test/trs2xml.list
done
fi
if [ "1" == "0" ]; then
echo "conversion du test en .xml, similar to train"
rm -rf test
mkdir test
for i in /home/rojasbar/development/contnomina/corpus/ESTER2ftp/EN/test/*.trs
do
j=`echo $i | sed 's,/, ,g;s,trs$,,g' | awk '{print $NF}'`"xml"
echo "convert test to xml "$i" "$j
echo $i > tmp.trsl
java -cp "$JCP" ester2.ESTER2EN -trs2xml tmp.trsl
mv output.xml oo2.xml
java -cp "$JCP" jsafran.ponctuation.UttSegmenter oo2.xml
mv -f output.xml /tmp/
pushd .
cd ../jsafran
java -cp "$JCP" jsafran.JSafran -retag /tmp/output.xml
mv -f output_treetagged.xml /tmp/
popd
mv /tmp/output_treetagged.xml test/$j
echo $i" test/"$j >> test/trs2xml.list
done
fi
if [ "1" == "0" ]; then
echo "create the TAB files from the groups in the graphs.xml files"
ls test/*.xml | grep -v -e merged > test.xmll
for i in $allens
do
echo $i
# merge toutes les ENs qui commencent par $i en un seul fichier groups.$i.tab.crf
java -Xmx1g -cp "$JCP" ester2.ESTER2EN -saveNER test.xmll $i
cp -f groups.$i.tab.crf groups.$i.tab.crf.test
done
fi
if [ "1" == "0" ]; then
for en in $allens
do
echo "test the CRF for $en"
# I use a compiled version instead of the jar because I put verbose=2 so that to see all samples from Gibbs, and not just the best one
java -Xmx1g -cp ../stanfordNLP/stanford-ner-2014-01-04/stanford-ner-2014-01-04.jar edu.stanford.nlp.ie.crf.CRFClassifier -loadClassifier en.$en.mods -testFile groups.$en.tab.crf.test > test.$en.log
done
fi
#exit
# eval chaque EN individuellement
if [ "1" == "0" ]; then
for en in $allens
do
echo "evals individuelles baseline for $en $allens"
./conlleval.pl -d '\t' -o NO < test.$en.log > res.log
#./conlleval.pl -d '\t' -o NO < test.$en.log | grep $en >> res.log
done
fi
# merge les res dans un seul stmne
if [ "0" == "0" ]; then
echo "put all CRF outputs into a single xml file"
#ls test/*.xml | grep -v -e merged > train.xmll
java -cp "$JCP" ester2.ESTER2EN -mergeens esterTestALL.xmll $allens
echo "convert the graph.xml into a .stm-ne file"
nl=`wc -l test/trs2xml.list | cut -d' ' -f1`
for (( c=1; c<=$nl; c++ ))
do
echo " c = $c "
trs=`awk '{if (NR=='$c') print $1}' test/trs2xml.list`
grs=`awk '{if (NR=='$c') print $2}' test/trs2xml.list | sed 's,\.xml,.xml.merged.xml,g'`
out=`echo $grs | sed 's,\.xml\.merged\.xml,,g'`".stm-ne"
echo "build stmne from $trs $grs $out"
java -Xmx1g -cp "$JCP" ester2.STMNEParser -project2stmne $grs $trs $out
done
fi
# eval selon protocole ESTER2
if [ "0" == "0" ]; then
#analysis/spans/score-ne -rd $dest2/../../EN/test/ -cfg analysis/spans/NE-ESTER2.cfg -dic $dest2/tools/ESTER1-dictionnary-v1.9.1.dic test/*.stm-ne
score-ne -rd $dest2/../../EN/test/ -cfg $dest2/example/ref/NE-ESTER2.cfg -dic $dest2/tools/ESTER1-dictionnary-v1.9.1.dic test/*.stm-ne
fi