|
| 1 | +{% import 'sparql-helpers.sparql' as sparql_helpers -%} |
| 2 | + |
1 | 3 | #defaultView:Graph |
2 | 4 | PREFIX target: <http://www.wikidata.org/entity/{{ q }}> |
3 | 5 | PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> |
4 | 6 | PREFIX wdt: <http://www.wikidata.org/prop/direct/> |
5 | | -SELECT ?child ?childLabel ?rgb ?parent ?parentLabel WHERE { |
| 7 | +SELECT (?child_ AS ?child) ?childLabel ?rgb (?parent_ AS ?parent) ?parentLabel WHERE { |
6 | 8 | { |
7 | | - SELECT ?child ?rgb ?parent WHERE { |
8 | | - { |
9 | | - # Parent taxa |
10 | | - SELECT ?child ?rgb ?parent WHERE { |
11 | | - SERVICE gas:service { |
12 | | - gas:program gas:gasClass "com.bigdata.rdf.graph.analytics.BFS" ; |
13 | | - gas:in target: ; |
14 | | - # We should not do undirected here because this could result |
15 | | - # in very big graphs. |
16 | | - gas:traversalDirection "Forward" ; |
17 | | - gas:out ?child ; |
18 | | - gas:out1 ?depth ; |
19 | | - gas:out2 ?parent1 ; |
20 | | - gas:linkType wdt:P171 ; |
21 | | - } |
22 | | - ?child wdt:P171 ?parent . |
23 | | - BIND (IF(?child = target:,"FF0000","FFFFFF") AS ?rgb) |
24 | | - } |
25 | | - } |
26 | | - UNION { |
27 | | - # Child taxa |
28 | | - SELECT ?child ?rgb ?parent WHERE { |
29 | | - BIND (target: AS ?parent) |
30 | | - ?child wdt:P171 ?parent . |
31 | | - BIND ("DDDDDD" AS ?rgb) |
32 | | - } |
33 | | - LIMIT 100 |
34 | | - } |
35 | | - } |
| 9 | + # Parent taxa |
| 10 | + target: wdt:P171* ?child_ . |
| 11 | + ?child_ wdt:P171 ?parent_ . |
| 12 | + BIND ("FFFFFF" AS ?rgb) |
| 13 | + } UNION { |
| 14 | + # Child taxa |
| 15 | + {SELECT ?child_ ?parent_ WHERE { |
| 16 | + BIND (target: AS ?parent_) . |
| 17 | + ?child_ wdt:P171 ?parent_ . |
| 18 | + } LIMIT 100} |
| 19 | + BIND ("DDDDDD" AS ?rgb) |
| 20 | + } UNION { |
| 21 | + BIND (target: AS ?child_) . |
| 22 | + ?child_ wdt:P171 ?parent_ . |
| 23 | + BIND ("FF0000" AS ?rgb) |
36 | 24 | } |
37 | | - ?child rdfs:label ?child_label . FILTER (LANG(?child_label) = 'en') |
38 | | - ?parent rdfs:label ?parent_label . FILTER (LANG(?parent_label) = 'en') |
| 25 | + |
39 | 26 | OPTIONAL { |
40 | | - ?child wdt:P105/rdfs:label ?child_rank_label . FILTER (LANG(?child_rank_label) = 'en') |
| 27 | + ?child_ wdt:P105 ?child_rank_ . |
| 28 | + {{ sparql_helpers.labels(["?child_rank_"], languages) }} |
41 | 29 | } |
42 | 30 | OPTIONAL { |
43 | | - ?parent wdt:P105/rdfs:label ?parent_rank_label . FILTER (LANG(?parent_rank_label) = 'en') |
| 31 | + ?parent_ wdt:P105 ?parent_rank_ . |
| 32 | + {{ sparql_helpers.labels(["?parent_rank_"], languages) }} |
44 | 33 | } |
45 | | - BIND (CONCAT(?child_label, " - ", COALESCE(?child_rank_label, "???")) AS ?childLabel) |
46 | | - BIND (CONCAT(?parent_label, " - ", COALESCE(?parent_rank_label, "???")) AS ?parentLabel) |
| 34 | + {{ sparql_helpers.labels(["?child_", "?parent_"], languages) }} |
| 35 | + |
| 36 | + BIND (CONCAT(?child_Label, " - ", COALESCE(?child_rank_Label, "???")) AS ?childLabel) |
| 37 | + BIND (CONCAT(?parent_Label, " - ", COALESCE(?parent_rank_Label, "???")) AS ?parentLabel) |
47 | 38 | } |
0 commit comments