part_of_speech / install.sh
HoneyTian's picture
update
e778824
#!/usr/bin/env bash
# bash install.sh --stage 0 --stop_stage 2
# bash install.sh --stage 1 --stop_stage 1
verbose=true;
stage=-1
stop_stage=0
# parse options
while true; do
[ -z "${1:-}" ] && break; # break if there are no arguments
case "$1" in
--*) name=$(echo "$1" | sed s/^--// | sed s/-/_/g);
eval '[ -z "${'"$name"'+xxx}" ]' && echo "$0: invalid option $1" 1>&2 && exit 1;
old_value="(eval echo \\$$name)";
if [ "${old_value}" == "true" ] || [ "${old_value}" == "false" ]; then
was_bool=true;
else
was_bool=false;
fi
# Set the variable to the right value-- the escaped quotes make it work if
# the option had spaces, like --cmd "queue.pl -sync y"
eval "${name}=\"$2\"";
# Check that Boolean-valued arguments are really Boolean.
if $was_bool && [[ "$2" != "true" && "$2" != "false" ]]; then
echo "$0: expected \"true\" or \"false\": $1 $2" 1>&2
exit 1;
fi
shift 2;
;;
*) break;
esac
done
work_dir="$(pwd)"
data_dir="$(pwd)/data"
nltk_data_dir="${data_dir}/nltk_data"
nltk_data_tokenizers_dir="${nltk_data_dir}/tokenizers"
pyltp_models_dir="${data_dir}/pyltp_models"
mkdir -p "${data_dir}"
mkdir -p "${nltk_data_dir}"
mkdir -p "${nltk_data_tokenizers_dir}"
mkdir -p "${pyltp_models_dir}"
if [ ${stage} -le 0 ] && [ ${stop_stage} -ge 0 ]; then
$verbose && echo "stage 0: download nltk data punkt"
cd "${nltk_data_tokenizers_dir}" || exit 1;
# https://www.nltk.org/nltk_data/
if [ ! -d "punkt" ]; then
# nltk==3.8.1
wget -c https://raw.githubusercontent.com/nltk/nltk_data/gh-pages/packages/tokenizers/punkt.zip
unzip punkt.zip
rm punkt.zip
fi
if [ ! -d "punkt_tab" ]; then
# nltk==3.8.2
wget -c https://raw.githubusercontent.com/nltk/nltk_data/gh-pages/packages/tokenizers/punkt_tab.zip
unzip punkt_tab.zip
rm punkt_tab.zip
fi
fi
if [ ${stage} -le 1 ] && [ ${stop_stage} -ge 1 ]; then
$verbose && echo "stage 0: download pyltp models"
cd "${pyltp_models_dir}" || exit 1;
# pyltp
# https://ltp.ai/download.html
if [ ! -e "resources.json" ]; then
wget -c http://model.scir.yunfutech.com/model/ltp_data_v3.4.0.zip
unzip ltp_data_v3.4.0.zip
rm ltp_data_v3.4.0.zip
fi
fi