Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add wikidata link #165

Open
matyaskopp opened this issue Jul 6, 2022 · 2 comments
Open

Add wikidata link #165

matyaskopp opened this issue Jul 6, 2022 · 2 comments
Labels
enhancement New feature or request

Comments

@matyaskopp matyaskopp added the enhancement New feature or request label Jul 6, 2022
@matyaskopp
Copy link
Member Author

use LWP::UserAgent;
use Data::Dumper;
use JSON::XS;

sub wdSparqlQuery(@args) {
  my $agent = shift;
  my $query = shift;
  my $format = shift;
  my $endpointURL = "https://query.wikidata.org/sparql";
  my $queryURL = "${endpointURL}?query=${query}&format=${format}";
  my $ua = LWP::UserAgent -> new;
  $ua -> agent($agent);
  my $req = HTTP::Request -> new(GET => $queryURL);
  my $res = $ua -> request($req);
  my $str = $res -> content;
  return $str;
}

$agent = "WDQS-example "; # TODO adjust this; see https://w.wiki/CX6
$query = <<'_SPARQL_QUERY_';
SELECT ?person ?personLabel ?birth where {
  ?person wdt:P31 wd:Q5;
          wdt:P569 ?birth.
  FILTER (?birth = "1944-09-28T00:00:00Z"^^xsd:dateTime )
  ?person  ?label "Miloš Zeman".
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],cs,en". }
}
_SPARQL_QUERY_
$format = "json";
$data = JSON::XS::decode_json(wdSparqlQuery($agent, $query, $format));

print "Retrieved data:\n";
print Dumper($data);

@matyaskopp
Copy link
Member Author

matyaskopp commented Oct 4, 2022

members of Chamber of Deputies

SELECT ?person ?personLabel ?birth where {
  ?person wdt:P31 wd:Q5;
          wdt:P569 ?birth;
          wdt:P39 wd:Q19803234.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],cs,en". }
}

government members:

SELECT ?person ?personLabel ?birth ?ministerLabel where {
  ?person wdt:P31 wd:Q5;
          wdt:P569 ?birth;
          wdt:P39 ?minister.
  ?minister wdt:P31 wd:Q4164871;
            wdt:P361 wd:Q5015587.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],cs,en". }
}

members of Senate:

SELECT ?person ?personLabel ?birth where {
  ?person wdt:P31 wd:Q5;
          wdt:P569 ?birth;
          wdt:P39 wd:Q18941264.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],cs,en". }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant