#!/usr/bin/env bash

OPENNMT_DIR=OpenNMT
CURRENT_DIR=$(pwd)
GPUID=1

cd ${OPENNMT_DIR} || exit 1

while [[ $# -gt 0 ]];do
    key="$1"
    shift # past key
    case $key in
        -c|--continue)
            CONTINUE="Y"
            ;;
        -g|--gpuid)
            GPUID="$1"
            shift
            ;;
        *)
            POSITIONAL+=("$key")
            ;;
    esac
done

# restore positional parameters
set -- "${POSITIONAL[@]}"
echo "Positional arguments: $*"

if [ ! "$CONTINUE" = "" ];then
    th train.lua \
       -data "${CURRENT_DIR}/data/processed-data-train.t7" \
       -save_model "${CURRENT_DIR}/data/final-model" \
       -save_every 50 \
       -gpuid "$GPUID" \
       -train_from "$1" -continue
else
    th train.lua \
       -data "${CURRENT_DIR}/data/processed-data-train.t7" \
       -save_model "${CURRENT_DIR}/data/final-model" \
       -save_every 200 \
       -gpuid "$GPUID"
fi

cd "${CURRENT_DIR}" || exit 1
