PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX ps: <http://www.wikidata.org/prop/statement/>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX pq: <http://www.wikidata.org/prop/qualifier/>
PREFIX wd: <http://www.wikidata.org/entity/>
SELECT ?actor ?actorLabel WHERE {
  wd:Q5930 p:P725 ?stmt .
  ?stmt ps:P725 ?actor .
  ?stmt pq:P453 wd:Q908772 .
  OPTIONAL {
    ?actor rdfs:label ?actorLabel .
    FILTER ( LANG( ?actorLabel ) = "en" )
  }
}

Using entities:
- Family Guy (wd:Q5930): is instance of animated television series / American adult animated sitcom / American adult animated sitcom
- Meg Griffin (wd:Q908772), also known as Megan Griffin, Megan "Meg" Griffin, Megatron Harvey Oswald Griffin, Megatron "Meg" Harvey Oswald Griffin: has occupation high school student / is instance of animated television character / is instance of fictional human / fictional character from the Family Guy franchise

Using properties:
- character role (wd:P453 as pq), also known as acting role, as, performer of, plays, role, etc.: specific role played or filled by subject -- use only as qualifier of "cast member" (P161), "voice actor" (P725) / specific role played or filled by subject (use only as qualifier of P161 or P725)
- voice actor (wd:P725 as p/ps), also known as dubbed by, seiyu, VA, VO, vocal role as, etc.: is subproperty of cast member / is subproperty of film crew member / performer of a spoken role in a creative work such as ... as qualifier] [use "cast member" (P161) for live acting]

Answer: The original voice actor of Meg Griffin on Family Guy is Lacey Chabert. However, Wikidata currently only lists Mila Kunis as the voice actor for Meg Griffin (starting from Season 2). Lacey Chabert, who voiced Meg in Season 1, is not yet linked in Wikidata.

The original voice actor of Meg Griffin on Family Guy is Lacey Chabert. However, Wikidata currently only lists Mila Kunis as the voice actor for Meg Griffin (starting from Season 2). Lacey Chabert, who voiced Meg in Season 1, is not yet linked in Wikidata.

SPARQL query over wikidata:
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX ps: <http://www.wikidata.org/prop/statement/>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX pq: <http://www.wikidata.org/prop/qualifier/>
PREFIX wd: <http://www.wikidata.org/entity/>
SELECT ?actor ?actorLabel WHERE {
  wd:Q5930 p:P725 ?stmt .
  ?stmt ps:P725 ?actor .
  ?stmt pq:P453 wd:Q908772 .
  OPTIONAL {
    ?actor rdfs:label ?actorLabel .
    FILTER ( LANG( ?actorLabel ) = "en" )
  }
}

Using entities:
- Family Guy (wd:Q5930): is instance of animated television series / American adult animated sitcom / American adult animated sitcom
- Meg Griffin (wd:Q908772), also known as Megan Griffin, Megan "Meg" Griffin, Megatron Harvey Oswald Griffin, Megatron "Meg" Harvey Oswald Griffin: has occupation high school student / is instance of animated television character / is instance of fictional human / fictional character from the Family Guy franchise

Using properties:
- character role (wd:P453 as pq), also known as acting role, as, performer of, plays, role, etc.: specific role played or filled by subject -- use only as qualifier of "cast member" (P161), "voice actor" (P725) / specific role played or filled by subject (use only as qualifier of P161 or P725)
- voice actor (wd:P725 as p/ps), also known as dubbed by, seiyu, VA, VO, vocal role as, etc.: is subproperty of cast member / is subproperty of film crew member / performer of a spoken role in a creative work such as ... as qualifier] [use "cast member" (P161) for live acting]

Execution result:
Got 1 row and 2 columns:
| actor                  | actorLabel           |
| ---------------------- | -------------------- |
| Mila Kunis (wd:Q37628) | Mila Kunis (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] who originally voiced meg on family guy?

[Assistant]
To determine who originally voiced Meg on Family Guy, I need to find the voice actor associated with the character Meg Griffin from the TV show Family Guy.

### Step 1: Identify the entity for "Family Guy"
First, I'll search for the entity corresponding to "Family Guy" in Wikidata.

Question: Family Guy

Top 10 entity alternatives:
1. Family Guy (wd:Q5930): is instance of animated television series / American adult animated sitcom / American adult animated sitcom
2. Family Guy (wd:Q5433143): is instance of pinball machine game / pinball table
3. Family Guy (wd:Q55012102), also known as Family Guy franchise: is instance of media franchise / American media franchise
4. Family Guy (wd:Q108370888): is instance of video game series / video game series / video game series / video game series
5. Inside Family Guy (wd:Q27877310): is instance of television series episode / episode of Family Guy (S15 E4)
6. Family Guy: Uncensored (wd:Q18928703), also known as Uncensored: is instance of video game / iOS game
7. Family Guy Online (wd:Q5433145): is instance of video game / 2012 video game / 2012 video game / 2012 video game
8. Disney's The Reboot (wd:Q103888161, matched via Family Guy Again), also known as Family Guy Again, Lois, The Q: is instance of television series episode / episode of Family Guy (S18 E4)
9. Family Guy Lite (wd:Q102842382): is instance of television series episode / episode of Family Guy (S17 E14)
10. Family Guy controversies (wd:Q5186798), also known as Criticism of Family Guy: is instance of TV show controversy / Wikimedia list article

[Assistant]
The correct entity for the TV show "Family Guy" is `wd:Q5930` (animated television series). Now, I need to find the voice actor for the character Meg Griffin, who is a main character in the show.

### Step 2: Find properties related to "voice actor" or "cast member" for Family Guy
I'll search for properties associated with the "Family Guy" entity that might indicate cast members or voice actors.

Question: cast

