Ignore:
Timestamp:
2001-01-16T11:50:05+13:00 (23 years ago)
Author:
paynter
Message:

Updated classifiers to use the parsearg library instead of ad-hoc
"x=y" style parsing. (Backwards compatability maintained through
a quick hack to the load_classifier function in classfy.pm.)

File:
1 edited

Legend:

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

    r1483 r1839  
    3838#                      if metadata is also not included title will be 'List'
    3939
     40use BasClas;
    4041package List;
    4142
     
    4647}
    4748
     49sub print_usage {
     50    print STDERR "
     51  usage: classify List [options]
     52  options:
     53
     54   -metadata X    Metadata field used for classification,
     55                  list will be sorted by this element.
     56
     57   -title X       (optional) Title field for this classification.
     58                  if not included title field will be Metaname.
     59
     60   -sort X        (optional) Sort documents in list by this metadata field.
     61                  By default it will sort by Metaname, or (if this is not
     62                  set) in build (random) order.
     63";
     64}
     65
    4866sub new {
    49     my ($class, @options) = @_;
    50     my $self = new BasClas ($class, @_);
    51 
    52     my $list = [];
    53     my ($metaname, $title, $sortname);
    54 
    55     foreach $option (@options) {
    56     if ($option =~ /^metadata=(.*)$/i) {
    57         $metaname = $1;
    58         $list = {};
    59     } elsif ($option =~ /^title=(.*)$/i) {
    60         $title = $1;
    61     } elsif ($option =~ /^sort=(.*)$/i) {
    62         $sortname = $1;
    63     }
    64     }
    65 
    66     if (!defined $title) {
    67     if (defined $metaname) {
     67    my $class = shift (@_);
     68    my $self = new BasClas($class, @_);
     69   
     70    my ($metaname, $title, $sortname, $list);
     71
     72    if (!parsargv::parse(\@_,
     73             q^metadata/.*/^, \$metaname,
     74             q^title/.*/^, \$title,
     75             q^sort/.*/^, \$sortname,
     76             "allow_extra_options")) {
     77   
     78    print STDERR "\nIncorrect options passed to $class, check your collect.cfg file\n";
     79    &print_usage();
     80    die "\n";
     81    }
     82
     83    if (!$title) {
     84    if ($metaname) {
    6885        $title = $metaname;
    6986    } else {
     
    7289    }
    7390
    74     if (defined $sortname && $sortname =~ /^nosort$/i) {
    75     $sortname = undef;
    76     } elsif (!defined $sortname && defined $metaname) {
    77     $sortname = $metaname;
     91    if (!$sortname) {
     92    if ($metaname) {
     93        $sortname = $metaname;
     94    } else {
     95        $sortname = undef;
     96    }
     97    }
     98
     99    if ($metaname) {
     100    $list = {};
     101    } else {
     102    $list = [];
     103    $metaname = undef;
    78104    }
    79105
Note: See TracChangeset for help on using the changeset viewer.