App-wdq

 view release on metacpan or  search on metacpan

script/wdq  view on Meta::CPAN

        }
    };

    my $limit = $OPT{limit} // 0;
    if (@ARGV) {
        foreach (@ARGV) {
            $lookup->($_);
            last if !--$limit;
        }
    }
    else {
        while (<>) {
            $lookup->($_);
            last if !--$limit;
        }
    }

    $output->end() if $output;

    exit;
}

# search mode
elsif ( $MODE =~ /^p?search$/ ) {
    $query     = join ' ', @ARGV;
    $variables = [qw(id label alias description)];
    $iterator  = perform_search($query);
}

unless ( $OPT{ignore} || $iterator->peek ) {
    warning( $query ? "not found: $query" : "not found" );
    exit 1;
}

# postprocess results
unshift( @$variables, 'n' ) if $OPT{enumerate} and $variables;
$iterator = postprocess_iterator($iterator);

# emit results
{
    my $vars = $variables // sort keys %{ $iterator->peek };
    my $output = $format->start( $vars, \*STDOUT );
    my $n = 0;
    while ( my $row = $iterator->next ) {
        last if $OPT{limit} and $n++ >= $OPT{limit};
        $output->add($row);
    }
    $output->end;
}

__END__

=head1 NAME

wdq - command line access to Wikidata Query Service

=begin markdown

# STATUS

[![Build Status](https://travis-ci.org/nichtich/wdq.png)](https://travis-ci.org/nichtich/wdq)
[![Coverage Status](https://coveralls.io/repos/nichtich/App-wdq/badge.png)](https://coveralls.io/r/nichtich/App-wdq)
[![Kwalitee Score](http://cpants.cpanauthors.org/dist/App-wdq.png)](http://cpants.cpanauthors.org/dist/App-wdq)

=end markdown

=head1 SYNOPSIS

Access L<Wikidata Query Service|https://query.wikidata.org/> via command line
to perform SPARQL queries (C<query> mode), lookup entities (C<lookup>), or
search items and properties (C<search> or C<psearch>):

  wdq -g en solar system        # search 'solar system' in English
  wdq psearch -g es parte       # search property 'parte' in Spanish
  wdq P361 Q544                 # lookup properties and items
  wdq '?c wdt:P361 wd:Q544'     # query parts of the solar system

See the manual for details or get help via C<wdq help>:

  wdq help options              # list and explain command line options
  wdq help modes                # list and explain request modes
  wdq help output               # explain output control
  wdq help formats              # list and explain output formats
  wdq help ontology             # show Wikidata ontology in a nutshell
  wdq help prefixes             # list RDF prefixes allowed in queries
  wdq help version              # show version of wdq

=head1 DESCRIPTION

The command line script C<wdq>, included in CPAN module L<App::wdq>, provides a
tool to access L<Wikidata Query Service|https://query.wikidata.org/>. It
supports formulation and execution of L<SPARQL SELECT
queries|http://www.w3.org/TR/sparql11-query/#select> to extract selected
information from Wikidata or other Wikibase instances.

=head1 INSTALLATION

Perl should already installed at most operating systems. Otherwise
L<get Perl!|https://www.perl.org/get.html>

=head2 FROM CPAN

Install sources from CPAN including all dependencies:

  cpanm App::wdq

First L<install cpanm|https://github.com/miyagawa/cpanminus/#installation> if
missing. If installation of C<App::wdq> fails try cpanm option C<--notest> or
install dependencies as packages as described below.

=head2 PREBUILD PACKAGES

Install dependencies as prebuild packages for your operating system:

  # Debian based systems e.g. Ubuntu (>= 14.04)
  sudo apt-get install libhttp-tiny-perl librdf-query-perl

  # Windows/ActiveState
  ppm install HTTP-Tiny
  ppm install RDF-Query

Then install C<wdq> from CPAN as described above or copy the script to some
place in your C<$PATH>:



( run in 1.681 second using v1.01-cache-2.11-cpan-df04353d9ac )