The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Bib::Tools - For managing collections of Bib::CrossRef references.

SYNOPSIS

 use strict;
 use Bib::Tools;
 

# Create a new object

 my $refs = Bib::Tools->new();
 

# Add some bibliometric info e.g. as text, one reference per line

 $text=<<"END";
 10.1109/lcomm.2011.040111.102111
 10.1109/tnet.2010.2051038
 END
 open $fh, '<', \$text;
 $refs->add_fromfile($fh);
 
 or 
 
 $text=<<"END";
 Dangerfield, I., Malone, D., Leith, D.J., 2011, Incentivising fairness and policing nodes in WiFi, IEEE Communications Letters, 15(5), pp500-502
 D. Giustiniano, D. Malone, D.J. Leith and K. Papagiannaki, 2010. Measuring transmission opportunities in 802.11 links. IEEE/ACM Transactions on Networking, 18(5), pp1516-1529
 END
 open $fh, '<', \$text;
 $refs->add_fromfile($fh);

# or as text scraped from a google scholar personal home page

 $refs->add_google('http://scholar.google.com/citations?user=n8dX1fUAAAAJ');

# or as text obtained from ORCID (www.orcid.org)

 $refs->add_orcid('0000-0003-4056-4014');

# or as text from PubMed

 $refs->add_pubmed('mills kh[author]');
 

# or as text from DBLP

 $refs->add_dblp('http://www.informatik.uni-trier.de/~ley/pers/xx/l/Leith:Douglas_J=');

# Bib:Tools will use Bib:CrossRef to try to resolve the supplied text into full citations. It will try to detect duplicates using DOI information, so its fairly safe to import from multiple sources without creating clashes. Full citations without DOI information are kept separately from those with a DOI for better quality control.

# The resulting list of full citations containing DOI's can be printed out in human readable form using

 print $refs->print;

# and the list of full citations without DOI's

 print $refs->print_nodoi;

# or the complete citation list can also be output as a simple web page using

 print $refs->send_resp;

METHODS

new

 my $refs = Bib::Tools->new();

Creates a new Bib::Tools object. Queries to crossref via Bib::CrossRef are rate limited. To change the ratelimit pass this as an option to new e.g $refs = Bib::Tools->new(3) sets the rate limit to 3 queries per second.

add_google

 $refs->add_google($url);
 

Scrapes citation information from a google scholar personal home page (*not* a search page, see below) and tries resolve it into full citations using crossref.

 $refs->add_google_search($url);
 

Scrapes citation information from a google scholar search page and tries to resolve into full citations. A different method is needed for search and home pages due to the different html tags used.

add_orcid

 $refs->add_orcid($orcid_id);
 

Uses the ORCID API to extract citations for the specified user identifier. If possible, the DOI is obtained and then resolved using crossref.

add_dblp

 $refs->add_dblp($url);
 

Uses DBLP XML API to extract citations. If possible, the DOI is obtained and then resolved using crossref. E.g.

 $refs->add_dblp('http://www.informatik.uni-trier.de/~ley/pers/xx/l/Leith:Douglas_J=');
 

add_pubmed

 $refs->add_dblp($query);
 

Uses PubMed API to extract citations listed in response to a query. E.g.

 $refs->add_pubmed('mills kh[author]');
 

add_details

 $refs->add_details(@lines);
 

Given a array of strings, one per citation, tries to resolve these into full citations.

add_bibtex

 $refs->add_bibtex($fh, $opt);
 

Given a file handle to a file containing bibtex entries, imports these citations. If a citation has a DOI and $opt is non-zero (the default), this will be used to try to obtain the full citation from crossref.org.

add_fromfile

 $refs->add_fromfile($fh);
 

Given a file handle to a text file, with one citation per line, tries to resolve these into full citations.

print

 my $info = $refs->print;

Display the list of full citations that have DOIs in human readable form.

 my $info = $refs->print_nodoi;

Display the list of full citations without DOIs in human readable form.

sethtml

 $refs->sethtml
 

Set the output format to be html

clearhtml

 $refs->clearhtml
 

Set the output format to be plain text

send_resp

 my $info = $refs->send_resp;

num

 my $num = $refs->num;
 

Returns the number of full citations that have DOIs

num_nodoi

 my $num = $refs->num_nodoi;
 

Returns the number of full citations without DOIs

getref

 my $ref = $refs->getref($i);
 

Returns the $i citation from the list with DOIs. This can be used to walk the list of citations.

getref_nodoi

 my $ref = $refs->getref_nodoi($i);

Returns the $i citation from the list without DOIs

append

  my $ref = Bib::CrossRef->new;
  $refs->append($ref);

Adds a Bib::CrossRef to end of a Bib::Tools list of objects

EXPORTS

You can export the following functions if you do not want to use the object orientated interface:

sethtml clearhtml add_details add_google add_google_search add_orcid add_fromfile add_dblp add_pubmed send_resp print print_nodoi num num_nodoi getref getref_nodoi append add_bibtex

The tag all is available to easily export everything:

 use Bib::Tools qw(:all);

WEB INTERFACE

A simple web interface to Bib::Tools is contained in the examples folder. This consists of three files: query.html, handle_query.pl and post.js.

