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 ?place ?placeLabel WHERE {
  wd:Q8027 wdt:P20 ?place .
  ?place rdfs:label ?placeLabel .
  FILTER ( LANG( ?placeLabel ) = "en" )
}

Using entities:
- Martin Luther King Jr. (wd:Q8027): has occupation writer / has occupation politician / has occupation opinion journalist / has occupation preacher / has occupation civil rights advocate / has occupation peace activist / has occupation pacifist / has occupation pastor / has occupation human rights activist / is instance of human / American Baptist minister and civil rights leader (1929–1968) / American Baptist minister and civil rights leader (1929–1968) / American clergyman, activist and leader in the American Civil Rights Movement

Using properties:
- place of death (wd:P20 as wdt), also known as death location, death place, deathplace, died, died in, etc.: is subproperty of location / most specific known (e.g. city instead of country, or ... death location of a person, animal or fictional character / most specific known (e.g. city instead of country, or ... death location of a person, animal or fictional character / most specific known (e.g. city instead of country, or ... death location of a person, animal or fictional character

Answer: Martin Luther King Jr. was assassinated in Memphis.

Martin Luther King Jr. was assassinated in Memphis.

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 ?place ?placeLabel WHERE {
  wd:Q8027 wdt:P20 ?place .
  ?place rdfs:label ?placeLabel .
  FILTER ( LANG( ?placeLabel ) = "en" )
}

Using entities:
- Martin Luther King Jr. (wd:Q8027): has occupation writer / has occupation politician / has occupation opinion journalist / has occupation preacher / has occupation civil rights advocate / has occupation peace activist / has occupation pacifist / has occupation pastor / has occupation human rights activist / is instance of human / American Baptist minister and civil rights leader (1929–1968) / American Baptist minister and civil rights leader (1929–1968) / American clergyman, activist and leader in the American Civil Rights Movement

Using properties:
- place of death (wd:P20 as wdt), also known as death location, death place, deathplace, died, died in, etc.: is subproperty of location / most specific known (e.g. city instead of country, or ... death location of a person, animal or fictional character / most specific known (e.g. city instead of country, or ... death location of a person, animal or fictional character / most specific known (e.g. city instead of country, or ... death location of a person, animal or fictional character

Execution result:
Got 1 row and 2 columns:
| place               | placeLabel        |
| ------------------- | ----------------- |
| Memphis (wd:Q16563) | Memphis (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 town was martin luther king assassinated in?

[Assistant]
To determine the town where Martin Luther King Jr. was assassinated, I will follow these steps:

1. Identify the entity for Martin Luther King Jr. using `search_entity`.
2. Investigate his death-related properties, particularly the location of his assassination, using `search_property_of_entity`.
3. Construct a SPARQL query to retrieve the location (town) of his assassination.
4. Execute the query and return the result.

Let me begin with step 1: searching for Martin Luther King Jr. in Wikidata.

Question: martin luther king

Top 10 entity alternatives:
1. Martin Luther King Sr. (wd:Q2603376, matched via Martin Luther King), also known as Martin Luther King: American baptist pastor (1899–1984) / has occupation Christian minister / is instance of human
2. Martin Luther King (wd:Q123135762): Indian Telugu-language political satire film directed by Puja Kolluru / is instance of film
3. Martin Luther King (wd:Q124695769): painting by Alexey Akindinov / is instance of painting
4. Martin Luther King (wd:Q127414862): railway underpass in Helmond, the Netherlands / is instance of railway bridge
5. Martin Luther King (wd:Q126859789): written work by Mario Escobar / is instance of written work
6. Martin Luther King (wd:Q126859837): is instance of version, edition or translation / 2006 edition of written work by Mario Escobar
7. Martin Luther King (wd:Q110616895): is instance of streetcar stop / is instance of tram stop
8. Martin Luther King (wd:Q19338319): street in Culemborg, the Netherlands / is instance of street
9. Martin Luther King (wd:Q52858919): primary school in Florence, Florence, Tuscany, Italy / is instance of elementary school / is instance of Elementary school / is instance of primary school
10. Martin Luther King (wd:Q52755150): primary school in Pistoia, Pistoia, Tuscany, Italy / is instance of lower secondary school

[Assistant]
The top result, `wd:Q2603376`, corresponds to Martin Luther King Sr., the father of Martin Luther King Jr. This is not the correct entity. The actual Martin Luther King Jr. is likely among the results but not listed in the top 10. I will refine the search by explicitly including "Jr." in the query to narrow down the results.

Let me perform the search again with "Martin Luther King Jr.".

Question: martin luther king jr

Top 10 entity alternatives:
1. Martin Luther King Jr. (wd:Q8027): American clergyman, activist and leader in the American Civil Rights Movement / American Baptist minister and civil rights leader (1929–1968) / American Baptist minister and civil rights leader (1929–1968) / has occupation civil rights advocate / has occupation human rights activist / has occupation opinion journalist / has occupation peace activist / has occupation politician / has occupation preacher / has occupation pacifist / has occupation writer / has occupation pastor / is instance of human
2. Martin Luther King Jr. (wd:Q16974341): station on the Crenshaw Line, currently under construction / is instance of streetcar stop / is instance of tram stop
3. Martin Luther King, Jr. (wd:Q6776048): sculpture by John Woodrow Wilson / is instance of sculpture
4. Martin Luther King Jr. (wd:Q39073111): Outdoor bronze sculpture depicting the American civil rights leader  installed on the University of Texas at Austin campus. / is instance of work of art / is instance of Work of art
5. Martin Luther King, Jr. (wd:Q116445650): print at the Metropolitan Museum of Art (MET, 2022.102) / is instance of print
6. Martin Luther King, Jr. (wd:Q111842410): sculpture by artist unknown / is instance of sculpture
7. Martin Luther King, Jr. (wd:Q65577725): print in the National Gallery of Art (NGA 59040) / is instance of print
8. Martin Luther King, Jr. (wd:Q63570975): technical material in the National Gallery of Art (NGA 59039) / is instance of Work of art / is instance of work of art
9. Martin Luther King, Jr. (wd:Q47511447): painting by Boris Chaliapin / painting by Boris Chaliapin / is instance of painting
10. Martin Luther King, Jr. (wd:Q47509396): painting by Robert Vickrey / painting by Robert Vickrey / is instance of painting

[Assistant]
The top result, `wd:Q8027`, is clearly the correct entity for Martin Luther King Jr., as it describes him as an American clergyman, activist, and leader in the American Civil Rights Movement, with the lifespan (1929–1968). I will now investigate the properties related to his death, particularly the location of his assassination, using `search_property_of_entity`.

Let me search for properties related to "death" or "assassination" for Martin Luther King Jr.

Question: death

Top 10 property alternatives:
1. date of death (wd:P570 as p/wdt, matched via death), also known as date of the end, dead, death, death date, deathdate, etc.: is subproperty of dissolved, abolished or demolished date / is subproperty of dissolved, abolished or demolished / date on which the subject died / date on which the subject died / date on which the subject died / is subproperty of end time
2. manner of death (wd:P1196 as p/wdt, matched via death manner), also known as circumstance of death, death manner, death type, nature of death, type of death, etc.: general circumstances of a person's death; e.g. natural ... mechanism, e.g. heart attack, trauma, pneumonia etc. / general circumstances of a person's death; e.g. natural ... mechanism, e.g. heart attack, trauma, pneumonia etc. / general circumstances of a person's death; e.g. natural ... mechanism, e.g. heart attack, trauma, pneumonia...
3. place of death (wd:P20 as p/wdt, matched via death place), also known as death location, death place, deathplace, died, died in, etc.: most specific known (e.g. city instead of country, or ... death location of a person, animal or fictional character / most specific known (e.g. city instead of country, or ... death location of a person, animal or fictional character / most specific known (e.g. city instead of country, or ... death location of a person, animal or fictional character / is subproperty of location
4. cause of death (wd:P509 as p/wdt, matched via death cause), also known as death cause, died of, die from, die of, method of murder, etc.: underlying or immediate cause of death.  Underlying cause ... category, e.g. natural causes, accident, homicide, suicide / underlying or immediate cause of death.  Underlying cause ... category, e.g. natural causes, accident, homicide, suicide / an item describing the cause of a person or specific organism's death. Samples: leukaemia, car crash / medical cause of a person or specific organism's death (not to be confused with P1196)
5. killed by (wd:P157 as p/wdt), also known as assassin, assassinated by, executed by, executioner, killer, etc.: person or organization who killed the subject / is subproperty of significant person / person who killed the subject
6. place of burial (wd:P119 as p/wdt, matched via interment), also known as ashes scattered at, burial location, burial place, buried at, buried in, etc.: location of grave, resting place, place of ash-scattering, ... places: e.g., re-burials, parts of body buried separately. / location of grave, resting place, place of ash-scattering, ... places: e.g., re-burials, parts of body buried separately. / location of grave, resting place, place of ash-scattering, ... e.g. re-burials, cenotaphs, parts of body buried separately / location of grave, resting place, place of ash-scattering, etc, (e.g. city or cemetery) for a person / is subproperty of location
7. significant event (wd:P793 as p/wdt, matched via outcome), also known as big event, event, fate, important event, key event, etc.: significant or notable events associated with the subject / significant or notable events associated with the subject / significant or notable events associated with the subject
8. birth name (wd:P1477 as p/wdt, matched via nee), also known as birthname, bn, bname, born as, full birth name, etc.: full name of a person at birth, if different from their ... John Peter Doe for Joe Doe, Ann Smith for Ann Miller) / full name of a person at birth, if different from their current, generally used name / full name of a person at birth, if different from their current name / is subproperty of name
9. image of grave (wd:P1442 as p/wdt, matched via tombstone image), also known as cenotaph image, grave image, grave photo, grave picture, grave stone image, etc.: picture of a person or animal's grave, gravestone or tomb / picture of a person or animal's grave, gravestone or tomb / picture of a person or animal's grave, gravestone or tomb / is subproperty of image
10. ethnic group (wd:P172 as p/wdt, matched via race), also known as (cultural) nationality, culture, ethnicity, ethnic or cultural origin, people, etc.: subject's ethnicity (consensus is that a VERY high standard ... on by scholars, or 3) is fictional and portrayed as such) / subject's ethnicity (consensus is that a VERY high standard ... on by scholars, or 3) is fictional and portrayed as such)

No other items found

[Assistant]
The property `wdt:P20` (place of death) is the most relevant for determining where Martin Luther King Jr. was assassinated. I will now construct a SPARQL query to retrieve the place of death for Martin Luther King Jr. using this property.

The query will:
- Select the place of death (`wdt:P20`) for `wd:Q8027` (Martin Luther King Jr.).
- Retrieve the label of the place in English for better readability.

Let me execute this query.

execute

SELECT ?place ?placeLabel WHERE { wd:Q8027 wdt:P20 ?place . 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]
I see that the use of `SERVICE wikibase:label` caused an error because it is not supported in this SPARQL endpoint. I will revise the query to use `rdfs:label` with a language filter instead, as per the guidelines.

The corrected query will:
- Retrieve the place of death (`wdt:P20`) for Martin Luther King Jr.
- Fetch the English label of the place using `rdfs:label` and `FILTER(LANG(?placeLabel) = "en")`.

Let me execute the corrected SPARQL query.

SELECT ?place ?placeLabel WHERE { wd:Q8027 wdt:P20 ?place . ?place rdfs:label ?placeLabel . FILTER(LANG(?placeLabel) = "en") }

[Assistant]
The query successfully returned the place of death for Martin Luther King Jr. as Memphis, with the Wikidata identifier `wd:Q16563`. The label confirms that the location is "Memphis" in English.

Thus, Martin Luther King Jr. was assassinated in Memphis.

I will now provide the final answer with the SPARQL query used.

answer

SELECT ?place ?placeLabel WHERE { wd:Q8027 wdt:P20 ?place . ?place rdfs:label ?placeLabel . FILTER(LANG(?placeLabel) = "en") }

Answer: Martin Luther King Jr. was assassinated in Memphis.


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 ?country ?countryLabel WHERE {
  wd:Q6583 wdt:P131 ?country .
  ?country rdfs:label ?countryLabel .
  FILTER ( LANG( ?countryLabel ) = "en" )
}

Using entities:
- Sahara (wd:Q6583), also known as al-Sahara, al-Sahra, as-Sahra, as-Sahra al-Kubra, aṣ-Ṣaḥrāʾ al-Kubrā, etc.: is instance of desert / is instance of Desert / desert in Africa / desert on the African continent

Using properties:
- located in the administrative territorial entity (wd:P131 as wdt), also known as administrative territorial entity, administrative territory, city, happens in, in, etc.: is subproperty of location / is subproperty of part of / the item is located on the territory of the following administrative entity / the item is located on the territory of the following administrative entity / the item is located on the territory of the following ... the item falls only partially into the administrative entity. / the item is located on the territory of the following ... the item falls only partially into the administrative entity.

Got 9 rows and 2 columns:
| country               | countryLabel         |
| --------------------- | -------------------- |
| Libya (wd:Q1016)      | Libya (lang:en)      |
| Mauritania (wd:Q1025) | Mauritania (lang:en) |
| Morocco (wd:Q1028)    | Morocco (lang:en)    |
| Sudan (wd:Q1049)      | Sudan (lang:en)      |
| Algeria (wd:Q262)     | Algeria (lang:en)    |
| Chad (wd:Q657)        | Chad (lang:en)       |
| Egypt (wd:Q79)        | Egypt (lang:en)      |
| Mali (wd:Q912)        | Mali (lang:en)       |
| Tunisia (wd:Q948)     | Tunisia (lang:en)    |

Answer:
The Sahara Desert is located in the following nine countries in North Africa:

- Algeria
- Chad
- Egypt
- Libya
- Mali
- Mauritania
- Morocco
- Sudan
- Tunisia

These countries are confirmed through the administrative hierarchy (P131) of the Sahara Desert (wd:Q6583), and their names are retrieved in English using rdfs:label with the language filter.

Final SPARQL query:
```sparql
SELECT ?country ?countryLabel WHERE {
  wd:Q6583 wdt:P131 ?country .
  ?country rdfs:label ?countryLabel .
  FILTER(LANG(?countryLabel) = "en")
}
```

Answer: The Sahara Desert is located in Algeria, Chad, Egypt, Libya, Mali, Mauritania, Morocco, Sudan, and Tunisia.

The Sahara Desert is located in the following nine countries in North Africa:

- Algeria
- Chad
- Egypt
- Libya
- Mali
- Mauritania
- Morocco
- Sudan
- Tunisia

These countries are confirmed through the administrative hierarchy (P131) of the Sahara Desert (wd:Q6583), and their names are retrieved in English using rdfs:label with the language filter.

Final SPARQL query:
```sparql
SELECT ?country ?countryLabel WHERE {
  wd:Q6583 wdt:P131 ?country .
  ?country rdfs:label ?countryLabel .
  FILTER(LANG(?countryLabel) = "en")
}
```

Answer: The Sahara Desert is located in Algeria, Chad, Egypt, Libya, Mali, Mauritania, Morocco, Sudan, and Tunisia.

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 ?country ?countryLabel WHERE {
  wd:Q6583 wdt:P131 ?country .
  ?country rdfs:label ?countryLabel .
  FILTER ( LANG( ?countryLabel ) = "en" )
}

Using entities:
- Sahara (wd:Q6583), also known as al-Sahara, al-Sahra, as-Sahra, as-Sahra al-Kubra, aṣ-Ṣaḥrāʾ al-Kubrā, etc.: is instance of desert / is instance of Desert / desert in Africa / desert on the African continent

Using properties:
- located in the administrative territorial entity (wd:P131 as wdt), also known as administrative territorial entity, administrative territory, city, happens in, in, etc.: is subproperty of location / is subproperty of part of / the item is located on the territory of the following administrative entity / the item is located on the territory of the following administrative entity / the item is located on the territory of the following ... the item falls only partially into the administrative entity. / the item is located on the territory of the following ... the item falls only partially into the administrative entity.

Execution result:
Got 9 rows and 2 columns:
| country               | countryLabel         |
| --------------------- | -------------------- |
| Libya (wd:Q1016)      | Libya (lang:en)      |
| Mauritania (wd:Q1025) | Mauritania (lang:en) |
| Morocco (wd:Q1028)    | Morocco (lang:en)    |
| Sudan (wd:Q1049)      | Sudan (lang:en)      |
| Algeria (wd:Q262)     | Algeria (lang:en)    |
| Chad (wd:Q657)        | Chad (lang:en)       |
| Egypt (wd:Q79)        | Egypt (lang:en)      |
| Mali (wd:Q912)        | Mali (lang:en)       |
| Tunisia (wd:Q948)     | Tunisia (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] where are the sahara desert located?

[Assistant]
The Sahara Desert is a large desert in North Africa. To determine its location, I need to find the geographic and administrative details of the Sahara Desert in the knowledge graph.

First, I will search for the entity "Sahara Desert" to identify its correct identifier in Wikidata.

Question: Sahara Desert

Top 10 entity alternatives:
1. Sahara (wd:Q6583, matched via Sahara Desert), also known as al-Sahara, al-Sahra, as-Sahra, as-Sahra al-Kubra, aṣ-Ṣaḥrāʾ al-Kubrā, etc.: desert on the African continent / is instance of desert / is instance of Desert / desert in Africa
2. Sahara Desert (wd:Q3889421): is instance of WWF ecoregion / is instance of ecoregion / ecoregion
3. Sahara (Desert) (wd:Q104765650): painting by Jan Ciągliński (MNK MNK II-b-422) / painting by Jan Ciągliński / is instance of painting
4. Sahara (Desert) (wd:Q104765639): painting by Jan Ciągliński (MNK MNK II-b-419) / painting by Jan Ciągliński / is instance of painting
5. Sahara (Desert) (wd:Q104765619): painting by Jan Ciągliński (MNK MNK II-b-426) / painting by Jan Ciągliński / is instance of painting
6. Sahara (Desert) (wd:Q104765585): painting by Jan Ciągliński / painting by Jan Ciągliński / is instance of painting
7. Cataglyphis bicolor (wd:Q1717126, matched via Sahara desert ant), also known as Sahara desert ant: is instance of taxon / species of insect
8. South Saharan steppe and woodlands (wd:Q3890655, matched via South Sahara desert), also known as South Sahara desert: South Sahara desert ecoregion / is instance of WWF ecoregion / is instance of ecoregion
9. South Sahara Desert Ecoregion (wd:Q124457496): is instance of One Earth Ecoregion / One Earth Ecoregion
10. West Sahara Desert Ecoregion (wd:Q124309065): is instance of One Earth Ecoregion

[Assistant]
The primary entity for the Sahara Desert is `wd:Q6583` (Sahara), which is described as a desert on the African continent. I will now investigate its location by checking its geographic coordinates (P625) and administrative hierarchy (P131) to determine the countries it spans.

I will use the `list` function to retrieve triples related to `wd:Q6583` to explore its properties.

list

wd:Q6583

[Assistant]
The Sahara Desert has a central geographic coordinate at approximately POINT(12.612222 23.079722), which places it in North Africa. Now, I will check the administrative hierarchy (P131) to determine which countries the Sahara Desert spans. This will help identify the nations where the desert is located.

I will query for the P131 (located in the administrative territorial entity) property of the Sahara Desert.

wd:Q6583

Got 9 rows and 3 columns:
| subject           | property                                                    | object                |
| ----------------- | ----------------------------------------------------------- | --------------------- |
| Sahara (wd:Q6583) | located in the administrative territorial entity (wdt:P131) | Egypt (wd:Q79)        |
| Sahara (wd:Q6583) | located in the administrative territorial entity (wdt:P131) | Algeria (wd:Q262)     |
| Sahara (wd:Q6583) | located in the administrative territorial entity (wdt:P131) | Libya (wd:Q1016)      |
| Sahara (wd:Q6583) | located in the administrative territorial entity (wdt:P131) | Sudan (wd:Q1049)      |
| Sahara (wd:Q6583) | located in the administrative territorial entity (wdt:P131) | Morocco (wd:Q1028)    |
| Sahara (wd:Q6583) | located in the administrative territorial entity (wdt:P131) | Tunisia (wd:Q948)     |
| Sahara (wd:Q6583) | located in the administrative territorial entity (wdt:P131) | Chad (wd:Q657)        |
| Sahara (wd:Q6583) | located in the administrative territorial entity (wdt:P131) | Mali (wd:Q912)        |
| Sahara (wd:Q6583) | located in the administrative territorial entity (wdt:P131) | Mauritania (wd:Q1025) |

[Assistant]
The Sahara Desert spans multiple countries in North Africa. Based on the administrative hierarchy (P131), it is located in the following countries:

- Egypt (wd:Q79)
- Algeria (wd:Q262)
- Libya (wd:Q1016)
- Sudan (wd:Q1049)
- Morocco (wd:Q1028)
- Tunisia (wd:Q948)
- Chad (wd:Q657)
- Mali (wd:Q912)
- Mauritania (wd:Q1025)

To provide a complete and accurate answer, I will now construct a SPARQL query that retrieves the names of these countries in English, ensuring the results are human-readable and properly formatted.

execute

SELECT ?country ?countryLabel WHERE { wd:Q6583 wdt:P131 ?country . ?country rdfs:label ?countryLabel . FILTER(LANG(?countryLabel) = "en") }

Got 9 rows and 2 columns:
| country               | countryLabel         |
| --------------------- | -------------------- |
| Libya (wd:Q1016)      | Libya (lang:en)      |
| Mauritania (wd:Q1025) | Mauritania (lang:en) |
| Morocco (wd:Q1028)    | Morocco (lang:en)    |
| Sudan (wd:Q1049)      | Sudan (lang:en)      |
| Algeria (wd:Q262)     | Algeria (lang:en)    |
| Chad (wd:Q657)        | Chad (lang:en)       |
| Egypt (wd:Q79)        | Egypt (lang:en)      |
| Mali (wd:Q912)        | Mali (lang:en)       |
| Tunisia (wd:Q948)     | Tunisia (lang:en)    |

[Assistant]
The Sahara Desert is located in the following nine countries in North Africa:

- Algeria
- Chad
- Egypt
- Libya
- Mali
- Mauritania
- Morocco
- Sudan
- Tunisia

These countries are confirmed through the administrative hierarchy (P131) of the Sahara Desert (wd:Q6583), and their names are retrieved in English using rdfs:label with the language filter.

Final SPARQL query:
```sparql
SELECT ?country ?countryLabel WHERE {
  wd:Q6583 wdt:P131 ?country .
  ?country rdfs:label ?countryLabel .
  FILTER(LANG(?countryLabel) = "en")
}
```

Answer: The Sahara Desert is located in Algeria, Chad, Egypt, Libya, Mali, Mauritania, Morocco, Sudan, and Tunisia.


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 ?label WHERE {
  wd:Q766 wdt:P38 ?currency .
  ?currency rdfs:label ?label
  FILTER ( LANG( ?label ) = "en" )
}

Using entities:
- Jamaica (wd:Q766), also known as Commonwealth of Jamaica, JA, JAM, JM: is instance of island country / is instance of island nation / is instance of archipelagic state / is instance of Archipelagic state / is instance of Commonwealth realm / is instance of sovereign state / is instance of country / is instance of territorial evolution of the British Empire / country in the Caribbean / country in the Caribbean / island state in the Caribbean Sea

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

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

Answer: The Jamaican money is called the Jamaican dollar.

The Jamaican money is called the Jamaican dollar.

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 ?label WHERE {
  wd:Q766 wdt:P38 ?currency .
  ?currency rdfs:label ?label
  FILTER ( LANG( ?label ) = "en" )
}

Using entities:
- Jamaica (wd:Q766), also known as Commonwealth of Jamaica, JA, JAM, JM: is instance of island country / is instance of island nation / is instance of archipelagic state / is instance of Archipelagic state / is instance of Commonwealth realm / is instance of sovereign state / is instance of country / is instance of territorial evolution of the British Empire / country in the Caribbean / country in the Caribbean / island state in the Caribbean Sea

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:
| label                     |
| ------------------------- |
| Jamaican dollar (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 jamaican money called?

[Assistant]
To determine what Jamaican money is called, I need to find the currency used in Jamaica. This involves identifying the currency entity associated with Jamaica and retrieving its name.

### Step 1: Identify the entity for Jamaica
I will first search for the entity representing Jamaica in Wikidata.

Question: Jamaica

Top 10 entity alternatives:
1. Jamaica (wd:Q766), also known as Commonwealth of Jamaica, JA, JAM, JM: is instance of territorial evolution of the British Empire / is instance of archipelagic state / is instance of Archipelagic state / is instance of Commonwealth realm / island state in the Caribbean Sea / is instance of sovereign state / is instance of island country / is instance of island nation / country in the Caribbean / country in the Caribbean / is instance of country
2. Jamaica men's national association football team (wd:Q235399, matched via Jamaica), also known as Jamaica, Jamaica men's national football team, Jamaica national association football team, Jamaica national football team, Jamaica national soccer team, etc.: men's national association football team representing Jamaica / is instance of national association football team / is subclass of national association football team / is instance of national soccer team / is subclass of national soccer team / national association football team / national association football team
3. Jamaica (wd:Q1913470), also known as Jamaica, IA, Jamaica, Iowa: is instance of city of the United States / is instance of city in the United States / city in Iowa, United States
4. Jamaica (wd:Q1320403), also known as Jamaica, New York City, Jamaica, Queens: neighborhood of Queens, New York City, United States / is instance of neighborhood in Queens
5. Jamaica (wd:Q3450853), also known as Jamaica, Vermont, Jamaica, VT: is instance of New England town / town in Vermont, United States
6. Colony of Jamaica (wd:Q2526023, matched via Jamaica), also known as Jamaica, Jamaica and Dependencies, Jamaica Colony: British colony on the island of Jamaica, 1655–1962 / is instance of historical country / is instance of former entity
7. Jamaica (wd:Q11310077): Long Island Rail Road train station in Queens, New York / is instance of railway station / is instance of train station
8. Jamaica (wd:Q27119301), also known as Island of Jamaica, Jamaica island, main island of Jamaica, mainland Jamaica: largest island of Jamaica, comprising most of its territory / is instance of island / island in Jamaica / island in Jamaica
9. Jamaica (wd:Q3377006), also known as Jamaica metro station, Jamaica station: is instance of underground station / is instance of elevated station / is instance of metro station / metro station in Mexico City
10. Jamaica (wd:Q20221193): is instance of human settlement / human settlement in Mexico

[Assistant]
The primary entity for Jamaica is `wd:Q766`, which represents the sovereign state of Jamaica. Now, I need to find the currency used in Jamaica. To do this, I will search for properties related to currency for Jamaica.

### Step 2: Search for properties related to currency for Jamaica
I will use `search_property_of_entity` to find properties related to currency for Jamaica (`wd:Q766`).

Question: currency

Top 10 property alternatives:
1. currency (wd:P38 as p/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
2. capital (wd:P36 as p/wdt), 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
3. central bank (wd:P1304 as p/wdt), also known as P1304: country's central bank
4. 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))
5. nominal GDP (wd:P2131 as p/wdt, matched via GDP), also known as GDP, GDP, nominal, gross domestic product, nominal gross domestic product, P2131: market value of all officially recognized final goods and services produced within a country in a given period of time
6. economy of topic (wd:P8744 as p/wdt), also known as P8744: item that deals with the economy of the subject / is subproperty of studied by
7. 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
8. continent (wd:P30 as p/wdt), also known as P30: is subproperty of located in/on physical feature / is subproperty of located on terrain feature / continent of which the subject is a part / continent of which the subject is a part / continent of which the subject is a part
9. coordinate location (wd:P625 as p/wdt, matched via geo), also known as co-ordinate location, co-ordinates, coordinates, co-ords, coords, etc.: geocoordinates of the subject. For Earth, please note that only WGS84 coordinating system is supported at the moment / coordinates of the subject / coordinates of the subject
10. country (wd:P17 as p/wdt), also known as host country, land, sovereign state, state, P17: sovereign state that this item is in (not to be used for human beings) / sovereign state that this item is in (not to be used for human beings) / sovereign state that this item is in (not to be used for human beings) / sovereign state that this item is in (not to be used for human beings) / is subproperty of located in the administrative territorial entity

No other items found

[Assistant]
The property `wdt:P38` (currency) is the correct property to use for identifying the currency of a country. Now, I will retrieve the currency used in Jamaica by querying the `wdt:P38` property for `wd:Q766`.

### Step 3: Query the currency of Jamaica
I will execute a SPARQL query to get the currency of Jamaica (`wd:Q766`) using `wdt:P38`.

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

[Assistant]
The currency of Jamaica is the Jamaican dollar, which is represented by the entity `wd:Q209792`. To confirm the human-readable name of the currency, I will retrieve its label.

### Step 4: Retrieve the label of the currency entity
I will query the label of `wd:Q209792` to confirm the name of the currency in English.

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

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

[Assistant]
The currency of Jamaica is called the **Jamaican dollar**.

### Final SPARQL Query
The SPARQL query to retrieve the name of Jamaica's currency is:

```sparql
SELECT ?label WHERE {
  wd:Q766 wdt:P38 ?currency .
  ?currency rdfs:label ?label FILTER(LANG(?label) = "en")
}
```

This query first finds the currency used in Jamaica (`wd:Q766 wdt:P38 ?currency`) and then retrieves the English label of that currency entity.

### Answer
The Jamaican money is called the **Jamaican dollar**.

answer

SELECT ?label WHERE { wd:Q766 wdt:P38 ?currency . ?currency rdfs:label ?label FILTER(LANG(?label) = "en") }

Answer: The Jamaican money is called the Jamaican dollar.


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 ?country WHERE {
  wd:Q9441 wdt:P19 ?birthplace .
  ?birthplace wdt:P17 ?country .
  ?country rdfs:label ?countryLabel
  FILTER ( LANG( ?countryLabel ) = "en" )
}

Using entities:
- The Buddha (wd:Q9441), also known as Bhagwan Buddha, Buddha, Buddhadeva, Devarajalu, Fo, etc.: has occupation writer / has occupation Bhikkhu / has occupation bhikkhu / has occupation Philosopher / has occupation philosopher / has occupation preacher / has occupation religious leader / has occupation spiritual teacher / has occupation founder of a religion / has occupation father of faith / has occupation psychologist / has occupation psychiatrist / has occupation social reformer / is instance of human / Indian philosopher and the founder of Buddhism (623 or 563 BCE – 543 or 483 BCE) / Indian philosopher and the founder of Buddhism (623 or 563 BCE – 543 or 483 BCE)

Using properties:
- country (wd:P17 as wdt), also known as host country, land, sovereign state, state, P17: is subproperty of located in the administrative territorial entity / sovereign state that this item is in (not to be used for human beings) / sovereign state that this item is in (not to be used for human beings) / sovereign state that this item is in (not to be used for human beings) / sovereign state that this item is in (not to be used for human beings)
- place of birth (wd:P19 as wdt), also known as birth city, birth location, birth place, birthplace, born, etc.: is subproperty of location / most specific known birth location of a person, animal or fictional character / most specific known (e.g. city instead of country, or ... birth location of a person, animal or fictional character / most specific known (e.g. city instead of country, or ... birth location of a person, animal or fictional character

Got 1 row and 1 column:
| country         |
| --------------- |
| Nepal (wd:Q837) |

Answer: Nepal

Nepal

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 ?country WHERE {
  wd:Q9441 wdt:P19 ?birthplace .
  ?birthplace wdt:P17 ?country .
  ?country rdfs:label ?countryLabel
  FILTER ( LANG( ?countryLabel ) = "en" )
}

Using entities:
- The Buddha (wd:Q9441), also known as Bhagwan Buddha, Buddha, Buddhadeva, Devarajalu, Fo, etc.: has occupation writer / has occupation Bhikkhu / has occupation bhikkhu / has occupation Philosopher / has occupation philosopher / has occupation preacher / has occupation religious leader / has occupation spiritual teacher / has occupation founder of a religion / has occupation father of faith / has occupation psychologist / has occupation psychiatrist / has occupation social reformer / is instance of human / Indian philosopher and the founder of Buddhism (623 or 563 BCE – 543 or 483 BCE) / Indian philosopher and the founder of Buddhism (623 or 563 BCE – 543 or 483 BCE)

Using properties:
- country (wd:P17 as wdt), also known as host country, land, sovereign state, state, P17: is subproperty of located in the administrative territorial entity / sovereign state that this item is in (not to be used for human beings) / sovereign state that this item is in (not to be used for human beings) / sovereign state that this item is in (not to be used for human beings) / sovereign state that this item is in (not to be used for human beings)
- place of birth (wd:P19 as wdt), also known as birth city, birth location, birth place, birthplace, born, etc.: is subproperty of location / most specific known birth location of a person, animal or fictional character / most specific known (e.g. city instead of country, or ... birth location of a person, animal or fictional character / most specific known (e.g. city instead of country, or ... birth location of a person, animal or fictional character

Execution result:
Got 1 row and 1 column:
| country         |
| --------------- |
| Nepal (wd:Q837) |

[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 country did buddha come from?

[Assistant]
To determine the country where Buddha came from, I need to identify the entity representing Buddha and then find the country associated with him.

### Step 1: Search for the entity representing Buddha
I will first search for "Buddha" in Wikidata to identify the correct entity.

Question: buddha

Top 10 entity alternatives:
1. The Buddha (wd:Q9441, matched via Buddha), also known as Bhagwan Buddha, Buddha, Buddhadeva, Devarajalu, Fo, etc.: Indian philosopher and the founder of Buddhism (623 or 563 BCE – 543 or 483 BCE) / Indian philosopher and the founder of Buddhism (623 or 563 BCE – 543 or 483 BCE) / has occupation founder of a religion / has occupation spiritual teacher / has occupation religious leader / has occupation social reformer / has occupation father of faith / has occupation psychologist / has occupation psychiatrist / has occupation philosopher / has occupation Philosopher / has occupation preacher / has occupation bhikkhu / has occupation Bhikkhu / has occupation writer / is instance of human
2. Buddha (wd:Q7055), also known as Anuttara, Arhat, Bhagavān, Bhagavat, Lokavid, etc.: being who attains perfect enlightenment / is subclass of religious character / is instance of religious concept / is instance of honorific / is instance of title / is subclass of Arya
3. buddhahood (wd:Q56247062, matched via Buddha), also known as Buddha, buddhabhāva, buddhatta, Buddhatva, bukkai, etc.: condition or rank of fully awakened enlightenment / is subclass of title
4. Buddharupa (wd:Q1000809, matched via Buddha), also known as Buddha, Buddharūpa: statues of beings who have obtained Buddhahood / is subclass of artistic theme / is subclass of statue
5. Buddha (wd:Q945140): is instance of manga series / manga series
6. Ulf Ekberg (wd:Q2656667, matched via Buddha), also known as Buddha, Ulf Buddha Ekberg, Ulf Gunnar Ekberg: has occupation television producer / has occupation record producer / has occupation businessperson / has occupation Film producer / has occupation film producer / has occupation songwriter / has occupation composer / has occupation musician / has occupation singer / is instance of human / Swedish musician / Swedish musician / Swedish musician
7. Buddha (wd:Q851370): 1994 demo album by Blink-182 / is instance of album / album by blink-182 / album by blink-182
8. Buddha (wd:Q16954312), also known as Buddhaa-Rajaon Ka Raja, Buddhaa - The King of Kings: is instance of television series / is instance of serial / TV series
9. Huberht Taylor Hudson (wd:Q3787383, matched via Buddha), also known as Buddha, Hubert Hudson: British sailor who took part in Shackleton's Imperial Trans-Antarctic Expedition / has occupation navigator / has occupation Sailor / has occupation sailor / is instance of human
10. Buddha (wd:Q4984146), also known as Buddha, IN, Buddha, Indiana: is instance of unincorporated community in the United States / unincorporated community in Lawrence County, Indiana

[Assistant]
The most relevant entity for "Buddha" is **Q9441** ("The Buddha"), which is identified as a human, Indian philosopher, and the founder of Buddhism. This matches the historical figure Siddhartha Gautama, commonly known as Buddha.

### Step 2: Find the country associated with Buddha
Now, I will check the properties of this entity to find the country of origin. The most relevant property for country of origin is **P17 (country)** or **P19 (place of birth)**, which might lead to a location that can be linked to a country.

I will list the triples for Q9441 to explore its properties.

list

wd:Q9441

[Assistant]
The property `wdt:P17` (country) does not directly link to Buddha's country. This is common for historical figures, as modern country boundaries did not exist in their time. Instead, I should look at the **place of birth** (`wdt:P19`) to determine where he was born, and then infer the modern country.

### Step 3: Find Buddha's place of birth
I will now check the place of birth (`wdt:P19`) for Buddha (Q9441).

wd:Q9441

[Assistant]
Buddha's place of birth is **Lumbini (Q9213)**. Now I need to determine the modern country where Lumbini is located.

### Step 4: Find the country where Lumbini is located
I will now check the country (`wdt:P17`) associated with Lumbini (Q9213).

wd:Q9213

[Assistant]
Lumbini, the birthplace of Buddha, is located in **Nepal (Q837)**.

### Final Answer:
Buddha came from **Nepal**.

I will now construct and execute a final SPARQL query to confirm this result in a structured way.

execute

SELECT ?country WHERE { wd:Q9441 wdt:P19 ?birthplace . ?birthplace wdt:P17 ?country . ?country rdfs:label ?countryLabel FILTER(LANG(?countryLabel) = "en") }

Got 1 row and 1 column:
| country         |
| --------------- |
| Nepal (wd:Q837) |

[Assistant]
The SPARQL query confirms that Buddha's place of birth, Lumbini, is located in Nepal.

### Final Answer:
Buddha came from **Nepal**.

I will now provide the final SPARQL query and answer.

answer

SELECT ?country WHERE { wd:Q9441 wdt:P19 ?birthplace . ?birthplace wdt:P17 ?country . ?country rdfs:label ?countryLabel FILTER(LANG(?countryLabel) = "en") }

Answer: Nepal