Changeset 18455


Ignore:
Timestamp:
02/03/09 09:46:33 (12 years ago)
Author:
davidb
Message:

Addition of 'edit_mode' parameter to classify(). This can be either 'add' 'delete' or 'reindex' (should think about renaming the last one to something more appropriate, e.g. update).

Location:
gsdl/trunk/perllib
Files:
16 edited

Legend:

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

    r17288 r18455  
    280280# classify_doc lets each of the classifiers classify a document
    281281sub classify_doc {
    282     my ($classifiers, $doc_obj) = @_;
     282    my ($classifiers, $doc_obj, $edit_mode) = @_;
    283283   
    284284    foreach my $classobj (@$classifiers) {
    285285    my $title = $classobj->{'title'};
    286     $classobj->classify($doc_obj);
     286    $classobj->classify($doc_obj,$edit_mode);
    287287    }
    288288}
  • gsdl/trunk/perllib/classify/AZCompactList.pm

    r17209 r18455  
    180180{
    181181    my $self = shift (@_);
    182     my ($doc_obj) = @_;
     182    my ($doc_obj,$edit_mode) = @_;
    183183
    184184    my $doc_OID = $doc_obj->get_OID();
     
    211211    my $full_doc_OID
    212212        = ($thissection ne "") ? "$doc_OID.$thissection" : $doc_OID;
     213
     214    if ($edit_mode eq "delete") {
     215        print $outhandle "  Deleting $full_doc_OID\n";
     216        delete $self->{'list'}->{$full_doc_OID};
     217        delete $self->{'listmetavalue'}->{$full_doc_OID};
     218        delete $self->{'list_mvpair'}->{$full_doc_OID};
     219        delete $self->{'reclassify'}->{$full_doc_OID};
     220
     221        next;
     222    }
     223
     224
    213225    if (defined $self->{'list_mvpair'}->{$full_doc_OID})
    214226    {
     
    486498        if ($self->{'doclevel'} =~ m/^top/i) { # toplevel
    487499            $self->{'classifiers'}->{$node_name}->{'classifyobj'}
    488             ->classify($doc_obj, "Section=$section");
     500            ->classify($doc_obj,"add", "Section=$section");
    489501        } else { # section level
    490502            # Thanks to Don Gourley for this...
    491503            # classify can't handle multi-level section
    492504            $self->{'classifiers'}->{$node_name}->{'classifyobj'}
    493             ->classify_section($section, $doc_obj, $sortmeta);
     505            ->classify_section($section, $doc_obj, "add", $sortmeta);
    494506        }
    495507        }
     
    497509        {
    498510        $self->{'classifiers'}->{$node_name}->{'classifyobj'}
    499         ->classify($doc_obj);
     511        ->classify($doc_obj,"add");
    500512        }
    501513    } else { # this key is not in the hash
  • gsdl/trunk/perllib/classify/AZList.pm

    r17209 r18455  
    119119sub classify {
    120120    my $self = shift (@_);
    121     my ($doc_obj) = @_;
     121    my ($doc_obj,$edit_mode) = @_;
    122122
    123123    my $doc_OID = $doc_obj->get_OID();
    124124    my $outhandle = $self->{'outhandle'};
     125
     126    if ($edit_mode eq "delete") {
     127    $self->oid_hash_delete($doc_OID,'list');
     128    return;
     129    }
    125130
    126131    my $metavalue;
  • gsdl/trunk/perllib/classify/AZSectionList.pm

    r17209 r18455  
    7171sub classify {
    7272    my $self = shift (@_);
    73     my ($doc_obj) = @_;
     73    my ($doc_obj,$edit_mode) = @_;
    7474
    7575    my $doc_OID = $doc_obj->get_OID();
     
    7777
    7878    while (defined $thissection) {
    79     $self->classify_section ($thissection, $doc_obj);
     79    $self->classify_section ($thissection, $doc_obj, $edit_mode);
    8080    $thissection = $doc_obj->get_next_section ($thissection);
    8181    }
     
    8484sub classify_section {
    8585    my $self = shift (@_);
    86     my ($section, $doc_obj) = @_;
     86    my ($section, $doc_obj, $edit_mode) = @_;
    8787
    8888    my $doc_OID = $doc_obj->get_OID();
     89
     90    if ($edit_mode eq "delete") {
     91    $self->oid_hash_delete("$doc_OID$section",'list');
     92    return;
     93    }
    8994
    9095    my $metavalue;
  • gsdl/trunk/perllib/classify/AllList.pm

    r17209 r18455  
    7272sub classify {
    7373    my $self = shift (@_);
    74     my ($doc_obj) = @_;
     74    my ($doc_obj, $edit_mode) = @_;
    7575
    7676    my $doc_OID = $doc_obj->get_OID();
    7777   
    78     push (@{$self->{'list'}}, $doc_OID);
     78    if ($edit_mode eq "delete") {
     79    $self->oid_array_delete($doc_OID,'list');
     80    }
     81    else {
     82    push (@{$self->{'list'}}, $doc_OID);
     83    }
    7984
    8085    return;
  • gsdl/trunk/perllib/classify/BaseClassifier.pm

    r17209 r18455  
    298298}
    299299
     300sub oid_array_delete
     301{
     302    my $self = shift (@_);
     303    my ($delete_oid,$field) = @_;
     304
     305    my $outhandle = $self->{'outhandle'};
     306
     307    my @filtered_list = ();
     308    foreach my $existing_oid (@{$self->{$field}}) {
     309    if ($existing_oid eq $delete_oid) {
     310        print $outhandle "  Deleting $delete_oid\n";
     311    }
     312    else {
     313        push(@filtered_list,$existing_oid);
     314    }
     315    }
     316    $self->{$field} = \@filtered_list;
     317}
     318
     319sub oid_hash_delete
     320{
     321    my $self = shift (@_);
     322    my ($delete_oid,$field) = @_;
     323
     324    my $outhandle = $self->{'outhandle'};
     325
     326    print $outhandle "  Deleting $delete_oid\n";
     327    delete $self->{$field}->{$delete_oid};
     328}
     329
    300330sub classify {
    301331    my $self = shift (@_);
    302     my ($doc_obj) = @_;
     332    my ($doc_obj, $edit_mode) = @_;
    303333
    304334    my $outhandle = $self->{'outhandle'};
  • gsdl/trunk/perllib/classify/Collage.pm

    r17209 r18455  
    139139   
    140140    my $self = shift (@_);
    141     my ($doc_obj) = @_;
     141    my ($doc_obj,$edit_mode) = @_;
    142142
    143143    my $has_image_type = 0;
     
    159159
    160160    if ($has_image_type) {
     161
    161162    my $doc_OID = $doc_obj->get_OID();
    162     push (@{$self->{'list'}}, $doc_OID);
     163
     164    if ($edit_mode eq "delete") {
     165        $self->oid_array_delete($doc_OID,'list');
     166    }
     167    else {
     168        push (@{$self->{'list'}}, $doc_OID);
     169    }
    163170    }
    164171
  • gsdl/trunk/perllib/classify/DateList.pm

    r17209 r18455  
    129129sub classify {
    130130    my $self = shift (@_);
    131     my ($doc_obj) = @_;
     131    my ($doc_obj, $edit_mode) = @_;
    132132
    133133    my $doc_OID = $doc_obj->get_OID();
     
    147147    }
    148148   
     149    if ($edit_mode eq "delete") {
     150    $self->oid_hash_delete($doc_OID,'list');
     151    return;
     152    }
     153
    149154    my $sort_other = "";
    150155    if (defined $self->{'sort'} && $self->{'sort'} ne "") {
  • gsdl/trunk/perllib/classify/GenericList.pm

    r17209 r18455  
    194194{
    195195    my $self = shift(@_);
    196     my $doc_obj = shift(@_);
     196    my ($doc_obj,$edit_mode) = @_;
    197197
    198198    # If "-classify_sections" is set, classify every section of the document
     
    200200    my $section = $doc_obj->get_next_section($doc_obj->get_top_section());
    201201    while (defined $section) {
    202         $self->classify_section($doc_obj, $doc_obj->get_OID() . ".$section", $section);
     202        $self->classify_section($doc_obj, $doc_obj->get_OID() . ".$section", $section, $edit_mode);
    203203        $section = $doc_obj->get_next_section($section);
    204204    }
     
    206206    # Otherwise just classify the top document section
    207207    else {
    208     $self->classify_section($doc_obj, $doc_obj->get_OID(), $doc_obj->get_top_section());
     208    $self->classify_section($doc_obj, $doc_obj->get_OID(), $doc_obj->get_top_section(), $edit_mode);
    209209    }
    210210}
     
    214214{
    215215    my $self = shift(@_);
    216     my $doc_obj = shift(@_);
    217     my $section_OID = shift(@_);
    218     my $section = shift(@_);
     216    my ($doc_obj,$section_OID,$section,$edit_mode) = @_;
    219217
    220218    my @metadata_groups = @{$self->{'metadata_groups'}};
     
    235233    return if (!$classify_section);
    236234
     235    if ($edit_mode eq "delete") {
     236    $self->oid_array_delete($section_OID,'OIDs');
     237    return;
     238    }
     239   
    237240    # Otherwise, include this section in the classifier
    238241    push(@{$self->{'OIDs'}}, $section_OID);
  • gsdl/trunk/perllib/classify/HFileHierarchy.pm

    r17209 r18455  
    197197{
    198198    my $self = shift (@_);
    199     my ($doc_obj,$sortmeta,$metavalues) = @_;
     199    my ($doc_obj,$edit_mode,$sortmeta,$metavalues) = @_;
     200
     201    my $outhandle = $self->{'outhandle'};
    200202
    201203    my $doc_OID = $doc_obj->get_OID();
     
    204206    if ((defined $self->{'descriptorlist'}->{$metaelement}) &&
    205207        (defined $self->{'locatorlist'}->{$self->{'descriptorlist'}->{$metaelement}})) {
    206         push (@{$self->{'locatorlist'}->{$self->{'descriptorlist'}->{$metaelement}}->{'contents'}},
    207           [$doc_OID, $sortmeta]);
    208         my $localid = $self->{'descriptorlist'}->{$metaelement};
    209         my $classid = $self->get_number();
    210 
    211         $doc_obj->add_metadata($doc_obj->get_top_section(), "memberof", "CL$classid.$localid");
     208
     209        if ($edit_mode eq "delete") {
     210        # find it, and remove it
     211        my $existing_list = $self->{'locatorlist'}->{$self->{'descriptorlist'}->{$metaelement}}->{'contents'};
     212       
     213        my $filtered_list = [];
     214        foreach my $existing_oid_pair (@$existing_list) {
     215            if ($existing_oid_pair->[0] eq $doc_OID) {
     216            print $outhandle "  Deleting $doc_OID for $metaelement in hierarchy\n";
     217            }
     218            else {
     219            push(@$filtered_list,$existing_oid_pair);
     220            }
     221        }
     222        $self->{'locatorlist'}->{$self->{'descriptorlist'}->{$metaelement}}->{'contents'} = $filtered_list;
     223        }
     224        else {
     225        push (@{$self->{'locatorlist'}->{$self->{'descriptorlist'}->{$metaelement}}->{'contents'}},
     226              [$doc_OID, $sortmeta]);
     227        my $localid = $self->{'descriptorlist'}->{$metaelement};
     228        my $classid = $self->get_number();
     229
     230        $doc_obj->add_metadata($doc_obj->get_top_section(), "memberof", "CL$classid.$localid");
     231        }
    212232    }
    213233    }
  • gsdl/trunk/perllib/classify/HTML.pm

    r17209 r18455  
    8686sub classify {
    8787    my $self = shift (@_);
    88     my ($doc_obj) = @_;
     88    my ($doc_obj,$edit_mode) = @_;
    8989
    9090    # we don't do anything for individual documents
  • gsdl/trunk/perllib/classify/Hierarchy.pm

    r17209 r18455  
    8686sub auto_classify {
    8787    my $self = shift (@_);
    88     my ($doc_obj,$nosort,$sortmeta,$metavalues) = @_;
     88    my ($doc_obj,$edit_mode,$nosort,$sortmeta,$metavalues) = @_;
    8989
    9090    my $doc_OID = $doc_obj->get_OID();
    91    
     91
     92    if ($edit_mode eq "delete") {
     93    if ($nosort) {
     94        $self->oid_array_delete($doc_OID,'docs');
     95    }
     96    else {
     97        $self->oid_hash_delete($doc_OID,'docs');
     98    }
     99    return;
     100    }
     101
    92102    #Add all the metadata values to the hash
    93103    my $path_hash;
     
    133143sub classify {
    134144    my $self = shift (@_);
    135     my ($doc_obj) = @_;
     145    my ($doc_obj,$edit_mode) = @_;
    136146
    137147    my $doc_OID = $doc_obj->get_OID();
     
    175185
    176186    if (defined $self->{'subjectfile'}) {
    177     $self->hfile_classify($doc_obj,$sortmeta,$metavalues);
     187    $self->hfile_classify($doc_obj,$edit_mode,$sortmeta,$metavalues);
    178188    }
    179189    else {
    180     $self->auto_classify($doc_obj,$nosort,$sortmeta,$metavalues);
     190    $self->auto_classify($doc_obj,$edit_mode,$nosort,$sortmeta,$metavalues);
    181191    }
    182192}
  • gsdl/trunk/perllib/classify/List.pm

    r17209 r18455  
    123123sub classify {
    124124    my $self = shift (@_);
    125     my ($doc_obj) = @_;
     125    my ($doc_obj, $edit_mode) = @_;
    126126
    127127    my $doc_OID = $doc_obj->get_OID();
     128
    128129
    129130    # are we sorting the list??
     
    133134    }
    134135   
     136    if ($edit_mode eq "delete") {
     137    if ($nosort) {
     138        $self->oid_array_delete($doc_OID,'list');
     139    }
     140    else {
     141        $self->oid_hash_delete($doc_OID,'list');
     142    }
     143    return;
     144    }
     145
    135146    my $metavalue;
    136147    my $metaname;
  • gsdl/trunk/perllib/classify/Phind.pm

    r17209 r18455  
    242242sub classify {
    243243    my $self = shift (@_);
    244     my $doc_obj = shift @_;
     244    my ($doc_obj,$edit_mode) = @_;
    245245
    246246    my $verbosity = $self->{'verbosity'};
     
    260260    my $phrlanguage = $self->{'language'};
    261261    return if ($doclanguage && ($doclanguage !~ /$phrlanguage/i));
    262    
     262
     263    if ($edit_mode eq "delete") {
     264    # This classifier works quite differently to the others
     265    # Probably doesn't support incremental building anyway
     266    return;
     267    }
     268
    263269    # record this file
    264270    $self->{'total'} ++;
  • gsdl/trunk/perllib/classify/RecentDocumentsList.pm

    r17209 r18455  
    124124sub classify {
    125125    my $self = shift (@_);
    126     my ($doc_obj) = @_;
     126    my ($doc_obj,$edit_mode) = @_;
    127127
    128128    my $doc_OID = $doc_obj->get_OID();
     
    130130    if (!defined $lastmodified || $lastmodified eq "") {
    131131    print $self->{'outhandle'}, "RecentDocumentsList: $doc_OID has no lastmodified metadata, not classifying\n";
     132    return;
     133    }
     134
     135    if ($edit_mode eq "delete") {
     136    $self->oid_hash_delete($doc_OID,'list');
    132137    return;
    133138    }
  • gsdl/trunk/perllib/classify/SectionList.pm

    r17209 r18455  
    6363sub classify {
    6464    my $self = shift (@_);
    65     my ($doc_obj, @options) = @_;
     65    my ($doc_obj, $edit_mode, @options) = @_;
    6666   
    6767    # @options used by AZCompactList when is uses SectionList internally
     
    9797    if (defined $thissection) {
    9898    # just classify the one section
    99     $self->classify_section($thissection, $doc_obj, $sortmeta, $nosort);
     99    $self->classify_section($thissection, $doc_obj, $edit_mode, $sortmeta, $nosort);
    100100    } else   
    101101    {
    102102    $thissection = $doc_obj->get_next_section ($doc_obj->get_top_section());
    103103    while (defined $thissection) {
    104         $self->classify_section($thissection, $doc_obj, $sortmeta, $nosort);
     104        $self->classify_section($thissection, $doc_obj, $edit_mode, $sortmeta, $nosort);
    105105        $thissection = $doc_obj->get_next_section ($thissection);
    106106    }
     
    110110sub classify_section {
    111111    my $self = shift (@_);
    112     my ($section, $doc_obj, $sortmeta, $nosort) = @_;
     112    my ($section, $doc_obj, $edit_mode, $sortmeta, $nosort) = @_;
    113113
    114114    my $doc_OID = $doc_obj->get_OID();
Note: See TracChangeset for help on using the changeset viewer.