# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4
# $Id: Portfile 90590 2012-03-09 12:27:38Z hum@macports.org $

PortSystem          1.0

name                dualist
version             0.3
categories          java math textproc
platforms           darwin
maintainers         hum openmaintainer
license             Apache-2.0

description         An interactive machine learning system for building classifiers quickly.

long_description    DUALIST is an interactive machine learning system for building classifiers \
                    quickly. It does so by asking \"questions\" of the user in the form of both data \
                    instances (e.g., text documents) and features (e.g., words or phrases). It \
                    utilizes active and semi-supervised learning to quickly train a multinomial \
                    naive Bayes classifier for this setting.

homepage            http://code.google.com/p/dualist/
master_sites        googlecode:${name}
checksums           rmd160  74cd7775322249a2bd5791e7ca7d6ebbb75d0fb6 \
                    sha256  0b49f3d062b3587b7fc1bcd43b7fe8a618ecd869de00db2245209db96a4e8040

depends_run         port:play

use_zip             yes
worksrcdir          ${name}

use_configure       no
supported_archs     noarch

build.cmd           true

set share_java_dir  ${prefix}/share/java
set dualist_dir     ${share_java_dir}/${distname}

destroot {
    # Copy the distribution.
    xinstall -m 755 -d  ${destroot}${share_java_dir}
    copy ${worksrcpath} ${destroot}${dualist_dir}
    file attributes ${destroot}${dualist_dir}     -permissions 0777
    file attributes ${destroot}${dualist_dir}/gui -permissions 0777

    # Install the executable script.
    xinstall -m 755 ${worksrcpath}/dualist       ${destroot}${prefix}/bin
    reinplace "s|run gui|run ${dualist_dir}/gui|g" ${destroot}${prefix}/bin/dualist
    reinplace "s|-cp gui|-cp ${dualist_dir}/gui|g" ${destroot}${prefix}/bin/dualist
}

notes "To try DUALIST, run 'dualist gui' and open http://localhost:8080/."

post-deactivate {
    ui_msg "To revert the system after uninstalling the port,"
    ui_msg "delete the dualist directory:"
    ui_msg "  $ sudo rm -rf ${dualist_dir}"
}

variant mecab description {Use MeCab to analyze Japanese texts} {
    depends_lib-append port:mecab-java
    patchfiles-append  patch-mecab.diff

    post-extract {
        copy ${filespath}/SimpleMecabPipe.java ${worksrcpath}/core/src/dualist/pipes
        ln -s ${prefix}/share/java/mecab.jar ${worksrcpath}/core/lib/mecab.jar
    }

    build.cmd           ant
    build.target        main

    post-destroot {
        # Install another executable script using mecab.
        xinstall -m 755 ${filespath}/dualist-mecab     ${destroot}${prefix}/bin
        reinplace "s|run gui|run ${dualist_dir}/gui|g" ${destroot}${prefix}/bin/dualist-mecab
        reinplace "s|-cp gui|-cp ${dualist_dir}/gui|g" ${destroot}${prefix}/bin/dualist-mecab
        reinplace "s|@prefix@|${prefix}|g"             ${destroot}${prefix}/bin/dualist-mecab
    }

    notes-append "For Japanese texts, run 'dualist-mecab gui' instead of 'dualist gui'."
}
