Changeset 33369

Show
Ignore:
Timestamp:
29.07.2019 11:55:01 (3 weeks ago)
Author:
kjdon
Message:

instead of create_shortname, now have get_or_create_shortname. this does the working of looking in fieldnamemap to see if a shortname has already been defined, and saving the new shortnames into the map. get_or_create_sortfield_shortname does the same thing with sortfieldnamemap

Location:
main/trunk/greenstone2/perllib
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone2/perllib/lucenebuildproc.pm

    r33327 r33369  
    216216        my $shortname=""; 
    217217        my $new_field = 0; # have we found a new field name? 
    218         if (defined $self->{'fieldnamemap'}->{$real_field}) { 
    219         $shortname = $self->{'fieldnamemap'}->{$real_field}; 
    220         } else { 
    221         $shortname = $self->create_shortname($real_field); 
    222         $self->{'fieldnamemap'}->{$real_field} = $shortname; 
    223         $self->{'fieldnamemap'}->{$shortname} = 1; 
    224         } 
     218        $shortname = $self->get_or_create_shortname($real_field); 
    225219        my @metadata_list = (); # put any metadata values in here 
    226220        my $section_text = ""; # put the text in here 
     
    322316        &ghtml::htmlsafe($mvalue); 
    323317         
    324         if (defined $self->{'fieldnamemap'}->{$mfield}) { 
    325             $shortname = $self->{'fieldnamemap'}->{$mfield}; 
    326         } 
    327         else { 
    328             $shortname = $self->create_shortname($mfield); 
    329             $self->{'fieldnamemap'}->{$mfield} = $shortname; 
    330             $self->{'fieldnamemap'}->{$shortname} = 1; 
    331         } 
     318        $shortname = $self->get_or_create_shortname($mfield); 
    332319        $self->{'allindexfields'}->{$mfield} = 1; 
    333320        $new_text .= "<$shortname index=\"1\">$mvalue</$shortname>\n"; 
     
    376363        # ignore special field rank 
    377364        next if ($sfield eq "rank" || $sfield eq "none"); 
    378         my $sf_shortname; 
    379         if (defined $self->{'sortfieldnamemap'}->{$sfield}) { 
    380         $sf_shortname = $self->{'sortfieldnamemap'}->{$sfield}; 
    381         } 
    382         else { 
    383         $sf_shortname = $self->create_sortfield_shortname($sfield); 
    384         $self->{'sortfieldnamemap'}->{$sfield} = $sf_shortname; 
    385         $self->{'sortfieldnamemap'}->{$sf_shortname} = 1; 
    386         } 
     365        my $sf_shortname = $self->get_or_create_sortfield_shortname($sfield); 
     366      
    387367        my @metadata_list = (); # put any metadata values in here 
    388368        foreach my $submeta (split /,/, $sfield) { 
     
    397377        push (@metadata_list, @section_metadata); 
    398378        } 
    399         # my $new_text = ""; 
    400         # foreach my $item (@metadata_list) { 
    401         # &ghtml::htmlsafe($item); 
    402         # $new_text .= "$item"; # should be .="$item "; But will be commenting out and rewriting this entire thing, so it doesn't matter 
    403         # } 
    404         # if ($new_text =~ /\S/) { 
    405         # $new_text = "<$sf_shortname index=\"1\" tokenize=\"0\">$new_text</$sf_shortname>"; 
    406         # # filter the text??? 
    407         # $text .= "$new_text"; # add it to the main text block 
    408         # $self->{'actualsortfields'}->{$sfield} = 1; 
    409         # } 
    410379         
    411         foreach my $item (@metadata_list) { 
    412             &ghtml::htmlsafe($item); 
    413             if ($item =~ /\S/) { 
    414                 $item = "<$sf_shortname index=\"1\" tokenize=\"0\">$item</$sf_shortname>"; 
    415                 $text .= "$item"; # add it to the main text block 
    416             } 
    417         } 
    418         if(scalar @metadata_list > 0) { 
    419             $self->{'actualsortfields'}->{$sfield} = 1; 
     380        my $new_text = ""; 
     381        foreach my $item (@metadata_list) { 
     382        &ghtml::htmlsafe($item); 
     383        $new_text .= "$item "; 
     384        } 
     385        if ($new_text =~ /\S/) { 
     386        $new_text = "<$sf_shortname index=\"1\" tokenize=\"0\">$new_text</$sf_shortname>"; 
     387        $text .= "$new_text"; # add it to the main text block 
     388        $self->{'actualsortfields'}->{$sfield} = 1; 
    420389        } 
    421390    } 
     
    658627} 
    659628 
    660 sub create_sortfield_shortname { 
     629sub get_or_create_sortfield_shortname { 
    661630    my $self = shift(@_); 
    662631 
    663632    my ($realname) = @_; 
    664  
    665     my $index_shortname; 
    666     # if we have created a shortname for an index on this field, then use it. 
    667     if (defined $self->{'fieldnamemap'}->{$realname}) { 
    668     $index_shortname = $self->{'fieldnamemap'}->{$realname}; 
    669     } else { 
    670     $index_shortname = $self->create_shortname($realname); 
     633     
     634    if (defined $self->{'sortfieldnamemap'}->{$realname}) { 
     635    return $self->{'sortfieldnamemap'}->{$realname}; 
    671636    } 
    672     return "by".$index_shortname; 
     637 
     638    # get the shortname made for this index field 
     639 
     640    my $shortname = $self->get_or_create_shortname($realname); 
     641    $shortname = "by".$shortname; 
     642 
     643    $self->{'sortfieldnamemap'}->{$realname} = $shortname; 
     644    $self->{'sortfieldnamemap'}->{$shortname} = 1; 
     645    return $shortname; 
    673646} 
    674647   
  • main/trunk/greenstone2/perllib/mgppbuildproc.pm

    r33302 r33369  
    298298        my $shortname=""; 
    299299 
    300         if (defined $self->{'fieldnamemap'}->{$real_field}) { 
    301         $shortname = $self->{'fieldnamemap'}->{$real_field}; 
    302         } else { 
    303         $shortname = $self->create_shortname($real_field); 
    304         $self->{'fieldnamemap'}->{$real_field} = $shortname; 
    305         $self->{'fieldnamemap'}->{$shortname} = 1; 
    306         } 
    307  
    308         my @metadata_list = (); # put any meta values in here 
     300            $shortname = $self->get_or_create_shortname($real_field); 
     301         
     302            my @metadata_list = (); # put any meta values in here 
    309303        my $section_text = ""; # put any text in here 
    310304        foreach my $submeta (split /,/, $real_field) { 
     
    381375        next if ($mfield =~ /^gsdl/); 
    382376         
    383         if (defined $self->{'fieldnamemap'}->{$mfield}) { 
    384             $shortname = $self->{'fieldnamemap'}->{$mfield}; 
    385         } else { 
    386             $shortname = $self->create_shortname($mfield); 
    387             $self->{'fieldnamemap'}->{$mfield} = $shortname; 
    388             $self->{'fieldnamemap'}->{$shortname} = 1; 
    389         } 
     377        $shortname = $self->get_or_create_shortname($mfield); 
    390378        $self->{'allindexfields'}->{$mfield} = 1; 
    391379        $new_text .= "$paratag<$shortname>$mvalue</$shortname>\n"; 
     
    414402#chooses the first two letters or digits for the shortname 
    415403#now ignores non-letdig characters 
    416 sub create_shortname { 
     404sub get_or_create_shortname { 
    417405    my $self = shift(@_); 
    418406     
    419407    my ($realname) = @_; 
     408    if (defined $self->{'fieldnamemap'}->{$realname}) { 
     409    return $self->{'fieldnamemap'}->{$realname}; 
     410    } 
     411 
    420412    my @realnamelist = split(",", $realname); 
    421413    map {$_=~ s/^[a-zA-Z]+\.//;} @realnamelist; #remove namespaces 
     
    423415 
    424416    # try our predefined static mapping 
    425     my $name; 
    426     if (defined ($name = $static_indexfield_map{$singlename})) { 
    427     if (! defined $self->{'fieldnamemap'}->{$name}) { 
    428         # has this shortname already been used?? 
    429         return $static_indexfield_map{$singlename}; 
     417    my $shortname; 
     418    if (defined ($shortname = $static_indexfield_map{$singlename}) && (! defined $self->{'fieldnamemap'}->{$shortname})) { 
     419    # we have a shortname from the static list, and it hasn't already been used: we can use the shortname 
     420    } else { 
     421    # we can't use the quick map, so join all fields back together (without namespaces), and try sets of two characters. 
     422    $realname = join ("", @realnamelist); 
     423    #try the first two chars 
     424    if ($realname =~ /^[^\w]*(\w)[^\w]*(\w)/) { 
     425        $shortname = "$1$2"; 
     426    } else { 
     427        # there aren't two letdig's in the field - try arbitrary combinations 
     428        $realname = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; 
     429        $shortname = "AB"; 
     430    } 
     431    $shortname =~ tr/a-z/A-Z/; 
     432     
     433    #if already used, take the first and third letdigs and so on 
     434    my $count = 1; 
     435    while (defined $self->{'fieldnamemap'}->{$shortname} || defined $static_indexfield_map{$shortname}) { 
     436        if ($realname =~ /^[^\w]*(\w)([^\w]*\w){$count}[^\w]*(\w)/) { 
     437        $shortname = "$1$3"; 
     438        $count++; 
     439        $shortname =~ tr/a-z/A-Z/; 
     440         
     441        } 
     442        else { 
     443        #remove up to and incl the first letdig 
     444        $realname =~ s/^[^\w]*\w//; 
     445        $count = 0; 
     446        } 
    430447    } 
    431448    } 
    432     # we can't use the quick map, so join all fields back together (without namespaces), and try sets of two characters. 
    433     $realname = join ("", @realnamelist); 
    434     #try the first two chars 
    435     my $shortname; 
    436     if ($realname =~ /^[^\w]*(\w)[^\w]*(\w)/) { 
    437     $shortname = "$1$2"; 
    438     } else { 
    439     # there aren't two letdig's in the field - try arbitrary combinations 
    440     $realname = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; 
    441     $shortname = "AB"; 
    442     } 
    443     $shortname =~ tr/a-z/A-Z/; 
    444  
    445     #if already used, take the first and third letdigs and so on 
    446     my $count = 1; 
    447     while (defined $self->{'fieldnamemap'}->{$shortname} || defined $static_indexfield_map{$shortname}) { 
    448     if ($realname =~ /^[^\w]*(\w)([^\w]*\w){$count}[^\w]*(\w)/) { 
    449         $shortname = "$1$3"; 
    450         $count++; 
    451         $shortname =~ tr/a-z/A-Z/; 
    452      
    453     } 
    454     else { 
    455         #remove up to and incl the first letdig 
    456         $realname =~ s/^[^\w]*\w//; 
    457         $count = 0; 
    458     } 
    459     } 
     449    # we now have a new shortname. 
     450    # store it in fieldnamemap 
     451    $self->{'fieldnamemap'}->{$realname} = $shortname; 
     452    $self->{'fieldnamemap'}->{$shortname} = 1; 
    460453 
    461454    return $shortname;