Last active
November 23, 2022 10:46
-
-
Save JJ/8c199136c0c2006b26efd749ab3fc522 to your computer and use it in GitHub Desktop.
Check whether an item in a list is a product
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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