SPARQL examples: Difference between revisions

(add central topics)
m (→‎Simple Queries: fix wrong property)
 
(11 intermediate revisions by the same user not shown)
Line 1: Line 1:
This page is automatically parsed by the query page to provide examples.
This page is automatically parsed by the query page to provide examples.


== Simple Queries ==
== Simple Queries ==
=== Complete Dependency Graph ===
=== Complete Dependency Graph ===
{{#widget:SPARQLquery|code=
{{SPARQL2|query=
#defaultView:Graph
#defaultView:Graph
PREFIX wdt: <https://graphit.ur.de/prop/direct/>
PREFIX wdt: <https://graphit.ur.de/prop/direct/>
Line 9: Line 10:
   ?item wdt:P1 ?dependency.
   ?item wdt:P1 ?dependency.
   ?item wdt:P2 ?class
   ?item wdt:P2 ?class
   OPTIONAL{ ?item wdt:P9 ?image.}
   OPTIONAL{ ?item wdt:P11 ?image.}
   OPTIONAL{ ?class wdt:P9 ?image.}
   OPTIONAL{ ?class wdt:P11 ?image.}
   SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
   SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
}
}}
}}
=== All topics in the CGBV course ===
=== Educational resources for learning Python ===
=== Stuff you need to learn if you want to write a tool that counts objects in an image ===


