Skip to content

Instantly share code, notes, and snippets.

@JJ JJ/is-product.p6
Created Dec 2, 2017

Embed
What would you like to do?
Check whether an item in a list is a product
use v6;
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
You can’t perform that action at this time.