#!/bin/sh
#
#  Licensed Materials - Property of IBM
#
#  5724-A60
#  5765-F36
#  (C) Copyright IBM Corporation 2001, 2002, 2003
#
#  ALL rights reserved.
#  US Government Users Restricted Rights -
#  Use, duplication or disclosure restricted by GSA ADP
#  Schedule Contract with IBM Corporation.
#

# Description: Convert mining models from V6 format to XML

# path to IM Scoring Services
IMSCPATH=/opt/IMinerX/V8.2

# check arguments
if test $# -lt 2
then
        echo "Usage: $0 result-file output-file"
        exit 1
fi

# start with output
echo IBM Intelligent Miner Scoring
echo Copyright IBM Corporation 2003
echo

# check for existance of idmxtype
if test ! -x $IMSCPATH/bin/idmxtype
then
        echo Error: cannot find idmxtype in $IMSCPATH/bin
        echo
        exit 1
fi

# get type of result
$IMSCPATH/bin/idmxtype $1
RESULTTYPE=$?

# set converter appropriate for given result
case $RESULTTYPE in
   0) CONVERTER=noresult ;;
   1) CONVERTER=idmxrul; DESCRIPTION="Associations" ;;
   4) CONVERTER=idmxtree; DESCRIPTION="Tree Classification" ;;
   7) CONVERTER=idmxncla; DESCRIPTION="Neural Classification" ;;
  10) CONVERTER=idmxdclu; DESCRIPTION="Demographic Clustering" ;;
  13) CONVERTER=idmxnclu; DESCRIPTION="Neural Clustering" ;;
  16) CONVERTER=idmxrbf;  DESCRIPTION="Radial Basis Prediction" ;;
  18) CONVERTER=idmxnpre; DESCRIPTION="Neural Prediction" ;;
  20) CONVERTER=idmdxdqs; DESCRIPTION="Bivariate Statistics" ;;
  24) CONVERTER=idmxsreg; DESCRIPTION="Polynomial Regression" ;;
  *)  CONVERTER=error;;
esac

# handle exceptions
if test "$CONVERTER" = "error" -o "$CONVERTER" = "noresult"
then
   echo Error: cannot determine result type of $1
   exit 1
fi

# convert the result
echo Converting $DESCRIPTION result
$IMSCPATH/bin/$CONVERTER $1 $2
RC=$?

# finish up
if test $RC -eq 0
then
        echo Conversion finished successful
else
        echo Error: could not convert $1
fi
exit $RC

