[24341] | 1 | ###########################################################################
|
---|
| 2 | #
|
---|
| 3 | # audioDBBuilder.pm -- topup builder that gets audioDB initialized correctly
|
---|
| 4 | #
|
---|
| 5 | # A component of the Greenstone digital library software
|
---|
| 6 | # from the New Zealand Digital Library Project at the
|
---|
| 7 | # University of Waikato, New Zealand.
|
---|
| 8 | #
|
---|
| 9 | # Copyright (C) 1999 New Zealand Digital Library Project
|
---|
| 10 | #
|
---|
| 11 | # This program is free software; you can redistribute it and/or modify
|
---|
| 12 | # it under the terms of the GNU General Public License as published by
|
---|
| 13 | # the Free Software Foundation; either version 2 of the License, or
|
---|
| 14 | # (at your option) any later version.
|
---|
| 15 | #
|
---|
| 16 | # This program is distributed in the hope that it will be useful,
|
---|
| 17 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 18 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 19 | # GNU General Public License for more details.
|
---|
| 20 | #
|
---|
| 21 | # You should have received a copy of the GNU General Public License
|
---|
| 22 | # along with this program; if not, write to the Free Software
|
---|
| 23 | # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
| 24 | #
|
---|
| 25 | ###########################################################################
|
---|
| 26 |
|
---|
| 27 | package audioDBBuilder;
|
---|
| 28 |
|
---|
| 29 | use strict;
|
---|
| 30 | no strict 'refs'; # allow filehandles to be variables and viceversa
|
---|
| 31 |
|
---|
| 32 | use extrabuilder;
|
---|
| 33 |
|
---|
| 34 | sub BEGIN {
|
---|
| 35 | @audioDBBuilder::ISA = ('extrabuilder');
|
---|
| 36 | }
|
---|
| 37 |
|
---|
| 38 |
|
---|
| 39 | sub new {
|
---|
| 40 | my $class = shift(@_);
|
---|
| 41 | my $self = new extrabuilder (@_);
|
---|
| 42 | $self = bless $self, $class;
|
---|
| 43 |
|
---|
| 44 | $self->{'buildtype'} = "audioDB";
|
---|
| 45 |
|
---|
| 46 | return $self;
|
---|
| 47 | }
|
---|
| 48 |
|
---|
| 49 |
|
---|
| 50 | sub default_buildproc {
|
---|
| 51 | my $self = shift (@_);
|
---|
| 52 |
|
---|
| 53 | return "audioDBBuildproc";
|
---|
| 54 | }
|
---|
| 55 |
|
---|
| 56 |
|
---|
| 57 | sub build_indexes {
|
---|
| 58 | my $self = shift (@_);
|
---|
| 59 | my ($indexname) = @_;
|
---|
| 60 |
|
---|
| 61 | my $outhandle = $self->{'outhandle'};
|
---|
| 62 | my $build_dir = $self->{'build_dir'};
|
---|
| 63 | my $verbosity = $self->{'verbosity'};
|
---|
| 64 |
|
---|
| 65 | print $outhandle "\n*** audioDB local-sensitivity-hashing (LSH) on chroma features\n" if ($verbosity >= 1);
|
---|
| 66 |
|
---|
| 67 | my $audioDB_dir = &util::filename_cat($build_dir, "audioDB");
|
---|
| 68 |
|
---|
| 69 | if (! -d $audioDB_dir) {
|
---|
| 70 | &util::mk_all_dir ($audioDB_dir);
|
---|
| 71 | }
|
---|
| 72 |
|
---|
| 73 | my $opt_create_index = ($self->{'incremental'}) ? "" : "-removeold";
|
---|
| 74 |
|
---|
| 75 |
|
---|
| 76 | if ($opt_create_index) {
|
---|
| 77 |
|
---|
| 78 | # init an audioDB database
|
---|
| 79 |
|
---|
| 80 | my $adb_filename = &util::filename_cat($audioDB_dir,"lsh-features.adb");
|
---|
| 81 |
|
---|
| 82 | print $outhandle "\n creating audioDB database\n" if ($verbosity >= 1);
|
---|
| 83 |
|
---|
| 84 | my $init_cmd = "audioDB -N -d $adb_filename";
|
---|
| 85 | my $init_status = system($init_cmd);
|
---|
| 86 | if ($init_status != 0) {
|
---|
| 87 | print STDERR "Error: failed to initialize the audioDB database\n";
|
---|
| 88 | print STDERR " $adb_filename\n";
|
---|
| 89 | print STDERR " $!\n";
|
---|
| 90 | if ($verbosity>=2) {
|
---|
| 91 | print STDERR " cmd: $init_cmd\n";
|
---|
| 92 | }
|
---|
| 93 | return;
|
---|
| 94 | }
|
---|
| 95 |
|
---|
| 96 | # Turn on L2-norming (Lebesgue space??)
|
---|
| 97 | # => -L = "unit norm vectors and norm all future inserts"
|
---|
| 98 |
|
---|
| 99 | my $l2norm_cmd = "audioDB -L -d $adb_filename";
|
---|
| 100 | my $l2norm_status = system($l2norm_cmd);
|
---|
| 101 | if ($l2norm_status != 0) {
|
---|
| 102 | print STDERR "Error: failed to activate L2NORM tha audioDB database $\n";
|
---|
| 103 | print STDERR " $adb_filename\n";
|
---|
| 104 | print STDERR " $!\n";
|
---|
| 105 | if ($verbosity>=2) {
|
---|
| 106 | print STDERR " cmd: $l2norm_cmd\n";
|
---|
| 107 | }
|
---|
| 108 | return;
|
---|
| 109 | }
|
---|
| 110 |
|
---|
| 111 |
|
---|
| 112 | # Turn on power-log flag
|
---|
| 113 | my $pl_cmd = "audioDB -P -d $adb_filename";
|
---|
| 114 | my $pl_status = system($pl_cmd);
|
---|
| 115 | if ($pl_status != 0) {
|
---|
| 116 | print STDERR "Error: failed to add the power-log flag to audioDB database\n";
|
---|
| 117 | print STDERR " $adb_filename\n";
|
---|
| 118 | print STDERR " $!\n";
|
---|
| 119 | if ($verbosity>=2) {
|
---|
| 120 | print STDERR " cmd: $pl_cmd\n";
|
---|
| 121 | }
|
---|
| 122 | return;
|
---|
| 123 | }
|
---|
| 124 |
|
---|
| 125 | }
|
---|
| 126 |
|
---|
| 127 | # Run the docs through the audioDB document processor
|
---|
| 128 |
|
---|
| 129 | $self->{'buildproc'}->set_mode ('text');
|
---|
| 130 | $self->{'buildproc'}->reset();
|
---|
| 131 | &plugin::begin($self->{'pluginfo'}, $self->{'source_dir'},
|
---|
| 132 | $self->{'buildproc'}, $self->{'maxdocs'});
|
---|
| 133 | &plugin::read ($self->{'pluginfo'}, $self->{'source_dir'},
|
---|
| 134 | "", {}, {}, $self->{'buildproc'}, $self->{'maxdocs'}, 0, $self->{'gli'});
|
---|
| 135 | &plugin::end($self->{'pluginfo'});
|
---|
| 136 |
|
---|
| 137 |
|
---|
| 138 | }
|
---|
| 139 |
|
---|
| 140 | 1;
|
---|
| 141 |
|
---|