summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/scripts/crossrefware/bibzbladd.pl
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2016-02-15 22:07:53 +0000
committerKarl Berry <karl@freefriends.org>2016-02-15 22:07:53 +0000
commit73b1c209e75875c789db1f73464f5e118590ed9e (patch)
tree521e07c677e52390cea9d2ccbeeef4cbbbcad7e6 /Master/texmf-dist/scripts/crossrefware/bibzbladd.pl
parentf2d240e3af96300dd96067cd653bc34a08c47e26 (diff)
crossrefware (15feb16)
git-svn-id: svn://tug.org/texlive/trunk@39727 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/scripts/crossrefware/bibzbladd.pl')
-rwxr-xr-xMaster/texmf-dist/scripts/crossrefware/bibzbladd.pl138
1 files changed, 45 insertions, 93 deletions
diff --git a/Master/texmf-dist/scripts/crossrefware/bibzbladd.pl b/Master/texmf-dist/scripts/crossrefware/bibzbladd.pl
index 4059b7b0a12..f348cd4b946 100755
--- a/Master/texmf-dist/scripts/crossrefware/bibzbladd.pl
+++ b/Master/texmf-dist/scripts/crossrefware/bibzbladd.pl
@@ -8,12 +8,15 @@ bibzbladd.pl - add Zbl numbers to papers in a given bib file
=head1 SYNOPSIS
-bibzbladd [B<-o> I<output>] I<bib_file>
+bibzbladd [B<-f>] [B<-o> I<output>] I<bib_file>
=head1 OPTIONS
=over 4
+=item B<-f>
+
+Force searching for Zbl numbers even if the entry already has one.
=item B<-o> I<output>
@@ -25,7 +28,7 @@ output file is formed by adding C<_zbl> to the input file
=head1 DESCRIPTION
The script reads a BibTeX file. It checks whether the entries have
-Zbls. If now, tries to contact internet to get the numbers. The
+Zbls. If not, tries to contact internet to get the numbers. The
result is a BibTeX file with the fields
C<zblnumber=...> added.
@@ -38,7 +41,7 @@ Boris Veytsman
=head1 COPYRIGHT AND LICENSE
-Copyright (C) 2014 Boris Veytsman
+Copyright (C) 2014-2016 Boris Veytsman
This is free software. You may redistribute copies of it under the
terms of the GNU General Public License
@@ -48,16 +51,22 @@ extent permitted by law.
=cut
use strict;
-use Text::BibTeX;
-use Text::BibTeX::Name;
+BEGIN {
+ # find files relative to our installed location within TeX Live
+ chomp(my $TLMaster = `kpsewhich -var-value=SELFAUTOPARENT`); # TL root
+ if (length($TLMaster)) {
+ unshift @INC, "$TLMaster/texmf-dist/scripts/bibtexperllibs";
+ }
+}
+use IO::File;
+use BibTeX::Parser;
use Getopt::Std;
use URI::Escape;
use LWP::UserAgent;
-use TeX::Encode;
-my $USAGE="USAGE: $0 [-o output] file\n";
+my $USAGE="USAGE: $0 [-f] [-o output] file\n";
my $VERSION = <<END;
-bibzbladd v1.0
+bibzbladd v2.0
This is free software. You may redistribute copies of it under the
terms of the GNU General Public License
http://www.gnu.org/licenses/gpl.html. There is NO WARRANTY, to the
@@ -65,7 +74,7 @@ extent permitted by law.
$USAGE
END
my %opts;
-getopts('o:hV',\%opts) or die $USAGE;
+getopts('fo:hV',\%opts) or die $USAGE;
if ($opts{h} || $opts{V}){
print $VERSION;
@@ -86,41 +95,45 @@ if ($opts{o}) {
$outputfile = $opts{o};
}
-my $input = new Text::BibTeX::File "$inputfile" or
- die "Cannot BibTeX file $inputfile\n";
-my $output = new Text::BibTeX::File "> $outputfile" or
- die "Cannot write to $outputfile\n";
+my $forceSearch=$opts{f};
+
+my $input= IO::File->new($inputfile) or
+ die "Cannot find BibTeX file $inputfile\n$USAGE\n";
+my $output = IO::File->new("> $outputfile") or
+ die "Cannot write to $outputfile\n$USAGE\n";
+
+my $parser=new BibTeX::Parser($input);
+
# Creating the HTTP parameters
my $mirror =
- "http://www.zentralblatt-math.org/MIRROR/zmath/en/search/";
+ "https://zbmath.org/citationmatching/bibtex/match";
my $userAgent = LWP::UserAgent->new;
-# Processing the input
-while (my $entry = new Text::BibTeX::Entry $input) {
+while (my $entry = $parser->next ) {
if (!$entry->parse_ok()) {
print STDERR "Cannot understand entry: ";
$entry->print(*STDERR);
print STDERR "Skipping this entry\n";
next;
}
- if (!(($entry->metatype() eq BTE_REGULAR))) {
- $entry->write($output);
+ if (!($entry->type() eq 'ARTICLE')) {
+ print $output $entry->raw_bibtex(), "\n\n";
next;
}
- if ($entry->exists('zblnumber')) {
- $entry->write($output);
+ if ($entry->has('zblnumber') && !$forceSearch) {
+ print $output $entry->raw_bibtex(), "\n\n";
next;
}
- # Now we have an entry with no Zbl. Let us get to work.
- my $zbl = GetZbl($entry, $userAgent, $mirror);
- if (length($zbl)) {
- $entry->set('zblnumber',$zbl);
- }
- $entry->write($output);
+ # Now we have an entry with no Zbl. Let us get to work.
+ my $zbl = GetZbl($entry, $userAgent, $mirror);
+ if (length($zbl)) {
+ $entry->field('zblnumber',$zbl);
+ }
+ print $output $entry->to_string(), "\n\n";
}
@@ -139,77 +152,16 @@ sub GetZbl {
my @query;
- my @names=$entry->names ('author');
- if (scalar(@names)) {
- foreach my $name (@names) {
- my @lastnames = $name->part ('last');
- if (scalar(@lastnames)) {
- foreach my $lastname (@lastnames) {
- push @query, "au:$lastname";
- }
- }
- }
- }
- if (my $title = $entry->get('title')) {
- push @query, "ti:$title";
- }
+ my $string=uri_escape_utf8($entry->to_string());
- if (my $year = $entry->get('year')) {
- push @query, "py:$year";
- }
-
- if (my $year = $entry->get('year')) {
- push @query, "py:$year";
- }
- my $type = $entry->type;
- if ($type eq 'article') {
- push @query, "dt:j";
- }
- if ($type eq 'book') {
- push @query, "dt:b";
- }
- if ($type eq 'inproceedings' || $type eq 'incollection') {
- push @query, "dt:a";
- }
-
- my $source = "";
- if ($type eq 'article') {
- if ($entry->get('journal')) {
- $source .= $entry->get('journal');
- }
- if (my $vol=$entry->get('volume')) {
- $source .= ",$vol";
- }
- if (my $pages=$entry->get('pages')) {
- $source .= ",$pages";
- }
- } else {
- if (my $bt=$entry->get('booktitle')) {
- $source .= "$bt";
- }
- }
-
- if ($source) {
- push @query, "so:$source";
- }
-
-
- my $qstring = join(" & ", @query);
-# print STDERR "$qstring\n";
- my $form;
-
- $form->{name}='form';
- $form->{q} = $qstring;
- $form->{type} = "ascii";
- $form->{submit} = 'Search';
-
- my $response = $userAgent->post($mirror, $form);
- if ($response->decoded_content =~ /^an:\s*Zbl\s*(\S+)\s*$/m) {
+ my $response = $userAgent->get("$mirror?bibtex=$string");
+ if ($response->decoded_content =~ /^\s*"zbl_id":\s*"(.*)",\s*$/m) {
return $1;
- } else {
- return ("");
+ } else {
+ return ("");
}
+
}