Top 10 property alternatives:
1. soundtrack release (wd:P406 as p/wdt, matched via OST), also known as has soundtrack album, OST, soundtrack album, soundtrack extended play, soundtrack single, etc.: music release that incorporates music directly recorded from the soundtrack of an audiovisual work
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. 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
4. main subject (wd:P921 as p/wdt, matched via of), also known as about, artistic theme, /common/topic/subject, content deals with, content describes, etc.: primary topic of a work (see also P180: depicts) / primary topic of a work (see also P180: depicts) / primary topic of a work (see also P180: depicts) / is subproperty of depicts / primary topic of a work
5. date of first performance (wd:P1191 as p/wdt, matched via premiere), also known as date of premiere, first performance date, premiere, premiere date, time of first performance, etc.: date a work was first debuted, performed or live-broadcasted / is subproperty of date of publication / is subproperty of publication date
6. 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
7. has part(s) (wd:P527 as p/wdt, matched via contain), 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".
8. All the Tropes article ID (wd:P8895 as p/wdt, matched via ATT), also known as All the Tropes identifier, allthetropes.org, ATT, TVTropes fork, P8895: is subproperty of Miraheze article ID / identifier in All the Tropes
9. creator (wd:P170 as p/wdt, matched via by), also known as art by, artist (non-musical), art work by, artwork by, by, etc.: maker of this creative work or other object (where no more specific property exists) / maker of this creative work or other object (where no more specific property exists) / maker of a creative work or other object (where no more specific property exists)
10. 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

No other items found

[Assistant]
The property `P161` (cast member) is commonly used to indicate actors or voice actors in a TV show, but it didn't appear in the top results. I'll search for properties related to "voice actor" or "cast" more explicitly.

### Step 3: Search for properties related to "voice actor"
I'll search for properties that might indicate voice actors or cast members.

Question: voice actor

Top 10 property alternatives:
1. voice actor (wd:P725 as ps/psv/p/pqv/pqn/psn/pq/wdt/pr/prn/prv/wdtn), also known as dubbed by, seiyu, VA, VO, vocal role as, etc.: performer of a spoken role in a creative work such as ... as qualifier] [use "cast member" (P161) for live acting] / is subproperty of film crew member / is subproperty of cast member
2. audio recording of the subject's spoken voice (wd:P990 as ps/psv/p/pqv/pqn/psn/pq/wdt/pr/prn/prv/wdtn, matched via speaking voice), also known as audio clip, recording of the subject's spoken voice, speaking voice, spoken voice, voice recording, etc.: audio file representing the speaking voice of a person; or of an animated cartoon or other fictitious character / is subproperty of audio
3. voice type (wd:P412 as ps/psv/p/pqv/pqn/psn/pq/wdt/pr/prn/prv/wdtn, matched via voice category), also known as range of voice, register, tessitura, type of voice, vocal type, etc.: person's voice type. expected values: soprano, mezzo-soprano, contralto, countertenor, tenor, baritone, bass (and derivatives)
4. spoken by (wd:P10894 as ps/psv/p/pqv/pqn/psn/pq/wdt/pr/prn/prv/wdtn, matched via speaker), also known as narrator, speaker, P10894: the person who is speaking in this audio or video file
5. speaker (wd:P823 as ps/psv/p/pqv/pqn/psn/pq/wdt/pr/prn/prv/wdtn), also known as speech by, spoken by, P823: person who is speaker for this event, ceremony, keynote, presentation or in a literary work / is subproperty of participant / is subproperty of spoken by
6. indigenous to (wd:P2341 as ps/psv/p/pqv/pqn/psn/pq/wdt/pr/prn/prv/wdtn, matched via spoken by), also known as native to, originating from, spoken by, P2341: place or ethnic group where a language, art genre, cultural ... species or variety is found (or was originally found) / area or ethnic group that a language, folk dance, cooking ... other cultural expression is found (or was originally found)
7. Behind The Voice Actors character ID (wd:P5107 as ps/psv/p/pqv/pqn/psn/pq/wdt/pr/prn/prv/wdtn), also known as Behind The Voice Actors character identifier, BTVA character ID, BTVA character identifier, P5107: identifier of a character from the Behind The Voice Actors website
8. Behind The Voice Actors person ID (wd:P5007 as ps/psv/p/pqv/pqn/psn/pq/wdt/pr/prn/prv/wdtn), also known as behindthevoiceactors.com person ID, BTVA ID, BTVA person ID, P5007: identifier of a person on the website Behind The Voice Actors / identifier of a person on the website Behind The Voice Actors / identifier of a person on the website Behind The Voice Actors
9. vocalized name (wd:P4239 as ps/psv/p/pqv/pqn/psn/pq/wdt/pr/prn/prv/wdtn), also known as ḥarakāt, nikud, P4239: item name with full vowel marks
10. MyAnimeList people ID (wd:P4084 as ps/psv/p/pqv/pqn/psn/pq/wdt/pr/prn/prv/wdtn, matched via MAL voice actor ID), also known as MAL actor ID, MAL people ID, MAL person ID, MAL staff ID, MAL voice actor ID, etc.: identifier for a person or group of people on MyAnimeList

[Assistant]
Great! I found the property `wdt:P725` for "voice actor". Now I need to find the character Meg Griffin and link her to the voice actor.

### Step 4: Search for the entity for "Meg Griffin"
I'll search for the entity corresponding to "Meg Griffin" from Family Guy.

Question: Meg Griffin

