File Coverage

blib/lib/AIIA/GMT.pm
Criterion Covered Total %
statement 10 12 83.3
branch n/a
condition n/a
subroutine 4 4 100.0
pod n/a
total 14 16 87.5


line stmt bran cond sub pod time code
1             package AIIA::GMT;
2              
3 1     1   27011 use 5.008008;
  1         4  
  1         34  
4 1     1   7 use strict;
  1         2  
  1         90  
5 1     1   5 use warnings;
  1         7  
  1         51  
6 1     1   571 use Frontier::Client;
  0            
  0            
7              
8             require Exporter;
9             use AutoLoader qw(AUTOLOAD);
10              
11             our @ISA = qw(Exporter);
12              
13             # Items to export into callers namespace by default. Note: do not export
14             # names by default without a very good reason. Use EXPORT_OK instead.
15             # Do not simply export all your public functions/methods/constants.
16              
17             # This allows declaration use AIIA::GMT ':all';
18             # If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
19             # will save memory.
20             our %EXPORT_TAGS = ( 'all' => [ qw(pmid2entity text2entity) ] );
21              
22             our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
23              
24             our @EXPORT = qw(pmid2entity text2entity);
25              
26             our $VERSION = '0.05';
27              
28             require XSLoader;
29             XSLoader::load('AIIA::GMT', $VERSION);
30              
31             # Preloaded methods go here.
32              
33             # Autoload methods go after =cut, and are processed by the autosplit program.
34             my $SERVER_URL = 'http://bcsp1.iis.sinica.edu.tw:8080/aiiagmt/XmlRpcServlet';
35              
36             sub pmid2entity {
37             my $id = shift;
38             die "Usage: &pmid2entity(\'PubMed Article ID\');\n" if ($id !~ /^\d+$/);
39             return &submit($id);
40             }
41              
42             sub text2entity {
43             my $txt = shift;
44             $txt =~ s/\n//g;
45             my $num;
46             map {$num++;} split(/\s/, $txt);
47             die "Usage: &text2entity(\'less than 3000 words\');\n" if ($num > 3000);
48             return &submit($txt);
49             }
50              
51             sub submit {
52             my @args = (shift);
53             my $client = Frontier::Client->new(url => $SERVER_URL, debug => 0);
54             my $ret = $client->call('Annotator.getAnnotation', @args);
55             my @rep;
56             map {push @rep, $_->{'offset'} . "\t" . $_->{'mention'};} @{$ret->{'mentions'}};
57             @rep = sort @rep;
58             return \@rep;
59             }
60              
61             1;
62             __END__