A set of SPARQL examples
Author's topic of expertise.
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX bd: <http://www.bigdata.com/rdf#>
PREFIX hint: <http://www.bigdata.com/queryHints#>
#defaultView:BubbleChart
PREFIX target: <http://www.wikidata.org/entity/Q97455964>
SELECT ?score ?topic ?topicLabel WHERE {
{
SELECT (SUM(?score_) AS ?score) ?topic WHERE {
{ SELECT (64 AS ?score_) ?topic WHERE { target: wdt:P101 ?topic. } }
UNION
{ SELECT (32 AS ?score_) ?topic WHERE { target: (wdt:P101/wdt:P279) ?topic. } }
UNION
{ SELECT (16 AS ?score_) ?topic WHERE { target: (wdt:P101/wdt:P279/wdt:P279) ?topic. } }
UNION
{
SERVICE <https://query-scholarly.wikidata.org/sparql> {
SELECT (32 AS ?score_) ?topic WHERE {
?work wdt:P50 target:;
wdt:P921 ?topic.
}
}
}
UNION
{
SERVICE <https://query-scholarly.wikidata.org/sparql> {
SELECT (16 AS ?score_) ?topic WHERE {
?work wdt:P50 target:;
(wdt:P921/wdt:P279) ?topic.
}
}
}
UNION
{
SERVICE <https://query-scholarly.wikidata.org/sparql> {
SELECT (8 AS ?score_) ?topic WHERE {
?work wdt:P50 target:;
(wdt:P921/wdt:P279/wdt:P279) ?topic.
}
}
}
UNION
{
SERVICE <https://query-scholarly.wikidata.org/sparql> {
SELECT (16 AS ?score_) ?topic WHERE {
?work wdt:P50 target:;
wdt:P4510 ?topic.
}
}
}
UNION
{
SERVICE <https://query-scholarly.wikidata.org/sparql> {
SELECT (8 AS ?score_) ?topic WHERE {
?work wdt:P50 target:;
(wdt:P4510/wdt:P279) ?topic.
}
}
}
UNION
{
SERVICE <https://query-scholarly.wikidata.org/sparql> {
SELECT (4 AS ?score_) ?topic WHERE {
?work wdt:P50 target:;
(wdt:P4510/wdt:P279/wdt:P279) ?topic.
}
}
}
UNION
{
SELECT (32 AS ?score_) ?topic WHERE {
?work wdt:P50 target:;
wdt:P921 ?topic.
}
}
UNION
{
SELECT (16 AS ?score_) ?topic WHERE {
?work wdt:P50 target:;
(wdt:P921/wdt:P279) ?topic.
}
}
UNION
{
SELECT (8 AS ?score_) ?topic WHERE {
?work wdt:P50 target:;
(wdt:P921/wdt:P279/wdt:P279) ?topic.
}
}
UNION
{
SELECT (16 AS ?score_) ?topic WHERE {
?work wdt:P50 target:;
wdt:P4510 ?topic.
}
}
UNION
{
SELECT (8 AS ?score_) ?topic WHERE {
?work wdt:P50 target:;
(wdt:P4510/wdt:P279) ?topic.
}
}
UNION
{
SELECT (4 AS ?score_) ?topic WHERE {
?work wdt:P50 target:;
(wdt:P4510/wdt:P279/wdt:P279) ?topic.
}
}
}
GROUP BY ?topic
}
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],mul,en". }
}
ORDER BY DESC (?score)
LIMIT 36
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v5("?score"):::projected
v5("?score_")
v2("?topic"):::projected
v4("?work")
a1((" "))
a2((" "))
a3((" "))
a4((" "))
a5((" "))
a6((" "))
a7((" "))
a8((" "))
a9((" "))
a10((" "))
a11((" "))
a12((" "))
a13((" "))
a14((" "))
a15((" "))
c9([http://www.bigdata.com/rdf#serviceParam]):::iri
c1([http://www.wikidata.org/entity/Q97455964]):::iri
c11(["#91;AUTO_LANGUAGE#93;,mul,en"]):::literal
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;
subgraph union3[" Union "]
subgraph union3l[" "]
style union3l fill:#abf,stroke-dasharray: 3 3;
subgraph union4[" Union "]
subgraph union4l[" "]
style union4l fill:#abf,stroke-dasharray: 3 3;
subgraph union5[" Union "]
subgraph union5l[" "]
style union5l fill:#abf,stroke-dasharray: 3 3;
subgraph union6[" Union "]
subgraph union6l[" "]
style union6l fill:#abf,stroke-dasharray: 3 3;
subgraph union7[" Union "]
subgraph union7l[" "]
style union7l fill:#abf,stroke-dasharray: 3 3;
subgraph union8[" Union "]
subgraph union8l[" "]
style union8l fill:#abf,stroke-dasharray: 3 3;
subgraph union9[" Union "]
subgraph union9l[" "]
style union9l fill:#abf,stroke-dasharray: 3 3;
subgraph union10[" Union "]
subgraph union10l[" "]
style union10l fill:#abf,stroke-dasharray: 3 3;
subgraph union11[" Union "]
subgraph union11l[" "]
style union11l fill:#abf,stroke-dasharray: 3 3;
subgraph union12[" Union "]
subgraph union12l[" "]
style union12l fill:#abf,stroke-dasharray: 3 3;
subgraph union13[" Union "]
subgraph union13l[" "]
style union13l fill:#abf,stroke-dasharray: 3 3;
v4 --"wdt:P50"--> c1
v4 --"wdt:P4510"--> a14
a14 --"wdt:P279"--> a15
a15 --"wdt:P279"--> v2
bind0[/"'4^^xsd:integer'"/]
bind0 --as--o v5
end
subgraph union13r[" "]
style union13r fill:#abf,stroke-dasharray: 3 3;
v4 --"wdt:P50"--> c1
v4 --"wdt:P4510"--> a13
a13 --"wdt:P279"--> v2
bind1[/"'8^^xsd:integer'"/]
bind1 --as--o v5
end
union13r <== or ==> union13l
end
end
subgraph union12r[" "]
style union12r fill:#abf,stroke-dasharray: 3 3;
v4 --"wdt:P50"--> c1
v4 --"wdt:P4510"--> v2
bind2[/"'16^^xsd:integer'"/]
bind2 --as--o v5
end
union12r <== or ==> union12l
end
end
subgraph union11r[" "]
style union11r fill:#abf,stroke-dasharray: 3 3;
v4 --"wdt:P50"--> c1
v4 --"wdt:P921"--> a11
a11 --"wdt:P279"--> a12
a12 --"wdt:P279"--> v2
bind3[/"'8^^xsd:integer'"/]
bind3 --as--o v5
end
union11r <== or ==> union11l
end
end
subgraph union10r[" "]
style union10r fill:#abf,stroke-dasharray: 3 3;
v4 --"wdt:P50"--> c1
v4 --"wdt:P921"--> a10
a10 --"wdt:P279"--> v2
bind4[/"'16^^xsd:integer'"/]
bind4 --as--o v5
end
union10r <== or ==> union10l
end
end
subgraph union9r[" "]
style union9r fill:#abf,stroke-dasharray: 3 3;
v4 --"wdt:P50"--> c1
v4 --"wdt:P921"--> v2
bind5[/"'32^^xsd:integer'"/]
bind5 --as--o v5
end
union9r <== or ==> union9l
end
end
subgraph union8r[" "]
style union8r fill:#abf,stroke-dasharray: 3 3;
subgraph s1["https://query-scholarly.wikidata.org/sparql"]
style s1 stroke-width:4px;
v4 --"wdt:P50"--> c1
v4 --"wdt:P4510"--> a8
a8 --"wdt:P279"--> a9
a9 --"wdt:P279"--> v2
bind6[/"'4^^xsd:integer'"/]
bind6 --as--o v5
end
end
union8r <== or ==> union8l
end
end
subgraph union7r[" "]
style union7r fill:#abf,stroke-dasharray: 3 3;
subgraph s1["https://query-scholarly.wikidata.org/sparql"]
style s1 stroke-width:4px;
v4 --"wdt:P50"--> c1
v4 --"wdt:P4510"--> a7
a7 --"wdt:P279"--> v2
bind7[/"'8^^xsd:integer'"/]
bind7 --as--o v5
end
end
union7r <== or ==> union7l
end
end
subgraph union6r[" "]
style union6r fill:#abf,stroke-dasharray: 3 3;
subgraph s1["https://query-scholarly.wikidata.org/sparql"]
style s1 stroke-width:4px;
v4 --"wdt:P50"--> c1
v4 --"wdt:P4510"--> v2
bind8[/"'16^^xsd:integer'"/]
bind8 --as--o v5
end
end
union6r <== or ==> union6l
end
end
subgraph union5r[" "]
style union5r fill:#abf,stroke-dasharray: 3 3;
subgraph s1["https://query-scholarly.wikidata.org/sparql"]
style s1 stroke-width:4px;
v4 --"wdt:P50"--> c1
v4 --"wdt:P921"--> a5
a5 --"wdt:P279"--> a6
a6 --"wdt:P279"--> v2
bind9[/"'8^^xsd:integer'"/]
bind9 --as--o v5
end
end
union5r <== or ==> union5l
end
end
subgraph union4r[" "]
style union4r fill:#abf,stroke-dasharray: 3 3;
subgraph s1["https://query-scholarly.wikidata.org/sparql"]
style s1 stroke-width:4px;
v4 --"wdt:P50"--> c1
v4 --"wdt:P921"--> a4
a4 --"wdt:P279"--> v2
bind10[/"'16^^xsd:integer'"/]
bind10 --as--o v5
end
end
union4r <== or ==> union4l
end
end
subgraph union3r[" "]
style union3r fill:#abf,stroke-dasharray: 3 3;
subgraph s1["https://query-scholarly.wikidata.org/sparql"]
style s1 stroke-width:4px;
v4 --"wdt:P50"--> c1
v4 --"wdt:P921"--> v2
bind11[/"'32^^xsd:integer'"/]
bind11 --as--o v5
end
end
union3r <== or ==> union3l
end
end
subgraph union2r[" "]
style union2r fill:#abf,stroke-dasharray: 3 3;
c1 --"wdt:P101"--> a2
a2 --"wdt:P279"--> a3
a3 --"wdt:P279"--> v2
bind12[/"'16^^xsd:integer'"/]
bind12 --as--o v5
end
union2r <== or ==> union2l
end
end
subgraph union1r[" "]
style union1r fill:#abf,stroke-dasharray: 3 3;
c1 --"wdt:P101"--> a1
a1 --"wdt:P279"--> v2
bind13[/"'32^^xsd:integer'"/]
bind13 --as--o v5
end
union1r <== or ==> union1l
end
end
subgraph union0r[" "]
style union0r fill:#abf,stroke-dasharray: 3 3;
c1 --"wdt:P101"--> v2
bind14[/"'64^^xsd:integer'"/]
bind14 --as--o v5
end
union0r <== or ==> union0l
end
bind16[/"sum(?score_)"/]
v5 --o bind16
bind16 --as--o v5
subgraph s2["http://wikiba.se/ontology#label"]
style s2 stroke-width:4px;
c9 --"wikibase:language"--> c11
end