query.html

 <!DOCTYPE HTML>
 <html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"></head><body>
 <div style="position:relative; height:600px; padding:10px; border:1px solid">
 <h3>Import References</h3>
 <form action="handle_query.pl" method="POST" id="in" enctype="multipart/form-data">
 <table>
 <tr><td>Use ORCID id:<br><small style="color:#C0C0C0">e.g. 0000-0003-4056-4014</small></td>
 <td><INPUT type="text" name="orcid" size="128"></p></td></tr>
 <tr><td colspan=2>(to import from Scopus, follow these <a href="http://orcid.scopusfeedback.com/">instructions</a>, and for Web of Science/ResearcherId follow <a href="http://wokinfo.com/researcherid/integration/">these</a>)</td></tr>

 <tr><td width="150px">Use DBLP XML page:<br>
 <small style="color:#C0C0C0">e.g. http://www.informatik.uni-trier.de/~ley/pers/xx/l/Leith:Douglas_J=</small></td>
 <td> <INPUT type="text" name="dblp" size="128"></td></tr>

 <tr><td>Use PubMed query:<br><small style="color:#C0C0C0">e.g. mills kh[author]</small></td>
 <td> <INPUT type="text" name="query" size="128"></td></tr>

 <tr><td>BibTeX file:</td>
 <td> <INPUT type="file" name="bibtex"></td></tr>

 <tr><td>Use Google Scholar personal page:<br>
 <small style="color:#C0C0C0">e.g. http://scholar.google.com/citations?user=n8dX1fUAAAAJ</small></td>
 <td><INPUT type="text" name="google" size="128"></p></td></tr>

 <tr><td>Use Google Scholar search page:<br>
 <small style="color:#C0C0C0">e.g. http://scholar.google.com/scholar?q=andr%C3%A9s+garcia+saavedra</small></td>
 <td><INPUT type="text" name="google2" size="128"></p></td></tr>

 </table>
 <p>Enter references, one per line (free form text):</p>
 <textarea name="refs" rows="10" cols="128" form="in"></textarea><br>
 <INPUT type="submit" value="Submit">(can be slow, be patient)
 </form></div>
 <div style="position: absolute; bottom: 5px;"><small>Source: <a href="http://search.cpan.org/~dougleith/Bib-Tools/">Bib::Tools</a></div>
 </body></html>
 

handle_query.pl

 #!/usr/bin/perl
 use Bib::CrossRef;
 use Bib::Tools;
 use CGI;

 # send html header
 print "Content-Type: text/html;\n\n";

 my $q = CGI->new;
 my $refs = Bib::Tools->new;
 my $orcid = scalar $q->param('orcid');
 $orcid =~ /([0-9\-]+)$/; # extract id out of url
 $orcid = $1;
 if (length($orcid) > 5) {
   $refs->add_orcid($1);
 }

 my $google = scalar $q->param('google'); #NB: CGI has already carried out URL decoding
 if (length($google) > 5) {
   if (!($google =~ m/^http/)) { $google = "http://".$google;}
   $refs->add_google($google);
 }

 my $google2 = scalar $q->param('google2'); #NB: CGI has already carried out URL decoding
 if (length($google2) > 5) {
   if (!($google2 =~ m/^http/)) { $google2 = "http://".$google2;}
   $refs->add_google_search($google2);
 }

 my $dblp = scalar $q->param('dblp');
 if (length($dblp) > 5) {
   if (!($dblp =~ m/^http/)) { $dblp = "http://".$dblp;}
   if ($dblp =~ m/http:\/\/dblp.uni-trier.de\/pers\/xx\/l\/.+/) {
      # looks like a valid dblp url
      $refs->add_dblp($dblp);
   } else {
      print "<p style='color:red'>DBLP url looks invalid: ", $dblp,"</p>";
   }
 }

 my $pubmed = scalar $q->param('pubmed');
 if (length($pubmed) > 5) {
   $refs->add_pubmed($pubmed);
 }

 $filename = scalar $q->param('bibtex');
 $tmpfilename = $q->tmpFileName($filename);
 open my $fh, "<", $tmpfilename;
 $refs->add_bibtex($fh);
 
 my @values = $q->multi_param('refs');
 foreach my $value (@values) {
   open my $fh, "<", \$value; #NB: CGI has already carried out URL decoding
   $refs->add_fromfile($fh);
 }

 $refs->sethtml;
 print $refs->send_resp;

post.js

 function GetCellValues(dataTable) {
    var table = document.getElementById(dataTable);
    if (table == null) return;
    var i = 0; var Obj = [];
    var names = table.rows[0];
    for (var r = 1; r < table.rows.length; r++) {
        if (table.rows[r].id == 'cite') {
          var row = table.rows[r].cells;
          var check = table.rows[r].getElementsByTagName('Input');
          if (check.length>0){
            Obj[i] = {};
            for (var c = 3; c < row.length; c++){
              var tag = names.cells[c].textContent;
              Obj[i][tag] =row[c].textContent;
            }
            i = i+1;
          }
        }
    }
    var jsonString = JSON.stringify(Obj);
    document.getElementById('out').innerHTML = document.getElementById('out').innerHTML+jsonString;
    // or POST using ajax
 }

VERSION

Ver 0.15

AUTHOR

Doug Leith

BUGS

Please report any bugs or feature requests to bug-rrd-db at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Bib-Tools. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

COPYRIGHT

Copyright 2015 D.J.Leith.

This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.

See http://dev.perl.org/licenses/ for more information.