<!-- ant buildfile for orthophrase - a simple probabilsitic UMLS coder.

  Copyright (C) 2003, Regenstrief Institute. All rights reserved.

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

  Written and maintained by Gunther Schadow <gschadow@regenstrief.org>
  Regenstrief Institute, Inc.
  1050 Wishard Blvd., Indianapolis, IN 46202, USA.

  $Id: build.xml,v 1.1.1.1 2005/02/17 00:45:51 gschadow Exp $ 

  ROADMAP:

  ConceptFileBuilder(MRCON.sorted, 
                     MRSO.sorted, 
		     MRSTY.sorted, 
		     suppressibles.sorted) 
    -> concept.cnt, 
       stem-term.cnt,
       stem-term.txt,
       term-concept.txt,
       conceptname.seq.

  StemTermFileBuilder(stem-term.sorted
    -> stem-term.rec,
       stem-term.idx.

  TermConceptIndexBuilder(term-concept.sorted)
    -> term-concept.idx.
-->
<project name="orthophrase" default="all" basedir=".">

<property name="source.dir" value="src"/>
<property name="build.dir" value="build"/>
<property name="classes.dir" value="build/classes"/>
<property name="doc.dir" value="build/doc"/>
<property name="data.dir" value="build/orthophrase"/>
<property name="tmp.dir" value="build/tmp"/>
<property name="etc.dir" value="etc"/>
<property name="umls.dir" value="/rayde/2003AB/META"/>
<property name="datafiles.done.file" value="${tmp.dir}/datafiles.done"/>

<path id="class.path">
  <pathelement location="${classes.dir}"/>
  <pathelement path="${java.class.path}"/>
</path>

<target name="all" depends="fulljar, doc"/>

<target name="prepare">
  <mkdir dir="${build.dir}"/> 
  <mkdir dir="${doc.dir}"/> 
  <mkdir dir="${classes.dir}"/> 
  <mkdir dir="${data.dir}"/> 
  <mkdir dir="${tmp.dir}"/> 
</target>

<target name="uptodatecheck">
  <uptodate property="stem-term.txt-done"
          targetfile="${tmp.dir}/stem-term.txt">
    <srcfiles dir="${tmp.dir}" includes="MRCON.sorted"/>
    <srcfiles dir="${tmp.dir}" includes="MRSO.sorted"/>
    <srcfiles dir="${tmp.dir}" includes="MRSTY.sorted"/>
    <srcfiles dir="${tmp.dir}" includes="suppressibles.sorted"/>
  </uptodate>
  <uptodate property="datafiles.done"
          targetfile="${datafiles.done.file}">
    <srcfiles dir="${tmp.dir}" includes="stem-term.sorted"/>
  </uptodate>
</target>

<target name="compile" depends="prepare">
  <javac srcdir="${source.dir}"
         destdir="${classes.dir}"
	 debug="on"
	 source="1.4">
    <classpath refid="class.path"/>
  </javac>
</target>

<target name="jar" depends="compile">
  <jar jarfile="${build.dir}/orthophrase.jar"
      basedir="${build.dir}/classes"
      includes="**">
    <manifest>        
      <attribute name="Main-Class"
        value="org.regenstrief.orthophrase.PhraseCoder"/>
    </manifest>
  </jar>
</target>

<target name="fulljar" depends="compile,datafiles">
  <jar jarfile="${build.dir}/orthophrase.jar">
    <fileset dir="${build.dir}/classes" includes="**"/>
    <fileset dir="${build.dir}" includes="orthophrase/**"/>
    <manifest>        
      <attribute name="Main-Class"
         value="org.regenstrief.orthophrase.PhraseCoder"/>
    </manifest>
  </jar>
</target>

<target name="doc" depends="prepare">
 <javadoc packagenames="org.*"
   sourcepath="${source.dir}"
   destdir="${doc.dir}"
   source="1.4"
 />
</target>

<target name="clean">
 <delete dir="${build.dir}"/>
</target>

<target name="stem-term.txt" 
      depends="uptodatecheck,
               compile,
	       MRCON.sorted,
	       MRSO.sorted,
	       suppressibles.sorted"
        unless="stem-term.txt-done">
  <echo>building concept files ...</echo>
  <java classname="org.regenstrief.orthophrase.ConceptFileBuilder">
    <classpath refid="class.path"/>
    <sysproperty key="org.regenstrief.orthophrase.data" value="${data.dir}"/>
    <arg value="${tmp.dir}/MRCON.sorted"/>
    <arg value="${tmp.dir}/MRSO.sorted"/>
    <arg value="${tmp.dir}/MRSTY.sorted"/>
    <arg value="${tmp.dir}/suppressibles.sorted"/>
    <arg value="${tmp.dir}/stem-term.txt"/>
    <arg value="${tmp.dir}/term-concept.txt"/>
  </java>
</target>

<target name="datafiles" 
   depends="uptodatecheck, compile, stem-term.sorted, term-concept.sorted"
   unless="datafiles.done">
  <echo>building stem-term files ...</echo>
  <java classname="org.regenstrief.orthophrase.StemTermFileBuilder"
        failonerror="true">
    <classpath refid="class.path"/>
    <sysproperty key="org.regenstrief.orthophrase.data" value="${data.dir}"/>
    <arg value="${tmp.dir}/stem-term.sorted"/>
  </java>
  <echo>building term-concept index ...</echo>
  <java classname="org.regenstrief.orthophrase.TermConceptIndexBuilder"
        failonerror="true">
    <classpath refid="class.path"/>
    <sysproperty key="org.regenstrief.orthophrase.data" value="${data.dir}"/>
    <arg value="${tmp.dir}/term-concept.sorted"/>
  </java>
  <echo file="${datafiles.done.file}"/>
</target>

<target name="stem-term.sorted" depends="stem-term.txt">
  <apply executable="sort" dest="${tmp.dir}" failonerror="true">
    <arg value="-o"/>
    <targetfile/>
    <srcfile/>
    <mapper type="glob" from="*.txt" to="*.sorted"/>
    <fileset dir="${tmp.dir}">
      <include name="stem-term.txt"/>
    </fileset>
  </apply>
</target>

<target name="term-concept.sorted" depends="stem-term.txt">
  <apply executable="sort" dest="${tmp.dir}" failonerror="true">
    <arg value="-o"/>
    <targetfile/>
    <srcfile/>
    <mapper type="glob" from="*.txt" to="*.sorted"/>
    <fileset dir="${tmp.dir}">
      <include name="term-concept.txt"/>
    </fileset>
  </apply>
</target>

<target name="MRCON.sorted" depends="prepare">
  <apply executable="sort" dest="${tmp.dir}">
    <arg value="-o"/>
    <targetfile/>
    <arg value="-t|"/>
    <arg value="-s"/>
    <arg value="-k1,1"/>
    <arg value="-k4,4"/>
    <arg value="-k6,6"/>
    <srcfile/>
    <mapper type="glob" from="*" to="*.sorted"/>
    <fileset dir="${umls.dir}">
      <include name="MRCON"/>
    </fileset>
  </apply>
</target>

<target name="MRSO.sorted" depends="prepare">
  <apply executable="sort" dest="${tmp.dir}" failonerror="true">
    <arg value="-o"/>
    <targetfile/>
    <srcfile/>
    <mapper type="glob" from="*" to="*.sorted"/>
    <fileset dir="${umls.dir}">
      <include name="MRSO"/>
      <include name="MRSTY"/>
    </fileset>
  </apply>
</target>

<target name="suppressibles.sorted" depends="prepare">
  <apply executable="sort" dest="${tmp.dir}" failonerror="true">
    <arg value="-o"/>
    <targetfile/>
    <srcfile/>
    <mapper type="glob" from="*.txt" to="*.sorted"/>
    <fileset dir="${etc.dir}">
      <include name="suppressibles.txt"/>
    </fileset>
  </apply>
</target>

</project>
