PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
SELECT ?person ?personLabel ( COUNT( DISTINCT ?episode ) AS ?appearances ) WHERE {
  ?episode wdt:P179 wd:Q565894 ; wdt:P31 wd:Q21191270 .
  {
    ?episode wdt:P161 ?person .
  } UNION {
    ?episode wdt:P710 ?person .
  }
  ?person wdt:P31 wd:Q5 .
  FILTER ( ?person != wd:Q77772 ) OPTIONAL {
    ?person rdfs:label ?personLabel .
    FILTER ( LANG( ?personLabel ) = "en" )
  }
}
GROUP BY ?person ?personLabel
ORDER BY DESC ( ?appearances ) ?personLabel
LIMIT 1000

Using entities:
- television series episode (wd:Q21191270), also known as television episode, television show episode, TV episode, TV series episode, TV show episode: is subclass of episode / is subclass of audiovisual work / single installment of a television series / single installment of a television series / single installment of a television series
- Anne Will (wd:Q565894), also known as ANNE WILL, ANNEWILL: is instance of television program / is instance of television programme / German political TV talk show (2007–2023)
- human (wd:Q5), also known as human being, humans, individual Homo sapiens, individual human, modern humans, etc.: is instance of class of organisms known by one particular common name / is instance of organisms known by a particular common name / is subclass of mammal / is subclass of natural person / is subclass of omnivore / is subclass of person / is subclass of individual animal / any member of Homo sapiens, unique extant species of the genus Homo / common name of Homo sapiens, unique extant species of the genus Homo / common name of Homo sapiens, unique extant species of the genus Homo / common name of Homo sapiens, unique extant species of the genus Homo, from embryo to adult
- Anne Will (wd:Q77772): has occupation presenter / has occupation journalist / has occupation television presenter / is instance of human / German television journalist

Using properties:
- cast member (wd:P161 as wdt), also known as actor, actress, contestant of a play, feat., film starring, etc.: is subproperty of performer / is subproperty of significant person / actor in the subject production [use "character role" (P453) ... as qualifiers] [use "voice actor" (P725) for voice-only role] / actor in the subject production [use "character role" (P453) ... "recorded participant" (P11108) for non-fiction productions] / actor performing live for a camera or audience [use ... as qualifier] [use "voice actor" (P725) for voice-only role]
- part of the series (wd:P179 as wdt), also known as collection, episode of, in series, issue of, listed in, etc.: is subproperty of part of / series which contains the subject / series which contains the subject / series which contains the subject
- 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
- participant (wd:P710 as wdt), also known as accused, agent, attendee, belligerents, between, etc.: is subproperty of significant person / person, group of people or organization (object) that ... has role" (P3831). Use P1923 for participants that are teams. / person, group of people or organization that actively takes/took part in the event

Got 11 rows and 3 columns, showing the first 5 and last 5 rows below:
| person                          | personLabel                 | appearances |
| ------------------------------- | --------------------------- | ----------- |
| Olaf Scholz (wd:Q61053)         | Olaf Scholz (lang:en)       | 2 (xsd:int) |
| Alice Weidel (wd:Q27975838)     | Alice Weidel (lang:en)      | 1 (xsd:int) |
| Annalena Baerbock (wd:Q564328)  | Annalena Baerbock (lang:en) | 1 (xsd:int) |
| Armin Laschet (wd:Q78205)       | Armin Laschet (lang:en)     | 1 (xsd:int) |
| Carsten Linnemann (wd:Q1045606) | Carsten Linnemann (lang:en) | 1 (xsd:int) |
| ...                             | ...                         | ...         |
| Monika Schnitzer (wd:Q1944756)  | Monika Schnitzer (lang:en)  | 1 (xsd:int) |
| Reiner Holznagel (wd:Q15842048) | Reiner Holznagel (lang:en)  | 1 (xsd:int) |
| Sahra Wagenknecht (wd:Q77193)   | Sahra Wagenknecht (lang:en) | 1 (xsd:int) |
| Thomas Oppermann (wd:Q90833)    | Thomas Oppermann (lang:en)  | 1 (xsd:int) |
| Volker Kauder (wd:Q67164)       | Volker Kauder (lang:en)     | 1 (xsd:int) |

Answer:
Results (ordered by number of distinct episodes on which each person appears, based on Wikidata):

- http://www.wikidata.org/entity/Q61053 — Olaf Scholz — 2 episodes
- http://www.wikidata.org/entity/Q27975838 — Alice Weidel — 1 episode
- http://www.wikidata.org/entity/Q564328 — Annalena Baerbock — 1 episode
- http://www.wikidata.org/entity/Q78205 — Armin Laschet — 1 episode
- http://www.wikidata.org/entity/Q1045606 — Carsten Linnemann — 1 episode
- http://www.wikidata.org/entity/Q85806 — Christian Lindner — 1 episode
- http://www.wikidata.org/entity/Q1944756 — Monika Schnitzer — 1 episode
- http://www.wikidata.org/entity/Q15842048 — Reiner Holznagel — 1 episode
- http://www.wikidata.org/entity/Q77193 — Sahra Wagenknecht — 1 episode
- http://www.wikidata.org/entity/Q90833 — Thomas Oppermann — 1 episode
- http://www.wikidata.org/entity/Q67164 — Volker Kauder — 1 episode

Notes and assumptions:
- I treated any human linked to an episode via wdt:P161 (cast member) or wdt:P710 (participant) as someone who "appeared" on that episode.
- I excluded Anne Will herself (wd:Q77772) because the user asked for guests who appeared on the show (the host is typically not considered a guest).
- The counts are DISTINCT episode counts (how many different episodes the person appears in, according to Wikidata statements matching the above patterns).
- Wikidata coverage is incomplete and depends on contributors; other guests may exist on the show but not be recorded with these properties, or episodes may be represented differently. If you want, I can expand the query to include other properties/annotations or to return the underlying episodes for each person.

Results (ordered by number of distinct episodes on which each person appears, based on Wikidata):

- http://www.wikidata.org/entity/Q61053 — Olaf Scholz — 2 episodes
- http://www.wikidata.org/entity/Q27975838 — Alice Weidel — 1 episode
- http://www.wikidata.org/entity/Q564328 — Annalena Baerbock — 1 episode
- http://www.wikidata.org/entity/Q78205 — Armin Laschet — 1 episode
- http://www.wikidata.org/entity/Q1045606 — Carsten Linnemann — 1 episode
- http://www.wikidata.org/entity/Q85806 — Christian Lindner — 1 episode
- http://www.wikidata.org/entity/Q1944756 — Monika Schnitzer — 1 episode
- http://www.wikidata.org/entity/Q15842048 — Reiner Holznagel — 1 episode
- http://www.wikidata.org/entity/Q77193 — Sahra Wagenknecht — 1 episode
- http://www.wikidata.org/entity/Q90833 — Thomas Oppermann — 1 episode
- http://www.wikidata.org/entity/Q67164 — Volker Kauder — 1 episode

Notes and assumptions:
- I treated any human linked to an episode via wdt:P161 (cast member) or wdt:P710 (participant) as someone who "appeared" on that episode.
- I excluded Anne Will herself (wd:Q77772) because the user asked for guests who appeared on the show (the host is typically not considered a guest).
- The counts are DISTINCT episode counts (how many different episodes the person appears in, according to Wikidata statements matching the above patterns).
- Wikidata coverage is incomplete and depends on contributors; other guests may exist on the show but not be recorded with these properties, or episodes may be represented differently. If you want, I can expand the query to include other properties/annotations or to return the underlying episodes for each person.

SPARQL query over wikidata:
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
SELECT ?person ?personLabel ( COUNT( DISTINCT ?episode ) AS ?appearances ) WHERE {
  ?episode wdt:P179 wd:Q565894 ; wdt:P31 wd:Q21191270 .
  {
    ?episode wdt:P161 ?person .
  } UNION {
    ?episode wdt:P710 ?person .
  }
  ?person wdt:P31 wd:Q5 .
  FILTER ( ?person != wd:Q77772 ) OPTIONAL {
    ?person rdfs:label ?personLabel .
    FILTER ( LANG( ?personLabel ) = "en" )
  }
}
GROUP BY ?person ?personLabel
ORDER BY DESC ( ?appearances ) ?personLabel
LIMIT 1000

Using entities:
- television series episode (wd:Q21191270), also known as television episode, television show episode, TV episode, TV series episode, TV show episode: is subclass of episode / is subclass of audiovisual work / single installment of a television series / single installment of a television series / single installment of a television series
- Anne Will (wd:Q565894), also known as ANNE WILL, ANNEWILL: is instance of television program / is instance of television programme / German political TV talk show (2007–2023)
- human (wd:Q5), also known as human being, humans, individual Homo sapiens, individual human, modern humans, etc.: is instance of class of organisms known by one particular common name / is instance of organisms known by a particular common name / is subclass of mammal / is subclass of natural person / is subclass of omnivore / is subclass of person / is subclass of individual animal / any member of Homo sapiens, unique extant species of the genus Homo / common name of Homo sapiens, unique extant species of the genus Homo / common name of Homo sapiens, unique extant species of the genus Homo / common name of Homo sapiens, unique extant species of the genus Homo, from embryo to adult
- Anne Will (wd:Q77772): has occupation presenter / has occupation journalist / has occupation television presenter / is instance of human / German television journalist

Using properties:
- cast member (wd:P161 as wdt), also known as actor, actress, contestant of a play, feat., film starring, etc.: is subproperty of performer / is subproperty of significant person / actor in the subject production [use "character role" (P453) ... as qualifiers] [use "voice actor" (P725) for voice-only role] / actor in the subject production [use "character role" (P453) ... "recorded participant" (P11108) for non-fiction productions] / actor performing live for a camera or audience [use ... as qualifier] [use "voice actor" (P725) for voice-only role]
- part of the series (wd:P179 as wdt), also known as collection, episode of, in series, issue of, listed in, etc.: is subproperty of part of / series which contains the subject / series which contains the subject / series which contains the subject
- 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
- participant (wd:P710 as wdt), also known as accused, agent, attendee, belligerents, between, etc.: is subproperty of significant person / person, group of people or organization (object) that ... has role" (P3831). Use P1923 for participants that are teams. / person, group of people or organization that actively takes/took part in the event

Execution result:
Got 11 rows and 3 columns, showing the first 5 and last 5 rows below:
| person                          | personLabel                 | appearances |
| ------------------------------- | --------------------------- | ----------- |
| Olaf Scholz (wd:Q61053)         | Olaf Scholz (lang:en)       | 2 (xsd:int) |
| Alice Weidel (wd:Q27975838)     | Alice Weidel (lang:en)      | 1 (xsd:int) |
| Annalena Baerbock (wd:Q564328)  | Annalena Baerbock (lang:en) | 1 (xsd:int) |
| Armin Laschet (wd:Q78205)       | Armin Laschet (lang:en)     | 1 (xsd:int) |
| Carsten Linnemann (wd:Q1045606) | Carsten Linnemann (lang:en) | 1 (xsd:int) |
| ...                             | ...                         | ...         |
| Monika Schnitzer (wd:Q1944756)  | Monika Schnitzer (lang:en)  | 1 (xsd:int) |
| Reiner Holznagel (wd:Q15842048) | Reiner Holznagel (lang:en)  | 1 (xsd:int) |
| Sahra Wagenknecht (wd:Q77193)   | Sahra Wagenknecht (lang:en) | 1 (xsd:int) |
| Thomas Oppermann (wd:Q90833)    | Thomas Oppermann (lang:en)  | 1 (xsd:int) |
| Volker Kauder (wd:Q67164)       | Volker Kauder (lang:en)     | 1 (xsd:int) |

[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] Who are the guests who have appeared on the German political TV talk show "Anne Will," and how many distinct episodes has each guest appeared in, ordered by the number of appearances in descending order?

[Assistant]
Step 1: I'll search Wikidata for the entity corresponding to the German political TV talk show "Anne Will" to get its QID and confirm it's the right entity (a TV series / talk show). I'll use search_entity for that.

Question: Anne Will

Top 10 entity alternatives:
1. Anne Will (wd:Q77772): has occupation television presenter / German television journalist / has occupation journalist / has occupation presenter / is instance of human
2. Anne Will (wd:Q565894), also known as ANNE WILL, ANNEWILL: German political TV talk show (2007–2023) / is instance of television programme / is instance of television program
3. Ann Willing Bingham (wd:Q4766749, matched via Anne Willing), also known as Anne Willing, Anne Willing Bingham, Ann Willing, Lady Liberty: has occupation socialite / is instance of human / American socialite
4. Aenne Willkomm (wd:Q19973540, matched via Änne Willkomm), also known as Änne Willkomm: German costume designer (1902-1979) / has occupation costume designer / is instance of human
5. Anne Wills (wd:Q4768893), also known as Anne Shirley Wills: has occupation television presenter / Australian television presenter / is instance of human
6. Anne Williams (wd:Q15993657), also known as Anne Elizabeth Williams: British campaigner for the victims of the Hillsborough disaster / is instance of human
7. Elizabeth O'Conner (wd:Q5363274, matched via Anne Willard), also known as Anne Willard, Barbara Lowe, Barbara McNamara, Barbara Willard Lowe McNamara, Elizabeth O'Connor: has occupation novelist / is instance of human / Australian writer
8. Anne Willan (wd:Q4768891): English chef and writer / is instance of human / has occupation chef
9. Anne Williams-Isom (wd:Q110259960), also known as A. Williams-Isom: American government official, academic, lawyer, and nonprofit executive / has occupation business executive / has occupation Official / has occupation official / has occupation academic / has occupation lawyer / is instance of human
10. Anne Dutton (wd:Q18572248, matched via Anne Williams), also known as Anne Williams: English writer and autobiographer / has occupation religious writer / is instance of human

[Assistant]
I'll search for properties related to episodes for the TV show entity wd:Q565894 (the "Anne Will" TV programme) to find how episodes are connected in Wikidata (properties like "has part", "part of", "episodes", etc.).

Question: episode

