Editing QAWiki:Guide/Queries

Jump to navigation Jump to search

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.

Latest revision Your text
Line 5: Line 5:
The following are some tips to ensure high-quality and more uniform queries.
The following are some tips to ensure high-quality and more uniform queries.


=== Return what is asked for ===
== Return what is asked for ==


If the query asks for a count, you can simply return a number. If the query rather asks for an entity or a list of entities, return their IDs/URLs on Wikidata (applications can then decide what data about entities to return, such as labels, images, etc.). Return distinct results. Though it might be tempting to return more background, this can be done automatically, or otherwise, it can form a different question.
If the query asks for a count, you can simply return a number. If the query rather asks for an entity or a list of entities, return their IDs/URLs on Wikidata (applications can then decide what data about entities to return, such as labels, images, etc.). Return distinct results. Though it might be tempting to return more background, this can be done automatically, or otherwise, it can form a different question.


=== Try to keep queries general / Use elemental entities ===
== Try to keep queries general / Use elemental entities ==


The best queries work for a wide selection of entities. For example, consider the query for the question "[[Item:Q68|''Who is the president of Poland?'']]". One option would be to query for the value of the Wikidata property [https://www.wikidata.org/wiki/Property:P35 P35 (''head of state'')] for [https://www.wikidata.org/wiki/Q36 Poland], which will give us the correct answer. But if we swap Poland with the United Kingdom, we would get the answer of '''Charles III''' as the head of state of that country is a king, not a president. We could alternatively look for the value for [https://www.wikidata.org/wiki/Property:P1308 P1308 (''officeholder'')] on the [https://www.wikidata.org/wiki/Q1054799 President of the Republic of Poland], but this query is difficult to re-use for other entities due to the compound nature of this entity; rather we'd like to build the query from simpler, more elemental entities like [https://www.wikidata.org/wiki/Q30461 president] and [https://www.wikidata.org/wiki/Q36 Poland] that are more easily interchanged to generate new queries. Hence the most general form of the query looks for [https://query.wikidata.org/#SELECT%20DISTINCT%20%3Fobj%20WHERE%20%7B%20%3Fsbj%20wdt%3AP31%2a%2Fwdt%3AP279%2a%20wd%3AQ30461%20.%20%3Fsbj%20wdt%3AP1001%20wd%3AQ36%20.%20%3Fsbj%20wdt%3AP1308%20%3Fobj%20%7D officeholders of positions that are instance or sub-class of president, and whose jurisdiction is Poland.] Though a bit more complex, this query avoids conflating monarchs with presidents, generalises to other positions such as ministers, and generalises also to other countries.
The best queries work for a wide selection of entities. For example, consider the query for the question "[[Item:Q68|''Who is the president of Poland?'']]". One option would be to query for the value of the Wikidata property [https://www.wikidata.org/wiki/Property:P35 P35 (''head of state'')] for [https://www.wikidata.org/wiki/Q36 Poland], which will give us the correct answer. But if we swap Poland with the United Kingdom, we would get the answer of '''Charles III''' as the head of state of that country is a king, not a president. We could alternatively look for the value for [https://www.wikidata.org/wiki/Property:P1308 P1308 (''officeholder'')] on the [https://www.wikidata.org/wiki/Q1054799 President of the Republic of Poland], but this query is difficult to re-use for other entities due to the compound nature of this entity; rather we'd like to build the query from simpler, more elemental entities like [https://www.wikidata.org/wiki/Q30461 president] and [https://www.wikidata.org/wiki/Q36 Poland] that are more easily interchanged to generate new queries. Hence the most general form of the query looks for [https://query.wikidata.org/#SELECT%20DISTINCT%20%3Fobj%20WHERE%20%7B%20%3Fsbj%20wdt%3AP31%2a%2Fwdt%3AP279%2a%20wd%3AQ30461%20.%20%3Fsbj%20wdt%3AP1001%20wd%3AQ36%20.%20%3Fsbj%20wdt%3AP1308%20%3Fobj%20%7D officeholders of positions that are instance or sub-class of president, and whose jurisdiction is Poland.] Though a bit more complex, this query avoids conflating monarchs with presidents, generalises to other positions such as ministers, and generalises also to other countries.


=== Write the best query possible (even if not perfect) ===
== Write the best query possible (even if not perfect) ==


Sometimes a query might provide incomplete results. Or if a query features negation, it might return incorrect results due to incomplete data. We recommend adding the query in any case, and hopefully when Wikidata becomes more complete/correct, the query will provide good results. For such cases, QAWiki also provides the qualifier/property [[Property:P36|P36 (''issue'')]], which can be used to indicate [https://tinyurl.com/2klcg89g a variety of such issues].
Sometimes a query might provide incomplete results. Or if a query features negation, it might return incorrect results due to incomplete data. We recommend adding the query in any case, and hopefully when Wikidata becomes more complete/correct, the query will provide good results. For such cases, QAWiki also provides the qualifier/property [[Property:P36|P36 (''issue'')]], which can be used to indicate [https://tinyurl.com/2klcg89g a variety of such issues].
<!-- SELECT DISTINCT ?o ?oLabel WHERE { ?s wdt:P36|pq:P36 ?o . SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } } -->
<!-- SELECT DISTINCT ?o ?oLabel WHERE { ?s wdt:P36|pq:P36 ?o . SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } } -->

Please note that all contributions to QAWiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see Project:Copyrights for details). Do not submit copyrighted work without permission!

Cancel Editing help (opens in new window)