=== Central topics (topics with a high number of dependencies) ===
=== Central topics (topics with a high number of dependencies) ===
{{#widget:SPARQLquery|code=
{{SPARQL2|query=
#defaultView:Graph
#defaultView:Graph
PREFIX wd: <https://graphit.ur.de/entity/>
PREFIX wd: <https://graphit.ur.de/entity/>
Line 32: Line 27:
PREFIX pq: <https://graphit.ur.de/prop/qualifier/>
PREFIX pq: <https://graphit.ur.de/prop/qualifier/>


SELECT ?prerequisite ?prerequisiteLabel ?prerequisites ?dependency ?dependencyLabel WHERE {
SELECT ?dependency ?dependencyLabel ?prerequisites ?prerequisite ?prerequisiteLabel WHERE {
   {
   {
   SELECT ?dependency ?dependencyLabel (COUNT(DISTINCT ?prerequisite) as ?prerequisites) WHERE {
   SELECT ?dependency ?dependencyLabel (COUNT(DISTINCT ?prerequisite) as ?prerequisites) WHERE {
Line 42: Line 37:
}
}
}}
}}
=== Advanced topics (topics with a high number of prerequisites) ===
=== Advanced topics (topics with a high number of prerequisites) ===
{{#widget:SPARQLquery|code=
{{SPARQL2|query=
#defaultView:Graph
#defaultView:Graph
PREFIX wd: <https://graphit.ur.de/entity/>
PREFIX wd: <https://graphit.ur.de/entity/>
Line 63: Line 59:
}
}
}}
}}
=== Topics that Max Mustermann wants to complete ===


=== Topics that Max Mustermann has completed ===
=== Topics that Max Mustermann has completed ===
{{#widget:SPARQLquery|code=
{{SPARQL2|query=
#defaultView:Timeline
#defaultView:Timeline
PREFIX wd: <https://graphit.ur.de/entity/>
PREFIX wd: <https://graphit.ur.de/entity/>
Line 85: Line 79:
}
}
}}
}}
=== Stuff you need to learn if you want to write an image editor ===
{{SPARQL2|query=
#defaultView:Graph
PREFIX wd: <https://graphit.ur.de/entity/>
PREFIX wds: <https://graphit.ur.de/entity/statement/>
PREFIX wdv: <https://graphit.ur.de/value/>
PREFIX wdt: <https://graphit.ur.de/prop/direct/>
PREFIX p: <https://graphit.ur.de/prop/>
PREFIX ps: <https://graphit.ur.de/prop/statement/>
PREFIX pq: <https://graphit.ur.de/prop/qualifier/>
SELECT ?topic ?topicLabel ?item2 ?item2Label ?image WHERE {
  {
  SELECT ?goal ?goalLabel ?topic ?topicLabel ?image WHERE {
    {
    BIND(wd:Q76 as ?goal).
    ?goal wdt:P1+ ?topic.
    OPTIONAL{ ?topic wdt:P11 ?image.}
    } UNION {
      VALUES ?topic { wd:Q76 } # we also want to include the root node itself
    }
  }
  }
  ?topic wdt:P1 ?item2.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
}}
=== All backlinks to a given topic ===
{{SPARQL2|query=
#defaultView:Graph
PREFIX wdt: <https://graphit.ur.de/prop/direct/>
PREFIX wd: <https://graphit.ur.de/entity/>
select distinct ?subject ?subjectLabel ?item ?itemLabel { # ?property ?propertyLabel
  values (?item) {(wd:Q159)}
  ?subject ?predicate ?item .
  ?property wikibase:directClaim ?predicate
  service wikibase:label { bd:serviceParam wikibase:language "en" }
}
}}
== Not yet implemented ==
=== Topics that Max Mustermann wants to complete ===
=== All topics in the CGBV course ===
=== Educational resources for learning Python ===

Latest revision as of 13:08, 1 June 2023

This page is automatically parsed by the query page to provide examples.


Simple Queries

Complete Dependency Graph

Properties used: depends on (P1), subclass of (P2), image (P11)

#defaultView:Graph
PREFIX wdt: <https://graphit.ur.de/prop/direct/>
SELECT ?item ?itemLabel ?class ?classLabel ?image ?dependency ?dependencyLabel WHERE {
  ?item wdt:P1 ?dependency.
  ?item wdt:P2 ?class
  OPTIONAL{ ?item wdt:P11 ?image.}
  OPTIONAL{ ?class wdt:P11 ?image.}
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}

Try it!


Central topics (topics with a high number of dependencies)

Properties used: depends on (P1)

#defaultView:Graph
PREFIX wd: <https://graphit.ur.de/entity/>
PREFIX wds: <https://graphit.ur.de/entity/statement/>
PREFIX wdv: <https://graphit.ur.de/value/>
PREFIX wdt: <https://graphit.ur.de/prop/direct/>
PREFIX p: <https://graphit.ur.de/prop/>
PREFIX ps: <https://graphit.ur.de/prop/statement/>
PREFIX pq: <https://graphit.ur.de/prop/qualifier/>

SELECT ?dependency ?dependencyLabel ?prerequisites ?prerequisite ?prerequisiteLabel WHERE {
  {
  SELECT ?dependency ?dependencyLabel (COUNT(DISTINCT ?prerequisite) as ?prerequisites) WHERE {
      ?prerequisite wdt:P1 ?dependency.      
  } GROUP BY ?dependency ?dependencyLabel
  }
  ?prerequisite wdt:P1 ?dependency.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}

Try it!


Advanced topics (topics with a high number of prerequisites)

Properties used: depends on (P1)

#defaultView:Graph
PREFIX wd: <https://graphit.ur.de/entity/>
PREFIX wds: <https://graphit.ur.de/entity/statement/>
PREFIX wdv: <https://graphit.ur.de/value/>
PREFIX wdt: <https://graphit.ur.de/prop/direct/>
PREFIX p: <https://graphit.ur.de/prop/>
PREFIX ps: <https://graphit.ur.de/prop/statement/>
PREFIX pq: <https://graphit.ur.de/prop/qualifier/>

SELECT ?prerequisite ?prerequisiteLabel ?dependencies ?dependency ?dependencyLabel WHERE {
  {
  SELECT ?prerequisite ?prerequisiteLabel (COUNT(DISTINCT ?dependency) as ?dependencies) WHERE {
      ?prerequisite wdt:P1 ?dependency.      
  } GROUP BY ?prerequisite ?prerequisiteLabel
  }
  ?prerequisite wdt:P1 ?dependency.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}

Try it!


Topics that Max Mustermann has completed

Items used: Max Mustermann (Q157)

Properties used: image (P11), has completed (P12), on date (P19)

#defaultView:Timeline
PREFIX wd: <https://graphit.ur.de/entity/>
PREFIX wds: <https://graphit.ur.de/entity/statement/>
PREFIX wdv: <https://graphit.ur.de/value/>
PREFIX wdt: <https://graphit.ur.de/prop/direct/>
PREFIX p: <https://graphit.ur.de/prop/>
PREFIX ps: <https://graphit.ur.de/prop/statement/>
PREFIX pq: <https://graphit.ur.de/prop/qualifier/>
SELECT ?topic ?topicLabel ?image ?date WHERE {
  BIND(wd:Q157 as ?user).
  ?user p:P12 ?statement.
  ?statement ps:P12 ?topic.
  ?statement pq:P19 ?date.
  OPTIONAL{ ?topic wdt:P11 ?image.}
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}

Try it!


Stuff you need to learn if you want to write an image editor

Items used: Implementing an Image Editor (Q76)

Properties used: depends on (P1), image (P11)

#defaultView:Graph
PREFIX wd: <https://graphit.ur.de/entity/>
PREFIX wds: <https://graphit.ur.de/entity/statement/>
PREFIX wdv: <https://graphit.ur.de/value/>
PREFIX wdt: <https://graphit.ur.de/prop/direct/>
PREFIX p: <https://graphit.ur.de/prop/>
PREFIX ps: <https://graphit.ur.de/prop/statement/>
PREFIX pq: <https://graphit.ur.de/prop/qualifier/>

SELECT ?topic ?topicLabel ?item2 ?item2Label ?image WHERE {
  {
  SELECT ?goal ?goalLabel ?topic ?topicLabel ?image WHERE {
    {
    BIND(wd:Q76 as ?goal).
    ?goal wdt:P1+ ?topic.
    OPTIONAL{ ?topic wdt:P11 ?image.}
    } UNION {
      VALUES ?topic { wd:Q76 } # we also want to include the root node itself
    }
  }
  }
  ?topic wdt:P1 ?item2.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}

Try it!


All backlinks to a given topic

Items used: Tutorial (Q159)


#defaultView:Graph
PREFIX wdt: <https://graphit.ur.de/prop/direct/>
PREFIX wd: <https://graphit.ur.de/entity/>
select distinct ?subject ?subjectLabel ?item ?itemLabel { # ?property ?propertyLabel
  values (?item) {(wd:Q159)}
  ?subject ?predicate ?item .
  ?property wikibase:directClaim ?predicate
  service wikibase:label { bd:serviceParam wikibase:language "en" }
}

Try it!


Not yet implemented

Topics that Max Mustermann wants to complete

All topics in the CGBV course

Educational resources for learning Python