Project:Example Queries: Difference between revisions

no edit summary
No edit summary
Line 4: Line 4:
PREFIX wdt: <https://lgbtdb.wikibase.cloud/prop/direct/></syntaxhighlight>
PREFIX wdt: <https://lgbtdb.wikibase.cloud/prop/direct/></syntaxhighlight>


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


== Simple Queries ==
== Simple Queries ==
=== Instances and Subclasses ===
=== Instances and Subclasses ===
To retrieve all instances of an item, you can use the following:
To retrieve all instances of an item, you can use a query like this, which returns all instances of websites:


<syntaxhighlight lang="sparql">SELECT ?item ?itemLabel  
<syntaxhighlight lang="sparql">SELECT ?item ?itemLabel  
WHERE  
WHERE  
{
{
   ?item wdt:P9 wd:Q166.
   ?item wdt:P1 wd:Q179 .
   SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
   SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}</syntaxhighlight>
}</syntaxhighlight>


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


<syntaxhighlight lang="sparql">SELECT ?item ?itemLabel  
<syntaxhighlight lang="sparql">SELECT ?item ?itemLabel  
Line 26: Line 26:
}</syntaxhighlight>
}</syntaxhighlight>


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


<syntaxhighlight lang="sparql">SELECT ?item ?itemLabel  
<syntaxhighlight lang="sparql">SELECT ?item ?itemLabel  
Line 39: Line 39:
To get all individuals in lgbtDB with birth date and death date information, utilize the following query structure:
To get all individuals in lgbtDB with birth date and death date information, utilize the following query structure:


<syntaxhighlight lang="sparql">SELECT ?item ?itemLabel ?bdate ?ddate
<syntaxhighlight lang="sparql">SELECT DISTINCT ?item ?itemLabel ?bdate ?ddate
WHERE  
WHERE  
{
{
Line 49: Line 49:


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


<syntaxhighlight lang="sparql">SELECT ?item ?itemLabel ?time
<syntaxhighlight lang="sparql">SELECT ?item ?itemLabel ?time
Line 60: Line 60:
}</syntaxhighlight>
}</syntaxhighlight>


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


<syntaxhighlight lang="sparql">SELECT ?item ?itemLabel ?time
<syntaxhighlight lang="sparql">SELECT ?item ?itemLabel ?time
Line 90: Line 90:
WHERE  
WHERE  
{
{
   ?item wdt:P1 wd:Q10639.
   ?item wdt:P1 wd:Q10639 .
   SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
   SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}</syntaxhighlight>
}</syntaxhighlight>
Line 140: Line 140:
=== Graphs and Plots ===
=== Graphs and Plots ===
==== Scatter Plot ====
==== Scatter Plot ====
For example, we may want to graph [[Property:P242|Global Acceptance Index]] (P242) in relationship to [[Property:P362|Transgender Rights Score]] (P362) for countries which have both values indicated.
For example, we may want to graph [[Property:P242|Global Acceptance Index]] (P242) in relationship to [[Property:P362|Transgender Rights Score]] (P362) for countries which have both values indicated ('''NOT FUNCTIONAL''').


<syntaxhighlight lang="sparql">SELECT ?country (SAMPLE(?global_acceptance_index) AS ?global_acceptance_index) (SAMPLE(?transgender_rights_score) AS ?transgender_rights_score) ?countryLabel WHERE {
<syntaxhighlight lang="sparql">SELECT ?country (SAMPLE(?global_acceptance_index) AS ?global_acceptance_index) (SAMPLE(?transgender_rights_score) AS ?transgender_rights_score) ?countryLabel WHERE {
Line 159: Line 159:


<syntaxhighlight lang="sparql">SELECT DISTINCT ?lexemeId ?lemma ?sense
<syntaxhighlight lang="sparql">SELECT DISTINCT ?lexemeId ?lemma ?sense
WHERE  
WHERE {
{
   ?lexemeId dct:language wd:Q2 ;
   ?lexemeId dct:language wd:Q2 ;
     wikibase:lemma ?lemma ;
     wikibase:lemma ?lemma ;
Line 166: Line 165:
   ?sense wdt:P1/(wdt:P2)* wd:Q9507 .
   ?sense wdt:P1/(wdt:P2)* wd:Q9507 .
   SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
   SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
}</syntaxhighlight>
</syntaxhighlight>


== See Also ==
== See Also ==
* [https://www.wikidata.org/wiki/Wikidata:SPARQL_query_service/queries/examples Wikidata:SPARQL query service/queries/examples]
* [https://www.wikidata.org/wiki/Wikidata:SPARQL_query_service/queries/examples Wikidata:SPARQL query service/queries/examples]