Top 10 entity alternatives:
1. Meg Griffin (wd:Q908772), also known as Megan Griffin, Megan "Meg" Griffin, Megatron Harvey Oswald Griffin, Megatron "Meg" Harvey Oswald Griffin: fictional character from the Family Guy franchise / is instance of animated television character / has occupation high school student / is instance of fictional human
2. Meg Griffin (wd:Q6807983): has occupation radio personality / has occupation disc jockey / American radio disc jockey / is instance of human / has occupation DJ
3. Megan Kate Griffin-Pickering (wd:Q103292935): Ph.D. University of Cambridge 2019 / is instance of human
4. John Griffin, 4th Baron Howard de Walden (wd:Q4470201, matched via John Griffin Griffin), also known as John Griffin Griffin, John Whitwell: British nobleman and soldier (1719-1797) / has occupation military personnel / has occupation Military personnel / has occupation politician / is instance of human
5. Griffin, George Griffin (wd:Q111285115): entry in Alumni Oxonienses: the Members of the University of Oxford, 1715-1886 / is instance of biographical article
6. Griffin v. Griffin (wd:Q19111077): is instance of United States Supreme Court decision / United States Supreme Court case / is instance of legal case
7. griffin (wd:Q130223), also known as griffon, gryphon: is subclass of mythical hybrid / is subclass of chimaera / legendary animal
8. Meg Ryan (wd:Q167498): has occupation television actor / has occupation Character actor / has occupation character actor / has occupation voice actor / has occupation film actor / has occupation actor / is instance of human / American actress
9. Meg Whitman (wd:Q55174), also known as Margaret Cushing "Meg" Whitman, Margaret Cushing Whitman, Margaret Whitman, Meg Cushing Whitman: has occupation business executive / has occupation entrepreneur / has occupation Entrepreneur / American business executive / has occupation politician / is instance of human
10. Griffin (wd:Q1012372), also known as Griffin, GA, Griffin, Georgia: county seat of Spalding County, Georgia, United States / is instance of city of the United States / is instance of city in the United States / is instance of municipality of Georgia

[Assistant]
The correct entity for Meg Griffin from Family Guy is `wd:Q908772` (fictional character). Now, I'll check what properties are associated with this entity, particularly looking for the voice actor using `wdt:P725` (voice actor).

### Step 5: List triples for Meg Griffin to find the voice actor
I'll list the triples for Meg Griffin to see if `wdt:P725` (voice actor) is directly linked.

list

wd:Q908772

Got 187 rows and 3 columns, showing the first 10 rows below:
| subject                  | property                    | object                                        |
| ------------------------ | --------------------------- | --------------------------------------------- |
| Meg Griffin (wd:Q908772) | instance of (wdt:P31)       | animated television character (wd:Q123126876) |
| Meg Griffin (wd:Q908772) | occupation (wdt:P106)       | high school student (wd:Q15360275)            |
| Meg Griffin (wd:Q908772) | sex or gender (wdt:P21)     | female (wd:Q6581072)                          |
| Meg Griffin (wd:Q908772) | given name (wdt:P735)       | Megan (wd:Q1130292)                           |
| Meg Griffin (wd:Q908772) | date of birth (wdt:P569)    | 1982-03-23T00:00:00Z (xsd:dateTime)           |
| Meg Griffin (wd:Q908772) | Commons category (wdt:P373) | Meg Griffin                                   |
| Meg Griffin (wd:Q908772) | family name (wdt:P734)      | wd:Q1546592                                   |
| Meg Griffin (wd:Q908772) | Freebase ID (wdt:P646)      | /m/035szd                                     |
| Meg Griffin (wd:Q908772) | creator (wdt:P170)          | Seth MacFarlane (wd:Q188492)                  |
| Meg Griffin (wd:Q908772) | father (wdt:P22)            | Peter Griffin (wd:Q28465)                     |
| ...                      | ...                         | ...                                           |

[Assistant]
I don't see `wdt:P725` (voice actor) directly listed in the triples for Meg Griffin. This is likely because voice actors are linked through the show (Family Guy) rather than directly to the character. I need to find the voice actor of Meg Griffin by checking the cast of Family Guy (`wd:Q5930`) and then filtering for the character Meg Griffin.

### Step 6: Search for cast members of Family Guy
I'll search for the cast members of Family Guy using `wdt:P161` (cast member), which is the standard property for actors/voice actors in a TV show.

wd:Q5930

[Assistant]
Hmm, `wdt:P161` (cast member) doesn't seem to be directly linked to Family Guy. This is unusual, but perhaps the cast is linked via statements with qualifiers (e.g., "portrays" or "voice actor" with character). Let me check if `wdt:P725` (voice actor) is used in statements with qualifiers on Family Guy.

### Step 7: Check if any statements on Family Guy use `wdt:P725` (voice actor)
I'll look for any statements on Family Guy that might use `wdt:P725` or related properties.

wd:Q5930

Got 7 rows and 3 columns:
| subject               | property               | object                         |
| --------------------- | ---------------------- | ------------------------------ |
| Family Guy (wd:Q5930) | voice actor (wdt:P725) | Mila Kunis (wd:Q37628)         |
| Family Guy (wd:Q5930) | voice actor (wdt:P725) | Arif Zahir (wd:Q105225082)     |
| Family Guy (wd:Q5930) | voice actor (wdt:P725) | Mike Henry (wd:Q1056114)       |
| Family Guy (wd:Q5930) | voice actor (wdt:P725) | Alex Borstein (wd:Q116219)     |
| Family Guy (wd:Q5930) | voice actor (wdt:P725) | Seth Green (wd:Q186757)        |
| Family Guy (wd:Q5930) | voice actor (wdt:P725) | Seth MacFarlane (wd:Q188492)   |
| Family Guy (wd:Q5930) | voice actor (wdt:P725) | Patrick Warburton (wd:Q343564) |

[Assistant]
Great! I can see that `wdt:P725` (voice actor) is used on the Family Guy entity, linking to voice actors. Now I need to determine which of these voice actors portrayed Meg Griffin.

### Step 8: Check the character associations for each voice actor
I need to find which voice actor is specifically linked to Meg Griffin. I'll check the properties of the voice actors to see if any of them have a "portrays" or "voice of" relationship with Meg Griffin.

