Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
New item
New property
Special pages
QAWiki
Search
Search
English
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
QAWiki:Guide/Queries
Page
Discussion
English
Read
Edit
Edit source
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
Edit source
View history
General
What links here
Related changes
Page information
In other projects
Appearance
move to sidebar
hide
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.
Anti-spam check. Do
not
fill this in!
== Guide to creating queries to answer questions == The current focus is on generating SPARQL queries to answer questions over the [https://query.wikidata.org/ Wikidata Query Service]. You can write the query such that copying and pasting it into the service, it will generate the desired response; thus, for example, you can assume that Wikidata prefixes are defined, that features specific to the Wikidata Query Service are available, etc. The following are some tips to ensure high-quality and more uniform queries. === 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. === 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. === 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]. <!-- SELECT DISTINCT ?o ?oLabel WHERE { ?s wdt:P36|pq:P36 ?o . SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } } -->
Summary:
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
Wikibase:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Search
Search
Editing
QAWiki:Guide/Queries
Add languages
Add topic