#!/bin/sh

TESTDIR=`pwd`
JAVALIB=/Volumes/Phata/JAVA/ontoalign/lib

#################################################################
# 206-207-210 I still have my problems with UTF-8
# 102 does not pass
# Unfortunatelly memory get saturated... see if I can unload

COMP='edna falcon foam ctxMatch2-1 dublin20 soton isti-cnr-benchmarks ola'

#################################################################
## CLEAN-UP

\rm -rf MERGED
\rm -rf $COMP

#################################################################
## UNZIP

mkdir SRC
cd SRC

unzip ../ZIPFILES/edna.zip

# ------------
# Montréal
unzip ../ZIPFILES/Results-OAEI05-OLA.zip
\rm -rf JWNLResource_en.properties PrincetonResource_en.properties README.txt file_properties.xml params.xml results.html resultsDirectory
mv resultsBenchmarks ola
for i in `ls ola/ola-noinst-*-1.rdf | sed "s:ola/ola-noinst-\([0-9][0-9][0-9]\)-1.rdf:\1:"`
do
mkdir ola/$i
mv ola/ola-noinst-$i-1.rdf ola/$i/ola.rdf
ed -s ola/$i/ola.rdf <<EOF
1,$ s;file://localhost/u/guegan/workspace/WGen/test/;http://oaei.inrialpes.fr/2005/;
w
EOF
done

# ------------
# Trento
tar xzvf ../ZIPFILES/ctxMatch2-1.tgz
#unzip ../ZIPFILES/mapping_DL.zip
mv benchmarks ctxMatch2-1
for i in `ls ctxMatch2-1/*/ctxMatch2-1.rdf | sed "s:ctxMatch2-1/\([0-9][0-9][0-9]\)/ctxMatch2-1.rdf:\1:"`
do
ed -s ctxMatch2-1/$i/ctxMatch2-1.rdf <<EOF
1,$ s;file:///home/stefano/myDocuments/works/mySoftware/eclipse_workspace/ctxMatch2.1/lib/testingCases/;http://oaei.inrialpes.fr/2005/;
w
1,$ s;onto.xml;onto.rdf;
w
1,$ s;http://oaei.inrialpes.fr/2005/benchmarks/onto.rdf;http://oaei.inrialpes.fr/2005/benchmarks/101/onto.rdf;
w
EOF
done

# ------------
# Southampton
mkdir soton
cd soton
unzip ../../ZIPFILES/Southampton.zip
for i in `ls *.xml | sed "s:101-\([0-9][0-9][0-9]\)StructurePlus.xml:\1:"`
do
mkdir $i
mv 101-${i}StructurePlus.xml $i/soton.rdf
ed -s $i/soton.rdf <<EOF
1,$ s;file://localhost/RESEAR~1/Crosi-prog/;http://oaei.inrialpes.fr/2005/;
w
EOF
done
cd ..

# ------------
# Nijan
unzip ../ZIPFILES/falcon.zip
mv benchmark falcon
for i in `ls falcon/*/falcon.rdf | sed "s:falcon/\([0-9][0-9][0-9]\)/falcon.rdf:\1:"`
do
ed -s falcon/$i/falcon.rdf <<EOF
1,$ s;-utf8;;
w
EOF
done

# ------------
# Karlsruhe
unzip ../ZIPFILES/results.zip
mv results2/benchmark foam

