query-10d5258d94f0f5c3cfba0eff586623df
Optimization needed for artist dupe detection (and improve matching in other ways), now it's between 20 and 65 seconds, but then it times out.)(Q1028181)painter instead of just (Q3391743)visual artist and I'd like to use a version of it that checks subclasses of here(It's from Do you have any advice to speed up the following query?
Use at
- https://query.wikidata.org/sparql
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT DISTINCT ?itemName ?item ?dob1 ?dod1 ?item2 ?dob2 ?dod2 ?dobdiff ?doddiff ?meandiff WHERE {
?item (wdt:P106/wdt:P279*) wd:Q1028181. # painter or any subclass thereof
{ ?item rdfs:label ?itemName. } UNION { ?item skos:altLabel ?itemName. }
FILTER((LANG(?itemName)) = "en")
?item2 (wdt:P106/wdt:P279*) wd:Q1028181.
{ ?item2 rdfs:label ?itemName. } UNION { ?item2 skos:altLabel ?itemName. }
FILTER((STR(?item)) < (STR(?item2)))
MINUS { ?item wdt:P1889 ?item2. } # different from
MINUS { ?item2 wdt:P1889 ?item. }
MINUS { ?item wdt:P460 ?item2. } # said to be the same as
MINUS { ?item2 wdt:P460 ?item. }
MINUS { ?item wdt:P3373 ?item2. } # sibling
MINUS { ?item2 wdt:P3373 ?item. }
OPTIONAL { ?item wdt:P569 ?dob1. }
OPTIONAL { ?item2 wdt:P569 ?dob2. }
BIND((CEIL(ABS((?dob1 - ?dob2) / 3.652425))) / 100 AS ?dobdiff)
OPTIONAL { ?item wdt:P570 ?dod1. }
OPTIONAL { ?item2 wdt:P570 ?dod2. }
BIND((CEIL(ABS((?dod1 - ?dod2) / 3.652425))) / 100 AS ?doddiff)
BIND(BOUND(?dobdiff) AS ?dobdiffbound)
BIND(BOUND(?doddiff) AS ?doddiffbound)
BIND(IF(BOUND(?dobdiff), ?dobdiff, 0) AS ?dobdiffsafe)
BIND(IF(BOUND(?doddiff), ?doddiff, 0) AS ?doddiffsafe)
BIND((CEIL((?dobdiffsafe + ?doddiffsafe) / (xsd:integer(?dobdiffbound) + xsd:integer(?doddiffbound)) * 100) / 100) AS ?meandiff)
}
ORDER BY (!(?dobdiffbound) && !(?doddiffbound)) ?meandiff ?dobdiffbound ?dobdiff ?doddiffbound ?doddiff ?item
LIMIT 500
Query found at
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v9("?dob1"):::projected
v10("?dob2"):::projected
v11("?dobdiff"):::projected
v13("?dobdiffbound")
v13("?dobdiffsafe")
v11("?dod1"):::projected
v12("?dod2"):::projected
v13("?doddiff"):::projected
v13("?doddiffbound")
v14("?doddiffsafe")
v6("?item"):::projected
v7("?item2"):::projected
v8("?itemName"):::projected
v15("?meandiff"):::projected
a1((" "))
a2((" "))
c4(["wd:Q1028181"]):::iri
f0[["str(?item) < str(?item2)"]]
f0 --> v6
f0 --> v7
f1[["?itemName = 'en'"]]
f1 --> v8
v6 --"wdt:P106"--> a1
a1 --"wdt:P279"--> c4
subgraph union0[" Union "]
subgraph union0l[" "]
style union0l fill:#abf,stroke-dasharray: 3 3;
v6 --"skos:altLabel"--> v8
end
subgraph union0r[" "]
style union0r fill:#abf,stroke-dasharray: 3 3;
v6 --"rdfs:label"--> v8
end
union0r <== or ==> union0l
end
v7 --"wdt:P106"--> a2
a2 --"wdt:P279"--> c4
subgraph union1[" Union "]
subgraph union1l[" "]
style union1l fill:#abf,stroke-dasharray: 3 3;
v7 --"skos:altLabel"--> v8
end
subgraph union1r[" "]
style union1r fill:#abf,stroke-dasharray: 3 3;
v7 --"rdfs:label"--> v8
end
union1r <== or ==> union1l
end
subgraph minus2["MINUS"]
style minus2 stroke-width:6px,fill:pink,stroke:red;
v6 --"wdt:P1889"--> v7
end
subgraph minus3["MINUS"]
style minus3 stroke-width:6px,fill:pink,stroke:red;
v7 --"wdt:P1889"--> v6
end
subgraph minus4["MINUS"]
style minus4 stroke-width:6px,fill:pink,stroke:red;
v6 --"wdt:P460"--> v7
end
subgraph minus5["MINUS"]
style minus5 stroke-width:6px,fill:pink,stroke:red;
v7 --"wdt:P460"--> v6
end
subgraph minus6["MINUS"]
style minus6 stroke-width:6px,fill:pink,stroke:red;
v6 --"wdt:P3373"--> v7
end
subgraph minus7["MINUS"]
style minus7 stroke-width:6px,fill:pink,stroke:red;
v7 --"wdt:P3373"--> v6
end
subgraph optional0["(optional)"]
style optional0 fill:#bbf,stroke-dasharray: 5 5;
v6 -."wdt:P569".-> v9
end
subgraph optional1["(optional)"]
style optional1 fill:#bbf,stroke-dasharray: 5 5;
v7 -."wdt:P569".-> v10
end
bind8[/"numeric-ceil(numeric-abs(?dob1 - ?dob2 / '3.652425^^xsd:decimal')) / '100^^xsd:integer'"/]
v9 --o bind8
v10 --o bind8
bind8 --as--o v11
subgraph optional2["(optional)"]
style optional2 fill:#bbf,stroke-dasharray: 5 5;
v6 -."wdt:P570".-> v11
end
subgraph optional3["(optional)"]
style optional3 fill:#bbf,stroke-dasharray: 5 5;
v7 -."wdt:P570".-> v12
end
bind9[/"numeric-ceil(numeric-abs(?dod1 - ?dod2 / '3.652425^^xsd:decimal')) / '100^^xsd:integer'"/]
v11 --o bind9
v12 --o bind9
bind9 --as--o v13
bind10[/"bound(?dobdiff)"/]
v11 --o bind10
bind10 --as--o v13
bind11[/"bound(?doddiff)"/]
v13 --o bind11
bind11 --as--o v13
bind12[/"if(bound(?dobdiff),?dobdiff,'0^^xsd:integer')"/]
v11 --o bind12
bind12 --as--o v13
bind13[/"if(bound(?doddiff),?doddiff,'0^^xsd:integer')"/]
v13 --o bind13
bind13 --as--o v14
bind14[/"numeric-ceil(?dobdiffsafe + ?doddiffsafe / http://www.w3.org/2001/XMLSchema#integer(?dobdiffbound) + http://www.w3.org/2001/XMLSchema#integer(?doddiffbound) * '100^^xsd:integer') / '100^^xsd:integer'"/]
v13 --o bind14
v14 --o bind14
v13 --o bind14
v13 --o bind14
bind14 --as--o v15