Project:Example Queries

From lgbtDB
Revision as of 20:30, 26 March 2024 by Superraptor (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

This page includes some example queries which can be run using the Query service. Note that all queries in LGBTdb must be prepended with the following prefixes to function:

PREFIX wd: <https://lgbtdb.wikibase.cloud/entity/>
PREFIX wdt: <https://lgbtdb.wikibase.cloud/prop/direct/>

NOTE THAT MANY QUERIES BELOW ARE CURRENTLY NON-FUNCTIONAL. FUNCTIONING VERSIONS WILL BE ADDED SOON. NON-FUNCTIONING QUERIES ARE LABELED AS SUCH.

Simple Queries

Instances and Subclasses

To retrieve all instances of an item, you can use a query like this, which returns all instances of websites:

SELECT ?item ?itemLabel 
WHERE 
{
  ?item wdt:P1 wd:Q179 .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}

To retrieve all subclasses of an item, you can use this (NOT FUNCTIONAL):

SELECT ?item ?itemLabel 
WHERE 
{
  ?item wdt:P14 wd:Q7297.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}

In order to retrieve all instances of, and all instances of subclasses of, an item, you can utilize the following query structure (NOT FUNCTIONAL):

SELECT ?item ?itemLabel 
WHERE 
{
  ?item wdt:P9/(wdt:P14)* wd:Q7297.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}

Dates

Birth and Death Dates

To get all individuals in lgbtDB with birth date and death date information, utilize the following query structure:

SELECT DISTINCT ?item ?itemLabel ?bdate ?ddate
WHERE 
{
  ?item wdt:P141|wdt:P142 [] .
  OPTIONAL { ?item wdt:P141 ?bdate . }
  OPTIONAL {?item wdt:P142 ?ddate . }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}

Dates Covered

To locate collections which cover a given area of time (between X and Y), utilize the following query structure (NOT FUNCTIONAL):

SELECT ?item ?itemLabel ?time
WHERE
{
  ?item wdt:P9/wdt:P14* wd:Q3666;
    wdt:P220 ?time.
  FILTER (   YEAR(?time) > X && YEAR(?time) < Y  ).
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" }
}

For example, looking for collections which cover dates between 1900 and 1940 (NOT FUNCTIONAL):

SELECT ?item ?itemLabel ?time
WHERE
{
  ?item wdt:P9/wdt:P14* wd:Q3666;
    wdt:P220 ?time.
  FILTER (   YEAR(?time) > 1940 && YEAR(?time) < 1990  ).
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" }
}

Etymons

To get all of the terms derived from a given etymon, you can use the following:

SELECT ?l ?lemma ?languageLabel
WHERE 
{
  ?l a ontolex:LexicalEntry;
     dct:language ?language;
     wikibase:lemma ?lemma .
  ?l wdt:P32 wd:L127. 
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}

Gender Identities

To get all of the entities considered gender identities, you can use:

SELECT ?item ?itemLabel 
WHERE 
{
  ?item wdt:P1 wd:Q10639 .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}

External Identifiers

Mapping

This query allows you to map different version of the Homosaurus (versions 0, 1, 2, and 3) together:

SELECT DISTINCT ?item ?itemLabel ?val_0 ?val_1 ?val_2 ?val_3
WHERE 
{
  ?item wdt:P29|wdt:P28|wdt:P27|wdt:P26 [] .
  OPTIONAL { ?item wdt:P29 ?val_0 . }
  OPTIONAL { ?item wdt:P28 ?val_1 . }
  OPTIONAL { ?item wdt:P27 ?val_2 . }
  OPTIONAL { ?item wdt:P26 ?val_3 . }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}

The Template:Code argument here keeps in versions where the mappings do not exist in all of them.

Lexemes

Dictionary

To return all lexemes in English in dictionary order, you can use the following:

SELECT ?headword ?categoryLabel { 
  ?item wikibase:lemma ?headword .
  ?item wikibase:lexicalCategory ?category .
  ?item dct:language wd:Q2 .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
} ORDER BY ASC(UCASE(str(?headword)))

Lexical Categories

This query returns the different lexical categories and the number of lexemes in each:

SELECT ?item ?itemLabel ?count
WITH {
  SELECT ?item (COUNT(*) AS ?count) { 
    [] wikibase:lexicalCategory ?item 
  } GROUP BY ?item
} AS %stats 
WHERE 
{
  include %stats.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
} ORDER BY DESC(?count)

Complex Queries

Graphs and Plots

Scatter Plot

For example, we may want to graph Global Acceptance Index (P242) in relationship to Transgender Rights Score (P362) for countries which have both values indicated (NOT FUNCTIONAL).

SELECT ?country (SAMPLE(?global_acceptance_index) AS ?global_acceptance_index) (SAMPLE(?transgender_rights_score) AS ?transgender_rights_score) ?countryLabel WHERE {
  ?country wdt:P9 wd:Q2383;
    wdt:P242 ?global_acceptance_index_score;
    wdt:P362 ?transgender_rights_score_score.
  BIND(?global_acceptance_index_score AS ?global_acceptance_index).
  BIND(?transgender_rights_score_score AS ?transgender_rights_score).
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
GROUP BY ?country ?countryLabel

After the query finishes, select the eye icon on the left side above the query result and select "Scatter Chart" in the dropdown list.

Senses

To get all senses marked as American English gay slang terms or instances of subclasses of American English gay slang terms:

SELECT DISTINCT ?lexemeId ?lemma ?sense
WHERE {
  ?lexemeId dct:language wd:Q2 ;
     wikibase:lemma ?lemma ;
     ontolex:sense ?sense .
  ?sense wdt:P1/(wdt:P2)* wd:Q9507 .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}

See Also