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:Q181574 wdt:P527 ?country .
  ?country rdfs:label ?countryLabel
  FILTER ( LANG( ?countryLabel ) = 'en' )
}

Using entities:
- North American Free Trade Agreement (wd:Q181574), also known as NAFTA: is instance of trade bloc / is instance of free trade agreement / trade bloc / trade bloc

Using properties:
- has part(s) (wd:P527 as wdt), also known as amalgamation of, assembled from, assembled out of, composed of, comprised of, etc.: part of this subject, also valuable subclass or exemplar. Inverse property of "part of". / part of this subject; inverse property of "part of" (P361). See also "has parts of the class" (P2670). / part of this subject; inverse property of "part of" (P361). See also "has parts of the class" (P2670).

Got 3 rows and 2 columns:
| country                | countryLabel            |
| ---------------------- | ----------------------- |
| Canada (wd:Q16)        | Canada (lang:en)        |
| United States (wd:Q30) | United States (lang:en) |
| Mexico (wd:Q96)        | Mexico (lang:en)        |

Answer: The countries involved in NAFTA are Canada, the United States, and Mexico.

The countries involved in NAFTA are Canada, the United States, and Mexico.

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:Q181574 wdt:P527 ?country .
  ?country rdfs:label ?countryLabel
  FILTER ( LANG( ?countryLabel ) = 'en' )
}

Using entities:
- North American Free Trade Agreement (wd:Q181574), also known as NAFTA: is instance of trade bloc / is instance of free trade agreement / trade bloc / trade bloc

Using properties:
- has part(s) (wd:P527 as wdt), also known as amalgamation of, assembled from, assembled out of, composed of, comprised of, etc.: part of this subject, also valuable subclass or exemplar. Inverse property of "part of". / part of this subject; inverse property of "part of" (P361). See also "has parts of the class" (P2670). / part of this subject; inverse property of "part of" (P361). See also "has parts of the class" (P2670).

Execution result:
Got 3 rows and 2 columns:
| country                | countryLabel            |
| ---------------------- | ----------------------- |
| Canada (wd:Q16)        | Canada (lang:en)        |
| United States (wd:Q30) | United States (lang:en) |
| Mexico (wd:Q96)        | Mexico (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 countries are involved in the nafta?

[Assistant]
To determine the countries involved in NAFTA (North American Free Trade Agreement), I need to identify the entities associated with this agreement. NAFTA is a trade agreement between three countries: the United States, Canada, and Mexico.

I will first search for the entity representing NAFTA to confirm its details and then identify the countries involved.

Question: NAFTA

Top 10 entity alternatives:
1. North American Free Trade Agreement (wd:Q181574, matched via NAFTA), also known as NAFTA: is instance of free trade agreement / is instance of trade bloc / trade bloc / trade bloc
2. Nafta (wd:Q1026298), also known as Nefta: is instance of municipality of Tunisia / Tunisian town
3. NAFTA (wd:Q12772242), also known as NAFTA a.s.: Slovak multinational company operating in the field of storage and extraction of hydrocarbons / is instance of gas storage operator / is instance of enterprise / is instance of business
4. nafta (wd:Q1213853): is instance of type of chemical entity / is subclass of chemical compound / chemical compound / chemical compound / chemical compound
5. Nafta (wd:Q11788993): 1961 film by Stanisław Lenartowicz / is instance of film
6. Nafta (wd:Q52335786), also known as IMO 8853946: bunkering tanker built in 1978 / is instance of ship
7. Nafta (wd:Q6958220): Soviet Union oil company operating abroad / is instance of business
8. Naftalan (wd:Q152825): is instance of şəhər / city in Azerbaijan
9. Naphtali (wd:Q1771963, matched via Naftali), also known as Naftali: biblical figure and the sixth son of Jacob through his concubine Bilhah / is instance of human biblical character / is instance of human biblical figure
10. United States–Mexico–Canada Agreement (wd:Q56839716, matched via NAFTA 2.0), also known as Agreement between the United States of America, the United Mexican States, and Canada, Canada–United States–Mexico Agreement, CUSMA, NAFTA 2.0, NAFTA Redux, etc.: is instance of trade agreement / is instance of trade bloc / North American trade bloc

[Assistant]
The primary entity for NAFTA is "North American Free Trade Agreement" (wd:Q181574). Additionally, there is an updated version called the "United States–Mexico–Canada Agreement" (wd:Q56839716), which replaced NAFTA in 2020. Since the question asks about the countries involved in NAFTA, I will focus on the original NAFTA agreement (wd:Q181574) and identify the participating countries.

I will now explore the properties of the NAFTA entity to find the countries involved.

list

wd:Q181574

Got 516 rows and 3 columns, showing the first 10 rows below:
| subject                                          | property                                     | object                                          |
| ------------------------------------------------ | -------------------------------------------- | ----------------------------------------------- |
| North American Free Trade Agreement (wd:Q181574) | instance of (wdt:P31)                        | trade bloc (wd:Q1129645)                        |
| North American Free Trade Agreement (wd:Q181574) | Commons category (wdt:P373)                  | North American Free Trade Agreement             |
| North American Free Trade Agreement (wd:Q181574) | Freebase ID (wdt:P646)                       | /m/05jj_                                        |
| North American Free Trade Agreement (wd:Q181574) | inception (wdt:P571)                         | 1994-01-01T00:00:00Z (xsd:dateTime)             |
| North American Free Trade Agreement (wd:Q181574) | VIAF cluster ID (wdtn:P214)                  | <http://viaf.org/viaf/131292072>                |
| North American Free Trade Agreement (wd:Q181574) | short name (wdt:P1813)                       | ALENA (lang:fr)                                 |
| North American Free Trade Agreement (wd:Q181574) | has part(s) (wdt:P527)                       | United States (wd:Q30)                          |
| North American Free Trade Agreement (wd:Q181574) | GND ID (wdtn:P227)                           | <https://d-nb.info/gnd/5115385-3>               |
| North American Free Trade Agreement (wd:Q181574) | official website (wdt:P856)                  | <http://www.nafta-sec-alena.org/>               |
| North American Free Trade Agreement (wd:Q181574) | Library of Congress authority ID (wdtn:P244) | <http://id.loc.gov/authorities/names/n92099941> |
| ...                                              | ...                                          | ...                                             |

[Assistant]
From the list of triples, I can see that the "has part(s)" property (wdt:P527) links the NAFTA agreement to the United States (wd:Q30). To find all participating countries, I need to identify other countries involved in NAFTA. The three countries involved are the United States, Canada, and Mexico.

I will now check for Canada and Mexico as parts of NAFTA by querying for all countries associated with NAFTA via the "has part(s)" property.

execute

SELECT ?country ?countryLabel WHERE { wd:Q181574 wdt:P527 ?country . ?country rdfs:label ?countryLabel FILTER(LANG(?countryLabel) = 'en') }

Got 3 rows and 2 columns:
| country                | countryLabel            |
| ---------------------- | ----------------------- |
| Canada (wd:Q16)        | Canada (lang:en)        |
| United States (wd:Q30) | United States (lang:en) |
| Mexico (wd:Q96)        | Mexico (lang:en)        |

[Assistant]
The SPARQL query has successfully identified the three countries involved in NAFTA: Canada, the United States, and Mexico. These are the member countries of the North American Free Trade Agreement.

I will now provide the final answer.

answer

SELECT ?country ?countryLabel WHERE { wd:Q181574 wdt:P527 ?country . ?country rdfs:label ?countryLabel FILTER(LANG(?countryLabel) = 'en') }

Answer: The countries involved in NAFTA are Canada, the United States, and Mexico.


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 ?birthPlace ?education WHERE {
  wd:Q1744 wdt:P19 ?birthPlace .
  OPTIONAL {
    wd:Q1744 wdt:P69 ?education
  }
  .
  ?birthPlace rdfs:label ?birthPlaceLabel .
  FILTER ( LANG( ?birthPlaceLabel ) = "en" ) .
  ?education rdfs:label ?educationLabel .
  FILTER ( LANG( ?educationLabel ) = "en" )
}

Using entities:
- Madonna (wd:Q1744), also known as Madonna Ciccone, Madonna L. Ciccone, Madonna Louise Ciccone, Madonna Louise Veronica Ciccone: has occupation singer / has occupation actor / has occupation songwriter / is instance of human / American singer, songwriter and actress (born 1958) / American singer, songwriter, and actress (born 1958)

Using properties:
- 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
- educated at (wd:P69 as wdt), also known as alma mater, alumna of, alumni of, alumnus of, attended, etc.: is subproperty of affiliation / educational institution attended by subject / educational institution attended by the subject / educational institution attended by the subject

Answer: Madonna grew up in Michigan, USA. She was born in Bay City, Michigan, and was educated at Rochester Adams High School and the University of Michigan School of Music, Theatre & Dance, both located in Michigan.

Madonna grew up in Michigan, USA. She was born in Bay City, Michigan, and was educated at Rochester Adams High School and the University of Michigan School of Music, Theatre & Dance, both located in Michigan.

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 ?birthPlace ?education WHERE {
  wd:Q1744 wdt:P19 ?birthPlace .
  OPTIONAL {
    wd:Q1744 wdt:P69 ?education
  }
  .
  ?birthPlace rdfs:label ?birthPlaceLabel .
  FILTER ( LANG( ?birthPlaceLabel ) = "en" ) .
  ?education rdfs:label ?educationLabel .
  FILTER ( LANG( ?educationLabel ) = "en" )
}

Using entities:
- Madonna (wd:Q1744), also known as Madonna Ciccone, Madonna L. Ciccone, Madonna Louise Ciccone, Madonna Louise Veronica Ciccone: has occupation singer / has occupation actor / has occupation songwriter / is instance of human / American singer, songwriter and actress (born 1958) / American singer, songwriter, and actress (born 1958)

Using properties:
- 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
- educated at (wd:P69 as wdt), also known as alma mater, alumna of, alumni of, alumnus of, attended, etc.: is subproperty of affiliation / educational institution attended by subject / educational institution attended by the subject / educational institution attended by the subject

Execution result:
Got 2 rows and 2 columns:
| birthPlace            | education                                                             |
| --------------------- | --------------------------------------------------------------------- |
| Bay City (wd:Q746820) | Rochester Adams High School (wd:Q7353940)                             |
| Bay City (wd:Q746820) | University of Michigan School of Music, Theatre & Dance (wd:Q7895775) |

[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 did madonna grew up?

[Assistant]
To determine where Madonna grew up, I need to find information about her place of upbringing. This typically corresponds to her place of birth or where she spent her childhood, which may be captured in Wikidata using properties like "place of birth" (P19) or "residence" (P551). Let me start by searching for Madonna's entity in Wikidata.

Question: madonna

Top 10 entity alternatives:
1. Madonna (wd:Q1744), also known as Madonna Ciccone, Madonna L. Ciccone, Madonna Louise Ciccone, Madonna Louise Veronica Ciccone: American singer, songwriter, and actress (born 1958) / American singer, songwriter and actress (born 1958) / has occupation songwriter / has occupation singer / has occupation actor / is instance of human
2. Mary (wd:Q345, matched via Madonna), also known as Blessed Mother, Blessed Virgin, Blessed Virgin Mary, God-Bearer, Holy Mary, etc.: religious figure; mother of Jesus of Nazareth / is instance of human biblical character / is instance of human biblical figure / mother of Jesus
3. Madonna (wd:Q177943), also known as Madonna: The First Album: 1983 self-titled debut studio album by Madonna / is instance of album
4. Madonna (wd:Q1989780): painting composition by Edvard Munch, in different versions / is instance of painting series
5. Madonna (wd:Q926743), also known as Madonna in art, The Madonna in art, Virgin Mary in art: artistic representation of Mary, either alone or with her child Jesus / is subclass of religious work of art / is instance of artistic theme
6. Madonna (wd:Q19794647): 2015 South Korean film directed by Shin Su-won / is instance of film
7. Madonna (wd:Q1147459): album by …And You Will Know Us by the Trail of Dead / is instance of album
8. Virgin and Child with an Angel (Madonna del Latte) (wd:Q3842618, matched via Madonna), also known as Madonna, Madonna with child and John the Baptist: painting by Antonio da Correggio from 1520 / painting by Antonio da Correggio / is instance of painting
9. Madonna (wd:Q6728358), also known as Madonna, Maryland, Madonna, MD: is instance of unincorporated community in the United States / unincorporated community in Harford County, Maryland
10. Madonna (wd:Q486604): is instance of extended play / 2010 EP by Secret

[Assistant]
The top result for "Madonna" is wd:Q1744, which corresponds to Madonna Ciccone, the American singer, songwriter, and actress. This is the correct entity we are looking for. Now, I will check her properties to find information about where she grew up. The most relevant property for this is likely "place of birth" (P19), as it often indicates where someone spent their early years. I will retrieve this information.

list

wd:Q1744

[Assistant]
Madonna's place of birth is Bay City (wd:Q746820). However, I need to verify whether this is where she grew up, as place of birth does not always equate to where someone was raised. Let me check for other properties that might indicate her upbringing, such as "residence" (P551) or "educated at" (P69), which could provide more context about where she spent her formative years.

wd:Q1744

[Assistant]
There are no residence records (P551) listed for Madonna in Wikidata. Let me check for "educated at" (P69) to see if there is any information about where she went to school, which might indicate where she grew up.

wd:Q1744

[Assistant]
Madonna was educated at Rochester Adams High School and the University of Michigan School of Music, Theatre & Dance. Rochester Adams High School is located in Rochester Hills, Michigan, which is near Bay City. This suggests that she spent her formative years in Michigan, particularly in the Detroit metropolitan area.

Since her place of birth is Bay City, Michigan, and her high school is in Rochester Hills, Michigan, it is reasonable to conclude that she grew up in Michigan. While there is no explicit "grew up" property in Wikidata, the combination of place of birth and education strongly indicates that she spent her childhood and adolescence in Michigan.

I will now construct a SPARQL query to return the place of birth and educational institutions to support this conclusion.

execute

SELECT ?birthPlace ?education WHERE { wd:Q1744 wdt:P19 ?birthPlace . OPTIONAL { wd:Q1744 wdt:P69 ?education } . ?birthPlace rdfs:label ?birthPlaceLabel . FILTER(LANG(?birthPlaceLabel) = "en") . ?education rdfs:label ?educationLabel . FILTER(LANG(?educationLabel) = "en") }

[Assistant]
The SPARQL query results confirm that Madonna was born in Bay City, Michigan, and was educated at Rochester Adams High School and the University of Michigan School of Music, Theatre & Dance. Both educational institutions are located in Michigan, which strongly indicates that she grew up in Michigan.

Based on this evidence, I can confidently answer that Madonna grew up in Michigan, USA.

Here is the final SPARQL query that retrieves this information:

answer

SELECT ?birthPlace ?education WHERE { wd:Q1744 wdt:P19 ?birthPlace . OPTIONAL { wd:Q1744 wdt:P69 ?education } . ?birthPlace rdfs:label ?birthPlaceLabel . FILTER(LANG(?birthPlaceLabel) = "en") . ?education rdfs:label ?educationLabel . FILTER(LANG(?educationLabel) = "en") }

Answer: Madonna grew up in Michigan, USA. She was born in Bay City, Michigan, and was educated at Rochester Adams High School and the University of Michigan School of Music, Theatre & Dance, both located in Michigan.


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:Q928 wdt:P122 ?governmentType .
  ?governmentType rdfs:label ?label .
  FILTER ( LANG( ?label ) = "en" )
}

Using entities:
- Philippines (wd:Q928), also known as ph, PH, PHI, Philippine Islands, PHL, etc.: is instance of archipelagic state / is instance of Archipelagic state / is instance of sovereign state / is instance of country / archipelagic country in Southeast Asia / archipelagic country in Southeast Asia

Using properties:
- basic form of government (wd:P122 as wdt), also known as form of government, government, type of government, P122: subject's government / the subject's government / the subject's government

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

Answer:
The form of government in the Philippines is a **republic**.

### Final SPARQL Query and Answer:
The SPARQL query to determine the form of government of the Philippines is:

```sparql
SELECT ?label WHERE {
  wd:Q928 wdt:P122 ?governmentType .
  ?governmentType rdfs:label ?label .
  FILTER(LANG(?label) = "en")
}
```

This query retrieves the English label for the government type of the Philippines, which is "republic".

### Answer:
The Philippines has a **republic** form of government.

The form of government in the Philippines is a **republic**.

### Final SPARQL Query and Answer:
The SPARQL query to determine the form of government of the Philippines is:

```sparql
SELECT ?label WHERE {
  wd:Q928 wdt:P122 ?governmentType .
  ?governmentType rdfs:label ?label .
  FILTER(LANG(?label) = "en")
}
```

This query retrieves the English label for the government type of the Philippines, which is "republic".

### Answer:
The Philippines has a **republic** form of government.

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:Q928 wdt:P122 ?governmentType .
  ?governmentType rdfs:label ?label .
  FILTER ( LANG( ?label ) = "en" )
}

