Project:SPARQL/examples: Difference between revisions

Jump to navigation Jump to search
No edit summary
Line 254: Line 254:
PREFIX wdt: <https://lgbtdb.wikibase.cloud/prop/direct/>
PREFIX wdt: <https://lgbtdb.wikibase.cloud/prop/direct/>


#defaultView:Graph
SELECT ?subject1 ?subject1Label ?subject2 ?subject2Label
SELECT ?subject1 ?subject1Label ?subject2 ?subject2Label {
WITH {
   ?item wdt:P134*/wdt:135*/wdt:P136*/wdt:P206* ?subject1. # Selects a first subject.
   SELECT (COUNT(DISTINCT ?item) AS ?count) ?subject1 ?subject2
  ?item wdt:P134*/wdt:135*/wdt:P136*/wdt:P206* ?subject2 . # Selects a second subject.
  WHERE {
    ?item wdt:P134*/wdt:135*/wdt:P136*/wdt:P206* ?subject1. # Selects a first subject.
    ?item wdt:P134*/wdt:135*/wdt:P136*/wdt:P206* ?subject2 . # Selects a second subject.
    ?item wdt:P134*/wdt:135*/wdt:P136*/wdt:P206* ?subject1, ?subject2 . # Find co-occurring subjects.
    FILTER (?subject1 != ?subject2) # Removes self-relations.
  }
  GROUP BY ?subject1 ?subject2
  ORDER BY DESC(?count)
  LIMIT 500
} AS %results
WHERE {
  INCLUDE %results
   SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } # Helps get the label in your language, if not, then en (English) language
   SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } # Helps get the label in your language, if not, then en (English) language
}
}

Navigation menu