PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX geo: <http://www.opengis.net/ont/geosparql#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
SELECT ?place ?placeLabel WHERE {
  ?place wdt:P625 'POINT(-77.232200 39.828300)' ^^ geo:wktLiteral .
  ?place rdfs:label ?placeLabel .
  FILTER ( LANG( ?placeLabel ) = "en" ) .
  ?place wdt:P31 ?instance .
  FILTER ( ?instance IN ( wd:Q62049 , wd:Q777120 ) )
}

Using entities:
- county seat (wd:Q62049), also known as borough seat, county site, parish capitals, parish seat, parish seats, etc.: is subclass of administrative center / is subclass of administrative centre / is subclass of seat / is subclass of human settlement / administrative center for a county or civil parish in the United States
- borough of Pennsylvania (wd:Q777120), also known as boro of Pennsylvania: is subclass of borough in the United States / is subclass of local government in Pennsylvania / type of municipality in the U.S. state of Pennsylvania

Using properties:
- instance of (wd:P31 as wdt), also known as example of, has type, is a, is an, is of type, etc.: that class of which this subject is a particular example and ... a subclass of mountain (and an instance of volcanic landform) / type to which this subject corresponds/belongs. Different ... and the volcano is a type (instance) of volcanic landform
- coordinate location (wd:P625 as wdt), also known as co-ordinate location, co-ordinates, coordinates, co-ords, coords, etc.: coordinates of the subject / coordinates of the subject / geocoordinates of the subject. For Earth, please note that only WGS84 coordinating system is supported at the moment

Got 2 rows and 2 columns:
| place                   | placeLabel           |
| ----------------------- | -------------------- |
| Gettysburg (wd:Q694550) | Gettysburg (lang:en) |
| Gettysburg (wd:Q694550) | Gettysburg (lang:en) |

Answer: The Gettysburg Address was delivered in Gettysburg, Pennsylvania, United States.

The Gettysburg Address was delivered in Gettysburg, Pennsylvania, United States.

SPARQL query over wikidata:
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX geo: <http://www.opengis.net/ont/geosparql#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
SELECT ?place ?placeLabel WHERE {
  ?place wdt:P625 'POINT(-77.232200 39.828300)' ^^ geo:wktLiteral .
  ?place rdfs:label ?placeLabel .
  FILTER ( LANG( ?placeLabel ) = "en" ) .
  ?place wdt:P31 ?instance .
  FILTER ( ?instance IN ( wd:Q62049 , wd:Q777120 ) )
}

Using entities:
- county seat (wd:Q62049), also known as borough seat, county site, parish capitals, parish seat, parish seats, etc.: is subclass of administrative center / is subclass of administrative centre / is subclass of seat / is subclass of human settlement / administrative center for a county or civil parish in the United States
- borough of Pennsylvania (wd:Q777120), also known as boro of Pennsylvania: is subclass of borough in the United States / is subclass of local government in Pennsylvania / type of municipality in the U.S. state of Pennsylvania

Using properties:
- instance of (wd:P31 as wdt), also known as example of, has type, is a, is an, is of type, etc.: that class of which this subject is a particular example and ... a subclass of mountain (and an instance of volcanic landform) / type to which this subject corresponds/belongs. Different ... and the volcano is a type (instance) of volcanic landform
- coordinate location (wd:P625 as wdt), also known as co-ordinate location, co-ordinates, coordinates, co-ords, coords, etc.: coordinates of the subject / coordinates of the subject / geocoordinates of the subject. For Earth, please note that only WGS84 coordinating system is supported at the moment