Top 10 property alternatives:
1. number of episodes (wd:P1113 as p/wdt, matched via episodes), also known as episode count, episodes, no. of episodes, series length, P1113: is subproperty of number of parts of a work of art / is subproperty of number of parts of this work / number of episodes in a film/TV/radio series / number of episodes in a film/TV/radio series / number of episodes in a film/TV/radio series
2. original broadcaster (wd:P449 as p/wdt, matched via channel), also known as aired on, airs on, broadcast on, channel, first air channel, etc.: network(s) or service(s) that originally broadcasted a radio or television programme / network(s) or service(s) that originally broadcast a radio or television program / is subproperty of broadcast by
3. duration (wd:P2047 as p/wdt, matched via era), also known as cook time, era, interval, length, length of time, etc.: length of time of an event or process / length of time of an event or process / length of time of an event or process
4. end time (wd:P582 as p/wdt, matched via ends), also known as abolished, cease date, cease operation, cease time, closed, etc.: moment when an entity ceases to exist and a statement stops being entirely valid or no longer be true / indicates the time an item ceases to exist or a statement stops being valid / indicates the time an item ceases to exist or a statement stops being valid / is subproperty of point in time
5. title (wd:P1476 as p/wdt), also known as article title, full title, headline, known as, name, etc.: published name of a work, such as a newspaper article, a literary work, piece of music, a website, or a performance work / published title of a work, such as a newspaper article, a literary work, a website, or a performance work / published title of a work, such as a newspaper article, a literary work, a website, or a performance work / is subproperty of name
6. replaced by (wd:P1366 as p/wdt, matched via continued by), also known as becomes, continued by, heir, mediatised to, next job holder, etc.: other person or item which continues the item by replacing it ... identical, but adds to the series (e.g. books in a series). / person or state or item who replaces another in an office, ... by) if the item is not replaced, e.g. books in a series / is subproperty of followed by
7. start time (wd:P580 as p/wdt, matched via from), also known as began, beginning, building date, effective, effectivity, etc.: indicates the time an item begins to exist or a statement starts being valid / indicates the time an item begins to exist or a statement starts being valid / time an entity begins to exist or a statement starts being valid / is subproperty of point in time
8. number of seasons (wd:P2437 as p/wdt, matched via no. of series), also known as no. of seasons, no. of series, number of series, seasons, P2437: number of seasons a television or radio series has had / number of series a television or radio show has had / is subproperty of number of parts of a work of art / is subproperty of number of parts of this work
9. has part(s) (wd:P527 as p/wdt, matched via includes part), also known as amalgamation of, assembled from, assembled out of, composed of, comprised of, etc.: 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). / part of this subject, also valuable subclass or exemplar. Inverse property of "part of".
10. publication date (wd:P577 as p/wdt, matched via air date), also known as air date, airdate, be published during, be published in, broadcast date, etc.: date or point in time when a work was first published or released / date or point in time a work is first published or released / date or point in time a work is first published or released / is subproperty of point in time

No other items found

[Assistant]
I'll run a SPARQL query to retrieve some episodes of the "Anne Will" series (wd:Q565894) and see how persons (guests) are linked to those episodes. I'll check both common properties for people on episodes: cast member (P161) and participant (P710), and ensure persons are humans (instance of Q5). This will help determine the correct property to use for guest appearances.

execute

SELECT ?episode ?episodeLabel ?person ?personLabel ?p WHERE {
  ?episode wdt:P179 wd:Q565894; wdt:P31 wd:Q21191270 .
  OPTIONAL { ?episode wdt:P161 ?person . BIND(wdt:P161 as ?p) }
  OPTIONAL { ?episode wdt:P710 ?person . BIND(wdt:P710 as ?p) }
  FILTER(!BOUND(?person) || ?person wdt:P31 wd:Q5)
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
} LIMIT 200

Call to function execute returned an error:
failed to parse input: parse error at position 281 for token PNAME_LN with content 'wdt:P31' (the input most likely does not follow the grammar)

[Assistant]
I'll query episodes that explicitly use wdt:P161 (cast member) linking to humans, to see if guests are recorded with P161.

SELECT ?episode ?episodeLabel ?person ?personLabel WHERE {
  ?episode wdt:P179 wd:Q565894; wdt:P31 wd:Q21191270; wdt:P161 ?person .
  ?person wdt:P31 wd:Q5 .
  ?episode rdfs:label ?episodeLabel . FILTER(LANG(?episodeLabel) = "en")
  ?person rdfs:label ?personLabel . FILTER(LANG(?personLabel) = "en")
} LIMIT 100

Got 5 rows and 4 columns:
| episode                                                                       | episodeLabel                                                             | person                          | personLabel                 |
| ----------------------------------------------------------------------------- | ------------------------------------------------------------------------ | ------------------------------- | --------------------------- |
| Milliarden gegen die Krise – wird das Geld richtig investiert? (wd:Q95584385) | Milliarden gegen die Krise – wird das Geld richtig investiert? (lang:en) | Carsten Linnemann (wd:Q1045606) | Carsten Linnemann (lang:en) |
| Milliarden gegen die Krise – wird das Geld richtig investiert? (wd:Q95584385) | Milliarden gegen die Krise – wird das Geld richtig investiert? (lang:en) | Reiner Holznagel (wd:Q15842048) | Reiner Holznagel (lang:en)  |
| Milliarden gegen die Krise – wird das Geld richtig investiert? (wd:Q95584385) | Milliarden gegen die Krise – wird das Geld richtig investiert? (lang:en) | Monika Schnitzer (wd:Q1944756)  | Monika Schnitzer (lang:en)  |
| Milliarden gegen die Krise – wird das Geld richtig investiert? (wd:Q95584385) | Milliarden gegen die Krise – wird das Geld richtig investiert? (lang:en) | Annalena Baerbock (wd:Q564328)  | Annalena Baerbock (lang:en) |
| Milliarden gegen die Krise – wird das Geld richtig investiert? (wd:Q95584385) | Milliarden gegen die Krise – wird das Geld richtig investiert? (lang:en) | Olaf Scholz (wd:Q61053)         | Olaf Scholz (lang:en)       |

