HTTP::OAI::Harvester 问题

HTTP::OAI::Harvester 问题

规格:

  • 戴尔 Latitude E6420
  • Ubuntu 版本 20.04.02 LTS
  • Perl 版本 5、版本 30

安装libhttp-oai-perlapt-get install

尝试使用位于以下位置的脚本来使用模块 HTTP::OAI::Harvester 后摘要部分这个的文章

           use HTTP::OAI;

           my $h = new HTTP::OAI::Harvester(baseURL=>'http://arXiv.org/oai2');
           my $response = $h->repository($h->Identify)
           if( $response->is_error ) {
                   print "Error requesting Identify:\n",
                           $response->code . " " . $response->message, "\n";
                   exit;
           }

           # Note: repositoryVersion will always be 2.0, $r->version returns
           # the actual version the repository is running
           print "Repository supports protocol version ", $response->version, "\n";

           # Version 1.x repositories don't support metadataPrefix,
           # but OAI-PERL will drop the prefix automatically
           # if an Identify was requested first (as above)
           $response = $h->ListIdentifiers(
                   metadataPrefix=>'oai_dc',
                   from=>'2001-02-03',
                   until=>'2001-04-10'
           );

           if( $response->is_error ) {
                   die("Error harvesting: " . $response->message . "\n");
           }

           print "responseDate => ", $response->responseDate, "\n",
                   "requestURL => ", $response->requestURL, "\n";

           while( my $id = $response->next ) {
                   print "identifier => ", $id->identifier;
                   # Only available from OAI 2.0 repositories
                   print " (", $id->datestamp, ")" if $id->datestamp;
                   print " (", $id->status, ")" if $id->status;
                   print "\n";
                   # Only available from OAI 2.0 repositories
                   for( $id->setSpec ) {
                           print "\t", $_, "\n";
                   }
           }

           # Using a handler
           $response = $h->ListRecords(
                   metadataPrefix=>'oai_dc',
                   handlers=>{metadata=>'HTTP::OAI::Metadata::OAI_DC'},
           );
           while( my $rec = $response->next ) {
                   print $rec->identifier, "\t",
                           $rec->datestamp, "\n",
                           $rec->metadata, "\n";
                   print join(',', @{$rec->metadata->dc->{'title'}}), "\n";
           }
           if( $rec->is_error ) {
                   die $response->message;
           }

           # Offline parsing
           $I = HTTP::OAI::Identify->new();
           $I->parse_string($content);
           $I->parse_file($fh);

我收到一条错误消息:

Can't locate object method "is_error" via package "HTTP::OAI::Identify" at ./test.pl line 7.

如何继续使脚本正常运行?

任何帮助,将不胜感激!

答案1

联系后[电子邮件保护]现在由谁来维护这个软件包而不是 Tim Brody,上面提到的例子需要做一些修改。

我不确定是否真的有必要进行一项修改,那就是添加

use HTTP::OAI::Metadata::OAI_DC;

然而,主要的修改是使用回调方法代替“next”方法。修改后的代码如下所示

# Using a handler
$response = $h->ListRecords(
   metadataPrefix=>'oai_dc',
   handlers=>{metadata=>'HTTP::OAI::Metadata::OAI_DC'},
   onRecord=>sub {
     my $rec = shift;

     printf"%s\t%s\t%s\n"
          , $rec->identifier
          , $rec->datestamp
          , join(',', @{$rec->metadata->dc->{'title'}});
   }
);

相关内容