query-7c4f0677fb3cbc5d4a8a8cf5f303ea27
Josh404Bot 3) logs • contribs • talk (Josh404 Operator: )xtools • User rights • User rights log • Block log • SUL • new lexemes • new items • contribs • talk (Josh404Bot Task/s: via the TMDb API. (P4835)TheTVDB series ID or (P345)IMDb ID that have an associated (P4983)TMDB TV series ID Fill missing Code: https://github.com/josh/wikidatabots/compare/d2dec28...4cd7cea
Use at
- https://query.wikidata.org/sparql
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
SELECT ?item ?imdb ?tvdb ?random WHERE {
# Items with either IMDb or TVDB IDs
{ ?item wdt:P4835 []. }
UNION
{ ?item wdt:P345 []. }
# P4983's type constraint
VALUES ?classes {
wd:Q15416
}
?item (wdt:P31/(wdt:P279*)) ?classes.
# Get IMDb and TVDB IDs
OPTIONAL { ?item wdt:P345 ?imdb. }
OPTIONAL { ?item wdt:P4835 ?tvdb. }
# Exclude items that already have a TMDB TV ID
OPTIONAL { ?item wdt:P4985 ?tmdb. }
FILTER(!(BOUND(?tmdb)))
# Generate random sorting key
BIND(MD5(CONCAT(STR(?item), STR(RAND()))) AS ?random)
}
ORDER BY ?random
LIMIT 1000
Query found at
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v4("?classes")
v5("?imdb"):::projected
v3("?item"):::projected
v7("?random"):::projected
v2("?tmdb")
v6("?tvdb"):::projected
a1((" "))
a2((" "))
a3((" "))
f0[["not bound(?tmdb)"]]
f0 --> v2
subgraph union0[" Union "]
subgraph union0l[" "]
style union0l fill:#abf,stroke-dasharray: 3 3;
v3 --"wdt:P345"--> a2
end
subgraph union0r[" "]
style union0r fill:#abf,stroke-dasharray: 3 3;
v3 --"wdt:P4835"--> a1
end
union0r <== or ==> union0l
end
bind1[/VALUES ?classes/]
bind1-->v4
bind10(["wd:Q15416"])
bind10 --> bind1
v3 --"wdt:P31"--> a3
a3 --"wdt:P279"--> v4
subgraph optional0["(optional)"]
style optional0 fill:#bbf,stroke-dasharray: 5 5;
v3 -."wdt:P345".-> v5
end
subgraph optional1["(optional)"]
style optional1 fill:#bbf,stroke-dasharray: 5 5;
v3 -."wdt:P4835".-> v6
end
subgraph optional2["(optional)"]
style optional2 fill:#bbf,stroke-dasharray: 5 5;
v3 -."wdt:P4985".-> v2
end
bind2[/"MD5(concat(str(?item),str(RAND())))"/]
v3 --o bind2
bind2 --as--o v7