Bundle-PBib

 view release on metacpan or  search on metacpan

lib/Biblio/bp/lib/bp-cstra.pl  view on Meta::CPAN

# This also should use less memory.
%orgmap = ();

sub maporg {
  local($org) = @_;
  local($fullname, $codename);

  ($fullname, $codename) = ($orgcodes =~ /\n$org:([^:]*):([^\n]*)\n/);
  if (!defined $fullname) {
    &bib'gotwarn("Unknown organization code: $org");
    $fullname = $org;
  }
  $orgmap{$org} = $fullname;
}

######

# This is modelled on the refer explode method.

sub explode {
  local($rec) = @_;
  local(%entry);
  local($field, $value);
  local(@lines);

  substr($rec, 0, 0) = "\n";
  @lines = split(/\n\%/, $rec);
  shift @lines;
  foreach (@lines) {
    $field = substr($_, 0, 2);
    if (length($_) < 4) {
      &bib'gotwarn("CSTRA explode got empty field \%$field");
      next;
    }
    $value = substr($_, 3);
    $value =~ s/\n+/ /g;
    $value =~ s/^\s+//;
    $value =~ s/\s+$//;
    if (defined $entry{$field}) {
      $entry{$field} .= $bib'cs_sep . $value;
    } else {
      $entry{$field} = $value;
    }
  }
  %entry;
}

######


sub implode {
  local(%entry) = @_;

  $ent = '';

  local(@keys) = sort { index($opt_order,$a) <=> index($opt_order,$b) }
                 keys(%entry);
  local($unknown_ent) = '';
  # unknown fields are at the top
  foreach $field (@keys) {
    last if index($opt_order,$field) >= $[;
    &bib'gotwarn("CSTRA implode: unknown field identifier: $field");
    $unknown_ent .= "\%$field $entry{$field}\n" if length($field) == 1;
    shift @keys;
  }
  foreach $field (@keys) {
    $entry{$field} =~ s/$bib'cs_sep/\n\%$field /go;
    $ent .= "\%$field $entry{$field}\n";
  }
  $ent .= $unknown_ent;

  $ent =~ s/$bib'cs_sep/ /go;
  $ent;
}

######

%tra_to_can_fields = (
 'TI',  'Title',
  # AU
 'RT',  'ReportType',
 'LT',  'ReportNumber',
  # OR
 'AB',  'Abstract',
  # AV
  # GP
  # DA
  # DY
 'MN',  'Month',
 'YR',  'Year',
 'PA',  'PagesWhole',
 'PL',  'PubAddress',
  # PU
 'LA',  'Language',
 'KW',  'KeyWords',
);

sub tocanon {
  local(%entry) = @_;
  local(%can);
  local($field);
  local($tag, $val);

  # AU
  if (defined $entry{'AU'}) {
    local(@cname) = ();
    foreach $field (split(/$bib'cs_sep/o, $entry{AU})) {
      push( @cname, &bp_util'name_to_canon($field, 0) );
    }
    $can{'Authors'} = join($bib'cs_sep, @cname);
    delete $entry{'AU'};
  }

  if (defined $entry{'AV'}) {
    local($sourceurl) = '';
    local($sourceoth) = '';
    foreach $field (split(/$bib'cs_sep/o, $entry{'AV'})) {
      ($tag, $val) = split(/\s+/, $field, 2);
      if ($tag =~ /^url$/i) {
        $sourceurl .= $bib'cs_sep . $val;
      } elsif ($tag =~ /^ftp$/i) {



( run in 1.934 second using v1.01-cache-2.11-cpan-364913b4093 )