Using entities:
- Philippines (wd:Q928), also known as ph, PH, PHI, Philippine Islands, PHL, etc.: is instance of archipelagic state / is instance of Archipelagic state / is instance of sovereign state / is instance of country / archipelagic country in Southeast Asia / archipelagic country in Southeast Asia

Using properties:
- basic form of government (wd:P122 as wdt), also known as form of government, government, type of government, P122: subject's government / the subject's government / the subject's government

Execution result:
Got 1 row and 1 column:
| label              |
| ------------------ |
| republic (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 form of government do we have in the philippines?

[Assistant]
To determine the form of government in the Philippines, I will follow these steps:

1. Identify the entity for the Philippines in Wikidata.
2. Find the property that describes the form of government (e.g., "government type" or similar).
3. Retrieve the value of that property for the Philippines.
4. Construct and execute a SPARQL query to get the answer.

### Step 1: Search for the Philippines entity
I will first search for the entity corresponding to the Philippines.

Question: philippines

Top 10 entity alternatives:
1. Philippines (wd:Q928), also known as ph, PH, PHI, Philippine Islands, PHL, etc.: archipelagic country in Southeast Asia / archipelagic country in Southeast Asia / is instance of archipelagic state / is instance of Archipelagic state / is instance of sovereign state / is instance of country
2. Philippines (wd:Q116754458): scientific article published on 15 November 2001 / scientific article published on 15 November 2001 / scientific article published on 15 November 2001 / is instance of scholarly article / is instance of academic article
3. Philippines. (wd:Q39611725): scientific article published on September 1983 / scientific article published on September 1983 / scientific article published on September 1983 / is instance of scholarly article / is instance of academic article
4. Philippines (wd:Q57715247): entry in Encyclopedia of Global Warming & Climate Change / is instance of encyclopaedic article / is instance of encyclopedia article / is instance of scholarly article / is instance of academic article
5. Philippines (wd:Q47409215): scientific article published in August 1986 / scientific article published in August 1986 / scientific article published in August 1986 / is instance of scholarly article / is instance of academic article
6. Philippines (wd:Q70886687): scientific article published on 01 January 1966 / is instance of scholarly article / is instance of academic article
7. Waray (wd:Q34279, matched via Waray (Philippines)), also known as Lineyte-Samarnon, war, Waray language, Waray (Philippines), Waray-Waray, etc.: Visayan language primarily spoken in the islands of Samar and Eastern Leyte / is instance of modern language / is subclass of Central Visayan / is instance of language
8. flag of the Philippines (wd:Q134627, matched via Philippines flag), also known as Philippine flag, Philippines flag, the Philippines flag: national flag of the Republic of the Philippines / is instance of national flag
9. Caroline Islands (wd:Q118350, matched via New Philippines), also known as Carolinas, Carolines, Chickpea Islands, Islands of the Kings, Islas de los Reyes, etc.: archipelago of tiny islands in the western Pacific Ocean, divided between the Federated States of Micronesia and Palau / is instance of archipelago
10. history of the Philippines (wd:Q830399, matched via Philippines history), also known as Philippine history, Philippines history, the Philippines history: is instance of aspect of history / aspect of history

[Assistant]
The correct entity for the Philippines is **wd:Q928**, which is described as an archipelagic country in Southeast Asia and a sovereign state.

### Step 2: Find the property for "form of government"
I will now search for properties related to "government" or "form of government" to identify the correct property (e.g., P1293 for "government type").

Question: form of government

Top 10 property alternatives:
1. basic form of government (wd:P122 as ps/psv/p/pqv/pqn/psn/pq/wdt/pr/prn/prv/wdtn, matched via form of government), also known as form of government, government, type of government, P122: the subject's government / the subject's government / subject's government
2. subclass of (wd:P279 as ps/psv/p/pqv/pqn/psn/pq/wdt/pr/prn/prv/wdtn, matched via form of), also known as all members of this class also belong to, category of, form of, has superclass, is a class of, etc.: this item is a subclass (subset) of that item; ALL instances ... of volcanic landform); Everest is an instance of mountain / this item is a subclass (subset) of that item; all instances ... instance of volcanic landform); K2 is an instance of mountain / this item is a subclass (subset) of that item; all instances ... instance of volcanic landform); K2 is an instance of mountain / this item is a subclass (subset) of that item; all instances ... instance of volcanic landform); K2 is an instance of mountain
3. capital (wd:P36 as ps/psv/p/pqv/pqn/psn/pq/wdt/pr/prn/prv/wdtn, matched via seat of government), 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
4. foundational text (wd:P457 as ps/psv/p/pqv/pqn/psn/pq/wdt/pr/prn/prv/wdtn, matched via constitution), also known as charter, constitution, constitutive text, created by, created in document, etc.: text through which an institution or object has been created or established / text through which an institution has been created
5. head of government (wd:P6 as ps/psv/p/pqv/pqn/psn/pq/wdt/pr/prn/prv/wdtn), also known as chancellor, executive power headed by, first minister, government headed by, governor, etc.: head of the executive power of this town, city, municipality, state, country, or other governmental body / head of the executive power of a town, city, municipality, state, country, or other governmental body / head of the executive power of a town, city, municipality, state, country, or other governmental body / is subproperty of director / manager / is subproperty of director/manager / is subproperty of manager/director / is subproperty of chairperson
6. Classification of the Functions of Government (wd:P9798 as ps/psv/p/pqv/pqn/psn/pq/wdt/pr/prn/prv/wdtn), also known as COFOG ID, COFOG number, P9798: UN classification to compare government agencies across countries
7. official religion (wd:P3075 as ps/psv/p/pqv/pqn/psn/pq/wdt/pr/prn/prv/wdtn, matched via state religion), also known as established religion, state religion, P3075: official religion in this administrative entity / official religion in this country
8. applies to part (wd:P518 as ps/psv/p/pqv/pqn/psn/pq/wdt/pr/prn/prv/wdtn, matched via in form), also known as applied to, applies to aspect, applies to form, applies to phase, apply to, etc.: part, aspect, or form of the item to which the claim applies / part of the item for which the claim is valid / part of the item for which the claim is valid
9. inception (wd:P571 as ps/psv/p/pqv/pqn/psn/pq/wdt/pr/prn/prv/wdtn, matched via formation), also known as broke ground, built, commenced on date, commencement date, completed, etc.: time when an entity begins to exist; for date of official opening use P1619 / time when an entity begins to exist; for date of official opening use P1619 / date or point in time when the organisation / object was founded / created / is subproperty of start time
10. military branch (wd:P241 as ps/psv/p/pqv/pqn/psn/pq/wdt/pr/prn/prv/wdtn, matched via formation), also known as branch, formation, service branch, unit branch, P241: branch to which this military unit, award, office, or person belongs, e.g. Royal Navy / is subproperty of part of

