#!/bin/sh

#   sanity check usage
if [ $# -lt 1 -o $# -gt 3 ]; then
    echo "Usage: fasttext-lid <filename>|- [<k>] [<th>]"
    exit 1
fi
input="$1"
k="${2-1}"
th="${3-0}"

#   determine model to use
model_bin="@l_prefix@/share/fasttext/lid.176.bin"
model_ftz="@l_prefix@/share/fasttext/lid.176.ftz"
if [ -f "$model_bin" ]; then
    model="$model_bin"
else
    model="$model_ftz"
fi

#   predict the language
@l_prefix@/bin/fasttext predict-prob "$model" "$input" "$k" "$th" | \
    sed -e 's;__label__;;g'