[Assistant]
Now I'll run the SPARQL that counts distinct episodes of "Anne Will" (wd:Q565894) in which each human person appears, using both P161 (cast member) and P710 (participant), and excluding the host Anne Will (wd:Q77772) as a reasonable assumption (the host isn't a guest). The query returns the person IRI, optional English label, and the number of distinct episodes they appear in, ordered by count descending.

SELECT ?person ?personLabel (COUNT(DISTINCT ?episode) AS ?appearances) WHERE {
  ?episode wdt:P179 wd:Q565894 ;
           wdt:P31 wd:Q21191270 .
  {
    ?episode wdt:P161 ?person .
  } UNION {
    ?episode wdt:P710 ?person .
  }
  ?person wdt:P31 wd:Q5 .
  FILTER(?person != wd:Q77772) # exclude the host Anne Will
  OPTIONAL { ?person rdfs:label ?personLabel . FILTER(LANG(?personLabel) = "en") }
}
GROUP BY ?person ?personLabel
ORDER BY DESC(?appearances) ?personLabel
LIMIT 1000

Got 11 rows and 3 columns, showing the first 5 and last 5 rows below:
| person                          | personLabel                 | appearances |
| ------------------------------- | --------------------------- | ----------- |
| Olaf Scholz (wd:Q61053)         | Olaf Scholz (lang:en)       | 2 (xsd:int) |
| Alice Weidel (wd:Q27975838)     | Alice Weidel (lang:en)      | 1 (xsd:int) |
| Annalena Baerbock (wd:Q564328)  | Annalena Baerbock (lang:en) | 1 (xsd:int) |
| Armin Laschet (wd:Q78205)       | Armin Laschet (lang:en)     | 1 (xsd:int) |
| Carsten Linnemann (wd:Q1045606) | Carsten Linnemann (lang:en) | 1 (xsd:int) |
| ...                             | ...                         | ...         |
| Monika Schnitzer (wd:Q1944756)  | Monika Schnitzer (lang:en)  | 1 (xsd:int) |
| Reiner Holznagel (wd:Q15842048) | Reiner Holznagel (lang:en)  | 1 (xsd:int) |
| Sahra Wagenknecht (wd:Q77193)   | Sahra Wagenknecht (lang:en) | 1 (xsd:int) |
| Thomas Oppermann (wd:Q90833)    | Thomas Oppermann (lang:en)  | 1 (xsd:int) |
| Volker Kauder (wd:Q67164)       | Volker Kauder (lang:en)     | 1 (xsd:int) |

[Assistant]
I'll re-run the same query to retrieve the full ordered list (to be certain of the exact order and full rows) before finalizing the answer.

SELECT ?person ?personLabel (COUNT(DISTINCT ?episode) AS ?appearances) WHERE {
  ?episode wdt:P179 wd:Q565894 ;
           wdt:P31 wd:Q21191270 .
  {
    ?episode wdt:P161 ?person .
  } UNION {
    ?episode wdt:P710 ?person .
  }
  ?person wdt:P31 wd:Q5 .
  FILTER(?person != wd:Q77772) # exclude the host Anne Will
  OPTIONAL { ?person rdfs:label ?personLabel . FILTER(LANG(?personLabel) = "en") }
}
GROUP BY ?person ?personLabel
ORDER BY DESC(?appearances) ?personLabel
LIMIT 1000

Got 11 rows and 3 columns, showing the first 5 and last 5 rows below:
| person                          | personLabel                 | appearances |
| ------------------------------- | --------------------------- | ----------- |
| Olaf Scholz (wd:Q61053)         | Olaf Scholz (lang:en)       | 2 (xsd:int) |
| Alice Weidel (wd:Q27975838)     | Alice Weidel (lang:en)      | 1 (xsd:int) |
| Annalena Baerbock (wd:Q564328)  | Annalena Baerbock (lang:en) | 1 (xsd:int) |
| Armin Laschet (wd:Q78205)       | Armin Laschet (lang:en)     | 1 (xsd:int) |
| Carsten Linnemann (wd:Q1045606) | Carsten Linnemann (lang:en) | 1 (xsd:int) |
| ...                             | ...                         | ...         |
| Monika Schnitzer (wd:Q1944756)  | Monika Schnitzer (lang:en)  | 1 (xsd:int) |
| Reiner Holznagel (wd:Q15842048) | Reiner Holznagel (lang:en)  | 1 (xsd:int) |
| Sahra Wagenknecht (wd:Q77193)   | Sahra Wagenknecht (lang:en) | 1 (xsd:int) |
| Thomas Oppermann (wd:Q90833)    | Thomas Oppermann (lang:en)  | 1 (xsd:int) |
| Volker Kauder (wd:Q67164)       | Volker Kauder (lang:en)     | 1 (xsd:int) |

[Assistant]
I'll run a single-query that aggregates the results into one concatenated string so the complete ordered list is returned without truncation. This inner query counts distinct episodes per person (same logic as before), and the outer GROUP_CONCAT will produce one string with all rows.

