query-6e7274b8fb324fb3e521f700f6bf98c5
Propertiesgenre (P136)instance of (P31)publication date (P577)
Use at
- https://query.wikidata.org/sparql
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wdno: <http://www.wikidata.org/prop/novalue/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX ps: <http://www.wikidata.org/prop/statement/>
PREFIX p: <http://www.wikidata.org/prop/>
SELECT
#(MIN(?dateYear) AS ?dateYears)
(GROUP_CONCAT(DISTINCT ?dateYear ; separator = ", ") AS ?dateYears)
(GROUP_CONCAT(DISTINCT ?gameENLabel ; separator = ", ") AS ?gameENLabels)
WHERE {
# test values
VALUES ?game {
wd:Q4850488 # Baldur's Gate III: The Black Hound (should have "no value" due to being cancelled)
wd:Q4931588 # Bob's Game (should have "no value" due to not being released yet)
wd:Q5315330 # Dunjonquest (1979)
wd:Q5250229 # Deep Labyrinth (should have multiple dates)
wd:Q1462499 # Starflight (1986, has multiple genres)
wd:Q23647080 # God Wars: Beyond Time (should have blank date since the property does not exist)
}
{?game wdt:P136 wd:Q744038} # regular RPGs
UNION {?game wdt:P136 wd:Q1529437} # tactical RPGs
UNION {?game wdt:P136 wd:Q1422746} # action RPGs
UNION {?game wdt:P136 wd:Q1143132} # roguelikes
?game wdt:P31 wd:Q7889. # instance of video game
?game rdfs:label ?gameENLabel.
FILTER(LANG(?gameENLabel) = "en"). # we mainly want English labels
?game p:P577 ?statementNode.
OPTIONAL {?statementNode ps:P577 ?date}
OPTIONAL {?statementNode rdf:type ?statementNodeType FILTER (?statementNodeType IN (wdno:P577))}
BIND(COALESCE(DATATYPE(?date) = xsd:dateTime , false) as ?check1). # real date?
BIND(COALESCE((wdno:P577 = ?statementNodeType), false) as ?check2). # no value?
BIND(COALESCE(isBlank(?date) , false) as ?check3). # unknown?
BIND(IF(?check1, YEAR(?date), IF(?check2, "no value", IF(?check3, "unknown", "error"))) as ?dateYear).
# OPTIONAL {?game wdt:P577 ?date}
# ?game <http://www.wikidata.org/prop/P577> ?whaat.
# OPTIONAL {?whaat rdf:type ?typeOfStatementNode}
# BIND(IF(isBlank(?whaat), "unknown value", IF(?typeOfStatementNode = IRI("http://www.wikidata.org/prop/novalue/P577"), "no value", YEAR(?date))) as ?dateYear).
# BIND(YEAR(?date) AS ?dateYear). # faster substitute
}
GROUP BY $game
ORDER BY asc (?dateYears) ASC (?gameENLabels)
#limit 100
Query found at
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v8("?check1")
v9("?check2")
v10("?check3")
v7("?date")
v11("?dateYear"):::projected
v12("?dateYears")
v5("?game")
v4("?gameENLabel"):::projected
v12("?gameENLabels")
v6("?statementNode")
v3("?statementNodeType")
c4(["wd:Q744038"]):::iri
c6(["wd:Q1422746"]):::iri
c5(["wd:Q1529437"]):::iri
c9(["wd:Q7889"]):::iri
c7(["wd:Q1143132"]):::iri
f0[["?gameENLabel = 'en'"]]
f0 --> v4
bind1[/VALUES ?game/]
bind1-->v5
bind10(["wd:Q4850488"])
bind10 --> bind1
bind11(["wd:Q4931588"])
bind11 --> bind1
bind12(["wd:Q5315330"])
bind12 --> bind1
bind13(["wd:Q5250229"])
bind13 --> bind1
bind14(["wd:Q1462499"])
bind14 --> bind1
bind15(["wd:Q23647080"])
bind15 --> bind1
subgraph union0[" Union "]
subgraph union0l[" "]
style union0l fill:#abf,stroke-dasharray: 3 3;
subgraph union1[" Union "]
subgraph union1l[" "]
style union1l fill:#abf,stroke-dasharray: 3 3;
subgraph union2[" Union "]
subgraph union2l[" "]
style union2l fill:#abf,stroke-dasharray: 3 3;
v5 --"p:direct/P136"--> c7
end
subgraph union2r[" "]
style union2r fill:#abf,stroke-dasharray: 3 3;
v5 --"p:direct/P136"--> c6
end
union2r <== or ==> union2l
end
end
subgraph union1r[" "]
style union1r fill:#abf,stroke-dasharray: 3 3;
v5 --"p:direct/P136"--> c5
end
union1r <== or ==> union1l
end
end
subgraph union0r[" "]
style union0r fill:#abf,stroke-dasharray: 3 3;
v5 --"p:direct/P136"--> c4
end
union0r <== or ==> union0l
end
v5 --"p:direct/P31"--> c9
v5 --"rdfs:label"--> v4
v5 --"p:P577"--> v6
subgraph optional0["(optional)"]
style optional0 fill:#bbf,stroke-dasharray: 5 5;
v6 -."p:statement/P577".-> v7
end
subgraph optional1["(optional)"]
style optional1 fill:#bbf,stroke-dasharray: 5 5;
v6 -."a".-> v3
end
bind2[/"?date = 'xsd:dateTime''false^^xsd:boolean'"/]
v7 --o bind2
bind2 --as--o v8
bind3[/"'p:novalue/P577' = ?statementNodeType'false^^xsd:boolean'"/]
v3 --o bind3
bind3 --as--o v9
bind4[/"isBlank(?date)'false^^xsd:boolean'"/]
v7 --o bind4
bind4 --as--o v10
bind5[/"if(?check1,year-from-dateTime(?date),if(?check2,'no value',if(?check3,'unknown','error')))"/]
v8 --o bind5
v7 --o bind5
v9 --o bind5
v10 --o bind5
bind5 --as--o v11
bind8[/"?dateYear"/]
v11 --o bind8
bind8 --as--o v12
bind9[/"?gameENLabel"/]
v4 --o bind9
bind9 --as--o v12