[Assistant]
The property **P122** ("basic form of government") is the most relevant one for determining the form of government of a country.

### Step 3: Find the government type of the Philippines
Now, I will query Wikidata to find the value of `wdt:P122` (basic form of government) for the Philippines (`wd:Q928`).

I will construct a SPARQL query to retrieve this information.

execute

SELECT ?governmentType WHERE { wd:Q928 wdt:P122 ?governmentType }

Got 1 row and 1 column:
| governmentType      |
| ------------------- |
| republic (wd:Q7270) |

[Assistant]
The form of government of the Philippines is a **republic**, as indicated by the value `wd:Q7270` (republic).

To provide a more human-readable answer, I will also retrieve the English label for `wd:Q7270` to confirm the term "republic".

I will now execute a query to get the label for `wd:Q7270`.

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

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

[Assistant]
The form of government in the Philippines is a **republic**.

### Final SPARQL Query and Answer:
The SPARQL query to determine the form of government of the Philippines is:

```sparql
SELECT ?label WHERE {
  wd:Q928 wdt:P122 ?governmentType .
  ?governmentType rdfs:label ?label .
  FILTER(LANG(?label) = "en")
}
```

This query retrieves the English label for the government type of the Philippines, which is "republic".

### Answer:
The Philippines has a **republic** form of government.