Execution result:
Got 2 rows and 2 columns:
| place                   | placeLabel           |
| ----------------------- | -------------------- |
| Gettysburg (wd:Q694550) | Gettysburg (lang:en) |
| Gettysburg (wd:Q694550) | Gettysburg (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 did the gettysburg address?

[Assistant]
The question "where did the gettysburg address?" appears to be asking for the location where the Gettysburg Address was delivered. The Gettysburg Address is a famous speech delivered by U.S. President Abraham Lincoln during the American Civil War.

I will first search for the Gettysburg Address as an entity in Wikidata to confirm its identifier and details.

Question: Gettysburg Address

Top 10 entity alternatives:
1. Gettysburg Address (wd:Q214524): speech by U.S. President Abraham Lincoln / speech by U.S. President Abraham Lincoln / is instance of oration
2. Gettysburg Address (wd:Q19046068): version of the text inscribed on the walls at the Lincoln Memorial in Washington, D.C. / is instance of inscription
3. The Gettysburg Address (wd:Q17097518, matched via Gettysburg Address), also known as Gettysburg Address: A 2017 film directed by Sean Conant / 2017 film directed by Sean Conant / is instance of film
4. A Gettysburg Address (wd:Q4656986): is instance of television series episode / episode of Homeland (S2 E6)
5. The Gettysburg Address (wd:Q14752119): live album by Moon Safari / is instance of album
6. Lincoln's Gettysburg Address (wd:Q3832569): is instance of short film / 1912 short film
7. Address at Gettysburg (wd:Q56524787), also known as The Gettysburg Address: is instance of version, edition or translation / version of Lincoln's speech, 1898 publication / is instance of oration
8. The Gettysburg Address (wd:Q124630230): episode of 12th season of Curb Your Enthusiasm / is instance of television series episode
9. The Gettysburg Address (wd:Q124046982): online exhibition from Cornell University and Carl A. Kroch Library, Cornell University Library / is instance of online exhibition
10. The Gettysburg Address (wd:Q132901481): online exhibition from Library of Congress / is instance of online exhibition

[Assistant]
The primary entity for the Gettysburg Address is Q214524, which is identified as a speech by U.S. President Abraham Lincoln. I will now investigate the location where this speech was delivered by examining the properties of this entity, particularly focusing on the location of the event.

I will use the `list` function to explore triples associated with the Gettysburg Address (Q214524) to find relevant properties such as the location of the event.

list

wd:Q214524

Got 354 rows and 3 columns, showing the first 10 rows below:
| subject                         | property                                 | object                                                                      |
| ------------------------------- | ---------------------------------------- | --------------------------------------------------------------------------- |
| Gettysburg Address (wd:Q214524) | instance of (wdt:P31)                    | oration (wd:Q861911)                                                        |
| Gettysburg Address (wd:Q214524) | title (wdt:P1476)                        | Address delivered at the dedication of the cemetery at Gettysburg (lang:en) |
| Gettysburg Address (wd:Q214524) | publication date (wdt:P577)              | 1863-11-19T00:00:00Z (xsd:dateTime)                                         |
| Gettysburg Address (wd:Q214524) | author (wdt:P50)                         | Abraham Lincoln (wd:Q91)                                                    |
| Gettysburg Address (wd:Q214524) | main subject (wdt:P921)                  | American Civil War (wd:Q8676)                                               |
| Gettysburg Address (wd:Q214524) | language of work or name (wdt:P407)      | English (wd:Q1860)                                                          |
| Gettysburg Address (wd:Q214524) | country (wdt:P17)                        | United States (wd:Q30)                                                      |
| Gettysburg Address (wd:Q214524) | coordinate location (wdt:P625)           | POINT(-77.232200 39.828300) (geo:wktLiteral)                                |
| Gettysburg Address (wd:Q214524) | full work available online at (wdt:P953) | <https://www.ourdocuments.gov/doc.php?flash=false&doc=36&page=transcript>   |
| Gettysburg Address (wd:Q214524) | Commons category (wdt:P373)              | Gettysburg Address                                                          |
| ...                             | ...                                      | ...                                                                         |

[Assistant]
The `list` results show that the Gettysburg Address (Q214524) has a coordinate location (P625) of POINT(-77.232200 39.828300), which corresponds to the location of the speech. This point is in Gettysburg, Pennsylvania, United States. Additionally, the speech was delivered on November 19, 1863, at the dedication of the Soldiers' National Cemetery.

To confirm the exact location name, I will use the coordinates to find the place name associated with this point. I can do this by querying for the place that contains this coordinate using the `wdt:P131` (located in the administrative territorial entity) or directly by checking the label of the place at these coordinates.

I will construct a SPARQL query to find the place name at the given coordinates.

execute

SELECT ?place ?placeLabel WHERE { ?place wdt:P625 'POINT(-77.232200 39.828300)'^^geo:wktLiteral . SERVICE wikibase:label { bd:serviceParam wikibase:language "en" . } }

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

301 Moved Permanently'

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

I will revise the SPARQL query to use `rdfs:label` with `FILTER(LANG(?placeLabel) = "en")` to get the English label of the place at the given coordinates.

SELECT ?place ?placeLabel WHERE { ?place wdt:P625 'POINT(-77.232200 39.828300)'^^geo:wktLiteral . ?place rdfs:label ?placeLabel . FILTER(LANG(?placeLabel) = "en") }

Got 2 rows and 2 columns:
| place                           | placeLabel                   |
| ------------------------------- | ---------------------------- |
| Gettysburg Address (wd:Q214524) | Gettysburg Address (lang:en) |
| Gettysburg (wd:Q694550)         | Gettysburg (lang:en)         |

[Assistant]
The query results show two entities at the coordinates POINT(-77.232200 39.828300):

1. **Gettysburg Address (wd:Q214524)** — This is the speech itself, not the location.
2. **Gettysburg (wd:Q694550)** — This is the actual place (a town in Pennsylvania, United States) where the speech was delivered.

The correct location of the Gettysburg Address is **Gettysburg, Pennsylvania, United States**. I will now confirm that Gettysburg (Q694550) is indeed a place (e.g., a city or town) by checking its instance-of (P31) property.

list

wd:Q694550

[Assistant]
The entity Gettysburg (Q694550) is classified as a "county seat" and a "borough of Pennsylvania," confirming it is a populated place (town) in Pennsylvania, United States. This is the correct location where the Gettysburg Address was delivered.

Thus, the answer to the question "Where did the Gettysburg Address?" is **Gettysburg, Pennsylvania, United States**.

I will now provide the final SPARQL query that retrieves this information and the answer.

answer

SELECT ?place ?placeLabel WHERE { ?place wdt:P625 'POINT(-77.232200 39.828300)'^^geo:wktLiteral . ?place rdfs:label ?placeLabel . FILTER(LANG(?placeLabel) = "en") . ?place wdt:P31 ?instance . FILTER(?instance IN (wd:Q62049, wd:Q777120)) }

Answer: The Gettysburg Address was delivered in Gettysburg, Pennsylvania, United States.


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 ?occ ?occLabel WHERE {
  wd:Q5702260 wdt:P106 ?occ .
  ?occ rdfs:label ?occLabel .
  FILTER ( LANG( ?occLabel ) = "en" )
}

Using entities:
- Helen Flanagan (wd:Q5702260): has occupation film actor / has occupation actor / has occupation model / has occupation Model / is instance of human / English actress

Using properties:
- occupation (wd:P106 as wdt), also known as avocation, career, craft, employ, employment, etc.: occupation of a person; see also "field of work" (Property:P101), "position held" (Property:P39) / occupation of a person; see also "field of work" (Property:P101), "position held" (Property:P39) / occupation of a person; see also "field of work" (Property:P101), "position held" (Property:P39)

Answer: Helen Flanagan is a film actor, actor, and model.

Helen Flanagan is a film actor, actor, and model.

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 ?occ ?occLabel WHERE {
  wd:Q5702260 wdt:P106 ?occ .
  ?occ rdfs:label ?occLabel .
  FILTER ( LANG( ?occLabel ) = "en" )
}

Using entities:
- Helen Flanagan (wd:Q5702260): has occupation film actor / has occupation actor / has occupation model / has occupation Model / is instance of human / English actress

Using properties:
- occupation (wd:P106 as wdt), also known as avocation, career, craft, employ, employment, etc.: occupation of a person; see also "field of work" (Property:P101), "position held" (Property:P39) / occupation of a person; see also "field of work" (Property:P101), "position held" (Property:P39) / occupation of a person; see also "field of work" (Property:P101), "position held" (Property:P39)

Execution result:
Got 3 rows and 2 columns:
| occ                       | occLabel             |
| ------------------------- | -------------------- |
| film actor (wd:Q10800557) | film actor (lang:en) |
| actor (wd:Q33999)         | actor (lang:en)      |
| model (wd:Q4610556)       | model (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 does helen flanagan do?

[Assistant]
To determine what Helen Flanagan does, I need to find her occupation. This involves identifying her entity in Wikidata and then retrieving her occupation (P106) property.

Step 1: Search for Helen Flanagan in Wikidata to find her entity.

Question: helen flanagan

Top 10 entity alternatives:
1. Helen Flanagan (wd:Q5702260): has occupation film actor / has occupation model / has occupation Model / has occupation actor / is instance of human / English actress
2. Helen Anna Flanagan (wd:Q108477380): has occupation performance artist / has occupation visual artist / has occupation video artist / has occupation artist / is instance of human
3. Flanagan solo Flanagan (wd:Q12388599): is instance of literary work
4. Helen Keller (wd:Q38203), also known as Helen Adams Keller: American author and activist (1880–1968) / has occupation political activist / has occupation trade unionist / has occupation autobiographer / has occupation peace activist / has occupation suffragette / has occupation essayist / has occupation linguist / has occupation writer / has occupation orator / is instance of human
5. Helen Mirren (wd:Q349391), also known as Dame Helen Lydia Mirren: has occupation television actor / has occupation Film producer / has occupation film producer / has occupation film director / has occupation voice actor / has occupation stage actor / has occupation film actor / English actor (born 1945) / has occupation actor / is instance of human / British actress / British actress
6. Helen of Troy (wd:Q164061, matched via Helen), also known as Helen, Helen of Argos, Helen of Sparta: is instance of mythological Greek character / is instance of legendary progenitor / daughter of Zeus in Greek mythology
7. Helen Clark (wd:Q180383), also known as Helen E. Clark, Helen Elizabeth Clark, The Right Honourable Helen Elizabeth Clark: Prime Minister of New Zealand from 1999 to 2008 / Prime Minister of New Zealand from 1999 to 2008 / has occupation political scientist / has occupation university teacher / has occupation politician / is instance of human
8. Helen Hunt (wd:Q170574), also known as Helen Elizabeth Hunt: has occupation television actor / American actress and director / has occupation film producer / has occupation film director / has occupation Film producer / has occupation screenwriter / has occupation voice actor / has occupation stage actor / has occupation film actor / has occupation actor / is instance of human
9. Helena Augusta (wd:Q170164, matched via Saint Helen), also known as Aelena, Beata Aelena, Flavia Aelena, Flavia Helena, Flavia Iulia Helena Augusta, etc.: saint, first wife of Roman emperor Constantius Chlorus, and mother of Emperor Constantine the Great (250-330) / has occupation politician / is instance of human
10. Helen Hayes (wd:Q213302), also known as Helen Hayes Brown, Helen Hayes MacArthur: has occupation television actor / has occupation autobiographer / American actress (1900–1993) / has occupation stage actor / has occupation film actor / is instance of human / American actress / American actress

[Assistant]
The top result for Helen Flanagan is wd:Q5702260, described as an English actress and model. To confirm her occupation, I will retrieve the occupation (P106) property for this entity and fetch the English labels for the occupations.

Step 2: Query the occupations of Helen Flanagan (wd:Q5702260) using SPARQL.

execute

SELECT ?occ ?occLabel WHERE { wd:Q5702260 wdt:P106 ?occ . ?occ rdfs:label ?occLabel . FILTER(LANG(?occLabel) = "en") }

[Assistant]
Helen Flanagan's occupations are film actor, actor, and model. These are confirmed by the SPARQL query results, which return the English labels for her occupations.

Final answer:

answer

SELECT ?occ ?occLabel WHERE { wd:Q5702260 wdt:P106 ?occ . ?occ rdfs:label ?occLabel . FILTER(LANG(?occLabel) = "en") }

Answer: Helen Flanagan is a film actor, actor, and model.