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:Q179 . # 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/>
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
}
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
}
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
}