Changeset 33369 for main/trunk/greenstone2/perllib/mgppbuildproc.pm
- Timestamp:
- 2019-07-29T11:55:01+12:00 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone2/perllib/mgppbuildproc.pm
r33302 r33369 298 298 my $shortname=""; 299 299 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 309 303 my $section_text = ""; # put any text in here 310 304 foreach my $submeta (split /,/, $real_field) { … … 381 375 next if ($mfield =~ /^gsdl/); 382 376 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); 390 378 $self->{'allindexfields'}->{$mfield} = 1; 391 379 $new_text .= "$paratag<$shortname>$mvalue</$shortname>\n"; … … 414 402 #chooses the first two letters or digits for the shortname 415 403 #now ignores non-letdig characters 416 sub create_shortname {404 sub get_or_create_shortname { 417 405 my $self = shift(@_); 418 406 419 407 my ($realname) = @_; 408 if (defined $self->{'fieldnamemap'}->{$realname}) { 409 return $self->{'fieldnamemap'}->{$realname}; 410 } 411 420 412 my @realnamelist = split(",", $realname); 421 413 map {$_=~ s/^[a-zA-Z]+\.//;} @realnamelist; #remove namespaces … … 423 415 424 416 # 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 } 430 447 } 431 448 } 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; 460 453 461 454 return $shortname;
Note:
See TracChangeset
for help on using the changeset viewer.