Changeset 6961


Ignore:
Timestamp:
2004-03-08T13:47:02+13:00 (20 years ago)
Author:
kjdon
Message:

removed some commented out stuff, changed the -metadata option to accept a comma separated list of metadata names - now uses the first one available, and list is sorted by this element

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl/perllib/classify/AZList.pm

    r6940 r6961  
    3636}
    3737
    38 use strict;
    3938
    4039my $arguments =
     
    6665        'args'     => $arguments };
    6766
    68 #  sub print_usage {
    69 #      print STDERR "
    70 #    usage: classify AZList [options]
    71 #    options:
    72  
    73 #    -metadata X           (required) Metadata field used for classification.
    74 #                          List will be sorted by this element.
    75 
    76 #    -buttonname X         (optional) Button name for this classification.
    77 #                          defaults to metadata name.
    78 
    79 #    -removeprefix regex   (optional) A prefix to ignore in the Metadata values
    80 #                          for the field when sorting.
    81 #  ";
    82 #  }
    8367
    8468sub new {
     
    8670    my $self = new BasClas($class, @_);
    8771   
    88     # 14-05-02 To allow for proper inheritance of arguments - John Thompson
    8972    my $option_list = $self->{'option_list'};
    9073    push( @{$option_list}, $options );
    9174   
    92     my ($metaname, $title, $removeprefix, $removesuffix);
     75    my ($metadata, $title, $removeprefix, $removesuffix);
    9376   
    9477    if (!parsargv::parse(\@_,
    95              q^metadata/.*/^, \$metaname,
     78             q^metadata/.*/^, \$metadata,
    9679             q^buttonname/.*/^, \$title,
    9780             q^removeprefix/.*/^, \$removeprefix,
     
    10184    print STDERR "\nIncorrect options passed to $class, check your collect.cfg file\n";
    10285    $self->print_txt_usage("");  # Use default resource bundle
    103     die "\n";
    104     }
    105 
    106     if (!defined $metaname) {
     86    die "incorrect options \n";
     87    }
     88
     89    if (!$metadata) {
     90    print STDERR "AZList: -metadata option REQUIRED \n";
    10791    $self->print_txt_usage("");  # Use default resource bundle
    108     print STDERR "AZList used with no metadata name\n";
    109     die "\n";
    110     }
    111    
    112     $title = $metaname unless ($title);
     92   
     93    die "AZList: -metadata option REQUIRED\n";
     94    }
     95   
     96    my @meta_list = split(/,/, $metadata);
     97    my $meta1 = $meta_list[0];
     98
     99    $title = $meta1 unless ($title);
    113100   
    114101    $self->{'list'} = {};
    115     $self->{'metaname'} = $metaname;
     102    $self->{'meta_list'} = \@meta_list;
    116103    $self->{'title'} = $title;
     104   
    117105    if (defined($removeprefix) && $removeprefix) {
    118106    $removeprefix =~ s/^\^//; # don't need a leading ^
     
    138126
    139127    my $doc_OID = $doc_obj->get_OID();
    140     my $metavalue = $doc_obj->get_metadata_element ($doc_obj->get_top_section(), $self->{'metaname'}, $self->{'ignore_namespace'});
    141 
    142     # if this document doesn't contain the metadata element we're
    143     # sorting by we won't include it in this classification
    144     if (defined $metavalue && $metavalue ne "") {
    145     if (defined($self->{'removeprefix'}) &&
    146         length($self->{'removeprefix'})) {
    147         $metavalue =~ s/^$self->{'removeprefix'}//;
    148     }
    149     if (defined($self->{'removesuffix'}) &&
    150         length($self->{'removesuffix'})) {
    151         $metavalue =~ s/$self->{'removesuffix'}$//;
    152     }
    153 
    154     if ($self->{'metaname'} eq 'Language') {
    155         $metavalue = $iso639::fromiso639{$metavalue};
    156     } elsif ($self->{'metaname'} eq 'Creator') {
    157         &sorttools::format_string_name_english (\$metavalue);
    158     } else {
    159         &sorttools::format_string_english (\$metavalue);
    160     }
    161     if (defined $self->{'list'}->{$doc_OID}) {
    162         my $outhandle = $self->{'outhandle'};
    163         print $outhandle "WARNING: AZList::classify called multiple times for $doc_OID\n";
    164     }
    165     if ($metavalue) {
    166         $self->{'list'}->{$doc_OID} = $metavalue;
    167     } else {
    168         my $outhandle = $self->{'outhandle'};
    169         print $outhandle "WARNING: AZList: $doc_OID metadata is empty - not classifying\n";
    170     }
    171     }
     128    my $outhandle = $self->{'outhandle'};
     129
     130    my $metavalue;
     131    my $metaname;
     132    # should we extend this to use all available metadata not just the first?
     133    if (!defined $self->{'meta_list'}) {
     134    # just in case
     135    return;
     136    }
     137
     138    # find the first available metadata
     139    foreach $m (@{$self->{'meta_list'}}) {
     140    $metavalue = $doc_obj->get_metadata_element($doc_obj->get_top_section(), $m);
     141    $metaname = $m;
     142    last if defined $metavalue;
     143    }
     144   
     145    #if we haven't found a metavalue here, then the doc shouldn't be included
     146    if (!defined $metavalue || $metavalue eq "") {
     147    print $outhandle "WARNING: AZList: $doc_OID metadata is empty - not classifying\n";
     148    return;
     149    }
     150
     151    if (defined($self->{'removeprefix'}) &&
     152    length($self->{'removeprefix'})) {
     153    $metavalue =~ s/^$self->{'removeprefix'}//;
     154    }
     155    if (defined($self->{'removesuffix'}) &&
     156    length($self->{'removesuffix'})) {
     157    $metavalue =~ s/$self->{'removesuffix'}$//;
     158    }
     159   
     160    $metavalue = $self->format_metadata_for_sorting($metaname, $metavalue, $doc_obj);
     161   
     162    if (defined $self->{'list'}->{$doc_OID}) {
     163    print $outhandle "WARNING: AZList::classify called multiple times for $doc_OID\n";
     164    }
     165    if ($metavalue) {
     166    $self->{'list'}->{$doc_OID} = $metavalue;
     167    } else {
     168    # the formatting has made it empty
     169    my $outhandle = $self->{'outhandle'};
     170    print $outhandle "WARNING: AZList: $doc_OID metadata has become empty - not classifying\n";
     171    }
     172   
    172173}
    173174
Note: See TracChangeset for help on using the changeset viewer.