query-c83171ce1519575d71ade35e1255aabe
Regex variables
Use at
- https://query.wikidata.org/sparql
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX ps: <http://www.wikidata.org/prop/statement/>
PREFIX pq: <http://www.wikidata.org/prop/qualifier/>
PREFIX p: <http://www.wikidata.org/prop/>
SELECT ?item ?id ?name ?first ?second ?birth ?death
WHERE {
?item p:P396 [ ps:P396 ?id ; pq:P1810 ?name ] .
FILTER REGEX(?name, "<(.*\\d+.*)-(.*)")
BIND(REPLACE(?name, "^.*<(.*\\d+.*)-(.*)>$", "$1") AS ?first)
BIND(REPLACE(?name, "^.*<(.*\\d+.*)-(.*)>$", "$2") AS ?second)
OPTIONAL { ?item wdt:P569 ?born } . BIND(YEAR(?born) AS ?birth)
OPTIONAL { ?item wdt:P570 ?died } . BIND(YEAR(?died) AS ?death)
FILTER(STR(?first) != STR(?birth))
}
ORDER BY ?birth
Query found at
- https://www.wikidata.org/wiki/User:Ep%C3%ACdosis/Queries
- https://www.wikidata.org/wiki/User:Ep%C3%ACdosis/sandbox
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v8("?birth"):::projected
v7("?born")
v9("?death"):::projected
v8("?died")
v6("?first"):::projected
v4("?id"):::projected
v5("?item"):::projected
v3("?name"):::projected
v6("?second"):::projected
a1((" "))
f0[["str(?first) != str(?birth)"]]
f0 --> v6
f0 --> v8
f1[["regex(?name,'<(.*\d+.*)-(.*)')"]]
f1 --> v3
a1 --"p:statement/P396"--> v4
a1 --"p:qualifier/P1810"--> v3
v5 --"p:P396"--> a1
bind2[/"replace(?name,'^.*<(.*\d+.*)-(.*)>$','$1')"/]
v3 --o bind2
bind2 --as--o v6
bind3[/"replace(?name,'^.*<(.*\d+.*)-(.*)>$','$2')"/]
v3 --o bind3
bind3 --as--o v6
subgraph optional0["(optional)"]
style optional0 fill:#bbf,stroke-dasharray: 5 5;
v5 -."p:direct/P569".-> v7
end
bind4[/"year-from-dateTime(?born)"/]
v7 --o bind4
bind4 --as--o v8
subgraph optional1["(optional)"]
style optional1 fill:#bbf,stroke-dasharray: 5 5;
v5 -."p:direct/P570".-> v8
end
bind5[/"year-from-dateTime(?died)"/]
v8 --o bind5
bind5 --as--o v9