Project:SPARQL/examples
This page is parsed by the web interface of the query service to fill the query example dialog. For general examples and their explanations, please see here.
Simple Queries
Instances
Instances of gender identities
This query returns all instances of gender identities in lgbtDB. It uses the service wikibase:label to return the labels in your default language or in English.
PREFIX wd: <https://lgbtdb.wikibase.cloud/entity/>
PREFIX wdt: <https://lgbtdb.wikibase.cloud/prop/direct/>
SELECT ?item ?itemLabel
WHERE
{
?item wdt:P1 wd:Q10639 . # Must be a gender identity
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } # Helps get the label in your language, if not, then en (English) language
}
Instances of romantic orientations
This query returns all instances of romantic orientations in lgbtDB. It uses the service wikibase:label to return the labels in your default language or in English.
PREFIX wd: <https://lgbtdb.wikibase.cloud/entity/>
PREFIX wdt: <https://lgbtdb.wikibase.cloud/prop/direct/>
SELECT ?item ?itemLabel
WHERE
{
?item wdt:P1 wd:Q226 . # Must be a romantic orientation
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } # Helps get the label in your language, if not, then en (English) language
}
Instances of sexual orientations
This query returns all instances of sexual orientations in lgbtDB. It uses the service wikibase:label to return the labels in your default language or in English.
PREFIX wd: <https://lgbtdb.wikibase.cloud/entity/>
PREFIX wdt: <https://lgbtdb.wikibase.cloud/prop/direct/>
SELECT ?item ?itemLabel
WHERE
{
?item wdt:P1 wd:Q10638 . # Must be a sexual orientation
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } # Helps get the label in your language, if not, then en (English) language
}
Instances of websites
This query returns all instances of websites in lgbtDB. It uses the service wikibase:label to return the labels in your default language or in English.
PREFIX wd: <https://lgbtdb.wikibase.cloud/entity/>
PREFIX wdt: <https://lgbtdb.wikibase.cloud/prop/direct/>
SELECT ?item ?itemLabel
WHERE
{
?item wdt:P1 wd:Q21333 . # Must be a website
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } # Helps get the label in your language, if not, then en (English) language
}
Subclasses
Dates
Instances of real-life people with a birth or death date available
This query returns all instances of real-life (human) persons with a birth or death date available. It uses the service wikibase:label to return the labels in your default language or in English.
PREFIX wd: <https://lgbtdb.wikibase.cloud/entity/>
PREFIX wdt: <https://lgbtdb.wikibase.cloud/prop/direct/>
SELECT DISTINCT ?item ?itemLabel ?bdate ?ddate
WHERE
{
?item wdt:P1 wd:Q8775 . # Must be a human person (a real-life person)
?item wdt:P141|wdt:P142 [] . # Must have a birthdate or deathdate available
OPTIONAL { ?item wdt:P141 ?bdate . } # Date of birth
OPTIONAL { ?item wdt:P142 ?ddate . } # Date of death
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } # Helps get the label in your language, if not, then en (English) language
}
Lexemes
Instances of lexemes returned in dictionary order
This query returns all instances of English lexemes in dictionary order. It uses the service wikibase:label to return the labels in your default language or in English.
PREFIX wd: <https://lgbtdb.wikibase.cloud/entity/>
PREFIX wdt: <https://lgbtdb.wikibase.cloud/prop/direct/>
SELECT ?headword ?categoryLabel {
?item wikibase:lemma ?headword . # Returns the lemma as the headword for the entry
?item wikibase:lexicalCategory ?category . # Returns the lexical category (noun, verb, etc.)
?item dct:language wd:Q2 . # Returns only English-language lexemes
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } # Helps get the label in your language, if not, then en (English) language
} ORDER BY ASC(UCASE(str(?headword))) # Orders the headwords in ascending order after being sent to uppercase
Instances of lexemes derived from a particular lexeme
This query returns all instances of lexemes wherein at least one of the indicated etyma is the lexeme 'queen' (L127). It uses the service wikibase:label to return the labels in your default language or in English.
PREFIX wd: <https://lgbtdb.wikibase.cloud/entity/>
PREFIX wdt: <https://lgbtdb.wikibase.cloud/prop/direct/>
SELECT ?l ?lemma ?languageLabel
WHERE
{
?l a ontolex:LexicalEntry; # Indicates that the entity is of the type lexical entry
dct:language ?language; # Returns the language
wikibase:lemma ?lemma . # Returns the lemma
?l wdt:P32 wd:L127. # Returns all lexemes with an etymon for 'queen' indicated.
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } # Helps get the label in your language, if not, then en (English) language
}
Instances of English-language pronoun sets with different forms
This query returns all instances of English-language pronoun sets with the assorted pronoun forms (subject, object, dependent possessive, independent possessive, and reflexive forms). It uses the service wikibase:label to return the labels in your default language or in English.
PREFIX wd: <https://lgbtdb.wikibase.cloud/entity/>
PREFIX wdt: <https://lgbtdb.wikibase.cloud/prop/direct/>
SELECT ?pronounSetLabel ?subjectLabel ?objectLabel ?dependentPossessiveLabel ?independentPossessiveLabel ?reflexiveLabel
WHERE
{
?pronounSet wdt:P1 wd:Q2524 .
?pronounSet wdt:P216 ?subject .
?subject ontolex:representation ?subjectLabel .
?pronounSet wdt:P217 ?object .
?object ontolex:representation ?objectLabel .
?pronounSet wdt:P218 ?dependentPossessive .
?dependentPossessive ontolex:representation ?dependentPossessiveLabel .
?pronounSet wdt:P219 ?independentPossessive .
?independentPossessive ontolex:representation ?independentPossessiveLabel .
?pronounSet wdt:P220 ?reflexive .
?reflexive ontolex:representation ?reflexiveLabel .
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } # Helps get the label in your language, if not, then en (English) language
}
ORDER BY ?pronounSetLabel
Maps
Map of instances of gay bars
This query returns all instances of gay bars (or instances of subclasses of gay bars) in the form of a map. It uses the service wikibase:label to return the labels in your default language or in English.
PREFIX wd: <https://lgbtdb.wikibase.cloud/entity/>
PREFIX wdt: <https://lgbtdb.wikibase.cloud/prop/direct/>
#defaultView:Map
SELECT ?gayBar ?gayBarLabel ?coor
WHERE
{
?gayBar wdt:P1/wdt:P2* wd:Q1106 . # Returns instances of gay bars or instances of subclasses of gay bars (such as lesbian bars)
?gayBar wdt:P638 ?coor . # Returns instances of gay bars with geographic coordinates available.
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } # Helps get the label in your language, if not, then en (English) language
}
Map of entities listed as affiliations
This query returns a map of all entities referred to as affiliations (such as academic departments, hospital departments, universities, and other types of organizations) by authors of academic works.
PREFIX wd: <https://lgbtdb.wikibase.cloud/entity/>
PREFIX wdt: <https://lgbtdb.wikibase.cloud/prop/direct/>
#defaultView:Map
SELECT DISTINCT ?affiliation ?affiliationLabel ?coor
WHERE
{
?item wdt:P838 ?affiliation. # Returns entities referred as as affiliations across all items.
?affiliation wdt:P638 ?coor . # Returns instances of affiliations with geographic coordinates available.
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } # Helps get the label in your language, if not, then en (English) language
}
Identifiers
COEXISTENCE Thesaurus
This query returns all instances of items with at least one mapping to an identifier in the COEXISTENCE Thesaurus. It uses the service wikibase:label to return the labels in your default language or in English.
PREFIX wd: <https://lgbtdb.wikibase.cloud/entity/>
PREFIX wdt: <https://lgbtdb.wikibase.cloud/prop/direct/>
SELECT DISTINCT ?item ?itemLabel ?coexist
WHERE
{
?item wdt:P652 ?coexist . # Returns COEXISTENCE identifiers.
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } # Helps get the label in your language, if not, then en (English) language
}
ORDER BY xsd:integer(?coexist)
GSSO
This query returns all instances of items with at least one mapping to an identifier in the GSSO (version 2). It uses the service wikibase:label to return the labels in your default language or in English.
PREFIX wd: <https://lgbtdb.wikibase.cloud/entity/>
PREFIX wdt: <https://lgbtdb.wikibase.cloud/prop/direct/>
SELECT DISTINCT ?item ?itemLabel ?gsso
WHERE
{
?item wdt:P25 ?gsso . # Returns GSSO identifiers.
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } # Helps get the label in your language, if not, then en (English) language
}
Mappings
Mappings between all versions of the Homosaurus
This query returns all instances of items with at least one mapping to one of the versions of the Homosaurus, providing mappings between them where possible. It uses the service wikibase:label to return the labels in your default language or in English.
PREFIX wd: <https://lgbtdb.wikibase.cloud/entity/>
PREFIX wdt: <https://lgbtdb.wikibase.cloud/prop/direct/>
SELECT DISTINCT ?item ?itemLabel ?val_0 ?val_1 ?val_2 ?val_3
WHERE
{
?item wdt:P29|wdt:P28|wdt:P27|wdt:P26 [] . # Must have a mapping to at least one of the versions of the Homosaurus available
OPTIONAL { ?item wdt:P29 ?val_0 . } # Homosaurus Version 0
OPTIONAL { ?item wdt:P28 ?val_1 . } # Homosaurus Version 1
OPTIONAL { ?item wdt:P27 ?val_2 . } # Homosaurus Version 2
OPTIONAL { ?item wdt:P26 ?val_3 . } # Homosaurus Version 3
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } # Helps get the label in your language, if not, then en (English) language
}
Visualization Queries
Line Charts
MAP Overall Policy Tallies Over Time
This query returns a line chart showcasing how the MAP (Movement Advancement Project) Overall Tally (P863) has changed in all U.S. states and territories over the past decade. It uses the service wikibase:label to return the labels in your default language or in English.
PREFIX wd: <https://lgbtdb.wikibase.cloud/entity/>
PREFIX wdt: <https://lgbtdb.wikibase.cloud/prop/direct/>
PREFIX p: <https://lgbtdb.wikibase.cloud/prop/>
PREFIX pq: <https://lgbtdb.wikibase.cloud/prop/qualifier/>
PREFIX ps: <https://lgbtdb.wikibase.cloud/prop/statement/>
#defaultView:LineChart
SELECT ?USState ?PointInTime ?OverallTally ?USStateLabel
WHERE
{
?USState p:P863 ?OverallTallyProp .
?OverallTallyProp pq:P19 ?PointInTime ;
ps:P863 ?OverallTally .
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
ORDER BY ?USStateLabel ?PointInTime
Graphs
Subclass tree for a class entity
This query returns a graph of the subclass tree for the class of animals (Q4243). It uses the service wikibase:label to return the labels in your default language or in English.
PREFIX wd: <https://lgbtdb.wikibase.cloud/entity/>
PREFIX wdt: <https://lgbtdb.wikibase.cloud/prop/direct/>
#defaultView:Graph
SELECT ?item ?itemLabel ?linkTo {
wd:Q4243 wdt:P2* ?item
OPTIONAL { ?item wdt:P2 ?linkTo }
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } # Helps get the label in your language, if not, then en (English) language
}
NIH grant award types
This query returns a bubble chart visualization of different NIH grant award types (P805). It uses the service wikibase:label to return the labels in your default language or in English.
PREFIX wd: <https://lgbtdb.wikibase.cloud/entity/>
PREFIX wdt: <https://lgbtdb.wikibase.cloud/prop/direct/>
#defaultView:BubbleChart
SELECT ?grantAwardTypeLabel ?count
WITH {
SELECT DISTINCT ?grantAwardType (COUNT (?grant) as ?count) {
?grant wdt:P805 ?grantAwardType . # Selects an award type.
}
GROUP BY ?grantAwardType
ORDER BY DESC (?count)
} AS %i
WHERE {
INCLUDE %i
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } # Helps get the label in your language, if not, then en (English) language
}
Co-authorship clustering
This query returns a graph linking authors (P72) who have authored pieces with one another. It uses the service wikibase:label to return the labels in your default language or in English. WARNING: Be extremely careful with this query as it will take several minutes to run or may crash. Use at your own risk.
PREFIX wd: <https://lgbtdb.wikibase.cloud/entity/>
PREFIX wdt: <https://lgbtdb.wikibase.cloud/prop/direct/>
#defaultView:Graph
SELECT ?author1 ?author1Label ?author2 ?author2Label {
?item wdt:P72 ?author1 . # Selects a first author.
?item wdt:P72 ?author2 . # Selects a second author.
FILTER (?author1 != ?author2) # Removes self-relations.
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } # Helps get the label in your language, if not, then en (English) language
} LIMIT 10000
Subject clustering
This query returns a graph of subjects (P134: indexing concept, P135: subject, P136: key concept, and P206: MeSH subject) which are listed alongside one another. It uses the service wikibase:label to return the labels in your default language or in English. WARNING: Be extremely careful with this query as it will take several minutes to run or may crash. Use at your own risk.
PREFIX wd: <https://lgbtdb.wikibase.cloud/entity/>
PREFIX wdt: <https://lgbtdb.wikibase.cloud/prop/direct/>
#defaultView:Graph
SELECT ?subject1 ?subject1Label ?subject2 ?subject2Label
WITH {
SELECT (COUNT(DISTINCT ?item) AS ?count) ?subject1 ?subject2
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
}