A set of SPARQL examples that are used in different TGX resources
License: https://www.gnu.org/licenses/gpl-3.0
Uses method in: https://github.com/WDscholia/scholia/tree/master/scholia/app/templates/topic_co-occurring.sparql
Topic aspect: co occurring
PREFIX bd: <http://www.bigdata.com/rdf#>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wikibase: <http://wikiba.se/ontology#>
#defaultView:Graph
PREFIX target: <http://www.wikidata.org/entity/Q45340488>
SELECT
?topic1 ?topic1Label ?topic2 ?topic2Label
WITH {
SELECT
(COUNT(DISTINCT ?work) AS ?count) ?topic1 ?topic2
WHERE {
# Find works that are marked with main subject of the topic.
?work wdt:P921 / ( wdt:P31*/wdt:P279* | wdt:P361+ | wdt:P1269+ ) target: .
# Identify co-occuring topics.
?work wdt:P921 ?topic1, ?topic2 .
# Exclude the topic it self
FILTER (target: != ?topic1 && target: != ?topic2 && ?topic1 != ?topic2)
}
GROUP BY ?topic1 ?topic2
ORDER BY DESC(?count)
# There a performance problems in the browser: We cannot show large graphs,
# so we put a limit on the number of links displayed.
LIMIT 400
} AS %results
WHERE {
INCLUDE %results
# Label the results
SERVICE wikibase:label {
bd:serviceParam wikibase:language "[AUTO_LANGUAGE],mul,en" .
}
}
graph TD