Changeset 15702

Show
Ignore:
Timestamp:
26.05.2008 16:28:00 (11 years ago)
Author:
mdewsnip
Message:

(Adding new DB support) Tidying up output_classify_info() and changing print_classify_info() to use dbutil::write_infodb_entry() instead of having GDBM-specific code.

Files:
1 modified

Legend:

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

    r14239 r15702  
    4242 
    4343 
    44 $next_classify_num = 1; 
    4544$oid_to_clids = {}; 
    4645 
     
    295294} 
    296295 
     296 
    297297# output_classify_info outputs all the info needed for the classification 
    298 # to the gdbm 
    299 sub output_classify_info { 
    300     my ($classifiers, $handle, $remove_empty_classifications, $gli) = @_; 
    301 #    $handle = "main::STDOUT"; 
     298# to the database 
     299sub output_classify_info 
     300{ 
     301    my ($classifiers, $infodb_handle, $remove_empty_classifications, $gli) = @_; 
    302302 
    303303    $gli = 0 unless defined $gli; 
    304304 
    305305    # create a classification containing all the info 
    306     my $classifyinfo = {'classifyOID'=>'browse', 
    307             'contains'=>[]}; 
     306    my $classifyinfo = { 'classifyOID'=> 'browse', 
     307             'contains' => [] }; 
    308308 
    309309    # get each of the classifications 
    310     foreach $classobj (@$classifiers) { 
    311     my $tempinfo = $classobj->get_classify_info($gli); 
    312     my $classID = $tempinfo->{'classifyOID'}; 
    313  
    314     $tempinfo->{'classifyOID'} = "CL$next_classify_num" unless defined($tempinfo->{'classifyOID'}); 
     310    my $next_classify_num = 1; 
     311    foreach $classifier (@$classifiers) 
     312    { 
     313    my $classifier_info = $classifier->get_classify_info($gli); 
     314    $classifier_info->{'classifyOID'} = "CL$next_classify_num" unless defined($classifier_info->{'classifyOID'}); 
     315        print STDERR "*** outputting information for classifier: $classifier_info->{'classifyOID'}\n"; 
     316 
     317    push(@{$classifyinfo->{'contains'}}, $classifier_info); 
    315318    $next_classify_num++; 
    316  
    317         print STDERR "*** outputting information for classifier: $tempinfo->{'classifyOID'}\n"; 
    318  
    319     push (@{$classifyinfo->{'contains'}}, $tempinfo); 
    320     } 
    321  
    322     &print_classify_info ($handle, $classifyinfo, "", $remove_empty_classifications); 
    323 } 
    324  
    325 sub print_classify_info { 
    326     my ($handle, $classifyinfo, $OID, $remove_empty_classifications) = @_; 
     319    } 
     320 
     321    &print_classify_info ($infodb_handle, $classifyinfo, "", $remove_empty_classifications); 
     322} 
     323 
     324 
     325sub print_classify_info 
     326{ 
     327    my ($infodb_handle, $classifyinfo, $OID, $remove_empty_classifications) = @_; 
    327328 
    328329    $OID =~ s/^\.+//; # just for good luck 
     
    335336    
    336337    $OID = $classifyinfo->{'classifyOID'} if defined ($classifyinfo->{'classifyOID'}); 
    337      
    338     my $outputtext = "[$OID]\n"; 
    339     $outputtext .= "<doctype>classify\n"; 
    340     $outputtext .= "<hastxt>0\n"; 
    341     $outputtext .= "<childtype>$classifyinfo->{'childtype'}\n"  
     338 
     339    my %classify_infodb = (); 
     340    $classify_infodb{"doctype"} = [ "classify" ]; 
     341    $classify_infodb{"hastxt"} = [ "0" ]; 
     342    $classify_infodb{"childtype"} = [ $classifyinfo->{'childtype'} ] 
    342343    if defined $classifyinfo->{'childtype'}; 
    343     $outputtext .= "<Title>$classifyinfo->{'Title'}\n"  
     344    $classify_infodb{"Title"} = [ $classifyinfo->{'Title'} ] 
    344345    if defined $classifyinfo->{'Title'}; 
    345     $outputtext .= "<numleafdocs>$classifyinfo->{'numleafdocs'}\n"  
     346    $classify_infodb{"numleafdocs"} = [ $classifyinfo->{'numleafdocs'} ] 
    346347    if defined $classifyinfo->{'numleafdocs'}; 
    347     $outputtext .= "<thistype>$classifyinfo->{'thistype'}\n"  
     348    $classify_infodb{"thistype"} = [ $classifyinfo->{'thistype'} ] 
    348349    if defined $classifyinfo->{'thistype'}; 
    349     $outputtext .= "<parameters>$classifyinfo->{'parameters'}\n"  
     350    $classify_infodb{"parameters"} = [ $classifyinfo->{'parameters'} ] 
    350351    if defined $classifyinfo->{'parameters'}; 
    351     $outputtext .= "<supportsmemberof>$classifyinfo->{'supportsmemberof'}\n" 
     352    $classify_infodb{"supportsmemberof"} = [ $classifyinfo->{'supportsmemberof'} ] 
    352353    if defined $classifyinfo->{'supportsmemberof'}; 
    353354     
    354     my $contains_text = "<contains>"; 
    355     my $mdoffset_text = "<mdoffset>"; 
     355    my $contains_text = ""; 
     356    my $mdoffset_text = ""; 
    356357     
    357358    my $next_subOID = 1; 
    358359    my $first = 1; 
    359     foreach $tempinfo (@{$classifyinfo->{'contains'}}) { 
     360    foreach my $tempinfo (@{$classifyinfo->{'contains'}}) { 
    360361    # empty contents were made undefined by clean_contents() 
    361362    next unless defined $tempinfo; 
     
    386387            #rint STDERR "Result: \"" . join(";", @{$clids}) . "\"\n"; 
    387388             
    388         &print_classify_info ($handle, $tempinfo, $tempinfo->{'classifyOID'}, 
     389        &print_classify_info ($infodb_handle, $tempinfo, $tempinfo->{'classifyOID'}, 
    389390                  $remove_empty_classifications); 
    390391    } elsif (defined ($tempinfo->{'OID'})) { 
     
    431432                #rint STDERR "Result: \"" . join(";", @{$clids}) . "\"\n"; 
    432433         
    433         &print_classify_info ($handle, $tempinfo, "$OID.$next_subOID", 
     434        &print_classify_info ($infodb_handle, $tempinfo, "$OID.$next_subOID", 
    434435                      $remove_empty_classifications); 
    435436        $next_subOID++; 
     
    437438    } 
    438439     
    439     $outputtext .= "$contains_text\n"; 
    440     $outputtext .= "<mdtype>$classifyinfo->{'mdtype'}\n"  
     440    $classify_infodb{"contains"} = [ $contains_text ]; 
     441    $classify_infodb{"mdtype"} = [ $classifyinfo->{'mdtype'} ] 
    441442    if defined $classifyinfo->{'mdtype'}; 
    442     $outputtext .= "$mdoffset_text\n" 
    443     if ($mdoffset_text !~ m/^<mdoffset>;+$/); 
    444      
    445     $outputtext .= '-' x 70 . "\n"; 
    446      
    447     print $handle $outputtext; 
    448  
    449 } 
     443    $classify_infodb{"mdoffset"} = [ $mdoffset_text ] 
     444    if ($mdoffset_text !~ m/^;+$/); 
     445     
     446    &dbutil::write_infodb_entry($infodb_handle, $OID, \%classify_infodb); 
     447} 
     448 
    450449 
    451450sub check_contents {