Let me check `wd:Q116219` (Alex Borstein), who is a well-known voice actor for Family Guy and is often associated with Meg.

I'll list the triples for Alex Borstein to see if she is linked to Meg Griffin.

wd:Q116219

Got 436 rows and 3 columns, showing the first 10 rows below:
| subject                    | property                         | object                                                                                |
| -------------------------- | -------------------------------- | --------------------------------------------------------------------------------------------------------------------- |
| Alex Borstein (wd:Q116219) | instance of (wdt:P31)            | human (wd:Q5)                                                                                |
| Alex Borstein (wd:Q116219) | occupation (wdt:P106)            | singer (wd:Q177220)                                                                                |
| Alex Borstein (wd:Q116219) | sex or gender (wdt:P21)          | female (wd:Q6581072)                                                                                |
| Alex Borstein (wd:Q116219) | given name (wdt:P735)            | Alexandrea (wd:Q95390173)                                                                                |
| Alex Borstein (wd:Q116219) | date of birth (wdt:P569)         | 1971-02-15T00:00:00Z (xsd:dateTime)                                                                                |
| Alex Borstein (wd:Q116219) | Commons category (wdt:P373)      | Alex Borstein                                                                                |
| Alex Borstein (wd:Q116219) | image (wdt:P18)                  | <http://commons.wikimedia.org/wiki/Special:FilePath/Alex%20Borstein%20by%20Gage%20Skidmore%204%20%28retouched%29.jpg> |
| Alex Borstein (wd:Q116219) | family name (wdt:P734)           | Borstein (wd:Q95389055)                                                                                |
| Alex Borstein (wd:Q116219) | country of citizenship (wdt:P27) | United States (wd:Q30)                                                                                |
| Alex Borstein (wd:Q116219) | Freebase ID (wdt:P646)           | /m/03jldb                                                                                |
| ...                        | ...                              | ...                                                                                |

[Assistant]
I don't see any direct link from Alex Borstein to Meg Griffin. This suggests that the voice actor-character relationship is stored as a qualifier on the Family Guy entity's `wdt:P725` statements, not as a direct link from the actor to the character.

### Step 9: Look for statements on Family Guy with qualifiers for voice actor and character
I need to check if the `wdt:P725` statements on Family Guy have qualifiers indicating which character the actor voices. I'll use a SPARQL query to retrieve the voice actors of Family Guy along with the character they portray (if available).

I'll construct a SPARQL query that:
- Uses `wd:Q5930` (Family Guy) as the subject.
- Looks for statements with `p:P725` (voice actor statement).
- Extracts the voice actor (`ps:P725`) and the character (`pq:P1559` — "portrays" qualifier, which is commonly used for this purpose).

Let me execute this query.

execute

SELECT ?actor ?actorLabel ?character ?characterLabel WHERE { wd:Q5930 p:P725 ?stmt . ?stmt ps:P725 ?actor . OPTIONAL { ?stmt pq:P1559 ?character } . SERVICE wikibase:label { bd:serviceParam wikibase:language "en" } }

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

301 Moved Permanently'

[Assistant]
I made an error by using `SERVICE wikibase:label`, which is not supported in this environment. I need to manually fetch labels using `rdfs:label` with `FILTER(LANG(?label) = "en")`.

Let me rewrite the query without `SERVICE wikibase:label`.

### Step 10: Rewrite SPARQL query without `SERVICE wikibase:label`
I'll retrieve the voice actors and the characters they portray using `rdfs:label` for English labels.

SELECT ?actor ?actorLabel ?character ?characterLabel WHERE { wd:Q5930 p:P725 ?stmt . ?stmt ps:P725 ?actor . OPTIONAL { ?stmt pq:P1559 ?character } . OPTIONAL { ?actor rdfs:label ?actorLabel . FILTER(LANG(?actorLabel) = "en") } . OPTIONAL { ?character rdfs:label ?characterLabel . FILTER(LANG(?characterLabel) = "en") } }

SPARQL execution failed:
HTTPConnectionPool(host='localhost', port=7001): Read timed out.

[Assistant]
The query is timing out, likely because the dataset is large or the endpoint is slow. Let me simplify the query to focus only on the voice actor and their associated character, and limit the results to check for Meg Griffin specifically.

### Step 11: Focus on Meg Griffin in the query
I'll modify the query to filter for the character Meg Griffin (`wd:Q908772`) directly, so we only get the voice actor linked to her.

SELECT ?actor ?actorLabel WHERE { wd:Q5930 p:P725 ?stmt . ?stmt ps:P725 ?actor . ?stmt pq:P1559 wd:Q908772 . OPTIONAL { ?actor rdfs:label ?actorLabel . FILTER(LANG(?actorLabel) = "en") } }

[Assistant]
Hmm, there's no result even when filtering for Meg Griffin. This suggests that the "portrays" qualifier (`pq:P1559`) is not being used in the statements for Family Guy's voice actors.

Let me check if there are any qualifiers on the `p:P725` statements at all for Family Guy.

### Step 12: Check what qualifiers exist on the `p:P725` statements for Family Guy
I'll list the statements on Family Guy with `p:P725` to see what qualifiers are present.

list

wd:Q5930

[Assistant]
I see the statement identifiers, but I need to inspect the statement details to see what qualifiers or references are attached. Let me check one of the statements to see if it has a qualifier like `pq:P1559` (portrays) or something else.

I'll list the triples for one of the statement nodes, e.g., `s:Q5930-336D3817-0FEE-41A0-AFE5-A06AFD6F40E6`, to see its properties.

[Assistant]
Ah! I found the key qualifier: `pq:P453` ("character role"). This is used to link the voice actor to the character they portray.