SELECT (GROUP_CONCAT(CONCAT(STR(?person),"||",COALESCE(?personLabel,"") ,"||",STR(?appearances)) ; separator=";;") AS ?all) WHERE {
  {
    SELECT ?person ?personLabel (COUNT(DISTINCT ?episode) AS ?appearances) WHERE {
      ?episode wdt:P179 wd:Q565894 ; wdt:P31 wd:Q21191270 .
      { ?episode wdt:P161 ?person } UNION { ?episode wdt:P710 ?person }
      ?person wdt:P31 wd:Q5 .
      FILTER(?person != wd:Q77772)
      OPTIONAL { ?person rdfs:label ?personLabel . FILTER(LANG(?personLabel) = "en") }
    }
    GROUP BY ?person ?personLabel
    ORDER BY DESC(?appearances) ?personLabel
  }
}

[Assistant]
I'll run a query to find persons with more than 1 appearance (to confirm Olaf Scholz is the only one with 2). I'll explain after this call.

SELECT ?person ?personLabel (COUNT(DISTINCT ?episode) AS ?appearances) WHERE {
  ?episode wdt:P179 wd:Q565894 ; wdt:P31 wd:Q21191270 .
  { ?episode wdt:P161 ?person } UNION { ?episode wdt:P710 ?person }
  ?person wdt:P31 wd:Q5 .
  FILTER(?person != wd:Q77772)
  OPTIONAL { ?person rdfs:label ?personLabel . FILTER(LANG(?personLabel) = "en") }
}
GROUP BY ?person ?personLabel
HAVING (COUNT(DISTINCT ?episode) > 1)
ORDER BY DESC(?appearances) ?personLabel

[Assistant]
I'll aggregate the persons with exactly 1 appearance into a single comma-separated string (using their English labels) so I can list them all reliably.

SELECT (GROUP_CONCAT(?personLabel; separator=", ") AS ?ones) WHERE {
  {
    SELECT ?person ?personLabel (COUNT(DISTINCT ?episode) AS ?appearances) WHERE {
      ?episode wdt:P179 wd:Q565894 ; wdt:P31 wd:Q21191270 .
      { ?episode wdt:P161 ?person } UNION { ?episode wdt:P710 ?person }
      ?person wdt:P31 wd:Q5 .
      FILTER(?person != wd:Q77772)
      OPTIONAL { ?person rdfs:label ?personLabel . FILTER(LANG(?personLabel) = "en") }
    }
    GROUP BY ?person ?personLabel
    HAVING (COUNT(DISTINCT ?episode) = 1)
    ORDER BY ?personLabel
  }
}

[Assistant]
I'll request the distinct persons (with English labels) who appear on Anne Will's episodes and order them alphabetically by label; this should let me list them clearly.

SELECT DISTINCT ?person ?personLabel WHERE {
  ?episode wdt:P179 wd:Q565894; wdt:P31 wd:Q21191270 .
  ?episode wdt:P161|wdt:P710 ?person .
  ?person wdt:P31 wd:Q5 .
  FILTER(?person != wd:Q77772)
  ?person rdfs:label ?personLabel . FILTER(LANG(?personLabel) = "en")
}
ORDER BY ?personLabel

Got 11 rows and 2 columns, showing the first 5 and last 5 rows below:
| person                          | personLabel                 |
| ------------------------------- | --------------------------- |
| Alice Weidel (wd:Q27975838)     | Alice Weidel (lang:en)      |
| Annalena Baerbock (wd:Q564328)  | Annalena Baerbock (lang:en) |
| Armin Laschet (wd:Q78205)       | Armin Laschet (lang:en)     |
| Carsten Linnemann (wd:Q1045606) | Carsten Linnemann (lang:en) |
| Christian Lindner (wd:Q85806)   | Christian Lindner (lang:en) |
| ...                             | ...                         |
| Olaf Scholz (wd:Q61053)         | Olaf Scholz (lang:en)       |
| Reiner Holznagel (wd:Q15842048) | Reiner Holznagel (lang:en)  |
| Sahra Wagenknecht (wd:Q77193)   | Sahra Wagenknecht (lang:en) |
| Thomas Oppermann (wd:Q90833)    | Thomas Oppermann (lang:en)  |
| Volker Kauder (wd:Q67164)       | Volker Kauder (lang:en)     |

[Assistant]
Final SPARQL query (same as executed): it counts distinct episodes of Anne Will (wd:Q565894) in which each human person appears via P161 (cast member) or P710 (participant), excluding the host Anne Will (wd:Q77772). I'll provide the query and the answer based on the query results.

answer

SELECT ?person ?personLabel (COUNT(DISTINCT ?episode) AS ?appearances) WHERE {
  ?episode wdt:P179 wd:Q565894 ;
           wdt:P31 wd:Q21191270 .
  {
    ?episode wdt:P161 ?person .
  } UNION {
    ?episode wdt:P710 ?person .
  }
  ?person wdt:P31 wd:Q5 .
  FILTER(?person != wd:Q77772) # exclude the host Anne Will
  OPTIONAL { ?person rdfs:label ?personLabel . FILTER(LANG(?personLabel) = "en") }
}
GROUP BY ?person ?personLabel
ORDER BY DESC(?appearances) ?personLabel
LIMIT 1000

Answer:
Results (ordered by number of distinct episodes on which each person appears, based on Wikidata):

