# SYNTAX :
#
#    <script> UNIV_NUM SEED
#
# Creates the LUBM(UNIV_NUM, SEED) N-Triples files
# and directs them to the standard output for redirection or pipe operations
#

SCRIPT_NAME=`basename "$0"`
SYNTAX="
SYNTAX: $SCRIPT_NAME <univ_num> <seed>
\t<univ_num>\t:\tNumber of universities,
\t<seed>\t\t:\tseed value"

# there should be 2 arguments
if [ "$#" -ne 2 ]; then
    echo -e "Illegal number of parameters ${SYNTAX}"
    exit 1
fi

# store current working directory
#echo "Storing current working directory"
PWD=`pwd`
# STEP 0: Find the directory where the script is located in
BASE="$( cd -P "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

# assign arguments to variables
UNIV_NUM=${1}
SEED=${2} # convert to capital

# echo -e "${SCRIPT_NAME} ${UNIV_NUM} ${SEED}"

# test valid range of UNIV_NUM
VALID_UNIV_NUM_INDEX="integer in [1, 50]";
if ((UNIV_NUM < 1 || UNIV_NUM > 50)); then 
	echo -e "Valid range for univ_num:  ${VALID_UNIV_NUM_INDEX}"
    echo -e "${SYNTAX}"
    exit 2 
fi

# create directory for specific LUBM dataset
mkdir -p  ${BASE}/${UNIV_NUM}_${SEED}
# change working directory to it
cd ${BASE}/${UNIV_NUM}_${SEED}

# call the UBA generator with the 3 parameters 
echo -e "\nUsing Lehigh University Benchmark (LUBM) Generator to generate LUBM(${UNIV_NUM}, ${SEED}) dataset\n> ..."
java -cp ${BASE}/UBA/uba-1.7.jar edu.lehigh.swat.bench.uba.Generator -univ ${UNIV_NUM} -seed ${SEED} -onto https://swat.cse.lehigh.edu/onto/univ-bench.owl

# convert OWL files to N-Triples
echo -e "\nUsing RDF2RDF utility to convert RDF/XML *.owl files to a single N-Triples file\n> ..."
java -jar ${BASE}/rdf2rdf-1.0.1-2.3.1.jar *.owl lubm-${UNIV_NUM}_${SEED}.nt

# restore current working directory
#echo "Restoring working directory to initial value: ${PWD}"
cd ${PWD}

