Bundle-PBib

 view release on metacpan or  search on metacpan

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

    'month',        'Month',
    'year',         'Year',
    'price',        'Price',
    'copyright',    'Copyright',
    'keywords',     'Keywords',
    'mrnumber',     'MRNumber',
    'language',     'Language',
    'annote',       'Annotation',
    'isbn',         'ISBN',
    'issn',         'ISSN',
    'subject',      'Field',
    'abstract',     'Abstract',
    'note',         'Note',
    'contents',     'Contents',
    'key',          'Key',
    'url',          'Source',
    'location',     'Location',
   );

sub tocanon {
  local(%rec) = @_;
  local(%can);
  local($name, $btxf, $canf, $btxv);
  local($_) = $rec{'TYPE'};
  tr/A-Z/a-z/;
  #                  NEW CANON TYPE <-- ORIGINAL BIBTEX
  $can{'CiteType'} = 'article'       if /^article/;
  $can{'CiteType'} = 'book'          if /^book/;
  $can{'CiteType'} = 'book'          if /^booklet/;
  $can{'CiteType'} = 'book'          if /^collection/;
  $can{'CiteType'} = 'inproceedings' if /^conference/;
  $can{'CiteType'} = 'inbook'        if /^inbook/;
  $can{'CiteType'} = 'inbook'        if /^incollection/;
  $can{'CiteType'} = 'inproceedings' if /^inproceedings/;
  $can{'CiteType'} = 'manual'        if /^manual/;
  $can{'CiteType'} = 'thesis'        if /^mastersthesis/;
  $can{'CiteType'} = 'misc'          if /^misc/;
  $can{'CiteType'} = 'thesis'        if /^phdthesis/;
  $can{'CiteType'} = 'proceedings'   if /^proceedings/;
  $can{'CiteType'} = 'report'        if /^techreport/;
  $can{'CiteType'} = 'unpublished'   if /^unpublished/;

  if (!defined $can{'CiteType'}) {
    &bib'gotwarn("Improper entry type: $rec{'TYPE'}");
    $can{'CiteType'} = 'misc';
  }

  if (!defined $rec{'type'}) {
    if ( $rec{'TYPE'} =~ /^phdthesis/i ) {
      $rec{'type'} = 'Ph.D.';
    } elsif ( $rec{'TYPE'} =~ /^mastersthesis/i ) {
      $rec{'type'} = 'Masters';
    }
  }


  if (defined $rec{'author'} ) {
    # check for braces around the whole name, in which case we will
    # assume it is a corporate author.
    if ( ($rec{'author'} =~ /^\{/) && ($rec{'author'} =~ /\}$/) ) {
      $can{'CorpAuthor'} = substr($rec{'author'}, $[+1, length($rec{'author'})-2);
    } else {
      $can{'Authors'} = &bibtex_name_to_canon( $rec{'author'} );
    }
    delete $rec{'author'};
  }

  if (defined $rec{'editor'}) {
    $can{'Editors'} = &bibtex_name_to_canon( $rec{'editor'} );
    # XXXXX either we don't need this, or we need it for authors also.
    delete $can{'Editors'} unless $can{'Editors'} =~ /\S/;
    delete $rec{'editor'};
  }

  if ( defined $rec{'organization'} && defined $rec{'school'} )  {
    &bib'gotwarn("Both school and organization defined.");
    delete $rec{'school'};
  }

  if ( defined $rec{'publisher'} && defined $rec{'institution'} )  {
    &bib'gotwarn("Both publisher and institution defined.");
    delete $rec{'institution'};
  }

  if (defined $rec{'number'}) {
    if ($can{'CiteType'} =~ /report|thesis/) {
      $can{'ReportNumber'} = $rec{'number'};
    } else {
      $can{'Number'} = $rec{'number'};
    }
    delete $rec{'number'};
  }

  if (defined $rec{'month'}) {
    $can{'Month'} = &bp_util'canon_month($rec{'month'});
    delete $rec{'month'} if defined $can{'Month'};
  }

  # done with massaging the fields
  delete $rec{'TYPE'};

  while ( ($btxf, $btxv) = each %rec) {
    next unless $btxv =~ /\S/;
    if (defined $btx_to_can_fields{$btxf}) {
      $can{$btx_to_can_fields{$btxf}} = $btxv;
    } else {
      # Unknown, so enter literal.  Perhaps a warning?
      $can{$btxf} = $btxv;
    }
  }

  # Handle title-like fields.
  foreach $canf ('Title', 'SuperTitle', 'ReportType') {
    next unless defined $can{$canf};
    $can{$canf} =~ s/\{([^\s}]+)\}/${bib'cs_meta}3100$1${bib'cs_meta}3110/g;
    $can{$canf} =~ s/\s\s+/ /g;
  }

  # tell them who we are
  $can{'OrigFormat'} = $version;



( run in 2.276 seconds using v1.01-cache-2.11-cpan-364913b4093 )