- http://www.wikidata.org/entity/Q61053 — Olaf Scholz — 2 episodes
- http://www.wikidata.org/entity/Q27975838 — Alice Weidel — 1 episode
- http://www.wikidata.org/entity/Q564328 — Annalena Baerbock — 1 episode
- http://www.wikidata.org/entity/Q78205 — Armin Laschet — 1 episode
- http://www.wikidata.org/entity/Q1045606 — Carsten Linnemann — 1 episode
- http://www.wikidata.org/entity/Q85806 — Christian Lindner — 1 episode
- http://www.wikidata.org/entity/Q1944756 — Monika Schnitzer — 1 episode
- http://www.wikidata.org/entity/Q15842048 — Reiner Holznagel — 1 episode
- http://www.wikidata.org/entity/Q77193 — Sahra Wagenknecht — 1 episode
- http://www.wikidata.org/entity/Q90833 — Thomas Oppermann — 1 episode
- http://www.wikidata.org/entity/Q67164 — Volker Kauder — 1 episode

Notes and assumptions:
- I treated any human linked to an episode via wdt:P161 (cast member) or wdt:P710 (participant) as someone who "appeared" on that episode.
- I excluded Anne Will herself (wd:Q77772) because the user asked for guests who appeared on the show (the host is typically not considered a guest).
- The counts are DISTINCT episode counts (how many different episodes the person appears in, according to Wikidata statements matching the above patterns).
- Wikidata coverage is incomplete and depends on contributors; other guests may exist on the show but not be recorded with these properties, or episodes may be represented differently. If you want, I can expand the query to include other properties/annotations or to return the underlying episodes for each person.


PREFIX p: <http://www.wikidata.org/prop/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX ps: <http://www.wikidata.org/prop/statement/>
SELECT ?stmt ?pubDate WHERE {
  wd:Q49740 p:P577 ?stmt .
  ?stmt ps:P577 ?pubDate .
}
ORDER BY DESC ( ?pubDate )
LIMIT 1

Using entities:
- Minecraft (wd:Q49740): is instance of esports discipline / is instance of video game / 2011 video game / 2011 video game / 2011 video game / sandbox indie video game

Using properties:
- publication date (wd:P577 as p/ps), also known as air date, airdate, be published during, be published in, broadcast date, etc.: is subproperty of point in time / date or point in time a work is first published or released / date or point in time a work is first published or released / date or point in time when a work was first published or released

Answer: The most recent publication date for Minecraft (wd:Q49740) is 2011-11-18 (2011-11-18T00:00:00Z).

The most recent publication date for Minecraft (wd:Q49740) is 2011-11-18 (2011-11-18T00:00:00Z).

SPARQL query over wikidata:
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX ps: <http://www.wikidata.org/prop/statement/>
SELECT ?stmt ?pubDate WHERE {
  wd:Q49740 p:P577 ?stmt .
  ?stmt ps:P577 ?pubDate .
}
ORDER BY DESC ( ?pubDate )
LIMIT 1

Using entities:
- Minecraft (wd:Q49740): is instance of esports discipline / is instance of video game / 2011 video game / 2011 video game / 2011 video game / sandbox indie video game

Using properties:
- publication date (wd:P577 as p/ps), also known as air date, airdate, be published during, be published in, broadcast date, etc.: is subproperty of point in time / date or point in time a work is first published or released / date or point in time a work is first published or released / date or point in time when a work was first published or released

Execution result:
Got 1 row and 2 columns:
| stmt                                          | pubDate                             |
| --------------------------------------------- | ----------------------------------- |
| s:Q49740-988392e9-4106-288e-f452-31ede9b4408d | 2011-11-18T00:00:00Z (xsd:dateTime) |

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

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

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

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

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

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

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

[User] What is the most recent publication date of "Minecraft"?

[Assistant]
Step 1 — I'll search Wikidata for the item corresponding to "Minecraft" (the video game). I want to confirm the correct entity and that it's the video game, not something else. I'll use search_entity for "Minecraft".

Question: Minecraft

Top 10 entity alternatives:
1. Minecraft (wd:Q49740): is instance of esports discipline / is instance of video game / sandbox indie video game / 2011 video game / 2011 video game / 2011 video game
2. A Minecraft Movie (wd:Q40083273, matched via Minecraft), also known as Minecraft, Minecraft Movie, Minecraft: The Movie: 2025 film directed by Jared Hess / is instance of film / Movie from 2025
3. Minecraft (wd:Q25445348), also known as Minecraft (franchise), Minecraft franchise: is instance of media franchise / media franchise
4. Minecraft: The Unlikely Tale of Markus "Notch" Persson and the Game That Changed Everything (wd:Q20926210, matched via Minecraft), also known as Minecraft: is instance of literary work / American non-fiction book
5. Minecraft (wd:Q126199422), also known as Minecraft Animated Series, Untitled Minecraft animated series: is instance of animated television series / upcoming animated series
6. Minecraft (wd:Q125765048), also known as calm1.ogg: is instance of musical work/composition / song by C418
7. Minecraft: Java Edition (wd:Q105729297, matched via Minecraft), also known as Java Edition, JE, MC Java Edition, MC: Java Edition, MC: JE, etc.: 2011 sandbox game developed by Mojang / is instance of video game
8. Minecraft (wd:Q125765049): instrumental track by C418; 2011 studio recording / is instance of music track without lyrics
9. Minecraft (wd:Q112863331): is instance of video game series / video game series
10. Minecraft Dungeons (wd:Q56884780), also known as Minecraft: Dungeons: 2020 video game developed by Mojang and Double Eleven / is instance of video game / 2020 video game / 2020 video game

