[537] | 1 | ###########################################################################
|
---|
| 2 | #
|
---|
| 3 | # classify.pm --
|
---|
| 4 | # A component of the Greenstone digital library software
|
---|
| 5 | # from the New Zealand Digital Library Project at the
|
---|
| 6 | # University of Waikato, New Zealand.
|
---|
| 7 | #
|
---|
| 8 | # Copyright (C) 1999 New Zealand Digital Library Project
|
---|
| 9 | #
|
---|
| 10 | # This program is free software; you can redistribute it and/or modify
|
---|
| 11 | # it under the terms of the GNU General Public License as published by
|
---|
| 12 | # the Free Software Foundation; either version 2 of the License, or
|
---|
| 13 | # (at your option) any later version.
|
---|
| 14 | #
|
---|
| 15 | # This program is distributed in the hope that it will be useful,
|
---|
| 16 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 17 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 18 | # GNU General Public License for more details.
|
---|
| 19 | #
|
---|
| 20 | # You should have received a copy of the GNU General Public License
|
---|
| 21 | # along with this program; if not, write to the Free Software
|
---|
| 22 | # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
| 23 | #
|
---|
| 24 | ###########################################################################
|
---|
| 25 |
|
---|
[214] | 26 | # functions to handle classifiers
|
---|
| 27 |
|
---|
| 28 | package classify;
|
---|
| 29 |
|
---|
| 30 | require util;
|
---|
[27303] | 31 | use FileUtils;
|
---|
[8220] | 32 | require AllList;
|
---|
[15703] | 33 |
|
---|
[15705] | 34 | use dbutil;
|
---|
[5682] | 35 | use gsprintf;
|
---|
[15703] | 36 | use strict; no strict 'subs';
|
---|
[214] | 37 |
|
---|
[11994] | 38 |
|
---|
[5682] | 39 | sub gsprintf
|
---|
| 40 | {
|
---|
| 41 | return &gsprintf::gsprintf(@_);
|
---|
| 42 | }
|
---|
| 43 |
|
---|
| 44 |
|
---|
[6967] | 45 | sub load_classifier_for_info {
|
---|
| 46 | my ($classifier) = shift @_;
|
---|
[214] | 47 |
|
---|
[6967] | 48 | # find the classifier
|
---|
[27303] | 49 | # - used to have hardcoded list of places to load classifier from. We
|
---|
| 50 | # should, instead, try loading from all of the perllib places on the
|
---|
| 51 | # library path, as that improves support for extensions. Special cases
|
---|
| 52 | # needed for collection specific and custom classifier. [jmt12]
|
---|
| 53 | my @possible_class_paths;
|
---|
[14239] | 54 | if (defined($ENV{'GSDLCOLLECTION'}))
|
---|
| 55 | {
|
---|
[27303] | 56 | push(@possible_class_paths, &FileUtils::filenameConcatenate($ENV{'GSDLCOLLECTDIR'}, 'custom', $ENV{'GSDLCOLLECTION'}, 'perllib', 'classify', $classifier . '.pm'));
|
---|
[14239] | 57 | }
|
---|
[27303] | 58 | # (why does GSDLCOLLECTDIR get set to GSDLHOME for classinfo calls?)
|
---|
| 59 | if ($ENV{'GSDLCOLLECTDIR'} ne $ENV{'GSDLHOME'})
|
---|
| 60 | {
|
---|
| 61 | push(@possible_class_paths, &FileUtils::filenameConcatenate($ENV{'GSDLCOLLECTDIR'}, 'perllib', 'classify', $classifier . '.pm'));
|
---|
| 62 | }
|
---|
| 63 | foreach my $library_path (@INC)
|
---|
| 64 | {
|
---|
| 65 | # only interested in classify paths found in the library paths
|
---|
| 66 | if ($library_path =~ /classify$/)
|
---|
| 67 | {
|
---|
| 68 | push(@possible_class_paths, &FileUtils::filenameConcatenate($library_path, $classifier . '.pm'));
|
---|
| 69 | }
|
---|
| 70 | }
|
---|
| 71 | my $found_class = 0;
|
---|
| 72 | foreach my $possible_class_path (@possible_class_paths)
|
---|
| 73 | {
|
---|
| 74 | if (-e $possible_class_path)
|
---|
| 75 | {
|
---|
| 76 | require $possible_class_path;
|
---|
| 77 | $found_class = 1;
|
---|
| 78 | last;
|
---|
| 79 | }
|
---|
| 80 | }
|
---|
| 81 | if (!$found_class)
|
---|
| 82 | {
|
---|
| 83 | &gsprintf(STDERR, "{classify.could_not_find_classifier}\n", $classifier) && die "\n";
|
---|
| 84 | }
|
---|
[6967] | 85 |
|
---|
| 86 | my ($classobj);
|
---|
| 87 | my $options = "-gsdlinfo";
|
---|
[10218] | 88 | eval ("\$classobj = new \$classifier([],[$options])");
|
---|
[6967] | 89 | die "$@" if $@;
|
---|
| 90 |
|
---|
| 91 | return $classobj;
|
---|
| 92 | }
|
---|
| 93 |
|
---|
[811] | 94 | sub load_classifiers {
|
---|
[1839] | 95 | my ($classify_list, $build_dir, $outhandle) = @_;
|
---|
[811] | 96 | my @classify_objects = ();
|
---|
[8220] | 97 | my $classify_number = 1;
|
---|
[13933] | 98 |
|
---|
[27303] | 99 | # - ensure colclassdir doesn't already exist in INC before adding, other-
|
---|
| 100 | # wise we risk clobbering classifier inheritence implied by order of paths
|
---|
| 101 | # in INC [jmt12]
|
---|
[27375] | 102 | my $colclassdir = &FileUtils::filenameConcatenate($ENV{'GSDLCOLLECTDIR'},"perllib/classify");
|
---|
| 103 | &util::augmentINC($colclassdir);
|
---|
[27303] | 104 |
|
---|
[15703] | 105 | foreach my $classifyoption (@$classify_list) {
|
---|
[214] | 106 |
|
---|
[811] | 107 | # get the classifier name
|
---|
| 108 | my $classname = shift @$classifyoption;
|
---|
| 109 | next unless defined $classname;
|
---|
[1839] | 110 |
|
---|
[811] | 111 | # find the classifier
|
---|
[27303] | 112 | # - replaced as explained in load_classifier_for_info() [jmt12]
|
---|
| 113 | my @possible_class_paths;
|
---|
| 114 | if (defined($ENV{'GSDLCOLLECTION'}))
|
---|
| 115 | {
|
---|
| 116 | push(@possible_class_paths, &FileUtils::filenameConcatenate($ENV{'GSDLCOLLECTDIR'}, 'custom', $ENV{'GSDLCOLLECTION'}, 'perllib', 'classify', $classname . '.pm'));
|
---|
[14112] | 117 | }
|
---|
[27303] | 118 | # (why does GSDLCOLLECTDIR get set to GSDLHOME for classinfo calls?)
|
---|
| 119 | if ($ENV{'GSDLCOLLECTDIR'} ne $ENV{'GSDLHOME'})
|
---|
| 120 | {
|
---|
| 121 | push(@possible_class_paths,&FileUtils::filenameConcatenate($ENV{'GSDLCOLLECTDIR'}, 'perllib', 'classify', $classname . '.pm'));
|
---|
| 122 | }
|
---|
| 123 | foreach my $library_path (@INC)
|
---|
| 124 | {
|
---|
| 125 | # only interested in classify paths found in the library paths
|
---|
| 126 | if ($library_path =~ /classify$/)
|
---|
| 127 | {
|
---|
| 128 | push(@possible_class_paths, &FileUtils::filenameConcatenate($library_path, $classname . '.pm'));
|
---|
| 129 | }
|
---|
| 130 | }
|
---|
| 131 | my $found_class = 0;
|
---|
| 132 | foreach my $possible_class_path (@possible_class_paths)
|
---|
| 133 | {
|
---|
| 134 | if (-e $possible_class_path)
|
---|
| 135 | {
|
---|
| 136 | require $possible_class_path;
|
---|
| 137 | $found_class = 1;
|
---|
| 138 | last;
|
---|
| 139 | }
|
---|
| 140 | }
|
---|
| 141 | if (!$found_class)
|
---|
| 142 | {
|
---|
| 143 | &gsprintf(STDERR, "{classify.could_not_find_classifier}\n", $classname) && die "\n";
|
---|
| 144 | }
|
---|
[214] | 145 |
|
---|
[811] | 146 | # create the classify object
|
---|
| 147 | my ($classobj);
|
---|
[1839] | 148 |
|
---|
| 149 | my @newoptions;
|
---|
[6964] | 150 |
|
---|
| 151 | # do these first so they can be overriden by user supplied options
|
---|
[27664] | 152 | (my $build_dir_re = $build_dir) =~ s@\\@\\\\@g;
|
---|
[6964] | 153 | push @newoptions, "-builddir", "$build_dir" if ($build_dir);
|
---|
| 154 | push @newoptions, "-outhandle", "$outhandle" if ($outhandle);
|
---|
| 155 | push @newoptions, "-verbosity", "2";
|
---|
| 156 |
|
---|
[6967] | 157 | # backwards compatability hack: if the classifier options are
|
---|
| 158 | # in "x=y" format, convert them to parsearg ("-x y") format.
|
---|
| 159 | my ($opt, $key, $value);
|
---|
[1839] | 160 | foreach $opt (@$classifyoption) {
|
---|
[11644] | 161 | # if ($opt =~ /^(\w+)=(.*)$/) {
|
---|
| 162 | # push @newoptions, "-$1", $2;
|
---|
| 163 | # } else {
|
---|
[1839] | 164 | push @newoptions, $opt;
|
---|
[11644] | 165 | #}
|
---|
[1839] | 166 | }
|
---|
| 167 |
|
---|
| 168 | map { $_ = "\"$_\""; } @newoptions;
|
---|
| 169 | my $options .= join (",", @newoptions);
|
---|
| 170 |
|
---|
[10218] | 171 |
|
---|
| 172 | eval ("\$classobj = new \$classname([],[$options])");
|
---|
[811] | 173 | die "$@" if $@;
|
---|
[1839] | 174 |
|
---|
[8220] | 175 | $classobj->set_number($classify_number);
|
---|
| 176 | $classify_number ++;
|
---|
| 177 |
|
---|
[1839] | 178 | # add this object to the list
|
---|
[811] | 179 | push (@classify_objects, $classobj);
|
---|
| 180 | }
|
---|
| 181 |
|
---|
[8220] | 182 | my ($classobj);
|
---|
| 183 | eval ("\$classobj = new AllList()");
|
---|
| 184 | die "$@" if $@;
|
---|
| 185 | push (@classify_objects, $classobj);
|
---|
| 186 |
|
---|
[811] | 187 | return \@classify_objects;
|
---|
[214] | 188 | }
|
---|
| 189 |
|
---|
| 190 | # init_classifiers resets all the classifiers and readys them to process
|
---|
[315] | 191 | # the documents.
|
---|
[214] | 192 | sub init_classifiers {
|
---|
| 193 | my ($classifiers) = @_;
|
---|
| 194 |
|
---|
[15703] | 195 | foreach my $classobj (@$classifiers) {
|
---|
[214] | 196 | $classobj->init();
|
---|
| 197 | }
|
---|
| 198 | }
|
---|
| 199 |
|
---|
[11994] | 200 |
|
---|
| 201 |
|
---|
[15704] | 202 | # takes a hashref containing the metadata for an infodb entry, and extracts
|
---|
[11994] | 203 | # the childrens numbers (from the 'contains' entry).
|
---|
| 204 | # assumes format is ".1;".2;".3
|
---|
| 205 | sub get_children {
|
---|
| 206 | my ($doc_db_hash) = @_;
|
---|
| 207 |
|
---|
| 208 | my $children = undef;
|
---|
| 209 |
|
---|
[15703] | 210 | my $contains = $doc_db_hash->{'contains'};
|
---|
| 211 | if (defined ($contains)) {
|
---|
| 212 | $contains =~ s/\@$//; #remove trailing @
|
---|
| 213 | $contains =~ s/^\"\.//; #remove initial ".
|
---|
| 214 | @$children = split /\;\"\./, $contains;
|
---|
[11994] | 215 | }
|
---|
| 216 |
|
---|
| 217 | return $children;
|
---|
| 218 | }
|
---|
| 219 |
|
---|
| 220 |
|
---|
| 221 | sub recurse_sections {
|
---|
[15704] | 222 | my ($doc_obj, $children, $parentoid, $parentsection, $database_recs) = @_;
|
---|
[11994] | 223 |
|
---|
| 224 | return if (!defined $children);
|
---|
| 225 |
|
---|
| 226 | foreach my $child (sort { $a <=> $b} @$children) {
|
---|
| 227 | $doc_obj->create_named_section("$parentsection.$child");
|
---|
[15704] | 228 | my $doc_db_rec = $database_recs->{"$parentoid.$child"};
|
---|
[11994] | 229 | my $doc_db_hash = db_rec_to_hash($doc_db_rec);
|
---|
| 230 |
|
---|
| 231 | # get child's children
|
---|
| 232 | my $newchildren = &get_children($doc_db_hash);
|
---|
| 233 |
|
---|
| 234 | # add content for current section
|
---|
| 235 | add_section_content($doc_obj, "$parentsection.$child", $doc_db_hash);
|
---|
| 236 |
|
---|
| 237 | # process all the children if there are any
|
---|
| 238 | if (defined ($newchildren))
|
---|
| 239 | {
|
---|
| 240 | recurse_sections($doc_obj, $newchildren, "$parentoid.$child",
|
---|
[15704] | 241 | "$parentsection.$child", $database_recs);
|
---|
[11994] | 242 | }
|
---|
| 243 | }
|
---|
| 244 | }
|
---|
| 245 |
|
---|
| 246 |
|
---|
| 247 | sub add_section_content {
|
---|
| 248 | my ($doc_obj, $cursection, $doc_db_hash) = @_;
|
---|
| 249 |
|
---|
[15703] | 250 | foreach my $key (keys %$doc_db_hash) {
|
---|
[11994] | 251 | #don't need to store these metadata
|
---|
| 252 | next if $key =~ /(thistype|childtype|contains|docnum|doctype|classifytype)/i;
|
---|
| 253 | # but do want things like hastxt and archivedir
|
---|
| 254 | my @items = split /@/, $doc_db_hash->{$key};
|
---|
[21564] | 255 | # metadata is all from the info database so should already be in utf8
|
---|
[17288] | 256 | map {$doc_obj->add_utf8_metadata ($cursection, $key, $_); } @items;
|
---|
[11994] | 257 |
|
---|
| 258 | }
|
---|
| 259 | }
|
---|
| 260 |
|
---|
| 261 |
|
---|
[15704] | 262 | # gets all the metadata from an infodb entry, and puts it into a hashref
|
---|
[11994] | 263 | sub db_rec_to_hash {
|
---|
| 264 |
|
---|
[21564] | 265 | my ($infodb_str_ref) = @_;
|
---|
[11994] | 266 |
|
---|
| 267 | my $hashref = {};
|
---|
| 268 |
|
---|
[21564] | 269 | my @entries = split(/\n/, $infodb_str_ref);
|
---|
[15703] | 270 | foreach my $entry (@entries) {
|
---|
[11994] | 271 | my($key, $value) = ($entry =~ /^<([^>]*)>(.*?)$/ );
|
---|
| 272 | $hashref->{$key} .= '@' if defined $hashref->{$key};
|
---|
| 273 | $hashref->{$key} .= $value;
|
---|
| 274 |
|
---|
| 275 | }
|
---|
| 276 |
|
---|
| 277 | return $hashref;
|
---|
| 278 | }
|
---|
| 279 |
|
---|
| 280 |
|
---|
| 281 | sub reconstruct_doc_objs_metadata
|
---|
| 282 | {
|
---|
[15725] | 283 | my $infodb_type = shift(@_);
|
---|
| 284 | my $infodb_file_path = shift(@_);
|
---|
[20575] | 285 | my $database_recs = shift(@_);
|
---|
[11994] | 286 |
|
---|
| 287 | # dig out top level doc sections
|
---|
| 288 | my %top_sections = ();
|
---|
[13068] | 289 | my %top_docnums = ();
|
---|
[20575] | 290 | foreach my $key ( keys %$database_recs )
|
---|
[11994] | 291 | {
|
---|
[20575] | 292 | my $md_rec = $database_recs->{$key};
|
---|
[11994] | 293 | my $md_hash = db_rec_to_hash($md_rec);
|
---|
| 294 |
|
---|
| 295 | if ((defined $md_hash->{'doctype'}) && ($md_hash->{'doctype'} eq "doc")) {
|
---|
| 296 | next if ($key =~ m/\./);
|
---|
| 297 | $top_sections{$key} = $md_hash;
|
---|
[13068] | 298 | $top_docnums{$key} = $md_hash->{'docnum'};
|
---|
[11994] | 299 | }
|
---|
| 300 | }
|
---|
| 301 |
|
---|
[15704] | 302 | # for greenstone document objects based on metadata in database file
|
---|
[11994] | 303 | my @all_docs = ();
|
---|
[13068] | 304 | # we need to make sure the documents were processed in the same order as
|
---|
| 305 | # before, so sort based on their docnums
|
---|
| 306 | foreach my $oid ( sort { $top_docnums{$a} <=> $top_docnums{$b} } keys %top_sections )
|
---|
[11994] | 307 | {
|
---|
| 308 | my $doc_db_hash = $top_sections{$oid};
|
---|
| 309 |
|
---|
| 310 | my $doc_obj = new doc();
|
---|
| 311 | $doc_obj->set_OID($oid);
|
---|
| 312 | my $top = $doc_obj->get_top_section();
|
---|
| 313 | add_section_content ($doc_obj, $top, $doc_db_hash);
|
---|
| 314 | my $children = &get_children($doc_db_hash);
|
---|
[20575] | 315 | recurse_sections($doc_obj, $children, $oid, $top, $database_recs);
|
---|
[11994] | 316 |
|
---|
| 317 | push(@all_docs,$doc_obj);
|
---|
| 318 | }
|
---|
| 319 |
|
---|
| 320 | return \@all_docs;
|
---|
| 321 | }
|
---|
| 322 |
|
---|
| 323 |
|
---|
| 324 |
|
---|
| 325 |
|
---|
| 326 |
|
---|
[214] | 327 | # classify_doc lets each of the classifiers classify a document
|
---|
| 328 | sub classify_doc {
|
---|
[23118] | 329 | my ($classifiers, $doc_obj) = @_;
|
---|
[19772] | 330 |
|
---|
[15703] | 331 | foreach my $classobj (@$classifiers) {
|
---|
[8220] | 332 | my $title = $classobj->{'title'};
|
---|
[19772] | 333 |
|
---|
[23118] | 334 | $classobj->classify($doc_obj);
|
---|
[214] | 335 | }
|
---|
| 336 | }
|
---|
| 337 |
|
---|
[15702] | 338 |
|
---|
[18520] | 339 | our $next_classify_num = 1;
|
---|
| 340 |
|
---|
[214] | 341 | # output_classify_info outputs all the info needed for the classification
|
---|
[15702] | 342 | # to the database
|
---|
| 343 | sub output_classify_info
|
---|
| 344 | {
|
---|
[15725] | 345 | my ($classifiers, $infodb_type, $infodb_handle, $remove_empty_classifications, $gli) = @_;
|
---|
[214] | 346 |
|
---|
[6332] | 347 | $gli = 0 unless defined $gli;
|
---|
| 348 |
|
---|
[315] | 349 | # create a classification containing all the info
|
---|
[15702] | 350 | my $classifyinfo = { 'classifyOID'=> 'browse',
|
---|
| 351 | 'contains' => [] };
|
---|
[315] | 352 |
|
---|
| 353 | # get each of the classifications
|
---|
[15703] | 354 | foreach my $classifier (@$classifiers)
|
---|
[15702] | 355 | {
|
---|
| 356 | my $classifier_info = $classifier->get_classify_info($gli);
|
---|
| 357 | $classifier_info->{'classifyOID'} = "CL$next_classify_num" unless defined($classifier_info->{'classifyOID'});
|
---|
| 358 | print STDERR "*** outputting information for classifier: $classifier_info->{'classifyOID'}\n";
|
---|
[8220] | 359 |
|
---|
[15702] | 360 | push(@{$classifyinfo->{'contains'}}, $classifier_info);
|
---|
[315] | 361 | $next_classify_num++;
|
---|
[214] | 362 | }
|
---|
| 363 |
|
---|
[15725] | 364 | &print_classify_info($infodb_type, $infodb_handle, $classifyinfo, "", $remove_empty_classifications);
|
---|
[214] | 365 | }
|
---|
| 366 |
|
---|
[831] | 367 |
|
---|
[15702] | 368 | sub print_classify_info
|
---|
| 369 | {
|
---|
[15725] | 370 | my ($infodb_type, $infodb_handle, $classifyinfo, $OID, $remove_empty_classifications) = @_;
|
---|
[15702] | 371 |
|
---|
[315] | 372 | $OID =~ s/^\.+//; # just for good luck
|
---|
[214] | 373 |
|
---|
[315] | 374 | # book information is printed elsewhere
|
---|
| 375 | return if (defined ($classifyinfo->{'OID'}));
|
---|
| 376 |
|
---|
| 377 | # don't want empty classifications
|
---|
[8445] | 378 | return if (&check_contents ($classifyinfo, $remove_empty_classifications) == 0 && $remove_empty_classifications);
|
---|
[315] | 379 |
|
---|
[8361] | 380 | $OID = $classifyinfo->{'classifyOID'} if defined ($classifyinfo->{'classifyOID'});
|
---|
[15702] | 381 |
|
---|
| 382 | my %classify_infodb = ();
|
---|
| 383 | $classify_infodb{"doctype"} = [ "classify" ];
|
---|
| 384 | $classify_infodb{"hastxt"} = [ "0" ];
|
---|
| 385 | $classify_infodb{"childtype"} = [ $classifyinfo->{'childtype'} ]
|
---|
[8361] | 386 | if defined $classifyinfo->{'childtype'};
|
---|
[15702] | 387 | $classify_infodb{"Title"} = [ $classifyinfo->{'Title'} ]
|
---|
[8361] | 388 | if defined $classifyinfo->{'Title'};
|
---|
[15702] | 389 | $classify_infodb{"numleafdocs"} = [ $classifyinfo->{'numleafdocs'} ]
|
---|
[8361] | 390 | if defined $classifyinfo->{'numleafdocs'};
|
---|
[15702] | 391 | $classify_infodb{"thistype"} = [ $classifyinfo->{'thistype'} ]
|
---|
[8361] | 392 | if defined $classifyinfo->{'thistype'};
|
---|
[15702] | 393 | $classify_infodb{"parameters"} = [ $classifyinfo->{'parameters'} ]
|
---|
[8361] | 394 | if defined $classifyinfo->{'parameters'};
|
---|
[15702] | 395 | $classify_infodb{"supportsmemberof"} = [ $classifyinfo->{'supportsmemberof'} ]
|
---|
[8361] | 396 | if defined $classifyinfo->{'supportsmemberof'};
|
---|
| 397 |
|
---|
[15702] | 398 | my $contains_text = "";
|
---|
| 399 | my $mdoffset_text = "";
|
---|
[8361] | 400 |
|
---|
| 401 | my $next_subOID = 1;
|
---|
| 402 | my $first = 1;
|
---|
[15702] | 403 | foreach my $tempinfo (@{$classifyinfo->{'contains'}}) {
|
---|
[8361] | 404 | # empty contents were made undefined by clean_contents()
|
---|
| 405 | next unless defined $tempinfo;
|
---|
| 406 | if (!defined ($tempinfo->{'classifyOID'}) ||
|
---|
| 407 | $tempinfo->{'classifyOID'} ne "oai") {
|
---|
| 408 | $contains_text .= ";" unless $first;
|
---|
| 409 | }
|
---|
| 410 | $mdoffset_text .= ";" unless $first;
|
---|
| 411 | $first = 0;
|
---|
[315] | 412 |
|
---|
[16959] | 413 | if (defined ($tempinfo->{'classifyOID'}))
|
---|
| 414 | {
|
---|
| 415 | if ($tempinfo->{'classifyOID'} ne "oai")
|
---|
| 416 | {
|
---|
[8361] | 417 | $contains_text .= $tempinfo->{'classifyOID'};
|
---|
[8275] | 418 | }
|
---|
[12844] | 419 |
|
---|
[15725] | 420 | &print_classify_info ($infodb_type, $infodb_handle, $tempinfo, $tempinfo->{'classifyOID'},
|
---|
[8361] | 421 | $remove_empty_classifications);
|
---|
[16959] | 422 | }
|
---|
| 423 | elsif (defined ($tempinfo->{'OID'}))
|
---|
| 424 | {
|
---|
[8361] | 425 | $contains_text .= $tempinfo->{'OID'};
|
---|
[12844] | 426 | $mdoffset_text .= $tempinfo->{'offset'} if (defined ($tempinfo->{'offset'}));
|
---|
[16959] | 427 | }
|
---|
| 428 | else
|
---|
| 429 | {
|
---|
| 430 | # Supress having top-level node in Collage classifier
|
---|
| 431 | # so no bookshelf icon appears, top-level, along with the
|
---|
| 432 | # applet
|
---|
| 433 | if (!defined ($tempinfo->{'Title'}) || $tempinfo->{'Title'} ne "Collage")
|
---|
| 434 | {
|
---|
| 435 | $contains_text .= "\".$next_subOID";
|
---|
| 436 | }
|
---|
[12844] | 437 |
|
---|
[16959] | 438 | &print_classify_info ($infodb_type, $infodb_handle, $tempinfo, "$OID.$next_subOID",
|
---|
| 439 | $remove_empty_classifications);
|
---|
| 440 | $next_subOID++;
|
---|
| 441 | }
|
---|
[315] | 442 | }
|
---|
[8361] | 443 |
|
---|
[15702] | 444 | $classify_infodb{"contains"} = [ $contains_text ];
|
---|
| 445 | $classify_infodb{"mdtype"} = [ $classifyinfo->{'mdtype'} ]
|
---|
[8361] | 446 | if defined $classifyinfo->{'mdtype'};
|
---|
[15702] | 447 | $classify_infodb{"mdoffset"} = [ $mdoffset_text ]
|
---|
| 448 | if ($mdoffset_text !~ m/^;+$/);
|
---|
[8361] | 449 |
|
---|
[15725] | 450 | &dbutil::write_infodb_entry($infodb_type, $infodb_handle, $OID, \%classify_infodb);
|
---|
[315] | 451 | }
|
---|
| 452 |
|
---|
[15702] | 453 |
|
---|
[637] | 454 | sub check_contents {
|
---|
[8445] | 455 | my ($classifyinfo,$remove_empty_classifications) = @_;
|
---|
| 456 | $remove_empty_classifications = 0 unless ($remove_empty_classifications);
|
---|
[637] | 457 | my $num_leaf_docs = 0;
|
---|
| 458 | my $sub_num_leaf_docs = 0;
|
---|
[315] | 459 |
|
---|
[637] | 460 | return $classifyinfo->{'numleafdocs'} if (defined $classifyinfo->{'numleafdocs'});
|
---|
| 461 |
|
---|
[15703] | 462 | foreach my $content (@{$classifyinfo->{'contains'}}) {
|
---|
[315] | 463 | if (defined $content->{'OID'}) {
|
---|
| 464 | # found a book
|
---|
[637] | 465 | $num_leaf_docs ++;
|
---|
[9790] | 466 | } elsif (($sub_num_leaf_docs = &check_contents ($content,$remove_empty_classifications)) > 0) {
|
---|
[315] | 467 | # there's a book somewhere below
|
---|
[637] | 468 | $num_leaf_docs += $sub_num_leaf_docs;
|
---|
[315] | 469 | } else {
|
---|
[8445] | 470 | if ($remove_empty_classifications){
|
---|
| 471 | # section contains no books so we want to remove
|
---|
| 472 | # it from its parents contents
|
---|
| 473 | $content = undef;
|
---|
| 474 | }
|
---|
[315] | 475 | }
|
---|
| 476 | }
|
---|
[637] | 477 |
|
---|
| 478 | $classifyinfo->{'numleafdocs'} = $num_leaf_docs;
|
---|
| 479 | return $num_leaf_docs;
|
---|
[315] | 480 | }
|
---|
| 481 |
|
---|
[214] | 482 | 1;
|
---|