forked from czcorpus/xmlanntools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathveld_standoff2xml.sh
executable file
·70 lines (55 loc) · 2.16 KB
/
veld_standoff2xml.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
#!/bin/bash
# This script is a wrapper for the underlying xmlanntools script. It handles input and output files,
# respective to the VELD design, and also constructs a command from the VELD compose file, which is
# then executed.
set -e
# because the script excpects additional files with specific naming, but the code veld enables more
# flexibility, a temporary input file is created for consumption of the underlying script, without
# modifying that.
in_json_file_expected="${in_txt_file%.txt}.json"
if [ -n "$in_json_file" ] && [ $in_json_file != $in_json_file_expected ]; then
cp /veld/input/"$in_json_file" /veld/input/"$in_json_file_expected"
rm_json_file=1
fi
in_ann_json_file_expected="${in_txt_file%.txt}.ann.json"
if [ -n "$in_ann_json_file" ] && [ $in_ann_json_file != $in_ann_json_file_expected ]; then
cp /veld/input/"$in_ann_json_file" /veld/input/"$in_ann_json_file_expected"
rm_ann_json_file=1
fi
command="./standoff2xml /veld/input/${in_txt_file}"
if [ "$token_annotation" = "true" ]; then
command+=" -t"
fi
if [ -n "$warn_breaking" ]; then
command+=" -Wb ${warn_breaking}"
fi
if [ -n "$token_element" ]; then
command+=" -te ${token_element}"
fi
if [ -n "$sentence_element" ]; then
command+=" -se ${sentence_element}"
fi
if [ "$keep_between_sentences" = "true" ]; then
command+=" -kb"
fi
echo "executing:"
echo "$command"
eval "$command"
if [ "$rm_json_file" = "1" ]; then
rm /veld/input/"$in_json_file_expected"
fi
if [ "$rm_ann_json_file" = "1" ]; then
rm /veld/input/"$in_ann_json_file_expected"
fi
# The underlying script produces output next to the input file, which clashes with VELD's design. So
# the output file is moved from the input folder to the respective output folder. In case that the
# chain veld actually maps the input and output folder to the same host path, the `mv` operation
# might crash; hence ignoring such crashes with `set +e` and `2> /dev/null`
set +e
out_ann_xml_file_generated="${in_txt_file%.txt}.ann.xml"
if [ -n "$out_ann_xml_file" ]; then
mv /veld/input/"$out_ann_xml_file_generated" /veld/output/"$out_ann_xml_file" 2> /dev/null
else
mv /veld/input/"$out_ann_xml_file_generated" /veld/output/ 2> /dev/null
fi
exit 0