[Assistant]
I'll search for the property corresponding to "publication date" (likely P577) to confirm its identifier.

Question: publication date

Top 10 property alternatives:
1. publication date (wd:P577 as pq/pqn/prv/ps/psn/pqv/prn/wdt/psv/wdtn/pr/p), also known as air date, airdate, be published during, be published in, broadcast date, etc.: date or point in time when a work was first published or released / date or point in time a work is first published or released / date or point in time a work is first published or released / is subproperty of point in time
2. dissolved, abolished or demolished date (wd:P576 as pq/pqn/prv/ps/psn/pqv/prn/wdt/psv/wdtn/pr/p, matched via publication end date), also known as abolished, abolishment date, ceased date, ceased on, ceased publication, etc.: point in time at which the subject (organisation, building) ...  "discontinued date" (P2669) for stopping a product / date or point in time on which the organisation was dissolved/disappeared or the building demolished / is subproperty of end time
3. announcement date (wd:P6949 as pq/pqn/prv/ps/psn/pqv/prn/wdt/psv/wdtn/pr/p, matched via date released), also known as announced in, announced on, date, date announced, date of announcement, etc.: time of the first public presentation of a subject by the creator, of information by the media / is subproperty of point in time
4. place of publication (wd:P291 as pq/pqn/prv/ps/psn/pqv/prn/wdt/psv/wdtn/pr/p, matched via publication place), also known as country (published in), location of publication, printed at, printed in, publication city, etc.: geographical place of publication of the edition (use 1st edition when referring to works) / geographical place of publication of the edition (use 1st edition when referring to works) / geographical place of publication of the edition (use 1st edition when referring to works) / is subproperty of significant place
5. publication interval (wd:P2896 as pq/pqn/prv/ps/psn/pqv/prn/wdt/psv/wdtn/pr/p, matched via interval of publication), also known as frequency of publication, interval of publication, publication cycle, publication frequency, update frequency, etc.: standard publication interval for daily or periodical publications / standard publication interval for daily or periodical publications / is subproperty of period of event / is subproperty of event interval
6. distribution format (wd:P437 as pq/pqn/prv/ps/psn/pqv/prn/wdt/psv/wdtn/pr/p, matched via publication format), also known as book format, distribution, distribution method, edition, format, etc.: method (or type) of distribution for the subject / method (or type) of distribution for the subject
7. published in (wd:P1433 as pq/pqn/prv/ps/psn/pqv/prn/wdt/psv/wdtn/pr/p), also known as album, article of, chapter of, essay of, music album, etc.: larger work that a given work was published in, like a journal, a website, a collection, a book or a music album / larger work that a given work was published in / is subproperty of part of
8. date of commercialization (wd:P5204 as pq/pqn/prv/ps/psn/pqv/prn/wdt/psv/wdtn/pr/p, matched via release date), also known as availability date, commercialization date, product release date, release date, P5204: date when a product was first commercialised / date when a product was first commercialized
9. house publication (wd:P2813 as pq/pqn/prv/ps/psn/pqv/prn/wdt/psv/wdtn/pr/p, matched via official publication), also known as has mouthpiece, house journal, house magazine, house organ, house periodical, etc.: media that speaks for an organization or a movement, and that is usually edited by its members
10. issuing agent of work (wd:P9901 as pq/pqn/prv/ps/psn/pqv/prn/wdt/psv/wdtn/pr/p, matched via official publication of), also known as house journal of, house organ of, house publication of, issued by, issuer, etc.: organization, agency, or other entity responsible for issuing ... entity; distinct from commercial publisher of the resource

[Assistant]
Plan: Query the p:P577 statements for the Minecraft item (wd:Q49740), extract the ps:P577 date values, sort descending and take the first to get the most recent publication date. I'll run a SELECT that returns the date literal (and the statement IRI optionally) to be safe. Now I'll execute that SPARQL.

execute

SELECT ?stmt ?pubDate WHERE { wd:Q49740 p:P577 ?stmt . ?stmt ps:P577 ?pubDate . } ORDER BY DESC(?pubDate) LIMIT 1

[Assistant]
Explanation of result: the executed query returned a single most-recent publication date value 2011-11-18T00:00:00Z for wd:Q49740 (Minecraft). This corresponds to the official full release (version 1.0.0) on 2011-11-18. I'll finalize with the SPARQL query I ran and the answer.

answer

SELECT ?stmt ?pubDate WHERE { wd:Q49740 p:P577 ?stmt . ?stmt ps:P577 ?pubDate . } ORDER BY DESC(?pubDate) LIMIT 1

Answer: The most recent publication date for Minecraft (wd:Q49740) is 2011-11-18 (2011-11-18T00:00:00Z).