forked from citiususc/Linguakit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlinguakit
448 lines (349 loc) · 14.7 KB
/
linguakit
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
#!/bin/bash
#shopt -s extglob
###################################################################
# Script to use different linguistic tools, for instance:
# - - dependency parser (DepPattern)
# - - PoS tagger + NER + NEC
# - - Sentiment Analysis
# - - Multiword Extractor (GaleXtra)
#
# Pablo Gamallo
# ProLNat@GE Group, CiTIUS
# University of Santiago de Compostela
###################################################################
############################
# Config
############################
MAIN_DIR="./Linguakit"
PROGS=$MAIN_DIR"/scripts"
DIRPARSER=$MAIN_DIR"/parsers"
############################
# Functions
############################
help()
{
echo "Syntax: linguakit <lang> <module> <input> [options]
language = gl, es, en, pt
module = dep, tagger, mwe, key, recog, sent, rel, tok, kwic, link, sum, conj, coref
input = path of the input (by default a txt file or gz/zip)
'dep' dependency syntactic analysis
'tagger' part-of-speech tagging
'mwe' multiword extraction
'key' keyword extraction
'recog' language recognition
'sent' sentiment analysis
'rel' relation extraction
'tok' tokenizer
'seg' sentence segmentation
'lem' lemmatization
'kwic' keyword in context (concordances)
'link' entity linking and semantic annotation
'sum' text summarizer
'conj' verb conjugator
'coref' named entity coreference solver
Available command-line options:
-a 'dep' option: simple dependency analysis (by default syntactic output)
-fa 'dep' option: full dependency analysis
-c 'dep' option: tagged text with syntactic information (for correction rules)
-conll 'dep' option: CoNLL output style
-noner 'tagger' option: no NER or NEC is processed (by default PoS tagger output)
-ner 'tagger' option: PoS tagger with Named Entity Recognition - NER (only with 'tagger' module)
-nec 'tagger' option: PoS tagger with Named Entity Classification - NEC (only with 'tagger' module)
-crnec 'coref' option: NEC correction with NE Coreference Resolution
-chi 'mwe' option: chi-square co-occurrence measure (by default)
-log 'mwe' option: loglikelihood
-scp 'mwe' option: symmetrical conditional probability
-mi 'mwe' option: mutual information
-cooc 'mwe' option: co-occurrence counting
-split 'tok' option: tokenization with splitting
-sort 'tok' option: tokenization with tokens sorted by frequency
-tokens 'kwic' option: contexts are tokens
The kwic option is mandatory and also requires another argument: the keyword to be searched
-json 'link' option: json output format of entity linking (by default)
-xml 'link' option: xml output format of entity linking
1-100 'sum' option: percentage of the input text that will be summarized (by default 10%)
-pe 'conj' option: the verb conjugator uses European Portuguese (by default)
-pb 'conj' option: the verb conjugator uses Brasilian Portuguese
-pen 'conj' option: the verb conjugator uses European Portuguese before the spell agreement
-pbn 'conj' option: the verb conjugator uses Brasilian Portuguese before the spell agreement
-s 'sent' and 'recog' options: if <input> is a string and not a file
"
exit
}
# Parámetros obrigatorios
[ $# -lt 3 ] && help
LING=$1
MOD=$2
FILE=$3
if [ "$LING" == "none" ] ; then
LING_back="none"
LING="en"
fi
# Parámetros opcionais
OPT=""
[ "$4" != "" ] && OPT=$4
NAMEPARSER="$DIRPARSER/parserDefault-$LING"
FILTER="$PROGS/AdapterFreeling-${LING}.perl"
CONLL="$PROGS/saidaCoNLL-fa.perl"
SENT=$MAIN_DIR"/tagger/"$LING"/sentences-"$LING"_exe.perl"
TOK=$MAIN_DIR"/tagger/"$LING"/tokens-"$LING"_exe.perl"
SPLIT=$MAIN_DIR"/tagger/"$LING"/splitter-"$LING"_exe.perl"
LEMMA=$MAIN_DIR"/tagger/"$LING"/lemma-"$LING"_exe.perl"
NER=$MAIN_DIR"/tagger/"$LING"/ner-"$LING"_exe.perl"
TAGGER=$MAIN_DIR"/tagger/"$LING"/tagger-"$LING"_exe.perl"
NEC=$MAIN_DIR"/tagger/"$LING"/nec-"$LING"_exe.perl"
COREF=$MAIN_DIR"/tagger/coref/coref_exe.perl"
SENTIMENT=$MAIN_DIR"/sentiment/nbayes.perl"
SENT_TRAIN=$MAIN_DIR"/sentiment/"$LING"/train_"$LING
SENT_LEX=$MAIN_DIR"/sentiment/"$LING"/lex_"$LING
MWE=$MAIN_DIR"/mwe/mwe.perl"
MWE_FILT=$MAIN_DIR"/mwe/filtro_galextra.perl"
MWE_SIX=$MAIN_DIR"/mwe/six_tokens.perl"
KEYWORD=$MAIN_DIR"/keywords/keywords_exe.perl"
REL=$MAIN_DIR"/triples/triples_exe.perl"
LINK=$MAIN_DIR"/linking/linking_exe.perl"
SUM=$MAIN_DIR"/summarizer/summarizer_exe.perl"
CONJ=$MAIN_DIR"/conjugator/conjugator_exe.perl"
QUELINGUA=$MAIN_DIR"/lanrecog/lanrecog.perl"
QUELINGUA_LEX=$MAIN_DIR"/lanrecog/lexicons"
QUELINGUA_SUFFIX=$MAIN_DIR"/lanrecog/morpho/suffix.txt"
###building a temporal lexicon:
for i in $QUELINGUA_LEX/* ; do cat $i |awk -v LANG=`basename $i |sed "s/\.lx//"` '{print $0"\t"LANG}' >> __tmp; done
QUELINGUA_LEX=__tmp
KWIC=$MAIN_DIR"/kwic/kwic.perl"
if [ "$MOD" != "dep" ] && [ "$MOD" != "tagger" ] && [ "$MOD" != "sent" ] && [ "$MOD" != "mwe" ] && [ "$MOD" != "recog" ] && [ "$MOD" != "tok" ] && [ "$MOD" != "kwic" ] && [ "$MOD" != "key" ] && [ "$MOD" != "rel" ] && [ "$MOD" != "link" ] && [ "$MOD" != "sum" ] && [ "$MOD" != "seg" ] && [ "$MOD" != "lem" ] && [ "$MOD" != "conj" ] && [ "$MOD" != "coref" ]; then
help;
echo "help" ;
fi
if [ "$OPT" != "-a" ] && [ "$OPT" != "-fa" ] && [ "$OPT" != "-c" ] && [ "$OPT" != "-conll" ] && [ "$OPT" != "-crnec" ] && [ "$OPT" != "-nec" ] && [ "$OPT" != "-ner" ] && [ "$OPT" != "-noner" ] && [ "$OPT" != "-s" ] && [ "$OPT" != "-chi" ] && [ "$OPT" != "-log" ] && [ "$OPT" != "-mi" ] && [ "$OPT" != "-cooc" ] && [ "$OPT" != "-scp" ] && [ "$OPT" != "-split" ] && [ "$OPT" != "-sort" ] && [ "$OPT" != "-tokens" ] && [ "$OPT" != "-xml" ] && [ "$OPT" != "-json" ] && ! [[ $OPT =~ [0-9][0-9]? ]] && [ "$OPT" != "-pe" ] && [ "$OPT" != "-pb" ] && [ "$OPT" != "-pen" ] && [ "$OPT" != "-pbn" ] && [ "$OPT" != "-crnec" ] && [ "$OPT" != "" ] ; then
#if [ "$OPT" != "-a" ] ; then
help;
echo "help" ;
fi
#if [[ $OPT != '^[0-9]+$' ]] ; then
# help;
# echo "help"
#fi
case $LING in
es) ;;
en) ;;
gl) ;;
pt) ;;
none) ;;
# fr) ;;
*) help
esac
#NAMEFILE=`basename $FILE`;
ZIP=`echo $FILE |awk '($0 ~ /(gz$|zip$)/) {print "zip"}'`
if [ "$MOD" != "recog" ] && [ "$LING_back" == "none" ] ; then
if [ "$OPT" == "-s" ] ; then
LING=`echo $FILE |tr -d '\015' | $SENT | $TOK | $QUELINGUA $QUELINGUA_LEX $QUELINGUA_SUFFIX`
elif [ "$ZIP" == "zip" ] ; then
LING=`zcat $FILE |tr -d '\015' | $SENT | $TOK | $QUELINGUA $QUELINGUA_LEX $QUELINGUA_SUFFIX`
else
LING=`cat $FILE |tr -d '\015' | $SENT | $TOK | $QUELINGUA $QUELINGUA_LEX $QUELINGUA_SUFFIX`
fi
echo "language = $LING"
NAMEPARSER="$DIRPARSER/parserDefault-$LING"
FILTER="$PROGS/AdapterFreeling-${LING}.perl"
CONLL="$PROGS/saidaCoNLL-fa.perl"
SENT=$MAIN_DIR"/tagger/"$LING"/sentences-"$LING"_exe.perl"
TOK=$MAIN_DIR"/tagger/"$LING"/tokens-"$LING"_exe.perl"
SPLIT=$MAIN_DIR"/tagger/"$LING"/splitter-"$LING"_exe.perl"
LEMMA=$MAIN_DIR"/tagger/"$LING"/lemma-"$LING"_exe.perl"
NER=$MAIN_DIR"/tagger/"$LING"/ner-"$LING"_exe.perl"
TAGGER=$MAIN_DIR"/tagger/"$LING"/tagger-"$LING"_exe.perl"
NEC=$MAIN_DIR"/tagger/"$LING"/nec-"$LING"_exe.perl"
COREF=$MAIN_DIR"/tagger/coref/coref_exe.perl"
SENTIMENT=$MAIN_DIR"/sentiment/nbayes.perl"
SENT_TRAIN=$MAIN_DIR"/sentiment/"$LING"/train_"$LING
SENT_LEX=$MAIN_DIR"/sentiment/"$LING"/lex_"$LING
fi
##by default dependency output
if [ "$MOD" == "dep" ] && [ "$OPT" == "" ] ; then
if [ "$ZIP" == "zip" ] ; then
zcat $FILE |tr -d '\015' | $SENT | $TOK | $SPLIT | $NER | $TAGGER |
$FILTER | $NAMEPARSER.perl "-a" ;
else
cat $FILE |tr -d '\015' | $SENT | $TOK | $SPLIT | $NER | $TAGGER |
$FILTER | $NAMEPARSER.perl "-a" ;
fi
##Conll dependency output
elif [ "$MOD" == "dep" ] && [ "$OPT" == "-conll" ] ; then
if [ "$ZIP" == "zip" ] ; then
zcat $FILE |tr -d '\015' | $SENT | $TOK | $SPLIT | $NER | $TAGGER |
$FILTER | $NAMEPARSER.perl "-fa" | $CONLL ;
else
cat $FILE |tr -d '\015' | $SENT | $TOK | $SPLIT | $NER | $TAGGER |
$FILTER | $NAMEPARSER.perl "-fa" | $CONLL ;
fi
##Other dependency outputs
elif [ "$MOD" == "dep" ] && [ "$OPT" != "" ] ; then
if [ "$ZIP" == "zip" ] ; then
zcat $FILE |tr -d '\015' | $SENT | $TOK | $SPLIT | $NER | $TAGGER |
$FILTER | $NAMEPARSER.perl $OPT ;
else
cat $FILE |tr -d '\015' | $SENT | $TOK | $SPLIT | $NER | $TAGGER |
$FILTER | $NAMEPARSER.perl $OPT ;
fi
##Triples extration (Open Information Extraction)
elif [ "$MOD" == "rel" ] ; then
if [ "$ZIP" == "zip" ] ; then
zcat $FILE |tr -d '\015' | $SENT | $TOK | $SPLIT | $NER | $TAGGER |
$FILTER | $NAMEPARSER.perl "-fa" | $CONLL | $REL $LING ;
else
cat $FILE |tr -d '\015' | $SENT | $TOK | $SPLIT | $NER | $TAGGER |
$FILTER | $NAMEPARSER.perl "-fa" | $CONLL | $REL $LING ;
fi
##by default PoS tagging
elif [ "$MOD" == "tagger" ] && [ "$OPT" == "" ] || [ "$OPT" == "-noner" ] ; then
if [ "$ZIP" == "zip" ] ; then
zcat $FILE |tr -d '\015' | $SENT | $TOK | $SPLIT | $LEMMA | $TAGGER
else
cat $FILE |tr -d '\015' | $SENT | $TOK | $SPLIT | $LEMMA | $TAGGER
fi
##PoS tagging with ner
elif [ "$MOD" == "tagger" ] && [ "$OPT" == "-ner" ] ; then
if [ "$ZIP" == "zip" ] ; then
zcat $FILE |tr -d '\015' | $SENT | $TOK | $SPLIT | $NER | $TAGGER
else
cat $FILE |tr -d '\015' | $SENT | $TOK | $SPLIT | $NER | $TAGGER
fi
##PoS tagging with nec
elif [ "$MOD" == "tagger" ] && [ "$OPT" == "-nec" ] ; then
if [ "$ZIP" == "zip" ] ; then
zcat $FILE |tr -d '\015' | $SENT | $TOK | $SPLIT | $NER | $TAGGER | $NEC
else
cat $FILE |tr -d '\015' | $SENT | $TOK | $SPLIT | $NER | $TAGGER | $NEC
fi
##PoS tagging with Coreference Resolution and NEC correction
elif [ "$MOD" == "coref" ] && [ "$OPT" == "-crnec" ] ; then
if [ "$ZIP" == "zip" ] ; then
zcat $FILE |tr -d '\015' | $SENT | $TOK | $SPLIT | $NER | $TAGGER | $NEC | $COREF "-n"
else
cat $FILE |tr -d '\015' | $SENT | $TOK | $SPLIT | $NER | $TAGGER | $NEC | $COREF "-n"
fi
##PoS tagging with Coreference Resolution
elif [ "$MOD" == "coref" ] ; then
if [ "$ZIP" == "zip" ] ; then
zcat $FILE |tr -d '\015' | $SENT | $TOK | $SPLIT | $NER | $TAGGER | $NEC | $COREF "-c"
else
cat $FILE |tr -d '\015' | $SENT | $TOK | $SPLIT | $NER | $TAGGER | $NEC | $COREF "-c"
fi
##multiword extraction
elif [ "$MOD" == "mwe" ] && [ "$OPT" == "" ] ; then
if [ "$ZIP" == "zip" ] ; then
zcat $FILE |tr -d '\015' | $SENT | $TOK | $SPLIT | $NER | $TAGGER | $MWE_FILT | $MWE_SIX | $MWE "-chi" 1
else
cat $FILE |tr -d '\015' | $SENT | $TOK | $SPLIT | $NER | $TAGGER | $MWE_FILT | $MWE_SIX |$MWE "-chi" 1
fi
elif [ "$MOD" == "mwe" ] && [ "$OPT" != "" ] ; then
if [ "$ZIP" == "zip" ] ; then
zcat $FILE |tr -d '\015' | $SENT | $TOK | $SPLIT | $NER | $TAGGER | $MWE_FILT | $MWE_SIX | $MWE $OPT 1
else
cat $FILE |tr -d '\015' | $SENT | $TOK | $SPLIT | $NER | $TAGGER | $MWE_FILT | $MWE_SIX |$MWE $OPT 1
fi
##keyword extraction
elif [ "$MOD" == "key" ] && [ "$OPT" == "" ] ; then
if [ "$ZIP" == "zip" ] ; then
zcat $FILE |tr -d '\015' | $SENT | $TOK | $SPLIT | $LEMMA | $TAGGER | $KEYWORD $LING
else
cat $FILE |tr -d '\015' | $SENT | $TOK | $SPLIT | $LEMMA | $TAGGER | $KEYWORD $LING
fi
##sentiment analysis
elif [ "$MOD" == "sent" ] && [ "$OPT" == "" ] ; then
if [ "$ZIP" == "zip" ] ; then
zcat $FILE |tr -d '\015' | $SENT | $TOK | $SPLIT | $NER | $TAGGER | $SENTIMENT $SENT_TRAIN $SENT_LEX
else
cat $FILE |tr -d '\015' | $SENT | $TOK | $SPLIT | $NER | $TAGGER | $SENTIMENT $SENT_TRAIN $SENT_LEX
fi
##sentiment analysis with a string as input
elif [ "$MOD" == "sent" ] && [ "$OPT" == "-s" ] ; then
echo $FILE |tr -d '\015' | $SENT | $TOK | $SPLIT | $NER | $TAGGER | $SENTIMENT $SENT_TRAIN $SENT_LEX
##language recognition
elif [ "$MOD" == "recog" ] && [ "$OPT" == "" ] ; then
if [ "$ZIP" == "zip" ] ; then
zcat $FILE |tr -d '\015' | $SENT | $TOK | $QUELINGUA $QUELINGUA_LEX $QUELINGUA_SUFFIX
else
cat $FILE |tr -d '\015' | $SENT | $TOK | $QUELINGUA $QUELINGUA_LEX $QUELINGUA_SUFFIX
fi
##tokenizer
elif [ "$MOD" == "tok" ] && [ "$OPT" == "" ] ; then
if [ "$ZIP" == "zip" ] ; then
zcat $FILE |tr -d '\015' | $SENT | $TOK
else
cat $FILE |tr -d '\015' | $SENT | $TOK
fi
##tokenizer with splitting
elif [ "$MOD" == "tok" ] && [ "$OPT" == "-split" ] ; then
if [ "$ZIP" == "zip" ] ; then
zcat $FILE |tr -d '\015' | $SENT | $TOK | $SPLIT
else
cat $FILE |tr -d '\015' | $SENT | $TOK | $SPLIT
fi
##tokenizer with sorting by frequency
elif [ "$MOD" == "tok" ] && [ "$OPT" == "-sort" ] ; then
if [ "$ZIP" == "zip" ] ; then
zcat $FILE |tr -d '\015' | $SENT | $TOK | $SPLIT | sort | uniq -c | sort -nr
else
cat $FILE |tr -d '\015' | $SENT | $TOK | $SPLIT | sort | uniq -c | sort -nr
fi
##segmentation
elif [ "$MOD" == "seg" ] && [ "$OPT" == "" ] ; then
if [ "$ZIP" == "zip" ] ; then
zcat $FILE |tr -d '\015' | $SENT
else
cat $FILE |tr -d '\015' | $SENT
fi
##lemmatizer and PoS tagging
elif [ "$MOD" == "lem" ] && [ "$OPT" == "" ] ; then
if [ "$ZIP" == "zip" ] ; then
zcat $FILE |tr -d '\015' | $SENT |$TOK | $SPLIT | $LEMMA
else
cat $FILE |tr -d '\015' | $SENT |$TOK | $SPLIT | $LEMMA
fi
##key word in context (kwic) or concordances with just tokens as context
elif [ "$MOD" == "kwic" ] && [ "$OPT" == "-tokens" ] ; then
if [ "$ZIP" == "zip" ] ; then
zcat $FILE |tr -d '\015' | $SENT | $KWIC $5
else
cat $FILE |tr -d '\015' | $SENT | $KWIC $5
fi
##entity linking
elif [ "$MOD" == "link" ] && [ "$OPT" == "" ] ; then
if [ "$ZIP" == "zip" ] ; then
zcat $FILE |tr -d '\015' | $LINK $LING "json"
else
cat $FILE |tr -d '\015' | $LINK $LING "json"
fi
##entity linking
elif [ "$MOD" == "link" ] && [ "$OPT" != "" ] ; then
if [ "$ZIP" == "zip" ] ; then
zcat $FILE |tr -d '\015' | $LINK $LING $OPT
else
cat $FILE |tr -d '\015' | $LINK $LING $OPT
fi
##summarizer
elif [ "$MOD" == "sum" ] && [ "$OPT" == "" ] ; then
if [ "$ZIP" == "zip" ] ; then
zcat $FILE |tr -d '\015' | $SUM $LING 10
else
cat $FILE |tr -d '\015' | $SUM $LING 10
fi
##summarizer
elif [ "$MOD" == "sum" ] && [ "$OPT" != "" ] ; then
if [ "$ZIP" == "zip" ] ; then
zcat $FILE |tr -d '\015' | $SUM $LING $OPT
else
cat $FILE |tr -d '\015' | $SUM $LING $OPT
fi
##conjugator
elif [ "$MOD" == "conj" ] && [ "$OPT" == "" ] ; then
echo $FILE | $CONJ $LING
elif [ "$MOD" == "conj" ] && [ "$LING" == "pt" ] &&[ "$OPT" != "" ] ; then
echo $FILE | $CONJ $LING $OPT
##language recognition with a string as input
elif [ "$MOD" == "recog" ] && [ "$OPT" == "-s" ] ; then
echo $FILE |tr -d '\015' | $SENT | $TOK | $QUELINGUA $QUELINGUA_LEX $QUELINGUA_SUFFIX
fi
rm __tmp