Ignore:
Timestamp:
2002-02-07T16:28:48+13:00 (22 years ago)
Author:
jrm21
Message:

Added removeprefix option. Added better usage information of the options.

File:
1 edited

Legend:

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

    r2897 r2955  
    5252sub print_usage {
    5353    print STDERR "
    54   usage: classify AZCompactList [options]
     54  usage: classify AZCompactList -metadata X [options]
    5555  options:
    56    -metadata     Metadata field used for classification
    57    -buttonname   Title to use on web pages
    58 
    59    -mingroup
    60    -minnesting
    61    -mincompact
    62    -maxcompact
    63    -doclevel
    64    -onlyfirst
     56   -metadata X            (required) Metadata field used for classification
     57   -buttonname X          Title to use on web pages (defaults to metadata)
     58   -removeprefix regex    pattern to remove from metadata before sorting
     59   -doclevel top|section  (Defaults to top)
     60   -mingroup N            Minimum num of documents required to form a new group
     61   -minnesting N          Minimum list size to become a nested list
     62   -mincompact N          Used in compact list
     63   -maxcompact N          Used in compact list
     64   -onlyfirst             Only use the first value if metadata is repeated.
    6565   -recopt
    6666";
     
    7171    my $self = new BasClas($class, @_);
    7272
    73     my ($metaname, $title);
     73    my ($metaname, $title, $removeprefix);
    7474    my $mingroup = 2;
    7575    my $minnesting = 20;
     
    8383             q^metadata/.*/^, \$metaname,
    8484             q^buttonname/.*/^, \$title,
    85 
     85             q^removeprefix/.*/^, \$removeprefix,
    8686             q^mingroup/.*/2^, \$mingroup,
    8787             q^minnesting/.*/20^, \$minnesting,
     
    9999    }
    100100
    101 # These are the old-fashioned optins to AZCompactList.
    102 # They should be deleted once we're sure the parsearg version is working.
    103 #    foreach $option (@options) {
    104 #   if ($option =~ /^metadata=(.*)$/i) {
    105 #       $metaname = $1;
    106 #   } elsif ($option =~ /^title=(.*)$/i) {
    107 #       $title = $1;
    108 #   } elsif ($option =~ /^mingroup(size)?=(.*)$/i) {
    109 #       $mingroup = $2;
    110 #   } elsif ($option =~ /^minnesting=(.*)$/i) {
    111 #       $minnesting = $1;
    112 #   } elsif ($option =~ /^mincompact=(.*)$/i) {
    113 #       $mincompact = $1;
    114 #   } elsif ($option =~ /^maxcompact=(.*)$/i) {
    115 #       $maxcompact = $1;
    116 #   } elsif ($option =~ /^doclevel=(.*)$/i) {
    117 #       $doclevel = $1;
    118 #   } elsif ($option =~ /^onlyfirst$/i) {
    119 #       $onlyfirst = 1;
    120 #   } elsif ($option =~ /^recopt$/i) {
    121 #       $recopt = "on";
    122 #   }
    123 #    }
    124 
    125101    if (!defined $metaname) {
    126102    my $outhandle = $self->{'outhandle'};
     
    137113    $self->{'metaname'} = $metaname;
    138114    $self->{'title'} = "$title";     # title for the titlebar.
     115    if (defined($removeprefix) && $removeprefix) {
     116    $self->{'removeprefix'} = $removeprefix;
     117    }
    139118    $self->{'mingroup'} = $mingroup;
    140119    $self->{'minnesting'} = $minnesting;
     
    216195    foreach $metavalue (@$metavalues)
    217196    {
    218 ###     print STDERR "$metaname :\tmetavalue = $metavalue\n";
    219197        # if this document doesn't contain the metadata element we're
    220198        # sorting by we won't include it in this classification
    221199        if (defined $metavalue && $metavalue =~ /\w/)
    222200        {
     201        if ($self->{'removeprefix'}) {
     202            $metavalue =~ s/^$self->{'removeprefix'}//;
     203        }
     204
    223205        my $formatted_metavalue = $metavalue;
     206
    224207        if ($self->{'metaname'} =~ m/^Creator(:.*)?$/)
    225208        {
     
    231214        }
    232215       
     216        #### prefix-str
     217        if (! defined($formatted_metavalue)) {
     218            print $outhandle "Warning: AZCompactList: metavalue is ";
     219            print $outhandle "empty\n";
     220            $formatted_metavalue="";
     221        }
     222
    233223        push(@{$self->{'list'}->{$full_doc_OID}},$formatted_metavalue);
    234224        push(@{$self->{'listmetavalue'}->{$full_doc_OID}} ,$metavalue);
     
    245235{
    246236    my ($self,$classlist_ref) = @_;
     237    my $outhandle = $self->{'outhandle'};
    247238   
    248239    my %mtfreq = ();
     
    294285    else
    295286    {
    296         my $outhandle = $self->{'outhandle'};
    297287        print $outhandle "AZCompactList ERROR - couldn't find classifier \"$listname\"\n";
    298288        die "\n";
     
    342332        }
    343333        if ($@) {
    344         my $outhandle = $self->{'outhandle'};
    345334        print $outhandle "$@";
    346335        die "\n";
     
    352341        {
    353342        my $formatted_node = $metavalue;
     343
     344        if ($self->{'removeprefix'}) {
     345            $formatted_node =~ s/^$self->{'removeprefix'}//;
     346        }
     347
    354348        if ($self->{'metaname'} =~ m/^Creator(:.*)?$/)
    355349        {
     
    360354            &sorttools::format_string_english(\$formatted_node);
    361355        }
    362        
     356
     357        # In case our formatted string is empty...
     358        if (! defined($formatted_node)) {
     359            print $outhandle "Warning: AZCompactList: metavalue is ";
     360            print $outhandle "empty\n";
     361            $formatted_node="";
     362        }
     363
    363364        $self->{'classifiers'}->{$metavalue}
    364365        = { 'classifyobj'   => $listclassobj,
     
    418419        my $outhandle=$self->{outhandle};
    419420        print $outhandle "Warning: AZCompactList::reclassify ";
    420         print $outhandle "could not find sub-node for $metavalue with doc_OID $doc_OID\n";
     421        print $outhandle "could not find sub-node for metadata=`$metavalue' with doc_OID $doc_OID\n";
    421422    }
    422423    }
Note: See TracChangeset for help on using the changeset viewer.