#!/usr/bin/perl # # $Id: citations.pl,v 1.1 1997/03/19 20:20:50 alberto Exp alberto $ # # Test program for the ADS WWW library. # # Searcheable fields are: # au = author # kw = keyword # ti = title # ab = abstract text # # Example: # citations.pl au=geller and ti="(structure bubble)" # # Written by Alberto Accomazzi , # http://cfa-www.harvard.edu/~alberto # # $Log: citations.pl,v $ # Revision 1.1 1997/03/19 20:20:50 alberto # Initial revision # # # unshift(@INC, $libloc) if ($libloc = $ENV{'LIBWWW_PERL'}); push(@INC,"/opt/local/lib/perl") if (-d "/opt/local/lib/perl"); require "adswww.pl"; while ($ARGV[0] =~ /^\-/) { $_ = shift(@ARGV); if (/^\-debug/) { $debug++; } elsif (/^\-db/) { &Usage("missing argument for \"-db\" option") unless ($opts{'db_key'} = shift(@ARGV)); } elsif (/^-totref/) { &Usage("missing argument for \"-totref\" option") unless (($opts{'nr_to_return'} = shift(@ARGV)) > 0); } else { &Usage("unknown option \"$_\""); } } $ads'debug = 1 #' if ($debug > 1); # process keyword=value pairs on the command line or STDIN # interpreting them as WAIS syntax ($waisq = join(' ',@ARGV)) =~ s/^\s+|\s+$//g; if (! $waisq) { while () { chop; $waisq .= "$_ "; } chop($waisq); } # translate original WAIS query into an ADS fielded query %query = &ads'wais2ads($waisq); #' # add options specified on the command line foreach (keys(%opts)) { $query{$_} = $opts{$_}; } $query{'data_type'} = 'PORTABLE'; # force refer style output $query{'query_type'} = 'CITES'; # return citations $totref = $query{'nr_to_return'}; # tot number of references we want returned # loop here to repeatedly retrieve references until we have as many # as we want while ($references < $totref) { # now issue the WWW query print STDERR "$0: retrieving references..."; ($result,$status) = &ads'abstract_query(%query); #' print STDERR "done!\n"; # did an error occurr? die "$0: ADS query returned the following error status: $status\n" . "$0: HTTP error message follows:\n$result\n" if ($status); print STDERR "$0: parsing references..."; push(@references,&ads'parse_bib($result,*score,*title,*author,*pubdate) #' ); print STDERR "done!\n"; # here we are saving all references in arrays instead of # printing them out out right away, but keep in mind that if # you're doing any of this from inside an nph CGI script, you # should do the printing as soon as you can, so that the user # will start recieving results right after the first pass. print STDERR "$0: total number of references selected: ", $ads'ref_selected, #' "\n$0: total number of references returned: ", $ads'ref_returned, #' "\n$0: references start from sequence number ", $ads'ref_start, #' "\n" if ($debug); # increase reference counters $references += $ads'ref_returned; #' $selected = $ads'ref_selected #' unless($selected); # exit loop when no more references are returned or if all # selected references have been returned this time around last unless $ads'ref_returned; #' last if ($ads'ref_selected == $ads'ref_returned); print STDERR "$0: parsed references $ads'ref_start - ", #' $ads'ref_start + $ads'ref_returned - 1 , "\n"; # update start reference counter $query{'start_nr'} = $ads'ref_start + $ads'ref_returned; #' } # sort, and print out citations array foreach (@references) { &PrintBib($_); } sub PrintBib { local($b) = $_[0]; return unless($b); print "Bibliographic Code: $b\n"; print "Score: $score{$b}\n" if ($score{$b}); print "Title: $title{$b}\n" if ($title{$b}); print "Authors: $author{$b}\n" if ($author{$b}); print "Publication Date: $pubdate{$b}\n" if ($pubdate{$b}); print "\n"; } sub Usage { print STDERR "$0: @_\n" if (@_); print STDERR <<"EOF"; Usage: $0 [-debug] [-db database] [-totref number] [query ...] If no query terms are specified on the command line, they are read from STDIN. EOF exit(1); }