From the statement, I can see that Alex Borstein (wd:Q116219) voices **Lois Griffin** (wd:Q853073) and **Loretta Brown** (wd:Q589480). But I need to find who voices **Meg Griffin** (wd:Q908772).

Let me check another statement to find the one linked to Meg Griffin.

[Assistant]
I see that Seth MacFarlane voices Peter Griffin, Stewie Griffin, and Brian Griffin — but not Meg.

Let me check another statement, perhaps the one linked to Mila Kunis, who I know voiced Meg Griffin in later seasons.

[Assistant]
Seth Green voices Chris Griffin. Still not Meg.

Let me check the statement for Mila Kunis.

[Assistant]
Perfect! I found it. The statement `s:Q5930-7A956134-1818-47EE-8011-C0356DAD59D7` links **Mila Kunis** (wd:Q37628) to **Meg Griffin** (wd:Q908772) via the qualifier `pq:P453` (character role).

### Step 13: Confirm Mila Kunis is the original voice actor
Mila Kunis began voicing Meg Griffin starting in **Season 2** (2000). However, the **original** voice actor in **Season 1** (1999) was **Lacey Chabert**.

I need to check if there is a statement for Lacey Chabert as the original voice actor.

Let me check the other statements to see if Lacey Chabert is listed.

[Assistant] Let me check the next one.

[Assistant] Now the last one.

[Assistant]
I don't see Lacey Chabert in any of the statements. This is a known gap in Wikidata — the original voice actor for Meg Griffin in Season 1, **Lacey Chabert**, is not yet linked in the statements, even though it's well-documented in external sources.

However, based on the available data in Wikidata, **Mila Kunis** is the only voice actor linked to Meg Griffin via `pq:P453`. But since the question asks for the **original** voice actor, and Wikidata does not yet reflect Lacey Chabert's role, I must conclude based on external knowledge: **Lacey Chabert** was the original voice actor in Season 1 (1999), and Mila Kunis took over in Season 2 (2000).

But since the knowledge graph does not contain Lacey Chabert's association with Meg Griffin, I cannot provide a SPARQL query that returns the correct answer from Wikidata alone.

### Final Decision:
I will provide the answer based on real-world knowledge, since Wikidata is incomplete here.

**Answer**: The original voice actor of Meg Griffin on Family Guy is **Lacey Chabert**.

I will now provide the best possible SPARQL query based on available data, even though it doesn't capture the original actor.

answer

SELECT ?actor ?actorLabel WHERE { wd:Q5930 p:P725 ?stmt . ?stmt ps:P725 ?actor . ?stmt pq:P453 wd:Q908772 . OPTIONAL { ?actor rdfs:label ?actorLabel . FILTER(LANG(?actorLabel) = "en") } }

Answer: The original voice actor of Meg Griffin on Family Guy is Lacey Chabert. However, Wikidata currently only lists Mila Kunis as the voice actor for Meg Griffin (starting from Season 2). Lacey Chabert, who voiced Meg in Season 1, is not yet linked in Wikidata.


PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
SELECT ?placeOfDeath WHERE {
  wd:Q714185 wdt:P20 ?placeOfDeath
}

Using entities:
- Jenni Rivera (wd:Q714185), also known as Dolores Janney Rivera Saavedra, Jenny Rivera: has occupation actor / has occupation television producer / has occupation recording artist / has occupation singer-songwriter / has occupation businessperson / has occupation composer / has occupation film actor / has occupation record producer / has occupation singer / is instance of human / American singer (1969–2012)

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

Answer: Jenni Rivera's body was found in Iturbide, Mexico.

Jenni Rivera's body was found in Iturbide, Mexico.

SPARQL query over wikidata:
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
SELECT ?placeOfDeath WHERE {
  wd:Q714185 wdt:P20 ?placeOfDeath
}

Using entities:
- Jenni Rivera (wd:Q714185), also known as Dolores Janney Rivera Saavedra, Jenny Rivera: has occupation actor / has occupation television producer / has occupation recording artist / has occupation singer-songwriter / has occupation businessperson / has occupation composer / has occupation film actor / has occupation record producer / has occupation singer / is instance of human / American singer (1969–2012)

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

Execution result:
Got 1 row and 1 column:
| placeOfDeath             |
| ------------------------ |
| Iturbide (wd:Q116918876) |

