WQS::SPARQL - Simple SPARQL query for Wikidata Query Service.
use WQS::SPARQL; my $obj = WQS::SPARQL->new; my $ret_hr = $obj->query($sparql); my $count = $obj->query_count($sparql_count);
new
my $obj = WQS::SPARQL->new;
Constructor.
Returns instance of class.
query
my $ret_hr = $obj->query($sparql);
Do SPARQL query and returns result.
Returns reference to hash with result.
query_count
my $count = $obj->query_count($sparql_count);
Get count value for $sparql_count SPARQL query.
$sparql_count
Returns number.
new(): From Class::Utils::set_params(): Unknown parameter '%s'. Parameter 'lwp_user_agent' must be a 'LWP::UserAgent' instance.
use strict; use warnings; use Data::Printer; use WQS::SPARQL; use WQS::SPARQL::Query::Count; if (@ARGV < 1) { print STDERR "Usage: $0 ccnb\n"; exit 1; } my $ccnb = $ARGV[0]; my $q = WQS::SPARQL->new; my $sparql = WQS::SPARQL::Query::Count->new->count_simple('P3184', $ccnb); my $ret_hr = $q->query($sparql); # Dump structure to output. p $ret_hr; # Output for cnb002826100: # \ { # head { # vars [ # [0] "count" # ] # }, # results { # bindings [ # [0] { # count { # datatype "http://www.w3.org/2001/XMLSchema#integer", # type "literal", # value 1 # } # } # ] # } # }
use strict; use warnings; use WQS::SPARQL; use WQS::SPARQL::Query::Count; if (@ARGV < 1) { print STDERR "Usage: $0 ccnb\n"; exit 1; } my $ccnb = $ARGV[0]; my $q = WQS::SPARQL->new; my $sparql = WQS::SPARQL::Query::Count->new->count_simple('P3184', $ccnb); my $ret = $q->query_count($sparql); # Print count. print "Count: $ret\n"; # Output for 'cnb002826100': # Count: 1 # Output for 'bad': # Count: 0
Class::Utils, Error::Pure. HTTP::Request, JSON::XS, LWP::UserAgent, URI, URI::QueryParam.
Usefull Wikdata Query Service SPARQL queries.
https://github.com/michal-josef-spacek/WQS-SPARQL
Michal Josef Špaček mailto:skim@cpan.org
http://skim.cz
© Michal Josef Špaček 2020-2023
BSD 2-Clause License
0.01
To install WQS::SPARQL, copy and paste the appropriate command in to your terminal.
cpanm
cpanm WQS::SPARQL
CPAN shell
perl -MCPAN -e shell install WQS::SPARQL
For more information on module installation, please visit the detailed CPAN module installation guide.