# ------------
# Dublin
unzip ../ZIPFILES/dublin20.zip
mv dublin20/benchmark/* .
for i in `ls dublin20/*/dublin20.rdf | sed "s:dublin20/\([0-9][0-9][0-9]\)/dublin20.rdf:\1:"`
do
ed -s dublin20/$i/dublin20.rdf <<EOF
1,$ s;/Users/andreas/contest/;http://oaei.inrialpes.fr/2005/;
w
EOF
done

# ------------
# Padova
unzip ../ZIPFILES/Troncy_OMAP_results.zip
mv benchmarks isti-cnr-benchmarks
for i in `ls isti-cnr-benchmarks/*/isti-cnr-benchmarks.rdf | sed "s:isti-cnr-benchmarks/\([0-9][0-9][0-9]\)/isti-cnr-benchmarks.rdf:\1:"`
do
ed -s isti-cnr-benchmarks/$i/isti-cnr-benchmarks.rdf <<EOF
1,$ s;file:///D:/ERCIM/Ontologies/;http://oaei.inrialpes.fr/2005/;
w
EOF
done
\rm -rf directory anatomy

cd ..

#################################################################
## NEW DIR

mkdir MERGED

cp -r /Volumes/Phata/Web/html/co4/oaei/2005/benchmarks/[0-9][0-9][0-9] MERGED

cd MERGED

#################################################################
## COPY

for name in $COMP
do
for i in `ls -d ???`
do
#echo ../SRC/$name/$i/$name.rdf
cp ../SRC/$name/$i/$name.rdf $i
done
done

#################################################################
## SPECIAL PURPOSE UTF-8 EDITION

for dir in 206 207 210
do
mv -f $dir/onto-utf8.rdf $dir/onto.rdf
mv -f $dir/refalign-utf8.rdf $dir/refalign.rdf
ed -s $dir/refalign.rdf <<EOF &>/dev/null
1,$ s:-utf8::g
w
EOF
# I must transcript Marc's results
mv $dir/foam.rdf $dir/foam-iso.rdf
cat $dir/foam-iso.rdf | ../convert_iso2utf8.pl | sed "s:iso-8859-1:utf-8:"> $dir/foam.rdf
done

#################################################################
## SPECIAL PURPOSE OFF-LINE EDITION

for i in `ls -d ???`
do
for name in $COMP refalign
do
echo $i/$name.rdf
ed -s $i/$name.rdf <<EOF &>/dev/null
1,$ s;<onto1>http://oaei.inrialpes.fr/2005/benchmarks/;<onto1>file://localhost$TESTDIR/MERGED/;
1,$ s;<onto2>http://oaei.inrialpes.fr/2005/benchmarks/;<onto2>file://localhost$TESTDIR/MERGED/;
w
EOF
done
done

# UNDOING LOCAL EVALUATION IF NECESSARY... (UTF-8 WILL NOT WORK)
#for i in `ls -d ???`
#do
#for name in $COMP refalign
#do
#echo $i/$name.rdf
#ed -s $i/$name.rdf <<EOF &>/dev/null
#1,$ s;<onto1>file://localhost$TESTDIR/MERGED/;<onto1>http://oaei.inrialpes.fr/2005/benchmarks/;
#1,$ s;<onto2>file://localhost$TESTDIR/MERGED/;<onto2>http://oaei.inrialpes.fr/2005/benchmarks/;
#w
#EOF
#done
#done

#################################################################
## Retract 102 test

mv 102 ../SRC/102

#################################################################
## EVAL

FILES=refalign,`echo $COMP | sed "s: :,:g"` 

rm -rf .r1xx .r2xx .r3xx

java -Xmx1200m -cp $JAVALIB/procalign.jar fr.inrialpes.exmo.align.util.GroupEval -c -l $FILES > results.html

open results.html

#################################################################
## EDIT EVAL

mkdir .r1xx
cp -r 1?? .r1xx
cd .r1xx
java -Xmx1200m -cp $JAVALIB/procalign.jar fr.inrialpes.exmo.align.util.GroupEval -c -l $FILES > ../1xx.html
cd ..

mkdir .r2xx
cp -r 2?? .r2xx
cd .r2xx
java -Xmx1200m -cp $JAVALIB/procalign.jar fr.inrialpes.exmo.align.util.GroupEval -c -l $FILES > ../2xx.html
cd ..

mkdir .r3xx
cp -r 3?? .r3xx
cd .r3xx
java -Xmx1200m -cp $JAVALIB/procalign.jar fr.inrialpes.exmo.align.util.GroupEval -c -l $FILES > ../3xx.html
cd ..

#################################################################
## GENERATE PRECISION/RECALL GRAPHS

java -Xmx1200m -cp $JAVALIB/procalign.jar fr.inrialpes.exmo.align.util.GenPlot -l edna $FILES > prgraph.tsv

#################################################################
## Unused

java -cp $JAVALIB/procalign.jar fr.inrialpes.exmo.align.util.EvalAlign refalign.rdf refalign.rdf

java -cp $JAVALIB/procalign.jar fr.inrialpes.exmo.align.util.EvalAlign -i fr.inrialpes.exmo.align.impl.eval.PRGraphEvaluator file://localhost$CWD/201/refalign.rdf file://localhost$CWD/201/dublin20.rdf

# Even better:

java -cp $JAVALIB/procalign.jar fr.inrialpes.exmo.align.util.GenPlot -l edna

Honestly I should provide directly the list of systems here...

