Skip to content

Instantly share code, notes, and snippets.

@JJ
Last active November 23, 2022 10:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JJ/8c199136c0c2006b26efd749ab3fc522 to your computer and use it in GitHub Desktop.
Save JJ/8c199136c0c2006b26efd749ab3fc522 to your computer and use it in GitHub Desktop.
Check whether an item in a list is a product
use JSON::Tiny;
use Wikidata::API;
sub MAIN( Str $toy-list = 'list.json' ) {
my $toys = from-json $toy-list.IO.slurp();
say $toys.grep( { is-product( $^þ) } );
}
sub is-product( Str $item ) {
my $query = q:to/END/;
SELECT DISTINCT ?item ?itemLabel WHERE {
?item (wdt:P31/wdt:P279*) wd:Q2424752.
?item rdfs:label ?itemLabel.
FILTER(CONTAINS(LCASE(?itemLabel),
END
$query ~= '"' ~ $item ~ '"))}';
my $result = query( $query );
return so $result<results><bindings>.elems;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment