PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
SELECT ?currency WHERE {
  wd:Q399 wdt:P38 ?currency
}

Using entities:
- Armenia (wd:Q399), also known as AM, ARM, Hayastan, Hayastani Hanrapetut’yun, Republic of Armenia: is instance of sovereign state / is instance of country / sovereign state in the South Caucasus region of Eurasia / sovereign state in the South Caucasus region of Eurasia

Using properties:
- currency (wd:P38 as wdt), also known as base currency, used money, P38: is subproperty of uses / currency used by item / currency used by item / currency used by item

Answer: The Armenian currency is the Armenian dram.

The Armenian currency is the Armenian dram.

SPARQL query over wikidata:
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
SELECT ?currency WHERE {
  wd:Q399 wdt:P38 ?currency
}

Using entities:
- Armenia (wd:Q399), also known as AM, ARM, Hayastan, Hayastani Hanrapetut’yun, Republic of Armenia: is instance of sovereign state / is instance of country / sovereign state in the South Caucasus region of Eurasia / sovereign state in the South Caucasus region of Eurasia

Using properties:
- currency (wd:P38 as wdt), also known as base currency, used money, P38: is subproperty of uses / currency used by item / currency used by item / currency used by item

Execution result:
Got 1 row and 1 column:
| currency                   |
| -------------------------- |
| Armenian dram (wd:Q130498) |

[System]
You are a question answering assistant. Your job is to generate a SPARQL query to answer a given user question.

You should follow a step-by-step approach to generate the SPARQL query:
1. Determine possible entities and properties implied by the user question.
2. Search for the entities and properties in the knowledge graphs. Where applicable, constrain the searches with already identified entities and properties.
3. Gradually build up the SPARQL query using the identified entities and properties. Start with simple queries and add more complexity as needed. Execute intermediate queries to get feedback and to verify your assumptions. You may need to refine or rethink your current plan based on the query results and go back to step 2 if needed, possibly multiple times.
4. Use the answer or cancel function to finalize your answer and stop the generation process.

Available knowledge graphs:
- wikidata at http://localhost:7001 with prefix index for entities and similarity index for properties, and notes:
  - P106 = occupation. Use wdt:P106 to get occupations and fetch English labels with rdfs:label + FILTER(LANG(?label)="en"). When returning human occupations confirm the subject is human (wdt:P31 wd:Q5) to avoid non-human items.
  - Population (P1082) and tabular (P4179): use wdt:P1082 for quick/direct values; for time-series/point-in-time use p:P1082 + ps:P1082 + pq:P585 and ORDER BY pq:P585 DESC. Inspect statement qualifiers (e.g., 'applies to part') and prov:wasDerivedFrom references (pr:P854 etc.) to detect city-proper vs metro/prefecture scopes before using values.
  - Common person properties: P31 (instance of human Q5), P106 (occupation), P569 (date of birth), P19 (place of birth), P27 (country of citizenship), P21 (sex/gender), P166 (award received). Use wdt: for direct values when possible.
  - P17 (country) can be incomplete/misleading for places (historical/overseas tags). To get modern cities in a country combine: instance-of city (P31=Q515) + wdt:P17 OR use wdt:P131* to find an admin parent whose wdt:P17 = the country. Also cross-check coordinates (P625) or admin hierarchy to spot outliers.
  - When filtering by date of birth (P569) use xsd:dateTime comparisons (e.g. >= "1900-01-01T00:00:00Z"^^xsd:dateTime). Be aware many items have year-only or imprecise dates and coverage is biased toward notable/public figures (sportspeople, politicians, artists).
  - To retrieve qualifiers (e.g., award year) use the statement/qualifier pattern: p:Pxxx / ps:Pxxx / pq:P585. Use wdt:Pxxx for normalized/direct values when you don't need qualifiers. Example: p:P166 + pq:P585 gives award year.
  - To get a person's occupations: use wdt:P106 for direct/normalized values and rdfs:label for human-readable names (FILTER(LANG(...))). Example: wd:Q... wdt:P106 ?occ . ?occ rdfs:label ?occLabel . FILTER(LANG(?occLabel)="en").
  - P166 = award received. Use wdt:P166 for normalized/direct values when you only need award items. To get award years or qualifiers use p:P166 / ps:P166 / pq:P585. Many statements lack pq:P585 — use OPTIONAL { ?stmt pq:P585 ?date } and ORDER BY DESC(?date). When listing award winners, filter ?person wdt:P31 wd:Q5 to ensure humans.
  - Population time-series pattern: wd:Q... p:P1082 ?stmt . ?stmt ps:P1082 ?pop . OPTIONAL { ?stmt pq:P585 ?date } . ORDER BY DESC(?date). pq:P585 is the point-in-time qualifier. IMPORTANT: time-series may mix scopes (city proper vs metro) — e.g., Tokyo has a 2016 entry ~38,140,000 likely metro vs smaller city figures. Inspect qualifiers/references for scope before use.
  - Use wdt:P131* to traverse the admin hierarchy and compare wdt:P17 on the place vs an admin parent to detect historical/colonial country assignments. When mismatches appear, inspect the admin parent's instance-of (P31), labels, qualifiers and references to interpret the historical scope.
  - wdt:P106 often yields multiple occupations for a person. Use GROUP_CONCAT(DISTINCT ?occLabel; separator=", ") or return multiple rows. Always fetch labels with rdfs:label + FILTER(LANG(?label)="en") to get readable occupation names.
  - When a search_entity returns multiple hits (person vs sculpture vs memorial), confirm you selected the human/statements by checking wdt:P31 (instance of) and relevant wdt: properties (e.g., wdt:P106). This avoids using a non-human QID by mistake.
  - search_autocomplete can be constrained with a SPARQL pattern containing ?search (e.g., SELECT * WHERE { ?search wdt:P31 wd:Q5 }). Use constraints to focus results (e.g., humans) and avoid ambiguous fallbacks; if it returns no results, fallback to search_entity and verify wdt:P31.
  - Use search_property_of_entity to find relevant properties for an entity (e.g., 'award' -> P166) and search_object_of_property to discover candidate objects (e.g., 'physicist' for P106). This reduces guessing P/Q ids and surfaces qualifiers.
  - Inspect statement references and qualifiers: use prov:wasDerivedFrom on p: statements to find sources, and check qualifiers (e.g., 'applies to part' or other scope qualifiers) to disambiguate city vs metro vs admin area. Reference labels can be empty; inspect reference node properties for URLs or publication dates.

Index types used for entities and properties:
- Prefix index: Retrieves items by overlap between query keywords and item words. The query keywords can match item words exactly or as prefixes.
- Similarity index: Retrieves items by cosine similarity between their embeddings and the query embedding.

General notes across knowledge graphs:
- Use rdfs:label + FILTER(LANG(?label)="en") for labels; avoid SERVICE wikibase:label. Use wdt:Pxxx for normalized/direct values when qualifiers aren't needed. Use p:Pxxx / ps:Pxxx / pq:Pxxx to access statement qualifiers (e.g., award year via pq:P585). When dates matter, prefer xsd:dateTime and watch for year-only precision.
- Practical query patterns: use rdfs:label + FILTER(LANG(...)) for labels. Use wdt:Pxxx for direct/normalized values when qualifiers aren't needed. Use p:Pxxx / ps:Pxxx / pq:Pxxx to access qualifiers (dates via pq:P585). For dates use xsd:dateTime and expect year-only precision. For places: combine P17 with P131 or coordinate (P625) filters to avoid historical/overseas mismatches.
- Use OPTIONAL for pq: qualifiers (e.g., pq:P585), sort by qualifier (ORDER BY pq:P585 DESC) to prefer recent values. Use GROUP_CONCAT to combine multiple labels/values in one row. Watch for typed literals (xsd:dateTime, xsd:decimal) when filtering or sorting.
- Before querying, use search_entity to resolve human-friendly names to wd:Q identifiers and verify instance-of (e.g., check wdt:P31 = wd:Q5 for humans) to avoid ambiguous matches. Prefer the top match but programmatically confirm P31 before using its data.
- Use search_property to confirm property identifiers (e.g., "country" -> P17) before embedding them in queries. This prevents mistakes from assuming an ID and helps pick the best property if multiple choices exist.
- search_autocomplete can fall back to an unconstrained search or error when there are too many candidates. If this happens (e.g., "more than the maximum supported number of subject candidates"), retry with narrower constraints such as instance-of (wdt:P31), additional type filters, or short prefixes to reduce the candidate set; otherwise fallback to search_entity and verify wdt:P31.
- Use list(...) to inspect all triples on an entity for exploration, but expect large results for notable items. Prefer wdt: properties or targeted p:/ps:/pq: patterns in SPARQL when you need normalized values or qualifiers, respectively.
- Before embedding property or item IDs in SPARQL, use search_property, search_property_of_entity, and search_object_of_property to discover the appropriate P/PID or object QIDs. This reduces errors from guessing IDs and surfaces better property alternatives and qualifiers.
- search_constrained and search_autocomplete can return no results for constrained queries or when the index is large. If they fail, fallback to search_entity + verify P31 (or use search_property_of_entity). Constrain with instance-of (wdt:P31) or other properties in the SPARQL to improve matches.
- When selecting awards by year, prefer xsd:dateTime range filters (e.g., >= "2001-01-01T00:00:00Z"^^xsd:dateTime && < "2002-01-01T00:00:00Z"^^xsd:dateTime) instead of YEAR() for portability and precision.
- When selecting award winners via wdt:P166, filter ?person wdt:P31 wd:Q5 to ensure humans — fictional characters or non-humans may have award claims. If you need award years use p:P166 / ps:P166 / pq:P585 and OPTIONAL { ?stmt pq:P585 ?year } to retrieve qualifier years.
- Use wdt:P625 (coordinates) together with wdt:P131* and wdt:P17 checks to validate a place's modern country or to filter by geography. When country labels mismatch historically, inspect admin parents and coordinates to resolve whether the item refers to historical/colonial scope or current boundaries.
- Prefer wdt:Pxxx for normalized/direct values when qualifiers aren't needed. Use p:Pxxx / ps:Pxxx / pq:Pxxx to access qualifiers (e.g., pq:P585 for award year). Always fetch labels with rdfs:label + FILTER(LANG(?label) = "en").
- If search_autocomplete returns too many candidates or errors, retry with constraints (e.g., SELECT * WHERE { ?search wdt:P31 wd:Q5 }) or narrower query text. If still failing, fallback to search_entity and verify wdt:P31 for type checks.
- For award-year queries use p:P166 / ps:P166 / pq:P585 to access award statements and year qualifiers. Filter by xsd:dateTime ranges (e.g., >= "2020-01-01T00:00:00Z"^^xsd:dateTime && < "2021-01-01T00:00:00Z"^^xsd:dateTime) instead of YEAR() for robustness.
- Use search_property_of_entity to surface relevant properties for an entity (e.g., 'birth' -> P569/P19). list(...) can inspect triples but may return large results for notable items—prefer targeted wdt: patterns (wdt:Pxxx) or p:/ps:/pq: patterns when you need qualifiers.

SPARQL prefixes for use in function calls:
- bd: <http://www.bigdata.com/rdf#
- cc: <http://creativecommons.org/ns#
- data: <https://www.wikidata.org/wiki/Special:EntityData/
- dc: <http://purl.org/dc/elements/1.1/
- dct: <http://purl.org/dc/terms/
- foaf: <http://xmlns.com/foaf/0.1/
- geo: <http://www.opengis.net/ont/geosparql#
- geof: <http://www.opengis.net/def/function/geosparql/
- gn: <http://www.geonames.org/ontology#
- hint: <http://www.bigdata.com/queryHints#
- imdb: <https://www.imdb.com/
- math: <http://www.w3.org/2005/xpath-functions/math#
- ontolex: <http://www.w3.org/ns/lemon/ontolex#
- owl: <http://www.w3.org/2002/07/owl#
- p: <http://www.wikidata.org/prop/
- pq: <http://www.wikidata.org/prop/qualifier/
- pqn: <http://www.wikidata.org/prop/qualifier/value-normalized/
- pqv: <http://www.wikidata.org/prop/qualifier/value/
- pr: <http://www.wikidata.org/prop/reference/
- prn: <http://www.wikidata.org/prop/reference/value-normalized/
- prov: <http://www.w3.org/ns/prov#
- prv: <http://www.wikidata.org/prop/reference/value/
- ps: <http://www.wikidata.org/prop/statement/
- psn: <http://www.wikidata.org/prop/statement/value-normalized/
- psv: <http://www.wikidata.org/prop/statement/value/
- qb: <http://purl.org/linked-data/cube#
- qfn: <http://qlever.cs.uni-freiburg.de/function#
- ql: <http://qlever.cs.uni-freiburg.de/builtin-functions/
- qlss: <https://qlever.cs.uni-freiburg.de/spatialSearch/
- rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#
- rdfs: <http://www.w3.org/2000/01/rdf-schema#
- ref: <http://www.wikidata.org/reference/
- s: <http://www.wikidata.org/entity/statement/
- schema: <http://schema.org/
- skos: <http://www.w3.org/2004/02/skos/core#
- v: <http://www.wikidata.org/value/
- void: <http://rdfs.org/ns/void#
- wd: <http://www.wikidata.org/entity/
- wdno: <http://www.wikidata.org/prop/novalue/
- wdt: <http://www.wikidata.org/prop/direct/
- wdtn: <http://www.wikidata.org/prop/direct-normalized/
- wikibase: <http://wikiba.se/ontology#
- xsd: <http://www.w3.org/2001/XMLSchema#

Additional rules to follow:
- Explain your thought process before and after each step and function call.
- Do not just use or make up entity or property identifiers without verifying their existence in the knowledge graphs first.
- Do not ask the user for clarifications without first attempting to complete the task. If the task input is incomplete or ambiguous, try to make reasonable assumptions and document them.
- Do not use "SERVICE wikibase:label { bd:serviceParam wikibase:language ..." in SPARQL queries. It is not SPARQL standard and unsupported by the used QLever SPARQL endpoints. Use rdfs:label or similar properties to get labels instead.
- Always execute your final SPARQL query before giving an answer to make sure it returns the expected results.
- The SPARQL query should always return the actual identifiers / IRIs of the items in its result. It additionally may return labels or other human-readable information, but they are optional and should be put within optional clauses unless explicitly requested by the user.
- Do not stop early if there are still obvious improvements to be made to the SPARQL query. For example, keep refining your SPARQL query if its result contains irrelevant items or is missing items you expected.
- Do not perform additional computation (e.g. filtering, sorting, calculations) on the result of the SPARQL query to determine the answer. All computation should be done solely within SPARQL.
- For questions with a "True" or "False" answer the SPARQL query should be an ASK query.

[User] what is armenian currency?

[Assistant]
To determine the Armenian currency, I need to find the official currency used in Armenia. This can be done by identifying the country Armenia and then retrieving its currency information.

### Step 1: Search for the entity "Armenia"
I will first search for the entity corresponding to Armenia in Wikidata.

Question: Armenia

Top 10 entity alternatives:
1. Armenia (wd:Q399), also known as AM, ARM, Hayastan, Hayastani Hanrapetut’yun, Republic of Armenia: sovereign state in the South Caucasus region of Eurasia / sovereign state in the South Caucasus region of Eurasia / is instance of sovereign state / is instance of country
2. Armenia (wd:Q328518): capital of the Colombian department of Quindío / is instance of municipality of Colombia / is instance of city in Colombia / is instance of big city / city in Colombia
3. First Republic of Armenia (wd:Q139670, matched via Armenia), also known as Armenia: Armenian state existing from 1918–1920 / is instance of historical country / former country
4. 780 Armenia (wd:Q157057, matched via Armenia), also known as (780) Armenia, Armenia: is instance of asteroid / main-belt asteroid / asteroid / asteroid
5. Roman Armenia (wd:Q1254480, matched via Armenia), also known as Armenia: is instance of Roman province / Roman province
6. Armenia (wd:Q934767), also known as Armenia, Antioquia: Colombian municipality of the department of Antioquia / is instance of municipality of Colombia
7. Armenia (wd:Q682015): is instance of administrative territorial entity / district in Eastern Sonsonate, El Salvador / is instance of district of El Salvador / is instance of human settlement
8. Armenia (wd:Q2219381), also known as Armenia, WI: is instance of civil town of Wisconsin / town in Wisconsin, United States
9. Armenia (wd:Q4069598), also known as Armenia (historical region): is instance of historical region / historical territory
10. Armênia (wd:Q5244779), also known as Armenia, Ponte Pequena: metro station in São Paulo, Brazil / is instance of elevated station / is instance of metro station

[Assistant]
The correct entity for the country Armenia is **wd:Q399** (Republic of Armenia). I will now look for the currency used in Armenia by exploring its properties.

### Step 2: List properties of Armenia to find the currency property
I will list the properties of Armenia (wd:Q399) to identify which property represents its currency.

list

wd:Q399

Got 2,322 rows and 3 columns, showing the first 10 rows below:
| subject           | property                       | object                                                                       |
| ----------------- | ------------------------------ | ---------------------------------------------------------------------------- |
| Armenia (wd:Q399) | instance of (wdt:P31)          | sovereign state (wd:Q3624078)                                                |
| Armenia (wd:Q399) | country (wdt:P17)              | Armenia (wd:Q399)                                                            |
| Armenia (wd:Q399) | coordinate location (wdt:P625) | POINT(44.950000 40.383333) (geo:wktLiteral)                                  |
| Armenia (wd:Q399) | Commons category (wdt:P373)    | Armenia                                                                      |
| Armenia (wd:Q399) | image (wdt:P18)                | <http://commons.wikimedia.org/wiki/Special:FilePath/Noravank%20panorama.jpg> |
| Armenia (wd:Q399) | part of (wdt:P361)             | West Asia (wd:Q27293)                                                        |
| Armenia (wd:Q399) | Freebase ID (wdt:P646)         | /m/0jgx                                                                      |
| Armenia (wd:Q399) | GeoNames ID (wdtn:P1566)       | <https://sws.geonames.org/174982/>                                           |
| Armenia (wd:Q399) | population (wdt:P1082)         | 2930450 (xsd:decimal)                                                        |
| Armenia (wd:Q399) | inception (wdt:P571)           | 1991-09-23T00:00:00Z (xsd:dateTime)                                          |
| ...               | ...                            | ...                                                                          |

[Assistant]
I need to find the property that represents the currency of a country. I'll search for properties related to "currency" to identify the correct one.

### Step 3: Search for properties related to "currency"
I will use the `search_property` function to find properties related to currency.

Question: currency

Top 10 property alternatives:
1. currency (wd:P38 as ps/psv/p/pqv/pqn/psn/pq/wdt/pr/prn/prv/wdtn), also known as base currency, used money, P38: is subproperty of uses / currency used by item / currency used by item / currency used by item
2. price (wd:P2284 as ps/psv/p/pqv/pqn/psn/pq/wdt/pr/prn/prv/wdtn, matched via exchange rate), also known as cost, exchange rate, list price, MSRP, published price, etc.: published price listed or paid for a product (use with unit of currency)
3. prize money (wd:P2121 as ps/psv/p/pqv/pqn/psn/pq/wdt/pr/prn/prv/wdtn, matched via money), also known as money, purse, value, P2121: amount in a specific currency / amount in a specific currency
4. ISO 4217 code (wd:P498 as ps/psv/p/pqv/pqn/psn/pq/wdt/pr/prn/prv/wdtn, matched via currency code), also known as currency code, ISO 4217, ISO 4217 alphabetic code, ISO currency code, P498: identifier for a currency per ISO 4217
5. capital of (wd:P1376 as ps/psv/p/pqv/pqn/psn/pq/wdt/pr/prn/prv/wdtn, matched via capital), also known as administrative seat of, capital, county seat for, county seat of, is capital of, etc.: country, state, department, canton or other administrative division of which the municipality is the governmental seat / country, state, department, canton or other administrative division of which the municipality is the governmental seat / country, state, department, canton or other administrative division of which the municipality is the governmental seat / is subproperty of located in the administrative territorial entity
6. capital (wd:P36 as ps/psv/p/pqv/pqn/psn/pq/wdt/pr/prn/prv/wdtn), also known as administrative capital, administrative center, administrative centre, administrative headquarters, administrative seat, etc.: location (city, municipality) of governmental seat of the country, or administrative territorial entity / seat of government of a country, province, state or other type of administrative territorial entity / city of governmental seat of the country, state or administrative subdivision
7. currency symbol description (wd:P489 as ps/psv/p/pqv/pqn/psn/pq/wdt/pr/prn/prv/wdtn), also known as P489: item with description of currency symbol / is subproperty of notation
8. face value (wd:P3934 as ps/psv/p/pqv/pqn/psn/pq/wdt/pr/prn/prv/wdtn, matched via coin value), also known as coin value, numeric value of coin, value of coin, P3934: value printed on a coin, stamp or banknote by the issuing authority
9. quantity (wd:P1114 as ps/psv/p/pqv/pqn/psn/pq/wdt/pr/prn/prv/wdtn, matched via amount), also known as amount, copies, count, instances, multiplicity, etc.: number of instances of this subject in the universe of the ... number of instances in Wikidata may be lower or higher) / number of instances of this subject
10. field of work (wd:P101 as ps/psv/p/pqv/pqn/psn/pq/wdt/pr/prn/prv/wdtn, matched via trade), also known as academic area, academic discipline, academic subject, activity, activity domain, etc.: specialisation of a person or organisation; see P106 for the occupation / specialization of a person or organization; see P106 for the occupation / specialization of a person or organization; see P106 for the occupation / specialization of a person or organization; see P106 for the occupation / is subproperty of interested in

[Assistant]
The relevant property for the currency of a country is **wdt:P38** (currency). I will now query for the currency of Armenia (wd:Q399) using this property.

### Step 4: Query for the currency of Armenia
I will execute a SPARQL query to retrieve the currency of Armenia using `wdt:P38`.

execute

SELECT ?currency WHERE { wd:Q399 wdt:P38 ?currency }

[Assistant]
The currency of Armenia is the **Armenian dram**, which is represented by the Wikidata item **wd:Q130498**.

### Final Answer:
The Armenian currency is the Armenian dram.

I will now provide the final SPARQL query and answer.

answer

SELECT ?currency WHERE { wd:Q399 wdt:P38 ?currency }

Answer: The Armenian currency is the Armenian dram.


PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
SELECT ?language ?languageLabel WHERE {
  wd:Q225 wdt:P37 ?language .
  ?language rdfs:label ?languageLabel .
  FILTER ( LANG( ?languageLabel ) = "en" )
}

Using entities:
- Bosnia and Herzegovina (wd:Q225), also known as 🇧🇦, ba, B&H, BiH, BIH, etc.: is instance of constitutional republic / is instance of sovereign state / is instance of Mediterranean country / is instance of country / country in Europe / country in Southeast Europe / republic in Southeast Europe

Using properties:
- official language (wd:P37 as wdt), also known as language official, language spoken, speaking, spoken in, P37: is subproperty of language used / language designated as official by this item / language designated as official by this item / language designated as official by this item / language designated as official by this item

Got 3 rows and 2 columns:
| language            | languageLabel      |
| ------------------- | ------------------ |
| Croatian (wd:Q6654) | Croatian (lang:en) |
| Serbian (wd:Q9299)  | Serbian (lang:en)  |
| Bosnian (wd:Q9303)  | Bosnian (lang:en)  |

Answer: The people from Bosnia and Herzegovina speak Bosnian, Croatian, and Serbian as official languages.

The people from Bosnia and Herzegovina speak Bosnian, Croatian, and Serbian as official languages.

SPARQL query over wikidata:
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
SELECT ?language ?languageLabel WHERE {
  wd:Q225 wdt:P37 ?language .
  ?language rdfs:label ?languageLabel .
  FILTER ( LANG( ?languageLabel ) = "en" )
}

Using entities:
- Bosnia and Herzegovina (wd:Q225), also known as 🇧🇦, ba, B&H, BiH, BIH, etc.: is instance of constitutional republic / is instance of sovereign state / is instance of Mediterranean country / is instance of country / country in Europe / country in Southeast Europe / republic in Southeast Europe

Using properties:
- official language (wd:P37 as wdt), also known as language official, language spoken, speaking, spoken in, P37: is subproperty of language used / language designated as official by this item / language designated as official by this item / language designated as official by this item / language designated as official by this item

Execution result:
Got 3 rows and 2 columns:
| language            | languageLabel      |
| ------------------- | ------------------ |
| Croatian (wd:Q6654) | Croatian (lang:en) |
| Serbian (wd:Q9299)  | Serbian (lang:en)  |
| Bosnian (wd:Q9303)  | Bosnian (lang:en)  |

[System]
You are a question answering assistant. Your job is to generate a SPARQL query to answer a given user question.

You should follow a step-by-step approach to generate the SPARQL query:
1. Determine possible entities and properties implied by the user question.
2. Search for the entities and properties in the knowledge graphs. Where applicable, constrain the searches with already identified entities and properties.
3. Gradually build up the SPARQL query using the identified entities and properties. Start with simple queries and add more complexity as needed. Execute intermediate queries to get feedback and to verify your assumptions. You may need to refine or rethink your current plan based on the query results and go back to step 2 if needed, possibly multiple times.
4. Use the answer or cancel function to finalize your answer and stop the generation process.

Available knowledge graphs:
- wikidata at http://localhost:7001 with prefix index for entities and similarity index for properties, and notes:
  - P106 = occupation. Use wdt:P106 to get occupations and fetch English labels with rdfs:label + FILTER(LANG(?label)="en"). When returning human occupations confirm the subject is human (wdt:P31 wd:Q5) to avoid non-human items.
  - Population (P1082) and tabular (P4179): use wdt:P1082 for quick/direct values; for time-series/point-in-time use p:P1082 + ps:P1082 + pq:P585 and ORDER BY pq:P585 DESC. Inspect statement qualifiers (e.g., 'applies to part') and prov:wasDerivedFrom references (pr:P854 etc.) to detect city-proper vs metro/prefecture scopes before using values.
  - Common person properties: P31 (instance of human Q5), P106 (occupation), P569 (date of birth), P19 (place of birth), P27 (country of citizenship), P21 (sex/gender), P166 (award received). Use wdt: for direct values when possible.
  - P17 (country) can be incomplete/misleading for places (historical/overseas tags). To get modern cities in a country combine: instance-of city (P31=Q515) + wdt:P17 OR use wdt:P131* to find an admin parent whose wdt:P17 = the country. Also cross-check coordinates (P625) or admin hierarchy to spot outliers.
  - When filtering by date of birth (P569) use xsd:dateTime comparisons (e.g. >= "1900-01-01T00:00:00Z"^^xsd:dateTime). Be aware many items have year-only or imprecise dates and coverage is biased toward notable/public figures (sportspeople, politicians, artists).
  - To retrieve qualifiers (e.g., award year) use the statement/qualifier pattern: p:Pxxx / ps:Pxxx / pq:P585. Use wdt:Pxxx for normalized/direct values when you don't need qualifiers. Example: p:P166 + pq:P585 gives award year.
  - To get a person's occupations: use wdt:P106 for direct/normalized values and rdfs:label for human-readable names (FILTER(LANG(...))). Example: wd:Q... wdt:P106 ?occ . ?occ rdfs:label ?occLabel . FILTER(LANG(?occLabel)="en").
  - P166 = award received. Use wdt:P166 for normalized/direct values when you only need award items. To get award years or qualifiers use p:P166 / ps:P166 / pq:P585. Many statements lack pq:P585 — use OPTIONAL { ?stmt pq:P585 ?date } and ORDER BY DESC(?date). When listing award winners, filter ?person wdt:P31 wd:Q5 to ensure humans.
  - Population time-series pattern: wd:Q... p:P1082 ?stmt . ?stmt ps:P1082 ?pop . OPTIONAL { ?stmt pq:P585 ?date } . ORDER BY DESC(?date). pq:P585 is the point-in-time qualifier. IMPORTANT: time-series may mix scopes (city proper vs metro) — e.g., Tokyo has a 2016 entry ~38,140,000 likely metro vs smaller city figures. Inspect qualifiers/references for scope before use.
  - Use wdt:P131* to traverse the admin hierarchy and compare wdt:P17 on the place vs an admin parent to detect historical/colonial country assignments. When mismatches appear, inspect the admin parent's instance-of (P31), labels, qualifiers and references to interpret the historical scope.
  - wdt:P106 often yields multiple occupations for a person. Use GROUP_CONCAT(DISTINCT ?occLabel; separator=", ") or return multiple rows. Always fetch labels with rdfs:label + FILTER(LANG(?label)="en") to get readable occupation names.
  - When a search_entity returns multiple hits (person vs sculpture vs memorial), confirm you selected the human/statements by checking wdt:P31 (instance of) and relevant wdt: properties (e.g., wdt:P106). This avoids using a non-human QID by mistake.
  - search_autocomplete can be constrained with a SPARQL pattern containing ?search (e.g., SELECT * WHERE { ?search wdt:P31 wd:Q5 }). Use constraints to focus results (e.g., humans) and avoid ambiguous fallbacks; if it returns no results, fallback to search_entity and verify wdt:P31.
  - Use search_property_of_entity to find relevant properties for an entity (e.g., 'award' -> P166) and search_object_of_property to discover candidate objects (e.g., 'physicist' for P106). This reduces guessing P/Q ids and surfaces qualifiers.
  - Inspect statement references and qualifiers: use prov:wasDerivedFrom on p: statements to find sources, and check qualifiers (e.g., 'applies to part' or other scope qualifiers) to disambiguate city vs metro vs admin area. Reference labels can be empty; inspect reference node properties for URLs or publication dates.

Index types used for entities and properties:
- Prefix index: Retrieves items by overlap between query keywords and item words. The query keywords can match item words exactly or as prefixes.
- Similarity index: Retrieves items by cosine similarity between their embeddings and the query embedding.

General notes across knowledge graphs:
- Use rdfs:label + FILTER(LANG(?label)="en") for labels; avoid SERVICE wikibase:label. Use wdt:Pxxx for normalized/direct values when qualifiers aren't needed. Use p:Pxxx / ps:Pxxx / pq:Pxxx to access statement qualifiers (e.g., award year via pq:P585). When dates matter, prefer xsd:dateTime and watch for year-only precision.
- Practical query patterns: use rdfs:label + FILTER(LANG(...)) for labels. Use wdt:Pxxx for direct/normalized values when qualifiers aren't needed. Use p:Pxxx / ps:Pxxx / pq:Pxxx to access qualifiers (dates via pq:P585). For dates use xsd:dateTime and expect year-only precision. For places: combine P17 with P131 or coordinate (P625) filters to avoid historical/overseas mismatches.
- Use OPTIONAL for pq: qualifiers (e.g., pq:P585), sort by qualifier (ORDER BY pq:P585 DESC) to prefer recent values. Use GROUP_CONCAT to combine multiple labels/values in one row. Watch for typed literals (xsd:dateTime, xsd:decimal) when filtering or sorting.
- Before querying, use search_entity to resolve human-friendly names to wd:Q identifiers and verify instance-of (e.g., check wdt:P31 = wd:Q5 for humans) to avoid ambiguous matches. Prefer the top match but programmatically confirm P31 before using its data.
- Use search_property to confirm property identifiers (e.g., "country" -> P17) before embedding them in queries. This prevents mistakes from assuming an ID and helps pick the best property if multiple choices exist.
- search_autocomplete can fall back to an unconstrained search or error when there are too many candidates. If this happens (e.g., "more than the maximum supported number of subject candidates"), retry with narrower constraints such as instance-of (wdt:P31), additional type filters, or short prefixes to reduce the candidate set; otherwise fallback to search_entity and verify wdt:P31.
- Use list(...) to inspect all triples on an entity for exploration, but expect large results for notable items. Prefer wdt: properties or targeted p:/ps:/pq: patterns in SPARQL when you need normalized values or qualifiers, respectively.
- Before embedding property or item IDs in SPARQL, use search_property, search_property_of_entity, and search_object_of_property to discover the appropriate P/PID or object QIDs. This reduces errors from guessing IDs and surfaces better property alternatives and qualifiers.
- search_constrained and search_autocomplete can return no results for constrained queries or when the index is large. If they fail, fallback to search_entity + verify P31 (or use search_property_of_entity). Constrain with instance-of (wdt:P31) or other properties in the SPARQL to improve matches.
- When selecting awards by year, prefer xsd:dateTime range filters (e.g., >= "2001-01-01T00:00:00Z"^^xsd:dateTime && < "2002-01-01T00:00:00Z"^^xsd:dateTime) instead of YEAR() for portability and precision.
- When selecting award winners via wdt:P166, filter ?person wdt:P31 wd:Q5 to ensure humans — fictional characters or non-humans may have award claims. If you need award years use p:P166 / ps:P166 / pq:P585 and OPTIONAL { ?stmt pq:P585 ?year } to retrieve qualifier years.
- Use wdt:P625 (coordinates) together with wdt:P131* and wdt:P17 checks to validate a place's modern country or to filter by geography. When country labels mismatch historically, inspect admin parents and coordinates to resolve whether the item refers to historical/colonial scope or current boundaries.
- Prefer wdt:Pxxx for normalized/direct values when qualifiers aren't needed. Use p:Pxxx / ps:Pxxx / pq:Pxxx to access qualifiers (e.g., pq:P585 for award year). Always fetch labels with rdfs:label + FILTER(LANG(?label) = "en").
- If search_autocomplete returns too many candidates or errors, retry with constraints (e.g., SELECT * WHERE { ?search wdt:P31 wd:Q5 }) or narrower query text. If still failing, fallback to search_entity and verify wdt:P31 for type checks.
- For award-year queries use p:P166 / ps:P166 / pq:P585 to access award statements and year qualifiers. Filter by xsd:dateTime ranges (e.g., >= "2020-01-01T00:00:00Z"^^xsd:dateTime && < "2021-01-01T00:00:00Z"^^xsd:dateTime) instead of YEAR() for robustness.
- Use search_property_of_entity to surface relevant properties for an entity (e.g., 'birth' -> P569/P19). list(...) can inspect triples but may return large results for notable items—prefer targeted wdt: patterns (wdt:Pxxx) or p:/ps:/pq: patterns when you need qualifiers.

SPARQL prefixes for use in function calls:
- bd: <http://www.bigdata.com/rdf#
- cc: <http://creativecommons.org/ns#
- data: <https://www.wikidata.org/wiki/Special:EntityData/
- dc: <http://purl.org/dc/elements/1.1/
- dct: <http://purl.org/dc/terms/
- foaf: <http://xmlns.com/foaf/0.1/
- geo: <http://www.opengis.net/ont/geosparql#
- geof: <http://www.opengis.net/def/function/geosparql/
- gn: <http://www.geonames.org/ontology#
- hint: <http://www.bigdata.com/queryHints#
- imdb: <https://www.imdb.com/
- math: <http://www.w3.org/2005/xpath-functions/math#
- ontolex: <http://www.w3.org/ns/lemon/ontolex#
- owl: <http://www.w3.org/2002/07/owl#
- p: <http://www.wikidata.org/prop/
- pq: <http://www.wikidata.org/prop/qualifier/
- pqn: <http://www.wikidata.org/prop/qualifier/value-normalized/
- pqv: <http://www.wikidata.org/prop/qualifier/value/
- pr: <http://www.wikidata.org/prop/reference/
- prn: <http://www.wikidata.org/prop/reference/value-normalized/
- prov: <http://www.w3.org/ns/prov#
- prv: <http://www.wikidata.org/prop/reference/value/
- ps: <http://www.wikidata.org/prop/statement/
- psn: <http://www.wikidata.org/prop/statement/value-normalized/
- psv: <http://www.wikidata.org/prop/statement/value/
- qb: <http://purl.org/linked-data/cube#
- qfn: <http://qlever.cs.uni-freiburg.de/function#
- ql: <http://qlever.cs.uni-freiburg.de/builtin-functions/
- qlss: <https://qlever.cs.uni-freiburg.de/spatialSearch/
- rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#
- rdfs: <http://www.w3.org/2000/01/rdf-schema#
- ref: <http://www.wikidata.org/reference/
- s: <http://www.wikidata.org/entity/statement/
- schema: <http://schema.org/
- skos: <http://www.w3.org/2004/02/skos/core#
- v: <http://www.wikidata.org/value/
- void: <http://rdfs.org/ns/void#
- wd: <http://www.wikidata.org/entity/
- wdno: <http://www.wikidata.org/prop/novalue/
- wdt: <http://www.wikidata.org/prop/direct/
- wdtn: <http://www.wikidata.org/prop/direct-normalized/
- wikibase: <http://wikiba.se/ontology#
- xsd: <http://www.w3.org/2001/XMLSchema#

Additional rules to follow:
- Explain your thought process before and after each step and function call.
- Do not just use or make up entity or property identifiers without verifying their existence in the knowledge graphs first.
- Do not ask the user for clarifications without first attempting to complete the task. If the task input is incomplete or ambiguous, try to make reasonable assumptions and document them.
- Do not use "SERVICE wikibase:label { bd:serviceParam wikibase:language ..." in SPARQL queries. It is not SPARQL standard and unsupported by the used QLever SPARQL endpoints. Use rdfs:label or similar properties to get labels instead.
- Always execute your final SPARQL query before giving an answer to make sure it returns the expected results.
- The SPARQL query should always return the actual identifiers / IRIs of the items in its result. It additionally may return labels or other human-readable information, but they are optional and should be put within optional clauses unless explicitly requested by the user.
- Do not stop early if there are still obvious improvements to be made to the SPARQL query. For example, keep refining your SPARQL query if its result contains irrelevant items or is missing items you expected.
- Do not perform additional computation (e.g. filtering, sorting, calculations) on the result of the SPARQL query to determine the answer. All computation should be done solely within SPARQL.
- For questions with a "True" or "False" answer the SPARQL query should be an ASK query.

[User] what language do people from bosnia speak?

[Assistant]
To determine the language spoken by people from Bosnia, I will follow these steps:

1. Identify the entity for Bosnia.
2. Find the official or commonly spoken language(s) associated with Bosnia.
3. Construct a SPARQL query to retrieve the language(s) spoken in Bosnia.

### Step 1: Search for the entity for Bosnia
I will first search for the entity representing Bosnia to ensure I have the correct identifier.

Question: Bosnia

Top 10 entity alternatives:
1. Bosnia and Herzegovina (wd:Q225, matched via Bosnia), also known as 🇧🇦, ba, B&H, BiH, BIH, etc.: is instance of constitutional republic / is instance of Mediterranean country / is instance of sovereign state / republic in Southeast Europe / country in Southeast Europe / is instance of country / country in Europe
2. Bosnia (wd:Q188736): is instance of geographical region / is instance of geographic region / is instance of historical region / region in Bosnia and Herzegovina
3. Bosnia (wd:Q4947317): live album by Grand Funk Railroad / is instance of album
4. Bosna (wd:Q25502969, matched via Bosnia), also known as Bosnia, Bosnia (song): is instance of musical work/composition / Croatian song
5. Bosnia (wd:Q10433448): 1996 live album by Ulf Lundell / is instance of album
6. Bosnia (wd:Q29021052): song by Argentine musician Luis Alberto Spinetta in the álbum Spinetta y los Socios del Desierto / is instance of musical work/composition
7. Bosnia (wd:Q119441173): painting by James Potter (active 1998–2000), Royal Military Police Museum / is instance of painting
8. Bosnia (wd:Q103894070): is instance of encyclopaedic article / is instance of encyclopedia article / encyclopedia article
9. Bosnia (wd:Q84728272), also known as IMO 1160388: general cargo ship built in 1928 / is instance of ship
10. Bosnia (wd:Q80218280): is instance of photograph / photograph by Ron Haviv

[Assistant]
The top result is "Bosnia and Herzegovina" (wd:Q225), which is the sovereign state commonly referred to as Bosnia. I will use this entity to find the official or commonly spoken language(s).

### Step 2: Find properties related to language for Bosnia and Herzegovina
I will now search for properties related to language for Bosnia and Herzegovina to identify the correct property for language(s) spoken.

Question: language

Top 10 property alternatives:
1. language used (wd:P2936 as p/wdt, matched via working language), also known as languages used, medium of instruction, used language, uses language, working language, etc.: language widely used (spoken or written) in this place or at this event or organisation
2. official language (wd:P37 as p/wdt, matched via language official), also known as language official, language spoken, speaking, spoken in, P37: language designated as official by this item / language designated as official by this item / language designated as official by this item / language designated as official by this item / is subproperty of language used
3. coat of arms image (wd:P94 as p/wdt, matched via symbol), also known as arms, CoA image, emblem, heraldic, image of coat of arms, representation (heraldic), etc.: image of the item's coat of arms - for the shield part only use P4004 / image of the item's coat of arms / image of the item's coat of arms / is subproperty of image
4. located in/on physical feature (wd:P706 as p/wdt, matched via on), also known as geographical region, is in, is on, landform, located on island, etc.: located on the specified landform or body of water. Should ... (provinces, states, countries, etc.). / located on the specified (geo)physical feature. Should not be ... political/administrative (P131) or a mountain range (P4552). / is subproperty of location / is subproperty of part of
5. applies to jurisdiction (wd:P1001 as p/wdt, matched via of), also known as applicable area, applicable country, applicable geographic place, applicable jurisdiction, applicable location, etc.: the item (institution, law, public office, public ... jurisdiction: a country, state, municipality, ...) / the item (an institution, law, public office ...) or ... jurisdiction: a country, state, municipality, ...) / is subproperty of significant place / is subproperty of characteristic of / is subproperty of operating area
6. part of (wd:P361 as p/wdt, matched via of), also known as assembly of, branch of, chain, collateral branch of, component of, etc.: object of which the subject is a part (if this subject is ... "has part" (P527, see also "has parts of the class" (P2670)) / object of which the subject is a part (if this subject is ... "has part" (P527, see also "has parts of the class" (P2670)) / object of which the subject is a part (if this subject is ... "has part" (P527, see also "has parts of the class" (P2670)) / object of which the subject is a part (if this subject is ... "has part" (P527, see also "has parts of the class" (P2670))
7. native label (wd:P1705 as p/wdt, matched via official language label), also known as autonym, label in official language, label in original language, name in official language, name in original language, etc.: label for the items in their official language (P37) or their original language (P364) / label for the items in their official language (P37) or their original language (P364) / label for the items in their official language (P37) or their original language (P364) / label for the items in their official language  or their original language / is subproperty of name
8. culture (wd:P2596 as p/wdt), also known as archaeological culture, civilisation, civilization, P2596: human culture or people (or several cultures) associated with this item / human culture or people (or several cultures) associated with this item / human culture or people (or several cultures) associated with this item / is subproperty of part of
9. topic's main category (wd:P910 as p/wdt, matched via category), also known as article's main category, category, category for this topic, catmain, has category, etc.: main category of this topic / main Wikimedia category
10. different from (wd:P1889 as p/wdt, matched via not), also known as confused with, differs from, disambiguated from, distinct from, distinguished from, etc.: item that is different from another item, with which it is often confused / item that is different from another item, with which it may be confused

No other items found

[Assistant]
The most relevant property for the official language is **P37 (official language)**. This property is commonly used to indicate the official language(s) of a country. I will now construct a SPARQL query to retrieve the official language(s) of Bosnia and Herzegovina (wd:Q225) using this property.

### Step 3: Construct and execute the SPARQL query
I will write a SPARQL query to fetch the official language(s) of Bosnia and Herzegovina and retrieve their English labels for readability.

execute

SELECT ?language ?languageLabel WHERE { wd:Q225 wdt:P37 ?language . SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } }

SPARQL execution failed:
Error while executing a SERVICE request to <http://wikiba.se:80/ontology#label>: SERVICE responded with HTTP status code: 301, Moved Permanently. First 100 bytes of the response: '
<title>301 Moved Permanently</title>

301 Moved Permanently'

[Assistant]
The error occurred because I used `SERVICE wikibase:label`, which is not supported in this environment. I need to use `rdfs:label` with a language filter instead to retrieve the English labels for the languages.

I will revise the SPARQL query to use `rdfs:label` with `FILTER(LANG(?languageLabel) = "en")` to get the English labels for the official languages of Bosnia and Herzegovina.

### Revised SPARQL Query:
I will now execute the corrected SPARQL query.

SELECT ?language ?languageLabel WHERE { wd:Q225 wdt:P37 ?language . ?language rdfs:label ?languageLabel . FILTER(LANG(?languageLabel) = "en") }

Got 3 rows and 2 columns:
| language            | languageLabel      |
| ------------------- | ------------------ |
| Croatian (wd:Q6654) | Croatian (lang:en) |
| Serbian (wd:Q9299)  | Serbian (lang:en)  |
| Bosnian (wd:Q9303)  | Bosnian (lang:en)  |

[Assistant]
The query successfully returned the official languages of Bosnia and Herzegovina. The three official languages are:

1. **Croatian**
2. **Serbian**
3. **Bosnian**

These are the languages spoken by people from Bosnia and Herzegovina.

### Final Answer:
The people from Bosnia and Herzegovina speak **Bosnian, Croatian, and Serbian** as official languages.

I will now provide the final SPARQL query and answer.

answer

SELECT ?language ?languageLabel WHERE { wd:Q225 wdt:P37 ?language . ?language rdfs:label ?languageLabel . FILTER(LANG(?languageLabel) = "en") }

Answer: The people from Bosnia and Herzegovina speak Bosnian, Croatian, and Serbian as official languages.


PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX wd: <http://www.wikidata.org/entity/>
SELECT ?label WHERE {
  wd:Q9299 rdfs:label ?label .
  FILTER ( LANG( ?label ) = "en" )
}

Using entities:
- Serbian (wd:Q9299), also known as Serbian language, Srpski: is instance of standard variety / is instance of language / is instance of pluricentric language variant / is subclass of Eastern Herzegovinian / standardized variety of Serbo-Croatian language used by Serbs

Got 1 row and 1 column:
| label             |
| ----------------- |
| Serbian (lang:en) |

Answer: Serbian

Serbian

SPARQL query over wikidata:
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX wd: <http://www.wikidata.org/entity/>
SELECT ?label WHERE {
  wd:Q9299 rdfs:label ?label .
  FILTER ( LANG( ?label ) = "en" )
}

Using entities:
- Serbian (wd:Q9299), also known as Serbian language, Srpski: is instance of standard variety / is instance of language / is instance of pluricentric language variant / is subclass of Eastern Herzegovinian / standardized variety of Serbo-Croatian language used by Serbs

Execution result:
Got 1 row and 1 column:
| label             |
| ----------------- |
| Serbian (lang:en) |

[System]
You are a question answering assistant. Your job is to generate a SPARQL query to answer a given user question.

You should follow a step-by-step approach to generate the SPARQL query:
1. Determine possible entities and properties implied by the user question.
2. Search for the entities and properties in the knowledge graphs. Where applicable, constrain the searches with already identified entities and properties.
3. Gradually build up the SPARQL query using the identified entities and properties. Start with simple queries and add more complexity as needed. Execute intermediate queries to get feedback and to verify your assumptions. You may need to refine or rethink your current plan based on the query results and go back to step 2 if needed, possibly multiple times.
4. Use the answer or cancel function to finalize your answer and stop the generation process.

Available knowledge graphs:
- wikidata at http://localhost:7001 with prefix index for entities and similarity index for properties, and notes:
  - P106 = occupation. Use wdt:P106 to get occupations and fetch English labels with rdfs:label + FILTER(LANG(?label)="en"). When returning human occupations confirm the subject is human (wdt:P31 wd:Q5) to avoid non-human items.
  - Population (P1082) and tabular (P4179): use wdt:P1082 for quick/direct values; for time-series/point-in-time use p:P1082 + ps:P1082 + pq:P585 and ORDER BY pq:P585 DESC. Inspect statement qualifiers (e.g., 'applies to part') and prov:wasDerivedFrom references (pr:P854 etc.) to detect city-proper vs metro/prefecture scopes before using values.
  - Common person properties: P31 (instance of human Q5), P106 (occupation), P569 (date of birth), P19 (place of birth), P27 (country of citizenship), P21 (sex/gender), P166 (award received). Use wdt: for direct values when possible.
  - P17 (country) can be incomplete/misleading for places (historical/overseas tags). To get modern cities in a country combine: instance-of city (P31=Q515) + wdt:P17 OR use wdt:P131* to find an admin parent whose wdt:P17 = the country. Also cross-check coordinates (P625) or admin hierarchy to spot outliers.
  - When filtering by date of birth (P569) use xsd:dateTime comparisons (e.g. >= "1900-01-01T00:00:00Z"^^xsd:dateTime). Be aware many items have year-only or imprecise dates and coverage is biased toward notable/public figures (sportspeople, politicians, artists).
  - To retrieve qualifiers (e.g., award year) use the statement/qualifier pattern: p:Pxxx / ps:Pxxx / pq:P585. Use wdt:Pxxx for normalized/direct values when you don't need qualifiers. Example: p:P166 + pq:P585 gives award year.
  - To get a person's occupations: use wdt:P106 for direct/normalized values and rdfs:label for human-readable names (FILTER(LANG(...))). Example: wd:Q... wdt:P106 ?occ . ?occ rdfs:label ?occLabel . FILTER(LANG(?occLabel)="en").
  - P166 = award received. Use wdt:P166 for normalized/direct values when you only need award items. To get award years or qualifiers use p:P166 / ps:P166 / pq:P585. Many statements lack pq:P585 — use OPTIONAL { ?stmt pq:P585 ?date } and ORDER BY DESC(?date). When listing award winners, filter ?person wdt:P31 wd:Q5 to ensure humans.
  - Population time-series pattern: wd:Q... p:P1082 ?stmt . ?stmt ps:P1082 ?pop . OPTIONAL { ?stmt pq:P585 ?date } . ORDER BY DESC(?date). pq:P585 is the point-in-time qualifier. IMPORTANT: time-series may mix scopes (city proper vs metro) — e.g., Tokyo has a 2016 entry ~38,140,000 likely metro vs smaller city figures. Inspect qualifiers/references for scope before use.
  - Use wdt:P131* to traverse the admin hierarchy and compare wdt:P17 on the place vs an admin parent to detect historical/colonial country assignments. When mismatches appear, inspect the admin parent's instance-of (P31), labels, qualifiers and references to interpret the historical scope.
  - wdt:P106 often yields multiple occupations for a person. Use GROUP_CONCAT(DISTINCT ?occLabel; separator=", ") or return multiple rows. Always fetch labels with rdfs:label + FILTER(LANG(?label)="en") to get readable occupation names.
  - When a search_entity returns multiple hits (person vs sculpture vs memorial), confirm you selected the human/statements by checking wdt:P31 (instance of) and relevant wdt: properties (e.g., wdt:P106). This avoids using a non-human QID by mistake.
  - search_autocomplete can be constrained with a SPARQL pattern containing ?search (e.g., SELECT * WHERE { ?search wdt:P31 wd:Q5 }). Use constraints to focus results (e.g., humans) and avoid ambiguous fallbacks; if it returns no results, fallback to search_entity and verify wdt:P31.
  - Use search_property_of_entity to find relevant properties for an entity (e.g., 'award' -> P166) and search_object_of_property to discover candidate objects (e.g., 'physicist' for P106). This reduces guessing P/Q ids and surfaces qualifiers.
  - Inspect statement references and qualifiers: use prov:wasDerivedFrom on p: statements to find sources, and check qualifiers (e.g., 'applies to part' or other scope qualifiers) to disambiguate city vs metro vs admin area. Reference labels can be empty; inspect reference node properties for URLs or publication dates.

Index types used for entities and properties:
- Prefix index: Retrieves items by overlap between query keywords and item words. The query keywords can match item words exactly or as prefixes.
- Similarity index: Retrieves items by cosine similarity between their embeddings and the query embedding.

General notes across knowledge graphs:
- Use rdfs:label + FILTER(LANG(?label)="en") for labels; avoid SERVICE wikibase:label. Use wdt:Pxxx for normalized/direct values when qualifiers aren't needed. Use p:Pxxx / ps:Pxxx / pq:Pxxx to access statement qualifiers (e.g., award year via pq:P585). When dates matter, prefer xsd:dateTime and watch for year-only precision.
- Practical query patterns: use rdfs:label + FILTER(LANG(...)) for labels. Use wdt:Pxxx for direct/normalized values when qualifiers aren't needed. Use p:Pxxx / ps:Pxxx / pq:Pxxx to access qualifiers (dates via pq:P585). For dates use xsd:dateTime and expect year-only precision. For places: combine P17 with P131 or coordinate (P625) filters to avoid historical/overseas mismatches.
- Use OPTIONAL for pq: qualifiers (e.g., pq:P585), sort by qualifier (ORDER BY pq:P585 DESC) to prefer recent values. Use GROUP_CONCAT to combine multiple labels/values in one row. Watch for typed literals (xsd:dateTime, xsd:decimal) when filtering or sorting.
- Before querying, use search_entity to resolve human-friendly names to wd:Q identifiers and verify instance-of (e.g., check wdt:P31 = wd:Q5 for humans) to avoid ambiguous matches. Prefer the top match but programmatically confirm P31 before using its data.
- Use search_property to confirm property identifiers (e.g., "country" -> P17) before embedding them in queries. This prevents mistakes from assuming an ID and helps pick the best property if multiple choices exist.
- search_autocomplete can fall back to an unconstrained search or error when there are too many candidates. If this happens (e.g., "more than the maximum supported number of subject candidates"), retry with narrower constraints such as instance-of (wdt:P31), additional type filters, or short prefixes to reduce the candidate set; otherwise fallback to search_entity and verify wdt:P31.
- Use list(...) to inspect all triples on an entity for exploration, but expect large results for notable items. Prefer wdt: properties or targeted p:/ps:/pq: patterns in SPARQL when you need normalized values or qualifiers, respectively.
- Before embedding property or item IDs in SPARQL, use search_property, search_property_of_entity, and search_object_of_property to discover the appropriate P/PID or object QIDs. This reduces errors from guessing IDs and surfaces better property alternatives and qualifiers.
- search_constrained and search_autocomplete can return no results for constrained queries or when the index is large. If they fail, fallback to search_entity + verify P31 (or use search_property_of_entity). Constrain with instance-of (wdt:P31) or other properties in the SPARQL to improve matches.
- When selecting awards by year, prefer xsd:dateTime range filters (e.g., >= "2001-01-01T00:00:00Z"^^xsd:dateTime && < "2002-01-01T00:00:00Z"^^xsd:dateTime) instead of YEAR() for portability and precision.
- When selecting award winners via wdt:P166, filter ?person wdt:P31 wd:Q5 to ensure humans — fictional characters or non-humans may have award claims. If you need award years use p:P166 / ps:P166 / pq:P585 and OPTIONAL { ?stmt pq:P585 ?year } to retrieve qualifier years.
- Use wdt:P625 (coordinates) together with wdt:P131* and wdt:P17 checks to validate a place's modern country or to filter by geography. When country labels mismatch historically, inspect admin parents and coordinates to resolve whether the item refers to historical/colonial scope or current boundaries.
- Prefer wdt:Pxxx for normalized/direct values when qualifiers aren't needed. Use p:Pxxx / ps:Pxxx / pq:Pxxx to access qualifiers (e.g., pq:P585 for award year). Always fetch labels with rdfs:label + FILTER(LANG(?label) = "en").
- If search_autocomplete returns too many candidates or errors, retry with constraints (e.g., SELECT * WHERE { ?search wdt:P31 wd:Q5 }) or narrower query text. If still failing, fallback to search_entity and verify wdt:P31 for type checks.
- For award-year queries use p:P166 / ps:P166 / pq:P585 to access award statements and year qualifiers. Filter by xsd:dateTime ranges (e.g., >= "2020-01-01T00:00:00Z"^^xsd:dateTime && < "2021-01-01T00:00:00Z"^^xsd:dateTime) instead of YEAR() for robustness.
- Use search_property_of_entity to surface relevant properties for an entity (e.g., 'birth' -> P569/P19). list(...) can inspect triples but may return large results for notable items—prefer targeted wdt: patterns (wdt:Pxxx) or p:/ps:/pq: patterns when you need qualifiers.

SPARQL prefixes for use in function calls:
- bd: <http://www.bigdata.com/rdf#
- cc: <http://creativecommons.org/ns#
- data: <https://www.wikidata.org/wiki/Special:EntityData/
- dc: <http://purl.org/dc/elements/1.1/
- dct: <http://purl.org/dc/terms/
- foaf: <http://xmlns.com/foaf/0.1/
- geo: <http://www.opengis.net/ont/geosparql#
- geof: <http://www.opengis.net/def/function/geosparql/
- gn: <http://www.geonames.org/ontology#
- hint: <http://www.bigdata.com/queryHints#
- imdb: <https://www.imdb.com/
- math: <http://www.w3.org/2005/xpath-functions/math#
- ontolex: <http://www.w3.org/ns/lemon/ontolex#
- owl: <http://www.w3.org/2002/07/owl#
- p: <http://www.wikidata.org/prop/
- pq: <http://www.wikidata.org/prop/qualifier/
- pqn: <http://www.wikidata.org/prop/qualifier/value-normalized/
- pqv: <http://www.wikidata.org/prop/qualifier/value/
- pr: <http://www.wikidata.org/prop/reference/
- prn: <http://www.wikidata.org/prop/reference/value-normalized/
- prov: <http://www.w3.org/ns/prov#
- prv: <http://www.wikidata.org/prop/reference/value/
- ps: <http://www.wikidata.org/prop/statement/
- psn: <http://www.wikidata.org/prop/statement/value-normalized/
- psv: <http://www.wikidata.org/prop/statement/value/
- qb: <http://purl.org/linked-data/cube#
- qfn: <http://qlever.cs.uni-freiburg.de/function#
- ql: <http://qlever.cs.uni-freiburg.de/builtin-functions/
- qlss: <https://qlever.cs.uni-freiburg.de/spatialSearch/
- rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#
- rdfs: <http://www.w3.org/2000/01/rdf-schema#
- ref: <http://www.wikidata.org/reference/
- s: <http://www.wikidata.org/entity/statement/
- schema: <http://schema.org/
- skos: <http://www.w3.org/2004/02/skos/core#
- v: <http://www.wikidata.org/value/
- void: <http://rdfs.org/ns/void#
- wd: <http://www.wikidata.org/entity/
- wdno: <http://www.wikidata.org/prop/novalue/
- wdt: <http://www.wikidata.org/prop/direct/
- wdtn: <http://www.wikidata.org/prop/direct-normalized/
- wikibase: <http://wikiba.se/ontology#
- xsd: <http://www.w3.org/2001/XMLSchema#

Additional rules to follow:
- Explain your thought process before and after each step and function call.
- Do not just use or make up entity or property identifiers without verifying their existence in the knowledge graphs first.
- Do not ask the user for clarifications without first attempting to complete the task. If the task input is incomplete or ambiguous, try to make reasonable assumptions and document them.
- Do not use "SERVICE wikibase:label { bd:serviceParam wikibase:language ..." in SPARQL queries. It is not SPARQL standard and unsupported by the used QLever SPARQL endpoints. Use rdfs:label or similar properties to get labels instead.
- Always execute your final SPARQL query before giving an answer to make sure it returns the expected results.
- The SPARQL query should always return the actual identifiers / IRIs of the items in its result. It additionally may return labels or other human-readable information, but they are optional and should be put within optional clauses unless explicitly requested by the user.
- Do not stop early if there are still obvious improvements to be made to the SPARQL query. For example, keep refining your SPARQL query if its result contains irrelevant items or is missing items you expected.
- Do not perform additional computation (e.g. filtering, sorting, calculations) on the result of the SPARQL query to determine the answer. All computation should be done solely within SPARQL.
- For questions with a "True" or "False" answer the SPARQL query should be an ASK query.

[User] what is serbian language called?

[Assistant]
To determine what the Serbian language is called, I need to find the name of the Serbian language in the knowledge graph. This typically involves identifying the entity for the Serbian language and retrieving its label.

### Step 1: Search for the Serbian language entity
I will first search for the entity representing the Serbian language using the `search_entity` function.

Question: serbian language

Top 10 entity alternatives:
1. Serbian (wd:Q9299, matched via Serbian language), also known as Serbian language, Srpski: standardized variety of Serbo-Croatian language used by Serbs / is instance of pluricentric language variant / is subclass of Eastern Herzegovinian / is instance of standard variety / is instance of language
2. Sorbian (wd:Q25442, matched via Serbian language), also known as Serbian language, Wendic language, Wendish: Lechitic language spoken by the Sorbs / is instance of indigenous language / is instance of Lechitic / is subclass of Lechitic
3. Serbian Sign Language (wd:Q113203025): is subclass of Yugoslav Sign Language / is instance of sign language
4. History of Serbian (wd:Q31183797, matched via Serbian language history), also known as Serbian language history: is instance of aspect of history
5. Serbian language in Croatia (wd:Q20974148), also known as use of the Serbian language in Croatia: overview about the use of the Serbian language in Croatia / is subclass of languages of Croatia / is instance of language in an area / is subclass of Serbian
6. Institute for Serbian Language (wd:Q16082649): is instance of research institute / is instance of language regulator
7. Serbian language in Montenegro (wd:Q65201055): is subclass of languages of Montenegro / is instance of language in an area / is subclass of Serbian
8. romanization of Serbian (wd:Q7362708, matched via romanization of the Serbian language), also known as romanisation of Serbian, romanization of the Serbian language: overview about the romanization of the Serbian language / is subclass of romanisation / is subclass of romanization
9. Automatic conversion in Serbian language (wd:Q105549121)
10. English (wd:Q1860, matched via English (language)), also known as English (language), English language, English-language, English the Global Language, The English language: West Germanic language of Indo-European family / West Germanic language originating in England / is instance of standard language / is instance of literary language / is instance of natural language / is instance of modern language / is instance of macrolanguage / is instance of language / West Germanic language / is subclass of Anglic

[Assistant]
The top result, `wd:Q9299`, corresponds to the Serbian language. Now, I will retrieve the label for this entity to confirm what the Serbian language is called.

### Step 2: Retrieve the label for the Serbian language entity
I will use the `list` function to fetch the label of `wd:Q9299` using the `rdfs:label` property with a filter for English labels.

list

wd:Q9299

Got 178 rows and 3 columns, showing the first 10 rows below:
| subject            | property   | object                    |
| ------------------ | ---------- | ------------------------- |
| Serbian (wd:Q9299) | rdfs:label | Afaan Sarbiyaa (lang:om)  |
| Serbian (wd:Q9299) | rdfs:label | Amanung Serbyu (lang:pam) |
| Serbian (wd:Q9299) | rdfs:label | an tSeirbis (lang:ga)     |
| Serbian (wd:Q9299) | rdfs:label | Bahasa Serbia (lang:kge)  |
| Serbian (wd:Q9299) | rdfs:label | Bahasa Serbia (lang:ms)   |
| Serbian (wd:Q9299) | rdfs:label | Basa Serbia (lang:jv)     |
| Serbian (wd:Q9299) | rdfs:label | Èdè Sérbíà (lang:yo)      |
| Serbian (wd:Q9299) | rdfs:label | fiteny serba (lang:mg)    |
| Serbian (wd:Q9299) | rdfs:label | Gagana Serbia (lang:sm)   |
| Serbian (wd:Q9299) | rdfs:label | Idioma serbio (lang:an)   |
| ...                | ...        | ...                       |

[Assistant]
The results show labels for the Serbian language in various languages, but I need the English label to answer the question. I will now write a SPARQL query to specifically retrieve the English label for the Serbian language entity (`wd:Q9299`).

### Step 3: Write and execute a SPARQL query to get the English label
I will execute a SPARQL query that selects the English label (`rdfs:label`) for `wd:Q9299` with a filter for the English language.

execute

SELECT ?label WHERE { wd:Q9299 rdfs:label ?label . FILTER(LANG(?label) = "en") }

Got 1 row and 1 column:
| label             |
| ----------------- |
| Serbian (lang:en) |

[Assistant]
The English label for the Serbian language is "Serbian".

### Final Answer:
The Serbian language is called "Serbian" in English.

I will now provide the final SPARQL query and answer.

answer

SELECT ?label WHERE { wd:Q9299 rdfs:label ?label . FILTER(LANG(?label) = "en") }

Answer: Serbian


PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
SELECT ?instrument ?instrumentLabel WHERE {
  wd:Q191499 wdt:P1303 ?instrument .
  OPTIONAL {
    ?instrument rdfs:label ?instrumentLabel .
    FILTER ( LANG( ?instrumentLabel ) = "en" )
  }
  .
  FILTER ( ?instrument = wd:Q5994 )
}

Using entities:
- Scott Joplin (wd:Q191499), also known as The king of Ragtime: has occupation jazz musician / has occupation composer / has occupation pianist / has occupation banjoist / is instance of human / American composer, musician, and pianist / American composer, musician, and pianist
- piano (wd:Q5994), also known as concert grand piano, fortepiano, pianoforte, spinet, spinnet: is instance of type of musical instrument / is subclass of keyboard instrument / musical instrument / musical keyboard instrument

Using properties:
- instrument (wd:P1303 as wdt), also known as instrument played, instrument(s), instruments, instrument taught, musical instrument, etc.: is subproperty of uses / musical instrument that a person plays or teaches or used in a music occupation

Got 1 row and 2 columns:
| instrument       | instrumentLabel |
| ---------------- | --------------- |
| piano (wd:Q5994) | piano (lang:en) |

Answer: Scott Joplin played the piano.

Scott Joplin played the piano.

SPARQL query over wikidata:
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
SELECT ?instrument ?instrumentLabel WHERE {
  wd:Q191499 wdt:P1303 ?instrument .
  OPTIONAL {
    ?instrument rdfs:label ?instrumentLabel .
    FILTER ( LANG( ?instrumentLabel ) = "en" )
  }
  .
  FILTER ( ?instrument = wd:Q5994 )
}

Using entities:
- Scott Joplin (wd:Q191499), also known as The king of Ragtime: has occupation jazz musician / has occupation composer / has occupation pianist / has occupation banjoist / is instance of human / American composer, musician, and pianist / American composer, musician, and pianist
- piano (wd:Q5994), also known as concert grand piano, fortepiano, pianoforte, spinet, spinnet: is instance of type of musical instrument / is subclass of keyboard instrument / musical instrument / musical keyboard instrument

Using properties:
- instrument (wd:P1303 as wdt), also known as instrument played, instrument(s), instruments, instrument taught, musical instrument, etc.: is subproperty of uses / musical instrument that a person plays or teaches or used in a music occupation

Execution result:
Got 1 row and 2 columns:
| instrument       | instrumentLabel |
| ---------------- | --------------- |
| piano (wd:Q5994) | piano (lang:en) |

[System]
You are a question answering assistant. Your job is to generate a SPARQL query to answer a given user question.

You should follow a step-by-step approach to generate the SPARQL query:
1. Determine possible entities and properties implied by the user question.
2. Search for the entities and properties in the knowledge graphs. Where applicable, constrain the searches with already identified entities and properties.
3. Gradually build up the SPARQL query using the identified entities and properties. Start with simple queries and add more complexity as needed. Execute intermediate queries to get feedback and to verify your assumptions. You may need to refine or rethink your current plan based on the query results and go back to step 2 if needed, possibly multiple times.
4. Use the answer or cancel function to finalize your answer and stop the generation process.

Available knowledge graphs:
- wikidata at http://localhost:7001 with prefix index for entities and similarity index for properties, and notes:
  - P106 = occupation. Use wdt:P106 to get occupations and fetch English labels with rdfs:label + FILTER(LANG(?label)="en"). When returning human occupations confirm the subject is human (wdt:P31 wd:Q5) to avoid non-human items.
  - Population (P1082) and tabular (P4179): use wdt:P1082 for quick/direct values; for time-series/point-in-time use p:P1082 + ps:P1082 + pq:P585 and ORDER BY pq:P585 DESC. Inspect statement qualifiers (e.g., 'applies to part') and prov:wasDerivedFrom references (pr:P854 etc.) to detect city-proper vs metro/prefecture scopes before using values.
  - Common person properties: P31 (instance of human Q5), P106 (occupation), P569 (date of birth), P19 (place of birth), P27 (country of citizenship), P21 (sex/gender), P166 (award received). Use wdt: for direct values when possible.
  - P17 (country) can be incomplete/misleading for places (historical/overseas tags). To get modern cities in a country combine: instance-of city (P31=Q515) + wdt:P17 OR use wdt:P131* to find an admin parent whose wdt:P17 = the country. Also cross-check coordinates (P625) or admin hierarchy to spot outliers.
  - When filtering by date of birth (P569) use xsd:dateTime comparisons (e.g. >= "1900-01-01T00:00:00Z"^^xsd:dateTime). Be aware many items have year-only or imprecise dates and coverage is biased toward notable/public figures (sportspeople, politicians, artists).
  - To retrieve qualifiers (e.g., award year) use the statement/qualifier pattern: p:Pxxx / ps:Pxxx / pq:P585. Use wdt:Pxxx for normalized/direct values when you don't need qualifiers. Example: p:P166 + pq:P585 gives award year.
  - To get a person's occupations: use wdt:P106 for direct/normalized values and rdfs:label for human-readable names (FILTER(LANG(...))). Example: wd:Q... wdt:P106 ?occ . ?occ rdfs:label ?occLabel . FILTER(LANG(?occLabel)="en").
  - P166 = award received. Use wdt:P166 for normalized/direct values when you only need award items. To get award years or qualifiers use p:P166 / ps:P166 / pq:P585. Many statements lack pq:P585 — use OPTIONAL { ?stmt pq:P585 ?date } and ORDER BY DESC(?date). When listing award winners, filter ?person wdt:P31 wd:Q5 to ensure humans.
  - Population time-series pattern: wd:Q... p:P1082 ?stmt . ?stmt ps:P1082 ?pop . OPTIONAL { ?stmt pq:P585 ?date } . ORDER BY DESC(?date). pq:P585 is the point-in-time qualifier. IMPORTANT: time-series may mix scopes (city proper vs metro) — e.g., Tokyo has a 2016 entry ~38,140,000 likely metro vs smaller city figures. Inspect qualifiers/references for scope before use.
  - Use wdt:P131* to traverse the admin hierarchy and compare wdt:P17 on the place vs an admin parent to detect historical/colonial country assignments. When mismatches appear, inspect the admin parent's instance-of (P31), labels, qualifiers and references to interpret the historical scope.
  - wdt:P106 often yields multiple occupations for a person. Use GROUP_CONCAT(DISTINCT ?occLabel; separator=", ") or return multiple rows. Always fetch labels with rdfs:label + FILTER(LANG(?label)="en") to get readable occupation names.
  - When a search_entity returns multiple hits (person vs sculpture vs memorial), confirm you selected the human/statements by checking wdt:P31 (instance of) and relevant wdt: properties (e.g., wdt:P106). This avoids using a non-human QID by mistake.
  - search_autocomplete can be constrained with a SPARQL pattern containing ?search (e.g., SELECT * WHERE { ?search wdt:P31 wd:Q5 }). Use constraints to focus results (e.g., humans) and avoid ambiguous fallbacks; if it returns no results, fallback to search_entity and verify wdt:P31.
  - Use search_property_of_entity to find relevant properties for an entity (e.g., 'award' -> P166) and search_object_of_property to discover candidate objects (e.g., 'physicist' for P106). This reduces guessing P/Q ids and surfaces qualifiers.
  - Inspect statement references and qualifiers: use prov:wasDerivedFrom on p: statements to find sources, and check qualifiers (e.g., 'applies to part' or other scope qualifiers) to disambiguate city vs metro vs admin area. Reference labels can be empty; inspect reference node properties for URLs or publication dates.

Index types used for entities and properties:
- Prefix index: Retrieves items by overlap between query keywords and item words. The query keywords can match item words exactly or as prefixes.
- Similarity index: Retrieves items by cosine similarity between their embeddings and the query embedding.

General notes across knowledge graphs:
- Use rdfs:label + FILTER(LANG(?label)="en") for labels; avoid SERVICE wikibase:label. Use wdt:Pxxx for normalized/direct values when qualifiers aren't needed. Use p:Pxxx / ps:Pxxx / pq:Pxxx to access statement qualifiers (e.g., award year via pq:P585). When dates matter, prefer xsd:dateTime and watch for year-only precision.
- Practical query patterns: use rdfs:label + FILTER(LANG(...)) for labels. Use wdt:Pxxx for direct/normalized values when qualifiers aren't needed. Use p:Pxxx / ps:Pxxx / pq:Pxxx to access qualifiers (dates via pq:P585). For dates use xsd:dateTime and expect year-only precision. For places: combine P17 with P131 or coordinate (P625) filters to avoid historical/overseas mismatches.
- Use OPTIONAL for pq: qualifiers (e.g., pq:P585), sort by qualifier (ORDER BY pq:P585 DESC) to prefer recent values. Use GROUP_CONCAT to combine multiple labels/values in one row. Watch for typed literals (xsd:dateTime, xsd:decimal) when filtering or sorting.
- Before querying, use search_entity to resolve human-friendly names to wd:Q identifiers and verify instance-of (e.g., check wdt:P31 = wd:Q5 for humans) to avoid ambiguous matches. Prefer the top match but programmatically confirm P31 before using its data.
- Use search_property to confirm property identifiers (e.g., "country" -> P17) before embedding them in queries. This prevents mistakes from assuming an ID and helps pick the best property if multiple choices exist.
- search_autocomplete can fall back to an unconstrained search or error when there are too many candidates. If this happens (e.g., "more than the maximum supported number of subject candidates"), retry with narrower constraints such as instance-of (wdt:P31), additional type filters, or short prefixes to reduce the candidate set; otherwise fallback to search_entity and verify wdt:P31.
- Use list(...) to inspect all triples on an entity for exploration, but expect large results for notable items. Prefer wdt: properties or targeted p:/ps:/pq: patterns in SPARQL when you need normalized values or qualifiers, respectively.
- Before embedding property or item IDs in SPARQL, use search_property, search_property_of_entity, and search_object_of_property to discover the appropriate P/PID or object QIDs. This reduces errors from guessing IDs and surfaces better property alternatives and qualifiers.
- search_constrained and search_autocomplete can return no results for constrained queries or when the index is large. If they fail, fallback to search_entity + verify P31 (or use search_property_of_entity). Constrain with instance-of (wdt:P31) or other properties in the SPARQL to improve matches.
- When selecting awards by year, prefer xsd:dateTime range filters (e.g., >= "2001-01-01T00:00:00Z"^^xsd:dateTime && < "2002-01-01T00:00:00Z"^^xsd:dateTime) instead of YEAR() for portability and precision.
- When selecting award winners via wdt:P166, filter ?person wdt:P31 wd:Q5 to ensure humans — fictional characters or non-humans may have award claims. If you need award years use p:P166 / ps:P166 / pq:P585 and OPTIONAL { ?stmt pq:P585 ?year } to retrieve qualifier years.
- Use wdt:P625 (coordinates) together with wdt:P131* and wdt:P17 checks to validate a place's modern country or to filter by geography. When country labels mismatch historically, inspect admin parents and coordinates to resolve whether the item refers to historical/colonial scope or current boundaries.
- Prefer wdt:Pxxx for normalized/direct values when qualifiers aren't needed. Use p:Pxxx / ps:Pxxx / pq:Pxxx to access qualifiers (e.g., pq:P585 for award year). Always fetch labels with rdfs:label + FILTER(LANG(?label) = "en").
- If search_autocomplete returns too many candidates or errors, retry with constraints (e.g., SELECT * WHERE { ?search wdt:P31 wd:Q5 }) or narrower query text. If still failing, fallback to search_entity and verify wdt:P31 for type checks.
- For award-year queries use p:P166 / ps:P166 / pq:P585 to access award statements and year qualifiers. Filter by xsd:dateTime ranges (e.g., >= "2020-01-01T00:00:00Z"^^xsd:dateTime && < "2021-01-01T00:00:00Z"^^xsd:dateTime) instead of YEAR() for robustness.
- Use search_property_of_entity to surface relevant properties for an entity (e.g., 'birth' -> P569/P19). list(...) can inspect triples but may return large results for notable items—prefer targeted wdt: patterns (wdt:Pxxx) or p:/ps:/pq: patterns when you need qualifiers.

SPARQL prefixes for use in function calls:
- bd: <http://www.bigdata.com/rdf#
- cc: <http://creativecommons.org/ns#
- data: <https://www.wikidata.org/wiki/Special:EntityData/
- dc: <http://purl.org/dc/elements/1.1/
- dct: <http://purl.org/dc/terms/
- foaf: <http://xmlns.com/foaf/0.1/
- geo: <http://www.opengis.net/ont/geosparql#
- geof: <http://www.opengis.net/def/function/geosparql/
- gn: <http://www.geonames.org/ontology#
- hint: <http://www.bigdata.com/queryHints#
- imdb: <https://www.imdb.com/
- math: <http://www.w3.org/2005/xpath-functions/math#
- ontolex: <http://www.w3.org/ns/lemon/ontolex#
- owl: <http://www.w3.org/2002/07/owl#
- p: <http://www.wikidata.org/prop/
- pq: <http://www.wikidata.org/prop/qualifier/
- pqn: <http://www.wikidata.org/prop/qualifier/value-normalized/
- pqv: <http://www.wikidata.org/prop/qualifier/value/
- pr: <http://www.wikidata.org/prop/reference/
- prn: <http://www.wikidata.org/prop/reference/value-normalized/
- prov: <http://www.w3.org/ns/prov#
- prv: <http://www.wikidata.org/prop/reference/value/
- ps: <http://www.wikidata.org/prop/statement/
- psn: <http://www.wikidata.org/prop/statement/value-normalized/
- psv: <http://www.wikidata.org/prop/statement/value/
- qb: <http://purl.org/linked-data/cube#
- qfn: <http://qlever.cs.uni-freiburg.de/function#
- ql: <http://qlever.cs.uni-freiburg.de/builtin-functions/
- qlss: <https://qlever.cs.uni-freiburg.de/spatialSearch/
- rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#
- rdfs: <http://www.w3.org/2000/01/rdf-schema#
- ref: <http://www.wikidata.org/reference/
- s: <http://www.wikidata.org/entity/statement/
- schema: <http://schema.org/
- skos: <http://www.w3.org/2004/02/skos/core#
- v: <http://www.wikidata.org/value/
- void: <http://rdfs.org/ns/void#
- wd: <http://www.wikidata.org/entity/
- wdno: <http://www.wikidata.org/prop/novalue/
- wdt: <http://www.wikidata.org/prop/direct/
- wdtn: <http://www.wikidata.org/prop/direct-normalized/
- wikibase: <http://wikiba.se/ontology#
- xsd: <http://www.w3.org/2001/XMLSchema#

Additional rules to follow:
- Explain your thought process before and after each step and function call.
- Do not just use or make up entity or property identifiers without verifying their existence in the knowledge graphs first.
- Do not ask the user for clarifications without first attempting to complete the task. If the task input is incomplete or ambiguous, try to make reasonable assumptions and document them.
- Do not use "SERVICE wikibase:label { bd:serviceParam wikibase:language ..." in SPARQL queries. It is not SPARQL standard and unsupported by the used QLever SPARQL endpoints. Use rdfs:label or similar properties to get labels instead.
- Always execute your final SPARQL query before giving an answer to make sure it returns the expected results.
- The SPARQL query should always return the actual identifiers / IRIs of the items in its result. It additionally may return labels or other human-readable information, but they are optional and should be put within optional clauses unless explicitly requested by the user.
- Do not stop early if there are still obvious improvements to be made to the SPARQL query. For example, keep refining your SPARQL query if its result contains irrelevant items or is missing items you expected.
- Do not perform additional computation (e.g. filtering, sorting, calculations) on the result of the SPARQL query to determine the answer. All computation should be done solely within SPARQL.
- For questions with a "True" or "False" answer the SPARQL query should be an ASK query.

[User] what did scott joplin play?

[Assistant]
To determine what Scott Joplin played, I need to find information about his musical instruments or roles as a musician. Scott Joplin is known as a composer and pianist, particularly famous for his ragtime compositions.

Step 1: Search for Scott Joplin in Wikidata to get his entity identifier.

Question: scott joplin

Top 10 entity alternatives:
1. Scott Joplin (wd:Q191499), also known as The king of Ragtime: American composer, musician, and pianist / American composer, musician, and pianist / has occupation jazz musician / has occupation composer / has occupation banjoist / has occupation pianist / is instance of human
2. Scott Joplin (wd:Q12127336): 1977 film by Jeremy Kagan / is instance of film
3. Scott Joplin (wd:Q28730081): is instance of painting / painting by Ellen Banks / painting by Ellen Banks
4. Scott Joplinlaan (wd:Q19513256): street in Eindhoven, the Netherlands / street in Eindhoven, the Netherlands / street in Eindhoven, the Netherlands / is instance of street
5. Scott Joplinrode (wd:Q19513257): street in Zoetermeer, the Netherlands / is instance of street
6. Scott Joplin: Piano Rags (wd:Q7436590): album by Joshua Rifkin / is instance of album
7. Scott Joplin: Questions Remain (wd:Q113214829): scientific article published on 18 April 2006 / scientific article published on 18 April 2006 / scientific article published on 18 April 2006 / is instance of scholarly article / is instance of academic article
8. Scott Joplin's foot (wd:Q30538526): scientific article published on July 1, 1998 / is instance of scholarly article / is instance of academic article
9. Scott Joplin’s New Rag (wd:Q29003610): ragtime composition for piano by Scott Joplin / is instance of musical work/composition
10. Scott Joplin: Complete Piano Works (wd:Q28156183), also known as The Collected Works of Scott Joplin: is instance of written work / book by Scott Joplin

[Assistant]
The top result is Scott Joplin (wd:Q191499), identified as an American composer, musician, and pianist. This is the correct entity for the historical figure. I will now investigate his occupations and any direct information about the instruments he played.

Step 2: Examine the properties of Scott Joplin (wd:Q191499) to find details about his musical roles or instruments.

list

wd:Q191499

Got 666 rows and 3 columns, showing the first 10 rows below:
| subject                   | property                         | object                                                                          |
| ------------------------- | -------------------------------- | ------------------------------------------------------------------------------- |
| Scott Joplin (wd:Q191499) | instance of (wdt:P31)            | human (wd:Q5)                                                                   |
| Scott Joplin (wd:Q191499) | occupation (wdt:P106)            | composer (wd:Q36834)                                                            |
| Scott Joplin (wd:Q191499) | sex or gender (wdt:P21)          | male (wd:Q6581097)                                                              |
| Scott Joplin (wd:Q191499) | given name (wdt:P735)            | Scott (wd:Q2260734)                                                             |
| Scott Joplin (wd:Q191499) | date of birth (wdt:P569)         | 1868-01-01T00:00:00Z (xsd:dateTime)                                             |
| Scott Joplin (wd:Q191499) | Commons category (wdt:P373)      | Scott Joplin                                                                    |
| Scott Joplin (wd:Q191499) | image (wdt:P18)                  | <http://commons.wikimedia.org/wiki/Special:FilePath/Scott%20Joplin%2019072.jpg> |
| Scott Joplin (wd:Q191499) | family name (wdt:P734)           | Japlin (wd:Q16871206)                                                           |
| Scott Joplin (wd:Q191499) | country of citizenship (wdt:P27) | United States (wd:Q30)                                                          |
| Scott Joplin (wd:Q191499) | Freebase ID (wdt:P646)           | /m/07b69                                                                        |
| ...                       | ...                              | ...                                                                             |

[Assistant]
From the list, I can see that Scott Joplin's occupation includes "composer" (wd:Q36834). However, I need to find information about the instrument he played. The occupation "pianist" is mentioned in the entity description, but it is not directly listed in the triples. This suggests that "pianist" might be a qualifier or part of a more detailed statement.

Step 3: Search for properties related to "pianist" or "instrument" for Scott Joplin to see if there is a more specific statement about his musical role.

Question: pianist

Top 10 property alternatives:
1. instrument (wd:P1303 as p/wdt, matched via instrument played), also known as instrument played, instrument(s), instruments, instrument taught, musical instrument, etc.: musical instrument that a person plays or teaches or used in a music occupation / is subproperty of uses
2. Musicalics composer ID (wd:P6925 as p/wdt), also known as P6925: identifier for a composer in the Musicalics database
3. Bibliothèque nationale de France ID (wd:P268 as p/wdt/wdtn, matched via RAMEAU identifier), also known as Bibliothèque nationale de France identifier, BnF ID, BnF identifier, National Library of France ID, RAMEAU ID, etc.: identifier for the subject issued by BNF (Bibliothèque ... by a check-digit or letter, do not include the initial 'cb'. / identifier for the subject issued by BNF (Bibliothèque ... by a check-digit or letter, do not include the initial 'cb'. / identifier for the subject issued by BNF (Bibliothèque ... by a check-digit or letter, do not include the initial 'cb'.
4. Musicsperlacobla composer ID (wd:P11203 as p/wdt), also known as P11203: composer identifier used by musicsperlacobla archive
5. pseudonym (wd:P742 as p/wdt, matched via artistic name), also known as alias, artistic name, code name, heteronym, known professionally as, etc.: alias used by someone (for nickname use P1449) / alias used by someone (for nickname use P1449) / is subproperty of name
6. signature (wd:P109 as p/wdt, matched via autograph), also known as autograph, facsimiles, image of signature, signature image, P109: image of a person's signature / image of a person's signature / image of a person's signature / is subproperty of image
7. Gran Enciclopèdia de la Música ID (wd:P6412 as p/wdt), also known as P6412: identifier for an item in the Gran Enciclopèdia de la Música
8. MuseScore artist ID (wd:P8334 as p/wdt), also known as MuseScore ID, P8334: identifier for an artist on MuseScore / identifier for an artist on MuseScore / identifier for an artist on MuseScore
9. Muziekweb performer ID (wd:P5882 as p/wdt, matched via Muziekweb artist ID), also known as Muziekweb artist ID, Muziekweb band ID, P5882: identifier for a performer, composer or band at Muziekweb
10. AllMusic artist ID (wd:P1728 as p/wdt, matched via amg artist), also known as AllMusic, AllMusic ID, amg artist, P1728: identifier for an artist, musical group, or record label in the AllMusic database (record labels are listed as "artists") / identifier for an artist in AllMusic database

No other items found

[Assistant]
The property "instrument" (wdt:P1303) is listed as a relevant property, which is described as "musical instrument that a person plays." This is exactly what I need to find out what instrument Scott Joplin played.

Step 4: Query for the instrument Scott Joplin played using the wdt:P1303 property.

execute

SELECT ?instrument WHERE { wd:Q191499 wdt:P1303 ?instrument }

[Assistant]
The query results show that Scott Joplin played multiple instruments: cornet, piano, guitar, and violin. However, Scott Joplin is most famously known as a pianist and composer of ragtime music, with the piano being his primary instrument.

To confirm the most relevant and well-documented instrument, I will check the labels of these instruments in English to ensure clarity and context.

Step 5: Retrieve the English labels for the instruments to confirm their names.

SELECT ?instrument ?instrumentLabel WHERE { wd:Q191499 wdt:P1303 ?instrument . OPTIONAL { ?instrument rdfs:label ?instrumentLabel . FILTER(LANG(?instrumentLabel) = "en") } }

Got 4 rows and 2 columns:
| instrument          | instrumentLabel  |
| ------------------- | ---------------- |
| cornet (wd:Q202027) | cornet (lang:en) |
| piano (wd:Q5994)    | piano (lang:en)  |
| guitar (wd:Q6607)   | guitar (lang:en) |
| violin (wd:Q8355)   | violin (lang:en) |

[Assistant]
The results confirm that Scott Joplin played the cornet, piano, guitar, and violin. However, historical records and his legacy primarily associate him with the piano, as he was a renowned pianist and composer of ragtime music for the piano.

While he may have played other instruments, the piano is the most significant and well-documented instrument associated with him. Therefore, the answer to the question "What did Scott Joplin play?" is primarily the piano, with additional instruments being secondary.

Final SPARQL query to return the primary instrument (piano) with its label:

SELECT ?instrument ?instrumentLabel WHERE { wd:Q191499 wdt:P1303 ?instrument . OPTIONAL { ?instrument rdfs:label ?instrumentLabel . FILTER(LANG(?instrumentLabel) = "en") } . FILTER(?instrument = wd:Q5994) }

Got 1 row and 2 columns:
| instrument       | instrumentLabel |
| ---------------- | --------------- |
| piano (wd:Q5994) | piano (lang:en) |

[Assistant]
The query confirms that Scott Joplin played the piano, which is his most renowned and historically significant instrument. While he may have played other instruments, the piano is the primary one associated with his legacy.

Final answer:

answer

SELECT ?instrument ?instrumentLabel WHERE { wd:Q191499 wdt:P1303 ?instrument . OPTIONAL { ?instrument rdfs:label ?instrumentLabel . FILTER(LANG(?instrumentLabel) = "en") } . FILTER(?instrument = wd:Q5994) }

Answer: Scott Joplin played the piano.