Changeset 384 for trunk


Ignore:
Timestamp:
1999-07-14T14:52:39+12:00 (25 years ago)
Author:
sjboddie
Message:

added a sort option

File:
1 edited

Legend:

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

    r342 r384  
    11# classifier plugin for generating hierarchical classifications
     2
     3# options for this classifier are:
     4# file.txt - classification file
     5# Metaname - metadata field to test against file.txt
     6# sort=Meta - this option is optional (genious;-). by default this
     7#             classifier will sort documents within each section
     8#             alphabetically by Title. sort=nosort prevents sorting
     9#             (i.e. documents will end up in build order), sort=Meta
     10#             will sort each field alphabetically by Meta (Meta may
     11#             also be 'Filename' to sort by the original filename).
     12
    213
    314package Hierarchy;
     
    516use util;
    617use cfgread;
     18use sorttools;
    719
    820sub new {
     
    1325        "Usage: Hierarchy subjectfile metadata\n";
    1426    }
    15 
     27    my $sortname = "Title";
     28    if ((scalar @options > 2) && $options[2] =~ /^sort=(.*)$/i) {
     29    $sortname = $1;
     30    $sortname = undef if $sortname =~ /^nosort$/;
     31    }
     32   
    1633    my $subjectfile = &util::filename_cat($ENV{'GSDLCOLLECTDIR'},"etc", $options[0]);
    1734    if (!-e $subjectfile) {
     
    2845    'locatorlist'=>{},    # second field in subject file
    2946    'subjectfile' => $subjectfile,
    30     'metaname' => $options[1]
     47    'metaname' => $options[1],
     48    'sortname' => $sortname
    3149    }, $class;
    3250}
     
    6280    if ((defined $self->{'descriptorlist'}->{$metaelement}) &&
    6381        (defined $self->{'locatorlist'}->{$self->{'descriptorlist'}->{$metaelement}})) {
    64         push (@{$self->{'locatorlist'}->{$self->{'descriptorlist'}->{$metaelement}}->{'contents'}}, $doc_OID);
     82
     83        my $sortmeta = "";
     84        if (defined $self->{'sortname'}) {
     85        if ($self->{'sortname'} =~ /^filename$/i) {
     86            $sortmeta = $doc_obj->get_source_filename();
     87        } else {
     88            $sortmeta = $doc_obj->get_metadata_element($doc_obj->get_top_section(),
     89                                   $self->{'sortname'});
     90            if ($self-{'sortname'} eq "Creator") {
     91            &sorttools::format_string_name_english ($sortmeta);
     92            } else {
     93            &sorttools::format_string_english ($sortmeta);
     94            }
     95        }
     96        $sortmeta = "" unless defined $sortmeta;
     97        }
     98
     99        push (@{$self->{'locatorlist'}->{$self->{'descriptorlist'}->{$metaelement}}->{'contents'}},
     100          [$doc_OID, $sortmeta]);
    65101    }
    66102    }
     
    76112    foreach $OID (keys (%$list)) {
    77113    my $tempinfo = $self->get_OID_entry ($OID, $classifyinfo, $list->{$OID}->{'title'}, "Hierarchy");
    78     foreach $subOID (@{$list->{$OID}->{'contents'}}) {
    79         push (@{$tempinfo->{'contains'}}, {'OID'=>$subOID});
     114
     115    if (defined $self->{'sortname'}) {
     116        foreach $subOID (sort {$a->[1] cmp $b->[1];} @{$list->{$OID}->{'contents'}}) {
     117        push (@{$tempinfo->{'contains'}}, {'OID'=>$subOID->[0]});
     118        }
     119    } else {
     120        foreach $subOID (@{$list->{$OID}->{'contents'}}) {
     121        push (@{$tempinfo->{'contains'}}, {'OID'=>$subOID->[0]});
     122        }
    80123    }
    81124    }
    82 
     125   
    83126    return $classifyinfo;
    84127}
     
    124167}
    125168
     169
     170
    1261711;
Note: See TracChangeset for help on using the changeset viewer.