#!/bin/bash


THEORY=tmp.theory`date +%s`
GROUND=tmp.ground`date +%s`
MODEL=tmp.model`date +%s`

touch $THEORY
touch $GROUND
touch $MODEL

cat /dev/stdin >$THEORY


CORRECT=0
if [[ $CORRECT -eq 0 ]]
then
	cat $THEORY | `dirname $0`/gringo --lparse --shift >$GROUND
	CORRECT=$?
fi

if [[ $CORRECT -eq 0 ]]
then
	`dirname $0`/minisatid --verbosity=1 --outputformat=asp --format=asp --defsem=stable $GROUND >>$MODEL
	RESULT=$?
	if [[ $RESULT -ne 10 && $RESULT -ne 20 ]]
	then
		CORRECT=1
	fi
fi

if [[ $CORRECT -eq 0 ]]
then
	`dirname $0`/aspcomp3 $3 <$MODEL
fi

if [[ $CORRECT -ne 0 ]]
then
	echo "UNKNOWN"
fi

rm $GROUND &>/dev/null
rm $MODEL &>/dev/null
rm $THEORY &>/dev/null