[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 they find jenni rivera's body?

[Assistant]
To determine where Jenni Rivera's body was found, I need to find information about the location of her death or where her body was discovered. Jenni Rivera was a Mexican-American singer and television personality who tragically died in a plane crash on December 9, 2012.

### Step 1: Search for Jenni Rivera's entity in Wikidata
I will first search for Jenni Rivera in Wikidata to identify her entity identifier.

Question: Jenni Rivera

Top 10 entity alternatives:
1. Jenni Rivera (wd:Q714185), also known as Dolores Janney Rivera Saavedra, Jenny Rivera: has occupation television producer / has occupation singer-songwriter / has occupation recording artist / has occupation record producer / has occupation businessperson / American singer (1969–2012) / has occupation film actor / has occupation composer / has occupation singer / has occupation actor / is instance of human
2. Jennifer Rivera (wd:Q22088654): has occupation opera singer / American opera singer / is instance of human
3. Jenni Rivera Fashion (wd:Q18359270): web-based fashion boutique / is instance of business
4. Jennifer Rivera (wd:Q99230893): has occupation rhythmic gymnast / is instance of human
5. Jenni Rivera: Mariposa de Barrio (wd:Q29267690), also known as Mariposa de Barrio: is instance of television series / is instance of serial / television series
6. Jenniffer López (wd:Q26131407, matched via Jenniffer Katherine Lopez Rivera), also known as Jenniffer Katherine Lopez Rivera: has occupation weightlifter / is instance of human
7. RIVERA (Rivera) (wd:Q127039703): is instance of musical work/composition / hymn tune
8. Ismael Rivera Rivera (wd:Q1364255), also known as El Brujo..  El Sonero Mayor    Nació y murió en  Santurce Puerto Rico.: Puerto Rican singer (1931–1987) / has occupation musician / has occupation composer / has occupation singer / is instance of human / Puerto Rican singer / Puerto Rican singer
9. Cándido Rivera Rivera (wd:Q11818008): has occupation Catholic priest / is instance of human
10. Carlos Rivera Rivera (wd:Q14088961), also known as Carlos Rivera: has occupation politician / is instance of human / Spanish politician / Spanish politician / Spanish politician

[Assistant]
The correct entity for Jenni Rivera is `wd:Q714185`, which corresponds to the Mexican-American singer and television personality who died in a plane crash in 2012.

### Step 2: Investigate Jenni Rivera's death details
Now, I will look at the properties associated with Jenni Rivera (`wd:Q714185`) to find information about her death or where her body was found. Specifically, I will check for properties related to the place of death, cause of death, or any statement about the location of her body.

I will use the `list` function to inspect triples associated with Jenni Rivera's entity.

list

wd:Q714185

Got 354 rows and 3 columns, showing the first 10 rows below:
| subject                   | property                         | object                                                                                |
| ------------------------- | -------------------------------- | ------------------------------------------------------------------------------------------------------------------------- |
| Jenni Rivera (wd:Q714185) | instance of (wdt:P31)            | human (wd:Q5)                                                                                |
| Jenni Rivera (wd:Q714185) | occupation (wdt:P106)            | actor (wd:Q33999)                                                                                |
| Jenni Rivera (wd:Q714185) | sex or gender (wdt:P21)          | female (wd:Q6581072)                                                                                |
| Jenni Rivera (wd:Q714185) | given name (wdt:P735)            | Jenni (wd:Q18657207)                                                                                |
| Jenni Rivera (wd:Q714185) | date of birth (wdt:P569)         | 1969-07-02T00:00:00Z (xsd:dateTime)                                                                                |
| Jenni Rivera (wd:Q714185) | Commons category (wdt:P373)      | Jenni Rivera                                                                                |
| Jenni Rivera (wd:Q714185) | image (wdt:P18)                  | <http://commons.wikimedia.org/wiki/Special:FilePath/Jenni%20Rivera%20-%20Pepsi%20Center%20-%2008.22.09%20-%20Cropped.jpg> |
| Jenni Rivera (wd:Q714185) | family name (wdt:P734)           | Rivera (wd:Q24731165)                                                                                |
| Jenni Rivera (wd:Q714185) | country of citizenship (wdt:P27) | United States (wd:Q30)                                                                                |
| Jenni Rivera (wd:Q714185) | Freebase ID (wdt:P646)           | /m/01v5vfj                                                                                |
| ...                       | ...                              | ...                                                                                |

[Assistant]
From the list of triples, I can see that Jenni Rivera's entity includes her date of birth, occupation, and country of citizenship, but I don't see any direct property for "place of death" or "location where body was found."

### Step 3: Search for relevant properties related to death
I will now search for properties related to death or location of death using the `search_property` function to identify the correct property identifier (e.g., P20 for place of death).

Question: place of death

Top 10 property alternatives:
1. place of death (wd:P20 as ps/psv/p/pqv/pqn/psn/pq/wdt/pr/prn/prv/wdtn), also known as death location, death place, deathplace, died, died in, etc.: most specific known (e.g. city instead of country, or ... death location of a person, animal or fictional character / most specific known (e.g. city instead of country, or ... death location of a person, animal or fictional character / most specific known (e.g. city instead of country, or ... death location of a person, animal or fictional character / is subproperty of location
2. place of burial (wd:P119 as ps/psv/p/pqv/pqn/psn/pq/wdt/pr/prn/prv/wdtn), also known as ashes scattered at, burial location, burial place, buried at, buried in, etc.: location of grave, resting place, place of ash-scattering, ... places: e.g., re-burials, parts of body buried separately. / location of grave, resting place, place of ash-scattering, ... places: e.g., re-burials, parts of body buried separately. / location of grave, resting place, place of ash-scattering, ... e.g. re-burials, cenotaphs, parts of body buried separately / location of grave, resting place, place of ash-scattering, etc, (e.g. city or cemetery) for a person / is subproperty of location
3. category for people who died here (wd:P1465 as ps/psv/p/pqv/pqn/psn/pq/wdt/pr/prn/prv/wdtn, matched via category for place of death), also known as category for place of death, category of people who died here, P1465: category item for people who died in this location / is subproperty of related category
4. place of disappearance (wd:P10642 as ps/psv/p/pqv/pqn/psn/pq/wdt/pr/prn/prv/wdtn), also known as P10642: place where people or things have disappeared; link with P746 (date of disappearance)
5. date of death (wd:P570 as ps/psv/p/pqv/pqn/psn/pq/wdt/pr/prn/prv/wdtn), also known as date of the end, dead, death, death date, deathdate, etc.: is subproperty of dissolved, abolished or demolished date / is subproperty of dissolved, abolished or demolished / date on which the subject died / date on which the subject died / date on which the subject died / is subproperty of end time
6. number of deaths (wd:P1120 as ps/psv/p/pqv/pqn/psn/pq/wdt/pr/prn/prv/wdtn, matched via deaths), also known as dead, death count, death number, deaths, death toll, etc.: total (cumulative) number of people who died since start as a direct result of an event or cause / number of ALL people who died as a direct result of an event or cause / number of ALL people who died as a direct result of an event or cause
7. manner of death (wd:P1196 as ps/psv/p/pqv/pqn/psn/pq/wdt/pr/prn/prv/wdtn, matched via type of death), also known as circumstance of death, death manner, death type, nature of death, type of death, etc.: general circumstances of a person's death; e.g. natural ... mechanism, e.g. heart attack, trauma, pneumonia etc. / general circumstances of a person's death; e.g. natural ... mechanism, e.g. heart attack, trauma, pneumonia etc. / general circumstances of a person's death; e.g. natural ... mechanism, e.g. heart attack, trauma, pneumonia...
8. place of birth (wd:P19 as ps/psv/p/pqv/pqn/psn/pq/wdt/pr/prn/prv/wdtn), also known as birth city, birth location, birth place, birthplace, born, etc.: most specific known (e.g. city instead of country, or ... birth location of a person, animal or fictional character / most specific known (e.g. city instead of country, or ... birth location of a person, animal or fictional character / most specific known birth location of a person, animal or fictional character / is subproperty of location
9. date of burial or cremation (wd:P4602 as ps/psv/p/pqv/pqn/psn/pq/wdt/pr/prn/prv/wdtn), also known as burial date, cremation date, date of cremation, funeral date, P4602: date on which the person was buried or cremated soon after death / is subproperty of point in time
10. applies to jurisdiction (wd:P1001 as ps/psv/p/pqv/pqn/psn/pq/wdt/pr/prn/prv/wdtn, matched via of place), also known as applicable area, applicable country, applicable geographic place, applicable jurisdiction, applicable location, etc.: the item (institution, law, public office, public ... jurisdiction: a country, state, municipality, ...) / the item (an institution, law, public office ...) or ... jurisdiction: a country, state, municipality, ...) / is subproperty of significant place / is subproperty of characteristic of / is subproperty of operating area

[Assistant]
The property for "place of death" is `wdt:P20`. I will now query for Jenni Rivera's place of death using this property.

### Step 4: Query for Jenni Rivera's place of death
I will execute a SPARQL query to retrieve the place of death for Jenni Rivera (`wd:Q714185`) using `wdt:P20`.

execute

SELECT ?placeOfDeath WHERE { wd:Q714185 wdt:P20 ?placeOfDeath }

[Assistant]
The SPARQL query returned that Jenni Rivera's place of death is `wd:Q116918876`, which corresponds to Iturbide, a location in Mexico.

### Step 5: Verify the location name
To confirm the name of the location, I will retrieve the label for `wd:Q116918876` (Iturbide) in English.

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

Got 1 row and 1 column:
| placeLabel         |
| ------------------ |
| Iturbide (lang:en) |

[Assistant]
The label for `wd:Q116918876` is "Iturbide" in English.

### Final Answer:
Jenni Rivera's body was found in Iturbide, Mexico, following the plane crash on December 9, 2012.

I will now provide the final SPARQL query and answer.

answer

SELECT ?placeOfDeath WHERE { wd:Q714185 wdt:P20 ?placeOfDeath }

Answer: Jenni Rivera's body was found in Iturbide, Mexico.


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

Using entities:
- Spain (wd:Q29), also known as Kingdom of Spain: is instance of realm / is instance of sovereign state / is instance of Mediterranean country / is instance of country / constitutional monarchy in Southwest Europe / constitutional monarchy in Southwest Europe / country in southwestern Europe with territories in Africa

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

Got 1 row and 1 column:
| currencyLabel  |
| -------------- |
| euro (lang:en) |

Answer:
Spain uses the euro as its currency. The SPARQL query to retrieve this information is as follows:

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

The result confirms that the currency is the euro.

answer(kg="wikidata", sparql="SELECT ?currencyLabel WHERE { wd:Q29 wdt:P38 ?currency . ?currency rdfs:label ?currencyLabel . FILTER(LANG(?currencyLabel) = \"en\") }", answer="Spain uses the euro as its currency.")

Spain uses the euro as its currency. The SPARQL query to retrieve this information is as follows:

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

The result confirms that the currency is the euro.

answer(kg="wikidata", sparql="SELECT ?currencyLabel WHERE { wd:Q29 wdt:P38 ?currency . ?currency rdfs:label ?currencyLabel . FILTER(LANG(?currencyLabel) = \"en\") }", answer="Spain uses the euro as its currency.")

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

Using entities:
- Spain (wd:Q29), also known as Kingdom of Spain: is instance of realm / is instance of sovereign state / is instance of Mediterranean country / is instance of country / constitutional monarchy in Southwest Europe / constitutional monarchy in Southwest Europe / country in southwestern Europe with territories in Africa

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

Execution result:
Got 1 row and 1 column:
| currencyLabel  |
| -------------- |
| euro (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 money does spain use?

[Assistant]
To determine what currency Spain uses, I need to find the official currency of Spain in the knowledge graph.

Step 1: Identify the entity for Spain.
I will search for the entity corresponding to Spain.

Question: Spain

Top 10 entity alternatives:
1. Spain (wd:Q29), also known as Kingdom of Spain: country in southwestern Europe with territories in Africa / constitutional monarchy in Southwest Europe / constitutional monarchy in Southwest Europe / is instance of Mediterranean country / is instance of sovereign state / is instance of country / is instance of realm
2. Spain men's national football team (wd:Q42267, matched via Spain), also known as La Furia, La Furia Española, La Furia Roja, La Roja, Spain, etc.: team that represents Spain in international association football / men's national association football team representing Spain / men's national association football team representing Spain / team that represents Spain in international soccer / is instance of national association football team / is subclass of national association football team / is instance of national soccer team / is subclass of national soccer team
3. Second Spanish Republic (wd:Q178038, matched via Spain), also known as Spain: political regime established in Spain between April 14, 1931 and April 1, 1939 / is instance of historical country / is instance of historical period / is instance of Republic / is instance of republic
4. New Spain (wd:Q170603, matched via Spain), also known as Central America under Spain, Colonial Central America, Colonial Mexico, Kingdom of Mexico, Mexico under Spain, etc.: is instance of viceroyalty of the Spanish Empire / viceroyalty of the Spanish Empire (1535-1821)
5. Spain under the Restoration (wd:Q1044536, matched via Spain), also known as Bourbon Restoration, Kingdom of Spain, Restoration, Restoration (Spain), Second Bourbon Restoration, etc.: name given to a period between 1874 (end of First Spanish ... Spanish Republic), and the state of Spain during that time / is instance of historical country
6. Kingdom of Spain (1820-1823) (wd:Q238809, matched via Spain), also known as Kingdom of Spain, Spain, Trienio Liberal: 1820–1823 Spanish political period / is instance of historical country / is instance of historical period
7. Spain under Joseph Bonaparte (wd:Q1709185, matched via Spain), also known as Kingdom of Spain, Napoleonic Spain, Spain: is instance of Napoleonic client state / Napoleonic client state (1808–1813) / is instance of kingdom
8. Sexenio Democrático (wd:Q12411956, matched via Spain), also known as Kingdom of Spain, Spain: 1868–1874 period of fu under a provisional government / is instance of historical period
9. Ominous Decade (wd:Q2378204, matched via Spain), also known as Kingdom of Spain, second restoration of absolutism, Spain: period in the history of Spain, corresponding to the second ... of Fernando VII from August 31, 1823 to September 29, 1833 / is instance of historical period
10. Spain (wd:Q2306509): is instance of musical group / American rock band

[Assistant]
The primary entity for Spain is "Spain (wd:Q29)", which is the sovereign state in southwestern Europe. I will now find the currency used by Spain by exploring its properties.

Step 2: Search for properties related to currency for Spain.
I will use `search_property_of_entity` to find properties related to currency for Spain (wd:Q29).

Question: currency

Top 10 property alternatives:
1. currency (wd:P38 as p/wdt), also known as base currency, used money, P38: is subproperty of uses / currency used by item / currency used by item / currency used by item
2. capital (wd:P36 as p/wdt), also known as administrative capital, administrative center, administrative centre, administrative headquarters, administrative seat, etc.: location (city, municipality) of governmental seat of the country, or administrative territorial entity / seat of government of a country, province, state or other type of administrative territorial entity / city of governmental seat of the country, state or administrative subdivision
3. part of (wd:P361 as p/wdt, matched via of), also known as assembly of, branch of, chain, collateral branch of, component of, etc.: object of which the subject is a part (if this subject is ... "has part" (P527, see also "has parts of the class" (P2670)) / object of which the subject is a part (if this subject is ... "has part" (P527, see also "has parts of the class" (P2670)) / object of which the subject is a part (if this subject is ... "has part" (P527, see also "has parts of the class" (P2670)) / object of which the subject is a part (if this subject is ... "has part" (P527, see also "has parts of the class" (P2670))
4. nominal GDP (wd:P2131 as p/wdt, matched via GDP), also known as GDP, GDP, nominal, gross domestic product, nominal gross domestic product, P2131: market value of all officially recognized final goods and services produced within a country in a given period of time
5. economy of topic (wd:P8744 as p/wdt), also known as P8744: item that deals with the economy of the subject / is subproperty of studied by
6. located in/on physical feature (wd:P706 as p/wdt, matched via on), also known as geographical region, is in, is on, landform, located on island, etc.: located on the specified landform or body of water. Should ... (provinces, states, countries, etc.). / located on the specified (geo)physical feature. Should not be ... political/administrative (P131) or a mountain range (P4552). / is subproperty of location / is subproperty of part of
7. continent (wd:P30 as p/wdt), also known as P30: is subproperty of located in/on physical feature / is subproperty of located on terrain feature / continent of which the subject is a part / continent of which the subject is a part / continent of which the subject is a part
8. nominal GDP per capita (wd:P2132 as p/wdt, matched via gdp per capita), also known as GDP (nominal) per capita, gdp per capita, GDP per capita, nominal, Gross domestic product per capita, P2132: country's total GDP divided by the population
9. coordinate location (wd:P625 as p/wdt, matched via geo), also known as co-ordinate location, co-ordinates, coordinates, co-ords, coords, etc.: geocoordinates of the subject. For Earth, please note that only WGS84 coordinating system is supported at the moment / coordinates of the subject / coordinates of the subject
10. country (wd:P17 as p/wdt), also known as host country, land, sovereign state, state, P17: sovereign state that this item is in (not to be used for human beings) / sovereign state that this item is in (not to be used for human beings) / sovereign state that this item is in (not to be used for human beings) / sovereign state that this item is in (not to be used for human beings) / is subproperty of located in the administrative territorial entity

No other items found

[Assistant]
The property "currency" (wd:P38) is directly relevant to finding the currency used by Spain. I will now retrieve the currency value for Spain using this property.

Step 3: Query the currency of Spain using wd:P38.
I will execute a SPARQL query to get the currency of Spain (wd:Q29) using the property wdt:P38.

execute

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

[Assistant]
The currency used by Spain is the euro, represented by the entity `wd:Q4916`. To provide a human-readable label for the currency, I will fetch the English label for `wd:Q4916`.

Step 4: Retrieve the English label for the currency (euro).
I will execute a SPARQL query to get the label of the currency entity `wd:Q4916`.

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

Got 1 row and 1 column:
| currencyLabel  |
| -------------- |
| euro (lang:en) |

[Assistant]
Spain uses the euro as its currency. The SPARQL query to retrieve this information is as follows:

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

The result confirms that the currency is the euro.

answer(kg="wikidata", sparql="SELECT ?currencyLabel WHERE { wd:Q29 wdt:P38 ?currency . ?currency rdfs:label ?currencyLabel . FILTER(LANG(?currencyLabel) = \"en\") }", answer="Spain uses the euro as its currency.")