Project:SPARQL/examples: Difference between revisions

From lgbtDB
Jump to navigation Jump to search
No edit summary
No edit summary
Line 83: Line 83:


=== Lexemes ===
=== 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.
<sparql tryit="1">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
</sparql>
==== Instances of lexemes derived from a particular lexeme ====
==== 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.
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.
Line 96: Line 110:
     wikibase:lemma ?lemma . # Returns the lemma
     wikibase:lemma ?lemma . # Returns the lemma
   ?l wdt:P32 wd:L127. # Returns all lexemes with an etymon for 'queen' indicated.
   ?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
}
</sparql>
=== 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.
<sparql tryit="1">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
   SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } # Helps get the label in your language, if not, then en (English) language
}
}

Revision as of 15:21, 24 August 2024

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
}

Try it!


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
}

Try it!


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
}

Try it!


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
}

Try it!


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
}

Try it!


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

Try it!


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
}

Try it!


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
}

Try it!