Index: /gs3-extensions/audioDB/trunk/src/perllib/audioDBBuilder.pm
===================================================================
--- /gs3-extensions/audioDB/trunk/src/perllib/audioDBBuilder.pm	(revision 24341)
+++ /gs3-extensions/audioDB/trunk/src/perllib/audioDBBuilder.pm	(revision 24341)
@@ -0,0 +1,141 @@
+###########################################################################
+#
+# audioDBBuilder.pm -- topup builder that gets audioDB initialized correctly
+#
+# A component of the Greenstone digital library software
+# from the New Zealand Digital Library Project at the 
+# University of Waikato, New Zealand.
+#
+# Copyright (C) 1999 New Zealand Digital Library Project
+#
+# 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+#
+###########################################################################
+
+package audioDBBuilder;
+
+use strict;
+no strict 'refs'; # allow filehandles to be variables and viceversa
+
+use extrabuilder;
+
+sub BEGIN {
+    @audioDBBuilder::ISA = ('extrabuilder');
+}
+
+
+sub new {
+    my $class = shift(@_);
+    my $self = new extrabuilder (@_);
+    $self = bless $self, $class;
+
+    $self->{'buildtype'} = "audioDB";
+
+    return $self;
+}
+
+
+sub default_buildproc {
+    my $self  = shift (@_);
+
+    return "audioDBBuildproc";
+}
+
+
+sub build_indexes {
+    my $self = shift (@_);
+    my ($indexname) = @_;
+
+    my $outhandle = $self->{'outhandle'};
+    my $build_dir = $self->{'build_dir'};
+    my $verbosity = $self->{'verbosity'};
+
+    print $outhandle "\n*** audioDB local-sensitivity-hashing (LSH) on chroma features\n"  if ($verbosity >= 1);
+
+    my $audioDB_dir = &util::filename_cat($build_dir, "audioDB");
+
+    if (! -d $audioDB_dir) {
+	&util::mk_all_dir ($audioDB_dir);
+    }
+    
+    my $opt_create_index = ($self->{'incremental'}) ? "" : "-removeold";
+
+
+    if ($opt_create_index) {
+
+	# init an audioDB database
+	
+	my $adb_filename = &util::filename_cat($audioDB_dir,"lsh-features.adb");
+
+	print $outhandle "\n    creating audioDB database\n"  if ($verbosity >= 1);
+
+	my $init_cmd = "audioDB -N -d $adb_filename";
+	my $init_status = system($init_cmd);
+	if ($init_status != 0) {
+	    print STDERR "Error: failed to initialize the audioDB database\n";
+	    print STDERR "         $adb_filename\n";
+	    print STDERR "       $!\n";
+	    if ($verbosity>=2) {
+		print STDERR "       cmd: $init_cmd\n";
+	    }
+	    return;
+	}
+
+	# Turn on L2-norming (Lebesgue space??) 
+	# => -L = "unit norm vectors and norm all future inserts"
+
+	my $l2norm_cmd = "audioDB -L -d $adb_filename";
+	my $l2norm_status = system($l2norm_cmd);
+	if ($l2norm_status != 0) {
+	    print STDERR "Error: failed to activate L2NORM tha audioDB database $\n";
+	    print STDERR "         $adb_filename\n";
+	    print STDERR "       $!\n";
+	    if ($verbosity>=2) {
+		print STDERR "       cmd: $l2norm_cmd\n";
+	    }
+	    return;
+	}
+
+
+	# Turn on power-log flag
+	my $pl_cmd = "audioDB -P -d $adb_filename";
+	my $pl_status = system($pl_cmd);
+	if ($pl_status != 0) {
+	    print STDERR "Error: failed to add the power-log flag to audioDB database\n";
+	    print STDERR "         $adb_filename\n";
+	    print STDERR "       $!\n";
+	    if ($verbosity>=2) {
+		print STDERR "       cmd: $pl_cmd\n";
+	    }
+	    return;
+	}
+
+    }
+
+    # Run the docs through the audioDB document processor
+
+    $self->{'buildproc'}->set_mode ('text');
+    $self->{'buildproc'}->reset();
+    &plugin::begin($self->{'pluginfo'}, $self->{'source_dir'},
+		   $self->{'buildproc'}, $self->{'maxdocs'});
+    &plugin::read ($self->{'pluginfo'}, $self->{'source_dir'},
+		   "", {}, {}, $self->{'buildproc'}, $self->{'maxdocs'}, 0, $self->{'gli'});
+    &plugin::end($self->{'pluginfo'});
+
+
+}
+
+1;
+
Index: /gs3-extensions/audioDB/trunk/src/perllib/audioDBBuildproc.pm
===================================================================
--- /gs3-extensions/audioDB/trunk/src/perllib/audioDBBuildproc.pm	(revision 24341)
+++ /gs3-extensions/audioDB/trunk/src/perllib/audioDBBuildproc.pm	(revision 24341)
@@ -0,0 +1,120 @@
+##########################################################################
+#
+# audioDBBuildproc.pm -- 
+# A component of the Greenstone digital library software
+# from the New Zealand Digital Library Project at the 
+# University of Waikato, New Zealand.
+#
+# Copyright (C) 1999 New Zealand Digital Library Project
+#
+# 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+#
+###########################################################################
+
+# This document processor outputs a document for indexing (should be 
+# implemented by subclass) and storing in the database
+
+package audioDBBuildproc;
+
+use strict; 
+no strict 'refs'; # allow filehandles to be variables and viceversa
+
+use util;
+
+use extrabuildproc;
+
+
+BEGIN {
+    @audioDBBuildproc::ISA = ('extrabuildproc');
+}
+
+sub new()
+  {
+    my $class = shift @_;
+
+    my $self = new extrabuildproc (@_);
+
+    return bless $self, $class;
+}
+
+
+sub textedit {
+    my $self = shift (@_);
+    my ($doc_obj,$file,$mode) = @_;
+
+    # Code written on the assumption that that audioDB does a replace
+    # operation when presented with a docid that already extis.
+    # => don't need to do anything special to distinguish between
+    #    a mode of "add" and "update"
+
+    my $outhandle = $self->{'outhandle'};
+
+
+    my $source_dir = $self->{'source_dir'}; # typically the archives dir
+    my $build_dir  = $self->{'build_dir'};
+
+    # full path to adb database
+    my $adb_filename 
+	= &util::filename_cat($build_dir, "audioDB", "lsh-features.adb");
+
+    # get doc id
+    my $doc_oid = $doc_obj->get_OID();
+
+    # map to assoc dir
+    my $top_section = $doc_obj->get_top_section();
+    my $assoc_file
+	= $doc_obj->get_metadata_element ($top_section,"assocfilepath");
+    my $assoc_filename = &util::filename_cat($source_dir,$assoc_file);
+
+    my $chr12_filename = &util::filename_cat($assoc_filename,"doc.chr12");
+    my $powerlog_filename = &util::filename_cat($assoc_filename,"doc.power");
+
+    print $outhandle "  Inserting features for $doc_oid\n";
+
+    my $cmd = "audioDB -d \"$adb_filename\" -I -k \"$doc_oid\" -f \"$chr12_filename\" -w \"$powerlog_filename\"";
+
+    my $status = system($cmd);
+    if ($status != 0) {
+	print STDERR "Error: failed to run:\n  $cmd\n$!\n";
+    }
+}
+
+sub text {
+    my $self = shift (@_);
+    my ($doc_obj,$file) = @_;
+
+    $self->textedit($doc_obj,$file,"add");
+}
+
+sub textreindex
+{
+    my $self = shift @_;
+    my ($doc_obj,$file) = @_;
+
+    $self->textedit($doc_obj,$file,"update");
+}
+
+sub textdelete
+{
+    my $self = shift @_;
+
+    my ($doc_obj,$file) = @_;
+
+    print STDERR "Warning: audioDB command-line does not currently support delete operation\n";
+
+    # $self->textedit($doc_obj,$file,"delete");
+}
+
+1;
