#! /bin/sh
#
# Constructs all tables for the Database.
# Works from scratch and assumes the standard 
# directory layout of the IFA corpus.
# Should be run from 
# 'SLcorpus/DatabaseFiles/scripts/ConstructTables'
# This takes a loooooong time.
#
# You can give mnemonic arguments to indicate what
# should be inserted. See --help for a complete list
# of arguments.
#
# The address and name of the the database.
# Is used by the SQL commands, should be the
# same as that used by the perl scripts,
# i.e., the address and name in Links.pl.
#
# What to do?
TABLELIST="Phonemes PhInfo"
TABLES=${@:-${TABLELIST}}

case $TABLES in (*--help*)
    echo ConstructAllTables '[' $TABLELIST ']'
    exit
esac

#
# The IP address (Domain Name) of the DBserver.
# Either address in the highest Links.pl file or localhost.
SQLHOST=$(perl -e '$L="../../../../Links.pl";$L=~s!^\.\./!!g unless -s $L;require $L;print $DBMSaddress;')||localhost;export SQLHOST
# The name of the database. The script will use 'ifacorpus' if $DBNAME does not exist.
DBNAME=$(perl -e '$L="../../../../Links.pl";$L=~s@^\.\./@@g unless -s $L;require $L; print $DBMSname;')||ifacorpus;export DBNAME
#
# Note that LOCALDBHOST takes precedence if it exists
# e.g.,
# >LOCALDBHOST=localhost;export LOCALDBHOST
# overrules SQLHOST with a locally running DB
# Uncomment the following if your DB always runs locally
# SQLHOST=${1:-localhost};export SQLHOST
case $TABLES in (*Phonemes*)
    echo ConstructPhonemeTables.pl: `date`
    perl ConstructPhonemeTables.pl '*'
esac

case $TABLES in (*PhInfo*)
    echo ConstructPhonLexInfoTables.pl: `date`
    perl ConstructPhonLexInfoTables.pl -d 'corpuswordlist' -d '../../../scripts/CelexWordList' -f FREQUENCY '*'
    echo ConstructPhInfoTwenteTables.pl: `date`
    perl ConstructPhInfoTwenteTables.pl '*'
esac



