sparql-examples

A set of SPARQL examples that are used in different TGX resources

View the Project on GitHub BiGCAT-UM/sparql-examples

106

rq turtle/ttl

Ontology aspect: reuse graph

Use at

PREFIX p: <http://www.wikidata.org/prop/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
#defaultView:Graph
PREFIX target: <http://www.wikidata.org/entity/Q116446479>

SELECT
  ?source ?sourceLabel (CONCAT("../ontology/", ?qs) AS ?sourceUrl)
  ?target ?targetLabel (CONCAT("../ontology/", ?qt) AS ?targetUrl)
WHERE {
  { # Ontologies that are used by the target: ontology
    BIND (target: AS ?source)
    ?source wdt:P2283 ?target .
    BIND(SUBSTR(STR(?source), 32) AS ?qs)
    BIND(SUBSTR(STR(?target), 32) AS ?qt)
    ?source rdfs:label ?source_string .
    FILTER (LANG(?source_string) = 'en')
    BIND(COALESCE(?source_string, ?qt) AS ?sourceLabel)
    ?target rdfs:label ?target_string .
    FILTER (LANG(?target_string) = 'en')
    BIND(COALESCE(?target_string, ?qt) AS ?targetLabel)
  }
  UNION
  { # Ontologies that use the target: ontology
    BIND (target: AS ?target)
    ?source wdt:P2283 ?target .
    BIND(SUBSTR(STR(?source), 32) AS ?qs)
    BIND(SUBSTR(STR(?target), 32) AS ?qt)
    ?source rdfs:label ?source_string .
    FILTER (LANG(?source_string) = 'en')
    BIND(COALESCE(?source_string, ?qt) AS ?sourceLabel)
    ?target rdfs:label ?target_string .
    FILTER (LANG(?target_string) = 'en')
    BIND(COALESCE(?target_string, ?qt) AS ?targetLabel)
  }  
}

graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
  v9("?qs"):::projected 
  v9("?qt"):::projected 
  v3("?source"):::projected 
  v9("?sourceLabel"):::projected 
  v9("?sourceUrl")
  v2("?source_string")
  v9("?target"):::projected 
  v9("?targetLabel"):::projected 
  v10("?targetUrl")
  v1("?target_string")
  subgraph union0[" Union "]
  subgraph union0l[" "]
    style union0l fill:#abf,stroke-dasharray: 3 3;
    f0[["?target_string = 'en'"]]
    f0 --> v1
    f1[["?source_string = 'en'"]]
    f1 --> v2
    bind2[/"http://www.wikidata.org/entity/Q116446479"/]
    bind2 --as--o v9
    v3 --"p:direct/P2283"-->  v9
    bind3[/"substring(str(?source),'32^^xsd:integer')"/]
    v3 --o bind3
    bind3 --as--o v9
    bind4[/"substring(str(?target),'32^^xsd:integer')"/]
    v9 --o bind4
    bind4 --as--o v9
    v3 --"rdfs:label"-->  v2
    bind5[/"?source_string?qt"/]
    v2 --o bind5
    v9 --o bind5
    bind5 --as--o v9
    v9 --"rdfs:label"-->  v1
    bind6[/"?target_string?qt"/]
    v1 --o bind6
    v9 --o bind6
    bind6 --as--o v9
  end
  subgraph union0r[" "]
    style union0r fill:#abf,stroke-dasharray: 3 3;
    f7[["?target_string = 'en'"]]
    f7 --> v1
    f8[["?source_string = 'en'"]]
    f8 --> v2
    bind9[/"http://www.wikidata.org/entity/Q116446479"/]
    bind9 --as--o v3
    v3 --"p:direct/P2283"-->  v9
    bind10[/"substring(str(?source),'32^^xsd:integer')"/]
    v3 --o bind10
    bind10 --as--o v9
    bind11[/"substring(str(?target),'32^^xsd:integer')"/]
    v9 --o bind11
    bind11 --as--o v9
    v3 --"rdfs:label"-->  v2
    bind12[/"?source_string?qt"/]
    v2 --o bind12
    v9 --o bind12
    bind12 --as--o v9
    v9 --"rdfs:label"-->  v1
    bind13[/"?target_string?qt"/]
    v1 --o bind13
    v9 --o bind13
    bind13 --as--o v9
  end
  union0r <== or ==> union0l
  end
  bind14[/"concat('../ontology/',?qs)"/]
  v9 --o bind14
  bind14 --as--o v9
  bind15[/"concat('../ontology/',?qt)"/]
  v9 --o bind15
  bind15 --as--o v10