From QAWiki
Jump to navigation Jump to search

Guide to creating queries to answer questions[edit | edit source]

The current focus is on generating SPARQL queries to answer questions over the 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[edit | edit source]

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[edit | edit source]

The best queries work for a wide selection of entities. For example, consider the query for the question "Who is the president of Poland?". One option would be to query for the value of the Wikidata property P35 (head of state) for 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 P1308 (officeholder) on the 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 president and Poland that are more easily interchanged to generate new queries. Hence the most general form of the query looks for 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)[edit | edit source]

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 P36 (issue), which can be used to indicate a variety of such issues.