From 73b1c209e75875c789db1f73464f5e118590ed9e Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Mon, 15 Feb 2016 22:07:53 +0000 Subject: crossrefware (15feb16) git-svn-id: svn://tug.org/texlive/trunk@39727 c570f23f-e606-0410-a88d-b1316a301751 --- .../texmf-dist/scripts/crossrefware/bibzbladd.pl | 138 +++++++-------------- 1 file changed, 45 insertions(+), 93 deletions(-) (limited to 'Master/texmf-dist/scripts/crossrefware/bibzbladd.pl') 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] I +bibzbladd [B<-f>] [B<-o> I] I =head1 OPTIONS =over 4 +=item B<-f> + +Force searching for Zbl numbers even if the entry already has one. =item B<-o> I @@ -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 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 = < $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 (""); } + } -- cgit v1.2.3