Project:Example Queries

From lgbtDB
Revision as of 17:05, 8 November 2023 by Superraptor (talk | contribs)
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 ALL QUERIES BELOW ARE CURRENTLY NON-FUNCTIONAL. FUNCTIONING VERSIONS WILL BE ADDED SOON.

Simple Queries

Instances and Subclasses

To retrieve all instances of an item, you can use the following:

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

To retrieve all subclasses of an item, you can use this:

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:

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

Dates

Dates Covered

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

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:

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 ?item ?itemLabel 
WHERE 
{
  ?item wdt:P49 wd:Q21. 
  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 ?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.

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.

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:Q9527 .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}

See Also