Changeset 316
- Timestamp:
- 1999-06-30T15:35:39+12:00 (25 years ago)
- Location:
- trunk/gsdl/perllib/classify
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl/perllib/classify/AZList.pm
r256 r316 11 11 12 12 return bless { 13 'OID'=>"NULL",14 13 'list'=>{}, 15 14 'metaname' => $options[0] … … 23 22 } 24 23 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 37 24 sub classify { 38 25 my $self = shift (@_); … … 45 32 # if this document doesn't contain the metadata element we're 46 33 # sorting by we won't include it in this classification 47 48 34 if (defined $metavalue) { 49 35 if ($self->{'metaname'} eq 'Creator') { … … 59 45 } 60 46 61 sub output_classify_info { 62 my $self = shift (@_); 63 my ($handle) = @_; 47 sub get_classify_info { 48 my $self = shift (@_); 64 49 65 50 my @classlist = sort {$self->{'list'}->{$a} cmp $self->{'list'}->{$b};} keys %{$self->{'list'}}; 66 51 my $subclasses = $self->splitlist (\@classlist); 67 52 53 my ($classifyinfo); 54 68 55 if (scalar @$subclasses) { 69 70 my @contents = ();71 map { push (@contents, "\".$_->[1]"); } @$subclasses;72 # write out top level entry73 $self->output_entry ($handle, $self->{'OID'}, $self->{'metaname'}, \@contents, "AZList");74 75 # write out the entries for each sub-classification76 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 } 77 64 78 65 } 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 75 sub 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; 83 85 } 84 86 … … 199 201 } 200 202 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 216 203 # format an english name for sorting 217 204 # i.e. convert to lowercase, put surname before -
trunk/gsdl/perllib/classify/Hierarchy.pm
r254 r316 25 25 26 26 return bless { 27 'OID'=>"NULL", 28 'descriptorlist'=>{}, 29 'locatorlist'=>{}, 27 'descriptorlist'=>{}, # first field in subject file 28 'locatorlist'=>{}, # second field in subject file 30 29 'subjectfile' => $subjectfile, 31 30 'metaname' => $options[1] … … 35 34 sub init { 36 35 my $self = shift (@_); 37 my $contenthash = {};38 36 39 37 # read in the subject file 40 38 my $list = &cfgread::read_cfg_file ($self->{'subjectfile'}, undef, '^[^#]?\w'); 41 39 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 42 43 foreach $descriptor (keys (%$list)) { 43 44 $self->{'descriptorlist'}->{$descriptor} = $list->{$descriptor}->[0]; … … 46 47 $self->{'locatorlist'}->{$list->{$descriptor}->[0]}->{'contents'} = []; 47 48 } 48 49 my $OID = $list->{$descriptor}->[0];50 if ($OID =~ s/\.(\d+)$//) {51 # $OID is now the parents OID52 my $child = $1;53 $contenthash->{$OID} = [] unless defined $contenthash->{$OID};54 push (@{$contenthash->{$OID}}, $child);55 }56 49 } 57 58 # need to shove each OID into the contents of its parent59 # do this separately in case classifications aren't in order in60 # subject file61 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'};78 50 } 79 51 … … 94 66 } 95 67 96 sub output_classify_info { 68 69 sub get_classify_info { 97 70 my $self = shift (@_); 98 my ($handle) = @_; 99 my $topcontents = []; 100 71 101 72 my $list = $self->{'locatorlist'}; 102 73 74 my $classifyinfo = $self->get_entry ($self->{'metaname'}, "Hierarchy"); 103 75 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 } 107 80 } 108 81 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; 113 83 } 114 84 115 sub output_entry { 85 86 sub get_OID_entry { 116 87 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/^\.+//; 118 92 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; 126 101 } 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); 128 111 } 129 112 130 sub numerically { $a <=> $b; } 113 sub 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 } 131 124 132 125 1; -
trunk/gsdl/perllib/classify/List.pm
r287 r316 20 20 21 21 return bless { 22 'OID'=>"NULL",23 22 'list'=>$list, 24 23 'metaname' => $options[0] … … 34 33 $self->{'list'} = []; 35 34 } 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'};48 35 } 49 36 … … 73 60 } 74 61 75 sub output_classify_info {62 sub get_classify_info { 76 63 my $self = shift (@_); 77 my ($handle) = @_;78 64 79 65 my $classifytitle = "List"; 80 66 my $contains = ""; 67 my @list = (); 81 68 if (defined $self->{'metaname'}) { 82 69 $classifytitle = $self->{'metaname'}; 83 70 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'}}; 86 73 } 87 74 } else { 88 if (scalar (@{$self->{'list'}}) > 0) { 89 $contains = join (";", @{$self->{'list'}}) . "\n"; 90 } 75 @list = @{$self->{'list'}}; 91 76 } 92 77 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; 100 87 } 101 88
Note:
See TracChangeset
for help on using the changeset viewer.