NAME

WQS::SPARQL::Query::Select - Simple SPARQL select query.

SYNOPSIS

use WQS::SPARQL::Query::Select;

my $obj = WQS::SPARQL::Query::Select->new;
my $sparql = $obj->select_value($property_pairs_hr);

METHODS

new

my $obj = WQS::SPARQL::Query::Select->new;

Constructor.

Returns instance of class.

select_value

my $sparql = $obj->select_value($property_pairs_hr);

Construct SPARQL command and return it. Input is reference to hash with pairs property => value.

Value could be in forms:

  • Q__number__

    QID identifier.

    Example output: Q42

  • __string__@__lang__

    String with language.

    'lang' is 2 character language code.

    Example output: 'string'@en

  • __string__

    String without language.

    Example output: 'string'

Returns string.

ERRORS

new():
        From Class::Utils::set_params():
                Unknown parameter '%s'.

select_value():
        Bad property '%s'.

EXAMPLE

use strict;
use warnings;

use WQS::SPARQL::Query::Select;

my $obj = WQS::SPARQL::Query::Select->new;

my $property = 'P957';
my $isbn = '80-239-7791-1';
my $sparql = $obj->select_value({$property => $isbn});

print "Property: $property\n";
print "ISBN: $isbn\n";
print "SPARQL:\n";
print $sparql;

# Output:
# Property: P957
# ISBN: 80-239-7791-1
# SPARQL:
# SELECT ?item WHERE {
#   ?item wdt:P957 '80-239-7791-1'.
# }

DEPENDENCIES

Class::Utils, Error::Pure.

SEE ALSO

WQS::SPARQL::Query

Useful Wikdata Query Service SPARQL queries.

WQS::SPARQL::Query::Count

Simple SPARQL count query.

REPOSITORY

https://github.com/michal-josef-spacek/WQS-SPARQL-Query

AUTHOR

Michal Josef Špaček mailto:skim@cpan.org

http://skim.cz

LICENSE AND COPYRIGHT

© 2020-2024 Michal Josef Špaček

BSD 2-Clause License

VERSION

0.03