Changeset 316 for trunk/gsdl/perllib


Ignore:
Timestamp:
1999-06-30T15:35:39+12:00 (25 years ago)
Author:
sjboddie
Message:
  • changed the way classifiers work
Location:
trunk/gsdl/perllib/classify
Files:
3 edited

Legend:

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

    r256 r316  
    1111
    1212    return bless {
    13     'OID'=>"NULL",
    1413    'list'=>{},
    1514    'metaname' => $options[0]
     
    2322}
    2423
    25 sub set_OID {
    26     my $self = shift (@_);
    27     my ($OID) = @_;
    28 
    29     $self->{'OID'} = $OID;
    30 }
    31 
    32 sub get_OID {
    33     my $self = shift (@_);
    34     return $self->{'OID'};
    35 }
    36 
    3724sub classify {
    3825    my $self = shift (@_);
     
    4532    # if this document doesn't contain the metadata element we're
    4633    # sorting by we won't include it in this classification
    47 
    4834    if (defined $metavalue) {
    4935    if ($self->{'metaname'} eq 'Creator') {
     
    5945}
    6046
    61 sub output_classify_info {
    62     my $self = shift (@_);
    63     my ($handle) = @_;
     47sub get_classify_info {
     48    my $self = shift (@_);
    6449
    6550    my @classlist = sort {$self->{'list'}->{$a} cmp $self->{'list'}->{$b};} keys %{$self->{'list'}};
    6651    my $subclasses = $self->splitlist (\@classlist);
    6752
     53    my ($classifyinfo);
     54
    6855    if (scalar @$subclasses) {
    69    
    70     my @contents = ();
    71     map { push (@contents, "\".$_->[1]"); } @$subclasses;
    72     # write out top level entry
    73     $self->output_entry ($handle, $self->{'OID'}, $self->{'metaname'}, \@contents, "AZList");
    74 
    75     # write out the entries for each sub-classification
    76     map {$self->output_entry ($handle, "$self->{'OID'}.$_->[1]", $_->[0], $_->[2]);} @$subclasses;
     56    $classifyinfo = $self->get_entry ($self->{'metaname'}, "AZList");
     57    foreach $subclass (@$subclasses) {
     58        my $tempclassify = $self->get_entry($subclass->[0], "AZList");
     59        foreach $subsubOID (@{$subclass->[2]}) {
     60        push (@{$tempclassify->{'contains'}}, {'OID'=>$subsubOID});
     61        }
     62        push (@{$classifyinfo->{'contains'}}, $tempclassify);
     63    }
    7764 
    7865    } else {
    79 
    80     # write out top level entry
    81     $self->output_entry ($handle, $self->{'OID'}, $self->{'metaname'}, \@classlist, "AZList");
    82     }
     66    $classifyinfo = $self->get_entry($self->{'metaname'}, "AZList");
     67    foreach $subOID (@classlist) {
     68        push (@{$classifyinfo->{'contains'}}, {'OID'=>$subOID});
     69    }
     70    }
     71
     72    return $classifyinfo;
     73}
     74
     75sub get_entry {
     76    my $self = shift (@_);
     77    my ($title, $classifytype) = @_;
     78   
     79    # organise into classification structure
     80    my %classifyinfo = ('classifytype'=>$classifytype,
     81            'Title'=>$title,
     82            'contains'=>[]);
     83
     84    return \%classifyinfo;
    8385}
    8486
     
    199201}
    200202
    201 sub output_entry {
    202     my $self = shift (@_);
    203     my ($handle, $OID, $title, $contentsref, $classifytype) = @_;
    204    
    205     print $handle "[$OID]\n";
    206     print $handle "<doctype>classify\n";
    207     print $handle "<hastxt>0\n";
    208     print $handle "<Title>$title\n";
    209     print $handle "<classifytype>$classifytype\n" if defined $classifytype;
    210     if (scalar @$contentsref) {
    211     print $handle "<contains>", join (";", @$contentsref), "\n";
    212     }
    213     print $handle '-' x 70, "\n";
    214 }
    215 
    216203# format an english name for sorting
    217204# i.e. convert to lowercase, put surname before
  • trunk/gsdl/perllib/classify/Hierarchy.pm

    r254 r316  
    2525
    2626    return bless {
    27     'OID'=>"NULL",
    28     'descriptorlist'=>{},
    29     'locatorlist'=>{},
     27    'descriptorlist'=>{}, # first field in subject file
     28    'locatorlist'=>{},    # second field in subject file
    3029    'subjectfile' => $subjectfile,
    3130    'metaname' => $options[1]
     
    3534sub init {
    3635    my $self = shift (@_);
    37     my $contenthash = {};
    3836
    3937    # read in the subject file
    4038    my $list = &cfgread::read_cfg_file ($self->{'subjectfile'}, undef, '^[^#]?\w');
    4139   
     40    # $list is a hash that is indexed by the descriptor. The contents of this
     41    # hash is a list of two items. The first item is the OID and the second item
     42    # is the title
    4243    foreach $descriptor (keys (%$list)) {
    4344    $self->{'descriptorlist'}->{$descriptor} = $list->{$descriptor}->[0];
     
    4647        $self->{'locatorlist'}->{$list->{$descriptor}->[0]}->{'contents'} = [];
    4748    }
    48    
    49     my $OID = $list->{$descriptor}->[0];
    50     if ($OID =~ s/\.(\d+)$//) {
    51         # $OID is now the parents OID
    52         my $child = $1;
    53         $contenthash->{$OID} = [] unless defined $contenthash->{$OID};
    54         push (@{$contenthash->{$OID}}, $child);
    55     }
    5649    }
    57 
    58     # need to shove each OID into the contents of its parent
    59     # do this separately in case classifications aren't in order in
    60     # subject file
    61     foreach $OID (keys (%$contenthash)) {
    62     push (@{$self->{'locatorlist'}->{$OID}->{'contents'}},
    63           sort numerically @{$contenthash->{$OID}});
    64     map { $_ = "\".$_"; } @{$self->{'locatorlist'}->{$OID}->{'contents'}};
    65     }
    66 }
    67 
    68 sub set_OID {
    69     my $self = shift (@_);
    70     my ($OID) = @_;
    71 
    72     $self->{'OID'} = $OID;
    73 }
    74 
    75 sub get_OID {
    76     my $self = shift (@_);
    77     return $self->{'OID'};
    7850}
    7951
     
    9466}
    9567
    96 sub output_classify_info {
     68
     69sub get_classify_info {
    9770    my $self = shift (@_);
    98     my ($handle) = @_;
    99     my $topcontents = [];
    100 
     71   
    10172    my $list = $self->{'locatorlist'};
    10273
     74    my $classifyinfo = $self->get_entry ($self->{'metaname'}, "Hierarchy");
    10375    foreach $OID (keys (%$list)) {
    104     $self->output_entry ($handle, "$self->{'OID'}.$OID",
    105                  $list->{$OID}->{'title'}, $list->{$OID}->{'contents'});
    106     push (@$topcontents, $OID) if $OID !~ /\./;
     76    my $tempinfo = $self->get_OID_entry ($OID, $classifyinfo, $list->{$OID}->{'title'}, "Hierarchy");
     77    foreach $subOID (@{$list->{$OID}->{'contents'}}) {
     78        push (@{$tempinfo->{'contains'}}, {'OID'=>$subOID});
     79    }
    10780    }
    10881
    109     # top level of classification
    110     map { $_ = "\".$_"; } sort numerically @$topcontents;
    111     $self->output_entry ($handle, $self->{'OID'}, $self->{'metaname'},
    112              $topcontents, "Hierarchy");
     82    return $classifyinfo;
    11383}
    11484
    115 sub output_entry {
     85
     86sub get_OID_entry {
    11687    my $self = shift (@_);
    117     my ($handle, $OID, $title, $contentsref, $classifytype) = @_;
     88    my ($OID, $classifyinfo, $title, $classifytype) = @_;
     89
     90    $OID = "" unless defined $OID;
     91    $OID =~ s/^\.+//;
    11892   
    119     print $handle "[$OID]\n";
    120     print $handle "<doctype>classify\n";
    121     print $handle "<hastxt>0\n";
    122     print $handle "<Title>$title\n";
    123     print $handle "<classifytype>$classifytype\n" if defined $classifytype;
    124     if (scalar @$contentsref) {
    125     print $handle "<contains>", join (";", @$contentsref), "\n";
     93    my ($headOID, $tailOID) = $OID =~ /^(\d+)(.*)$/;
     94    $tailOID = "" unless defined $tailOID;
     95
     96
     97    if (!defined $headOID) {
     98    $classifyinfo->{'Title'} = $title;
     99    $classifyinfo->{'classifytype'} = $classifytype;
     100    return $classifyinfo;
    126101    }
    127     print $handle '-' x 70, "\n";
     102
     103    $classifyinfo->{'contains'} = [] unless defined $classifyinfo->{'contains'};
     104   
     105    # add entries to the contains list until we have one for headOID
     106    while (scalar(@{$classifyinfo->{'contains'}}) < $headOID) {
     107    push (@{$classifyinfo->{'contains'}}, $self->get_entry("", $classifytype));
     108    }
     109
     110    return $self->get_OID_entry ($tailOID, $classifyinfo->{'contains'}->[($headOID-1)], $title, $classifytype);
    128111}
    129112
    130 sub numerically { $a <=> $b; }
     113sub get_entry {
     114    my $self = shift (@_);
     115    my ($title, $classifytype) = @_;
     116   
     117    # organise into classification structure
     118    my %classifyinfo = ('classifytype'=>$classifytype,
     119            'Title'=>$title,
     120            'contains'=>[]);
     121
     122    return \%classifyinfo;
     123}
    131124
    1321251;
  • trunk/gsdl/perllib/classify/List.pm

    r287 r316  
    2020
    2121    return bless {
    22     'OID'=>"NULL",
    2322    'list'=>$list,
    2423    'metaname' => $options[0]
     
    3433    $self->{'list'} = [];
    3534    }
    36 }
    37 
    38 sub set_OID {
    39     my $self = shift (@_);
    40     my ($OID) = @_;
    41 
    42     $self->{'OID'} = $OID;
    43 }
    44 
    45 sub get_OID {
    46     my $self = shift (@_);
    47     return $self->{'OID'};
    4835}
    4936
     
    7360}
    7461
    75 sub output_classify_info {
     62sub get_classify_info {
    7663    my $self = shift (@_);
    77     my ($handle) = @_;
    7864
    7965    my $classifytitle = "List";
    8066    my $contains = "";
     67    my @list = ();
    8168    if (defined $self->{'metaname'}) {
    8269    $classifytitle = $self->{'metaname'};
    8370    if (keys %{$self->{'list'}}) {
    84         $contains = join (";", sort {$self->{'list'}->{$a}
    85                      cmp $self->{'list'}->{$b};} keys %{$self->{'list'}}) . "\n";
     71        @list = sort {$self->{'list'}->{$a}
     72              cmp $self->{'list'}->{$b};} keys %{$self->{'list'}};
    8673    }
    8774    } else {
    88     if (scalar (@{$self->{'list'}}) > 0) {
    89         $contains = join (";", @{$self->{'list'}}) . "\n";
    90     }
     75    @list = @{$self->{'list'}};
    9176    }
    9277
    93     print $handle "[$self->{'OID'}]\n";
    94     print $handle "<doctype>classify\n";
    95     print $handle "<hastxt>0\n";
    96     print $handle "<classifytype>List\n";
    97     print $handle "<Title>$classifytitle\n";
    98     print $handle "<contains>$contains\n" if $contains =~ /\w/;
    99     print $handle '-' x 70, "\n";
     78    # organise into classification structure
     79    my %classifyinfo = ('classifytype'=>'List',
     80            'Title'=>$classifytitle,
     81            'contains'=>[]);
     82    foreach $OID (@list) {
     83    push (@{$classifyinfo{'contains'}}, {'OID'=>$OID});
     84    }
     85
     86    return \%classifyinfo;
    10087}
    10188
Note: See TracChangeset for help on using the changeset viewer.