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 ?character ?characterLabel WHERE {
  ?character wdt:P175 wd:Q358345 .
  ?character rdfs:label ?characterLabel .
  FILTER ( LANG( ?characterLabel ) = "en" ) .
  ?character wdt:P31 wd:Q33125444 .
}

Using entities:
- character from Star Wars (wd:Q33125444), also known as Star Wars character: is subclass of character from a certain fictional universe / character from the Star Wars universe
- Billy Dee Williams (wd:Q358345), also known as William December "Billy Dee" Williams Jr., William December Williams Jr.: has occupation voice actor / has occupation novelist / has occupation recording artist / has occupation writer / has occupation actor / has occupation screenwriter / has occupation painter / has occupation singer / has occupation film actor / has occupation television actor / is instance of human / American actor (born 1937)

Using properties:
- performer (wd:P175 as wdt), also known as actor, actress, artist, dancer, musical artist, etc.: is subproperty of contributor to the creative work or subject / actor, musician, band or other performer associated with this role or musical work / actor, musician, music group or other performer associated with this work
- instance of (wd:P31 as wdt), also known as example of, has type, is a, is an, is of type, etc.: that class of which this subject is a particular example and ... a subclass of mountain (and an instance of volcanic landform) / type to which this subject corresponds/belongs. Different ... and the volcano is a type (instance) of volcanic landform

Got 1 row and 2 columns:
| character                    | characterLabel             |
| ---------------------------- | -------------------------- |
| Lando Calrissian (wd:Q51799) | Lando Calrissian (lang:en) |

Answer: Billy Dee Williams played the character Lando Calrissian in Star Wars.

Billy Dee Williams played the character Lando Calrissian in Star Wars.

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 ?character ?characterLabel WHERE {
  ?character wdt:P175 wd:Q358345 .
  ?character rdfs:label ?characterLabel .
  FILTER ( LANG( ?characterLabel ) = "en" ) .
  ?character wdt:P31 wd:Q33125444 .
}

Using entities:
- character from Star Wars (wd:Q33125444), also known as Star Wars character: is subclass of character from a certain fictional universe / character from the Star Wars universe
- Billy Dee Williams (wd:Q358345), also known as William December "Billy Dee" Williams Jr., William December Williams Jr.: has occupation voice actor / has occupation novelist / has occupation recording artist / has occupation writer / has occupation actor / has occupation screenwriter / has occupation painter / has occupation singer / has occupation film actor / has occupation television actor / is instance of human / American actor (born 1937)

Using properties:
- performer (wd:P175 as wdt), also known as actor, actress, artist, dancer, musical artist, etc.: is subproperty of contributor to the creative work or subject / actor, musician, band or other performer associated with this role or musical work / actor, musician, music group or other performer associated with this work
- instance of (wd:P31 as wdt), also known as example of, has type, is a, is an, is of type, etc.: that class of which this subject is a particular example and ... a subclass of mountain (and an instance of volcanic landform) / type to which this subject corresponds/belongs. Different ... and the volcano is a type (instance) of volcanic landform

Execution result:
Got 1 row and 2 columns:
| character                    | characterLabel             |
| ---------------------------- | -------------------------- |
| Lando Calrissian (wd:Q51799) | Lando Calrissian (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 character did billy d williams play in star wars?

[Assistant]
To determine what character Billy D. Williams played in Star Wars, I will follow these steps:

1. Identify the entity for Billy D. Williams in Wikidata.
2. Find the relevant property that links actors to the characters they portrayed in films (likely P175, "portrayed character").
3. Confirm the specific Star Wars film context to ensure accuracy.
4. Construct and execute a SPARQL query to retrieve the character name.

### Step 1: Search for Billy D. Williams in Wikidata
I will first search for Billy D. Williams to identify his Wikidata entity.

Question: billy d williams

Top 10 entity alternatives:
1. Billy Dee Williams (wd:Q358345), also known as William December "Billy Dee" Williams Jr., William December Williams Jr.: has occupation recording artist / has occupation television actor / has occupation screenwriter / has occupation voice actor / American actor (born 1937) / has occupation film actor / has occupation novelist / has occupation painter / has occupation writer / has occupation singer / has occupation actor / is instance of human
2. Billy Drease Williams (wd:Q4912488), also known as Edreys, Edreys Wajed: has occupation record producer / has occupation songwriter / has occupation singer / has occupation rapper / is instance of human / American rapper
3. Billy Williams (wd:Q4913466, matched via William Dennis "Billy" Williams), also known as William Dennis "Billy" Williams, William Dennis Williams: has occupation association football player / has occupation soccer player / footballer, born 1905 / is instance of human
4. Billy Dee Williams Self-Portrait (wd:Q47513010): painting by Billy Dee Williams / painting by Billy Dee Williams / is instance of painting
5. J. D. Williams (wd:Q3110285), also known as Darnell "J.D." Williams: has occupation television actor / has occupation film actor / has occupation actor / is instance of human / American actor
6. Billy Williams (wd:Q123745): has occupation cinematographer / has occupation camera operator / has occupation film actor / British cinematographer / has occupation actor / is instance of human
7. Bill Maynard (wd:Q3736724, matched via Billy Williams), also known as Billy Williams: has occupation association football player / English comedian and actor (1928–2018) / has occupation stand-up comedian / has occupation television actor / has occupation soccer player / has occupation stage actor / comedy actor (1928–2018) / has occupation actor / is instance of human
8. Billy Williams (wd:Q4913471), also known as Billy Leo Williams: American former professional baseball outfielder / has occupation baseball player / is instance of human
9. David Williams (wd:Q1177203, matched via D. Williams), also known as D. Williams: Welsh mathematician working in probability theory / has occupation university teacher / has occupation mathematician / is instance of human
10. Mike IX Williams (wd:Q6849285, matched via Michael D. Williams), also known as Michael D. Williams, Michael Williams, Mike Williams: has occupation writer / has occupation singer / is instance of human / American vocalist

[Assistant]
The top result is Billy Dee Williams (wd:Q358345), an American actor born in 1937, which matches the person we are looking for. I will now investigate the properties of this entity to find the character he portrayed in Star Wars.

### Step 2: Search for properties related to "portrayed character" or "role"
I will use `search_property_of_entity` to find properties related to roles or characters portrayed by Billy Dee Williams.

Question: portrayed character

Top 10 property alternatives:
1. Behind The Voice Actors person ID (wd:P5007 as p/wdt, matched via behindthevoiceactors.com person ID), 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
2. given name (wd:P735 as p/wdt, matched via name), also known as Christian name, first name, forename, middle name, name, etc.: first name or another given name of this person; values used with the property should not link disambiguations nor family names / first name or another given name of this person; values used with the property shouldn't link disambiguations nor family names / first name or another given name of this person; values used with the property shouldn't link disambiguations nor family names / is subproperty of name
3. sex or gender (wd:P21 as p/wdt, matched via gender expression), also known as biological sex, gender, gender expression, gender identity, gender or sex, etc.: sexual identity of subject: male (Q6581097), female ... (Q43445). Groups of same gender use "subclass of" (P279) / sex or gender identity: male (Q6581097), female (Q6581072), ... (Q43445). Groups of same gender use subclass of (P279) / sex or gender identity of human or animal. For human: male, ... female organism. Groups of same gender use subclass of (P279)
4. nickname (wd:P1449 as p/wdt), also known as aka, also known as, epithet, fan-name, fanname, etc.: informal name (for a pseudonym use P742) / is subproperty of name
5. image (wd:P18 as p/wdt, matched via image of subject), also known as camera picture, Commons image, drawing, File:, graph, etc.: image of relevant illustration of the subject; if available, ... only images which exist on Wikimedia Commons are acceptable / image of relevant illustration of the subject; if available, ... only images which exist on Wikimedia Commons are acceptable / image of relevant illustration of the subject; if available, ... map, flag image, signature image, logo image, collage image) / image of relevant illustration of the subject; if available, ... map, flag image, signature image, logo image, collage image)
6. CineMagia person ID (wd:P4666 as p/wdt, matched via CineMagia actor identifier), also known as CineMagia actor ID, CineMagia actor identifier, CineMagia person identifier, Cinemagia.ro person ID, Cinemagia.ro person identifier, etc.: identifier for a person on the Cinemagia.ro website
7. Internet Off-Broadway Database ID (wd:P4456 as p/wdt, matched via Internet Off-Broadway Database actress  ID), also known as Internet Off-Broadway Database actress  ID, Internet Off-Broadway Database person ID, IOBDB actor ID, IOBDB actress ID, IOBDB.com actor ID, etc.: identifier for an actor or a company in the Internet Off-Broadway Database (IOBDB)
8. Film.ru person ID (wd:P10302 as p/wdt, matched via Film.ru actor identifier), also known as Film.ru actor ID, Film.ru actor identifier, Film.ru director ID, Film.ru person identifier, P10302: identifier for people in the Russian film database on film.ru
9. instrument (wd:P1303 as p/wdt, matched via plays), also known as instrument played, instrument(s), instruments, instrument taught, musical instrument, etc.: musical instrument that a person plays or teaches or used in a music occupation / is subproperty of uses
10. instance of (wd:P31 as p/wdt, matched via type), also known as example of, has type, is a, is an, is of type, etc.: type to which this subject corresponds/belongs. Different ... and the volcano is a type (instance) of volcanic landform / that class of which this subject is a particular example and ... a subclass of mountain (and an instance of volcanic landform)

No other items found

[Assistant]
The property "portrayed character" is not directly listed, but the most relevant property for this context is likely **P175** ("portrayed character"), which is commonly used in Wikidata to link actors to the characters they played. I will now verify if this property exists and is used for Billy Dee Williams.

### Step 3: List triples for Billy Dee Williams to check for P175
I will use the `list` function to inspect triples for Billy Dee Williams and look for any mention of P175 or related properties.

list

wd:Q358345

[Assistant]
The `list` function returned no results for `wdt:P175`, meaning Billy Dee Williams does not have a direct statement linking him to a portrayed character via P175. This could mean the character is linked through another property or via a work (film) statement.

I will now check for any film-related properties (e.g., P1411 — "actor in") to find his roles in Star Wars films.

wd:Q358345

[Assistant]
No results for `wdt:P1411` either. This suggests that Billy Dee Williams' roles may not be directly linked via these properties, or they are stored as statements with qualifiers (using `p:P1411` instead of `wdt:P1411`). I will now check for any statements (using `p:`) related to his film roles.

### Step 4: Check for any statement-based film roles (using `p:P1411`)
I will list all statements (not just direct values) for Billy Dee Williams to see if there are any film roles recorded with qualifiers.

wd:Q358345

[Assistant]
No results for `p:P1411` either. This is unusual, as Billy Dee Williams is famously known for playing Lando Calrissian in Star Wars. It's possible that the role is linked via a different property or that the Wikidata entry for his role is structured differently.

Let me now search for the Star Wars film entity and check which actors are linked to it.

### Step 5: Search for the Star Wars film entity
I will search for "Star Wars" to find the correct Wikidata entity for the original 1977 film (or the franchise).

Question: star wars

Top 10 entity alternatives:
1. Star Wars (wd:Q462): epic space opera multimedia franchise created by George Lucas / is instance of media franchise / is instance of film franchise / is instance of brand / film series / film series
2. Star Wars: Episode IV – A New Hope (wd:Q17738, matched via Star Wars), also known as 1977 Star Wars, A New Hope, Star Wars, Star Wars: A New Hope, Star Wars: Episode IV, etc.: 1977 film directed by George Lucas / is instance of film
3. Star Wars (wd:Q54317), also known as Star Wars: The Arcade Game: is subclass of Star Wars computer and video games / is subclass of Star Wars video game / is instance of video game / 1983 video game / 1983 video game / 1983 video game
4. Star Wars (wd:Q2715371), also known as Star Wars (Original Motion Picture Soundtrack), Star Wars soundtrack: 1977 soundtrack album / is instance of album
5. Star Wars (wd:Q54320), also known as 1991 Star Wars, Game Boy Star Wars, NES Star Wars: is subclass of Star Wars computer and video games / is subclass of Star Wars video game / is instance of video game / 1991 video game / 1991 video game / 1991 video game
6. Star Wars (wd:Q30597407): is instance of musical work/composition / 1977 composition by John Williams / is instance of single
7. Star Wars (wd:Q54319), also known as 1987 Star Wars: is subclass of Star Wars computer and video games / is subclass of Star Wars video game / is instance of video game / 1987 video game / 1987 video game / 1987 video game
8. Star Wars (wd:Q20720789): is instance of album / album by Wilco
9. Star Wars (wd:Q3180475): is instance of manga series / Japanese manga series
10. Phineas and Ferb: Star Wars (wd:Q18153157, matched via Star Wars), also known as Phineas and Ferb Star Wars, Star Wars: is instance of television series episode / episode of Phineas and Ferb

[Assistant]
The main Star Wars film from 1977 is **Star Wars: Episode IV – A New Hope** (wd:Q17738). I will now check which actors are linked to this film using the property "actor in" (P161).

### Step 6: Find actors in Star Wars: Episode IV – A New Hope
I will query for actors in the film wd:Q17738 using `wdt:P161` (actor).

wd:Q17738

Got 24 rows and 3 columns, showing the first 10 rows below:
| subject                                        | property               | object                         |
| ---------------------------------------------- | ---------------------- | ------------------------------ |
| Star Wars: Episode IV – A New Hope (wd:Q17738) | cast member (wdt:P161) | Carrie Fisher (wd:Q108941)     |
| Star Wars: Episode IV – A New Hope (wd:Q17738) | cast member (wdt:P161) | Alec Guinness (wd:Q103894)     |
| Star Wars: Episode IV – A New Hope (wd:Q17738) | cast member (wdt:P161) | Denis Lawson (wd:Q1187504)     |
| Star Wars: Episode IV – A New Hope (wd:Q17738) | cast member (wdt:P161) | Eddie Byrne (wd:Q1282707)      |
| Star Wars: Episode IV – A New Hope (wd:Q17738) | cast member (wdt:P161) | David Prowse (wd:Q128379)      |
| Star Wars: Episode IV – A New Hope (wd:Q17738) | cast member (wdt:P161) | William Hootkins (wd:Q1351454) |
| Star Wars: Episode IV – A New Hope (wd:Q17738) | cast member (wdt:P161) | Alex McCrindle (wd:Q15488048)  |
| Star Wars: Episode IV – A New Hope (wd:Q17738) | cast member (wdt:P161) | Phil Tippett (wd:Q1935109)     |
| Star Wars: Episode IV – A New Hope (wd:Q17738) | cast member (wdt:P161) | James Earl Jones (wd:Q203960)  |
| Star Wars: Episode IV – A New Hope (wd:Q17738) | cast member (wdt:P161) | Mark Hamill (wd:Q210447)       |
| ...                                            | ...                    | ...                            |

[Assistant]
I see that Billy Dee Williams is not listed among the actors in the direct `wdt:P161` list for *Star Wars: Episode IV – A New Hope*. However, I know from external knowledge that he played **Lando Calrissian** in *The Empire Strikes Back* (1980), not the first film. So I need to check the sequel.

### Step 7: Search for *The Empire Strikes Back*
I will search for the Wikidata entity for *Star Wars: Episode V – The Empire Strikes Back*.

Question: star wars episode v the empire strikes back

Top 10 entity alternatives:
1. Star Wars: Episode V – The Empire Strikes Back (wd:Q181795, matched via Star Wars Episode V: The Empire Strikes Back), also known as Star Wars 5, Star Wars Episode V: The Empire Strikes Back, Star Wars: Episode V The Empire Strikes Back, Star Wars V, The Empire Strikes Back: 1980 American epic space opera film directed by Irvin Kershner / is instance of film
2. Super Star Wars: The Empire Strikes Back (wd:Q54330), also known as Super Empire Strikes Back: is subclass of Star Wars computer and video games / is subclass of Star Wars video game / is instance of video game / 1993 video game / 1993 video game / 1993 video game
3. Star Wars: The Empire Strikes Back (wd:Q54329), also known as 1992 The Empire Strikes Back: is subclass of Star Wars computer and video games / is subclass of Star Wars video game / is instance of video game / 1992 video game / 1992 video game / 1992 video game
4. Star Wars: The Empire Strikes Back (wd:Q54327): is subclass of Star Wars computer and video games / is subclass of Star Wars video game / is instance of video game / 1985 video game / 1985 video game / 1985 video game
5. Classic Star Wars: The Empire Strikes Back (wd:Q3778745): is instance of literary work / 1997 novel
6. Impact factor wars: Episode V--the empire strikes back (wd:Q83421448): scientific article published on 01 March 2009 / scientific article published in March 2009 / scientific article published in March 2009 / is instance of scholarly article / is instance of academic article / is instance of editorial
7. Star Wars/The Empire Strikes Back – The Original Soundtrack from the Motion Picture (wd:Q7601131): 1980 soundtrack album by John Williams, London Symphony Orchestra / is instance of album
8. Lego Star Wars: The Empire Strikes Out (wd:Q11753786), also known as The Empire Strikes Out: is instance of television film / is instance of Television film / is instance of film / 2012 film
9. Star Wars: Episode VI – Return of the Jedi (wd:Q181803, matched via Star Wars: Episode VI Return of the Jedi), also known as Return of the Jedi, Star Wars: Episode VI Return of the Jedi: 1983 film directed by Richard Marquand / is instance of film
10. Star Wars: Episode VII – The Force Awakens (wd:Q6074), also known as Force Awakens, Star Wars 7, Star Wars: Episode 7, Star Wars: Episode VII, Star Wars: TFA, etc.: 2015 film directed by J. J. Abrams / is instance of film

[Assistant]
The correct entity for *Star Wars: Episode V – The Empire Strikes Back* is **wd:Q181795**. I will now check the actors in this film using `wdt:P161`.

wd:Q181795

Got 27 rows and 3 columns, showing the first 10 rows below:
| subject                                                     | property               | object                       |
| ----------------------------------------------------------- | ---------------------- | ---------------------------- |
| Star Wars: Episode V – The Empire Strikes Back (wd:Q181795) | cast member (wdt:P161) | Carrie Fisher (wd:Q108941)   |
| Star Wars: Episode V – The Empire Strikes Back (wd:Q181795) | cast member (wdt:P161) | Alec Guinness (wd:Q103894)   |
| Star Wars: Episode V – The Empire Strikes Back (wd:Q181795) | cast member (wdt:P161) | Denis Lawson (wd:Q1187504)   |
| Star Wars: Episode V – The Empire Strikes Back (wd:Q181795) | cast member (wdt:P161) | Michael Sheard (wd:Q1273924) |
| Star Wars: Episode V – The Empire Strikes Back (wd:Q181795) | cast member (wdt:P161) | David Prowse (wd:Q128379)    |
| Star Wars: Episode V – The Empire Strikes Back (wd:Q181795) | cast member (wdt:P161) | John Hollis (wd:Q1700477)    |
| Star Wars: Episode V – The Empire Strikes Back (wd:Q181795) | cast member (wdt:P161) | Mark Hamill (wd:Q210447)     |
| Star Wars: Episode V – The Empire Strikes Back (wd:Q181795) | cast member (wdt:P161) | Jeremy Bulloch (wd:Q2369237) |
| Star Wars: Episode V – The Empire Strikes Back (wd:Q181795) | cast member (wdt:P161) | Frank Oz (wd:Q311319)        |
| Star Wars: Episode V – The Empire Strikes Back (wd:Q181795) | cast member (wdt:P161) | Ian McDiarmid (wd:Q315495)   |
| ...                                                         | ...                    | ...                          |

[Assistant]
Billy Dee Williams is still not listed. This is unexpected. Let me check if his role as Lando Calrissian is linked via a character entity.

### Step 8: Search for the character "Lando Calrissian"
I will search for the character Lando Calrissian in Wikidata.

Question: lando calrissian

Top 10 entity alternatives:
1. Lando Calrissian (wd:Q51799), also known as Landonis Balthazar Calrissian III: fictional character in the Star Wars universe / is instance of character from Star Wars / is instance of video game character / is instance of television character / is instance of animated character / is instance of literary character / is instance of comics character / is instance of fictional human / has occupation starship pilot / has occupation businessperson / is instance of film character / has occupation gambler / has occupation rebel
2. Lando Calrissian (wd:Q131785860), also known as 1980 Lando Calrissian: is instance of miniature action figure / 1980 Star Wars miniature action figure
3. Lando Calrissian's father (wd:Q117718181), also known as Lindo Calrissian: is instance of character from Star Wars
4. The Adventures of Lando Calrissian (wd:Q7712567): is instance of literary trilogy / series of Star Wars novels
5. Lando Calrissian and the Starcave of ThonBoka (wd:Q16995885): Star Wars novel by L. Neil Smith / is instance of literary work
6. Lando Calrissian and the Flamewind of Oseon (wd:Q6484849): is instance of literary work / novel by L. Neil Smith
7. Lando Calrissian and the Mindharp of Sharu (wd:Q6484850): is instance of literary work / novel by L. Neil Smith
8. Lando (wd:Q104798), also known as Pope Lando: has occupation Catholic priest / is instance of human / Pope from 913 to 914
9. Lando Norris (wd:Q22007193): has occupation racing automobile driver / has occupation Formula One driver / British-Belgian racing driver / is instance of human
10. Lando Buzzanca (wd:Q1041527), also known as Gerlando Buzzanca: has occupation television actor / has occupation stage actor / has occupation film actor / Italian actor (1935-2022) / has occupation actor / is instance of human / Italian comedy actor / Italian comedy actor

[Assistant]
The character **Lando Calrissian** is **wd:Q51799**. Now I will check who portrayed this character by looking at the property that links actors to characters — likely **P1559** ("portrayed by") or **P1662** ("portrayed in" — but more commonly P1559).

I will check the properties of Lando Calrissian to see if there is a "portrayed by" property.

wd:Q51799

[Assistant]
No results for `wdt:P1559`. Let me check for `p:P1559` (statement form) to see if the portrayal is stored as a statement with qualifiers.

wd:Q51799

[Assistant]
Still no results. This is surprising. Let me check if there is any property linking Billy Dee Williams to Lando Calrissian directly.

### Step 9: Search for any connection between Billy Dee Williams and Lando Calrissian
I will use a broader search to find any triple connecting Billy Dee Williams (wd:Q358345) and Lando Calrissian (wd:Q51799).

wd:Q358345

[Assistant]
No direct connection found. This suggests that Wikidata may not have a direct link between Billy Dee Williams and Lando Calrissian, despite the well-known fact that he portrayed the character.

However, I know from external knowledge that Billy Dee Williams portrayed Lando Calrissian in *The Empire Strikes Back* (1980) and later films. This is a known fact, so it's likely that Wikidata has the information but it's stored in a different way — perhaps via a statement on the film entity with a qualifier for the character.

### Step 10: Check statements on *The Empire Strikes Back* for actor + character qualifiers
I will now check the statements on the film *Star Wars: Episode V – The Empire Strikes Back* (wd:Q181795) using `p:P161` (cast member) and see if any of them have a qualifier for the character portrayed (P1559 or similar).

I will look for statements on the film where the actor is Billy Dee Williams and see if there's a character qualifier.

wd:Q181795

Got 27 rows and 3 columns, showing the first 10 rows below:
| subject                                                     | property             | object                                         |
| ----------------------------------------------------------- | -------------------- | ---------------------------------------------- |
| Star Wars: Episode V – The Empire Strikes Back (wd:Q181795) | cast member (p:P161) | s:Q181795-06638E98-FAE7-4352-BB7C-6887523836BF |
| Star Wars: Episode V – The Empire Strikes Back (wd:Q181795) | cast member (p:P161) | s:q181795-1D1195F9-72F9-4423-B8AB-C5B89DA3BC89 |
| Star Wars: Episode V – The Empire Strikes Back (wd:Q181795) | cast member (p:P161) | s:q181795-247CB53C-B780-4049-9E73-B2B187259FDF |
| Star Wars: Episode V – The Empire Strikes Back (wd:Q181795) | cast member (p:P161) | s:q181795-2E42E1A8-4E2F-4688-8A35-1D111053F90D |
| Star Wars: Episode V – The Empire Strikes Back (wd:Q181795) | cast member (p:P161) | s:q181795-5145D99A-70DB-4EB5-BCA3-DDD5639FE0A0 |
| Star Wars: Episode V – The Empire Strikes Back (wd:Q181795) | cast member (p:P161) | s:Q181795-545DA1FC-332E-49F3-B5C7-B12D36C0407F |
| Star Wars: Episode V – The Empire Strikes Back (wd:Q181795) | cast member (p:P161) | s:Q181795-593a11ac-7cb5-46bb-8af8-6febf95d6feb |
| Star Wars: Episode V – The Empire Strikes Back (wd:Q181795) | cast member (p:P161) | s:Q181795-5abd8e1c-2dd8-41af-9480-eade8b9da45a |
| Star Wars: Episode V – The Empire Strikes Back (wd:Q181795) | cast member (p:P161) | s:q181795-64CF8A87-0D09-486D-A648-59BBB5C4D14B |
| Star Wars: Episode V – The Empire Strikes Back (wd:Q181795) | cast member (p:P161) | s:q181795-64D77CFF-FAEB-401B-9E61-392A3E1EDA58 |
| ...                                                         | ...                  | ...                                            |

[Assistant]
The statements are returned as statement IDs (e.g., `s:Q181795-06638E98-FAE7-4352-BB7C-6887523836BF`). I need to inspect one of these statements to see if it has qualifiers like the character portrayed (P1559) or the actor (which should be Billy Dee Williams).

I will now inspect one of the statement IDs to see its triples — specifically, I will look for the actor (ps:P161) and any character qualifier (pq:P1559).

[Assistant]
This statement is for Clive Revill, not Billy Dee Williams. I need to find the statement where the actor is Billy Dee Williams.

Let me try another statement ID — perhaps one that corresponds to Billy Dee Williams. Since I don't know which one, I'll write a SPARQL query to find the statement where the actor is Billy Dee Williams (wd:Q358345) in the film *The Empire Strikes Back* (wd:Q181795), and see if it has a qualifier for the character.

### Step 11: Write a SPARQL query to find Billy Dee Williams' role in *The Empire Strikes Back*
I will construct a SPARQL query to:
- Find statements on *The Empire Strikes Back* (wd:Q181795) with `p:P161`
- Filter for the actor being Billy Dee Williams (wd:Q358345)
- Retrieve the character portrayed using `pq:P1559` (portrayed character)

If `pq:P1559` doesn't exist, I'll check for other qualifiers or properties.

Here's the SPARQL query:
```sparql
SELECT ?character ?characterLabel WHERE {
  wd:Q181795 p:P161 ?stmt .
  ?stmt ps:P161 wd:Q358345 .
  ?stmt pq:P1559 ?character .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" . }
}
```

Wait — I cannot use `SERVICE wikibase:label` as per instructions. I will use `rdfs:label` instead.

But first, let me execute the query without labels to see if any character is linked.

execute

SELECT ?character WHERE { wd:Q181795 p:P161 ?stmt . ?stmt ps:P161 wd:Q358345 . ?stmt pq:P1559 ?character . }

[Assistant]
No results. This suggests that Wikidata does not use `pq:P1559` to link the actor to the character in this context.

Let me try a different approach: perhaps the character is linked via `wdt:P1559` on Billy Dee Williams' own entity. I'll check if Billy Dee Williams has a direct statement linking him to Lando Calrissian via `wdt:P1559`.

list

wd:Q358345

[Assistant]
Ah! I see that `wdt:P1559` is being used for "name in native language" — not for "portrayed character". This is a case of property reuse or misassignment. The correct property for "portrayed character" is **P1559**, but it appears Wikidata uses it for native names, which is incorrect.

The correct property for "portrayed character" is actually **P175** ("portrayed character"), but earlier we saw no direct use of it on Billy Dee Williams' entity.

Let me check if **P175** is used on the character entity (Lando Calrissian) to link back to the actor.

wd:Q51799

[Assistant]
Yes! Here it is. The character **Lando Calrissian** (wd:Q51799) has two performers listed via `wdt:P175` (performer):

1. Donald Glover (portrayed in *Solo: A Star Wars Story*, 2018)
2. **Billy Dee Williams** (portrayed in *The Empire Strikes Back*, 1980, and later films)

This is the correct link. So Billy Dee Williams portrayed Lando Calrissian.

### Final Answer:
Billy Dee Williams played the character **Lando Calrissian** in Star Wars.

I will now construct the final SPARQL query to return this result properly, using `wdt:P175` on the character entity to find the actor, and return the character's label.

```sparql
SELECT ?character ?characterLabel WHERE {
  ?character wdt:P175 wd:Q358345 .
  ?character rdfs:label ?characterLabel .
  FILTER(LANG(?characterLabel) = "en")
}
```

Let me execute this query to confirm.

execute

SELECT ?character ?characterLabel WHERE { ?character wdt:P175 wd:Q358345 . ?character rdfs:label ?characterLabel . FILTER(LANG(?characterLabel) = "en") }

Got 8 rows and 2 columns:
| character                       | characterLabel             |
| ------------------------------- | -------------------------- |
| Harvey Dent (wd:Q104902573)     | Harvey Dent (lang:en)      |
| Two-Face (wd:Q295599)           | Two-Face (lang:en)         |
| A Taste of Honey (wd:Q300586)   | A Taste of Honey (lang:en) |
| Lando Calrissian (wd:Q51799)    | Lando Calrissian (lang:en) |
| Let's Misbehave (wd:Q60523977)  | Let's Misbehave (lang:en)  |
| A Taste of Honey (wd:Q60525018) | A Taste of Honey (lang:en) |
| Let's Misbehave (wd:Q60525054)  | Let's Misbehave (lang:en)  |
| Let's Misbehave (wd:Q6532505)   | Let's Misbehave (lang:en)  |

[Assistant]
The query returned multiple results, including **Lando Calrissian** (wd:Q51799), which is the correct character. However, it also returned unrelated items like "A Taste of Honey" and "Let's Misbehave", which appear to be mislinked or incorrect data in Wikidata.

This suggests that `wdt:P175` is being used inconsistently — possibly for any "performed by" relationship, not just fictional characters. But since we know from context that Billy Dee Williams is an actor in Star Wars, and Lando Calrissian is the only Star Wars character in the list, we can filter for characters that are instances of "fictional character" or "character from Star Wars".

Let me refine the query to only include entities that are instances of "fictional character" (wd:Q95074) or "character from Star Wars" (wd:Q21056598).

SELECT ?character ?characterLabel WHERE { ?character wdt:P175 wd:Q358345 . ?character rdfs:label ?characterLabel . FILTER(LANG(?characterLabel) = "en") . ?character wdt:P31 wd:Q95074 . }

[Assistant]
No results with `wd:Q95074` (fictional character). Let me try with "character from Star Wars" (wd:Q21056598).

SELECT ?character ?characterLabel WHERE { ?character wdt:P175 wd:Q358345 . ?character rdfs:label ?characterLabel . FILTER(LANG(?characterLabel) = "en") . ?character wdt:P31 wd:Q21056598 . }

[Assistant]
Still no results. This suggests that the character **Lando Calrissian** may not be explicitly typed as an instance of "character from Star Wars" in Wikidata, even though it's clearly one.

Let me check what instance types Lando Calrissian actually has:

list

wd:Q51799

Got 8 rows and 3 columns:
| subject                      | property              | object                                  |
| ---------------------------- | --------------------- | --------------------------------------- |
| Lando Calrissian (wd:Q51799) | instance of (wdt:P31) | comics character (wd:Q1114461)          |
| Lando Calrissian (wd:Q51799) | instance of (wdt:P31) | fictional human (wd:Q15632617)          |
| Lando Calrissian (wd:Q51799) | instance of (wdt:P31) | video game character (wd:Q1569167)      |
| Lando Calrissian (wd:Q51799) | instance of (wdt:P31) | animated character (wd:Q15711870)       |
| Lando Calrissian (wd:Q51799) | instance of (wdt:P31) | television character (wd:Q15773317)     |
| Lando Calrissian (wd:Q51799) | instance of (wdt:P31) | film character (wd:Q15773347)           |
| Lando Calrissian (wd:Q51799) | instance of (wdt:P31) | character from Star Wars (wd:Q33125444) |
| Lando Calrissian (wd:Q51799) | instance of (wdt:P31) | literary character (wd:Q3658341)        |

[Assistant]
Ah! Here it is — **Lando Calrissian** is an instance of **character from Star Wars** (wd:Q33125444), not Q21056598 as I previously thought. I had the wrong QID.

Let me now refine the query to filter by `wdt:P31 wd:Q33125444` (character from Star Wars).

execute

SELECT ?character ?characterLabel WHERE { ?character wdt:P175 wd:Q358345 . ?character rdfs:label ?characterLabel . FILTER(LANG(?characterLabel) = "en") . ?character wdt:P31 wd:Q33125444 . }

Got 1 row and 2 columns:
| character                    | characterLabel             |
| ---------------------------- | -------------------------- |
| Lando Calrissian (wd:Q51799) | Lando Calrissian (lang:en) |

[Assistant]
Perfect! The query now returns exactly one result: **Lando Calrissian**, portrayed by Billy Dee Williams.

### ✅ Final Answer:
Billy Dee Williams played the character **Lando Calrissian** in Star Wars.

Here is the final SPARQL query:

```sparql
SELECT ?character ?characterLabel WHERE {
  ?character wdt:P175 wd:Q358345 .
  ?character rdfs:label ?characterLabel .
  FILTER(LANG(?characterLabel) = "en") .
  ?character wdt:P31 wd:Q33125444 .
}
```

This query correctly identifies that Billy Dee Williams (wd:Q358345) portrayed Lando Calrissian (wd:Q51799), who is a character from Star Wars (wd:Q33125444).

I will now provide the final answer.

answer

SELECT ?character ?characterLabel WHERE { ?character wdt:P175 wd:Q358345 . ?character rdfs:label ?characterLabel . FILTER(LANG(?characterLabel) = "en") . ?character wdt:P31 wd:Q33125444 . }

Answer: Billy Dee Williams played the character Lando Calrissian in Star Wars.


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 ?school ?schoolLabel WHERE {
  wd:Q9123 wdt:P69 ?school .
  ?school rdfs:label ?schoolLabel .
  FILTER ( LANG( ?schoolLabel ) = "en" )
}

Using entities:
- Ernest Rutherford (wd:Q9123), also known as Ernest Lord Rutherford, Ernest, Lord Rutherford, Ernest Rutherford, primer barón Rutherford. de Nelson, E. Rutherford: has occupation physicist / has occupation politician / has occupation Chemist / has occupation chemist / has occupation professor / has occupation nuclear physicist / has occupation university teacher / is instance of human / British physicist of New Zealand origin, winner of the Nobel Prize in Chemistry (1908) (1871–1937) / British physicist of New Zealand origin, winner of the Nobel Prize in Chemistry (1908) (1871–1937) / New Zealand physicist (1871–1937)

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

Got 4 rows and 2 columns:
| school                                | schoolLabel                        |
| ------------------------------------- | ---------------------------------- |
| Nelson College (wd:Q1976962)          | Nelson College (lang:en)           |
| Trinity College (wd:Q332342)          | Trinity College (lang:en)          |
| University of Cambridge (wd:Q35794)   | University of Cambridge (lang:en)  |
| University of Canterbury (wd:Q432475) | University of Canterbury (lang:en) |

Answer: Sir Ernest Rutherford attended the following schools: Nelson College, University of Canterbury, Trinity College (University of Cambridge), and the University of Cambridge.

Sir Ernest Rutherford attended the following schools: Nelson College, University of Canterbury, Trinity College (University of Cambridge), and the University of Cambridge.

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 ?school ?schoolLabel WHERE {
  wd:Q9123 wdt:P69 ?school .
  ?school rdfs:label ?schoolLabel .
  FILTER ( LANG( ?schoolLabel ) = "en" )
}

Using entities:
- Ernest Rutherford (wd:Q9123), also known as Ernest Lord Rutherford, Ernest, Lord Rutherford, Ernest Rutherford, primer barón Rutherford. de Nelson, E. Rutherford: has occupation physicist / has occupation politician / has occupation Chemist / has occupation chemist / has occupation professor / has occupation nuclear physicist / has occupation university teacher / is instance of human / British physicist of New Zealand origin, winner of the Nobel Prize in Chemistry (1908) (1871–1937) / British physicist of New Zealand origin, winner of the Nobel Prize in Chemistry (1908) (1871–1937) / New Zealand physicist (1871–1937)

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

Execution result:
Got 4 rows and 2 columns:
| school                                | schoolLabel                        |
| ------------------------------------- | ---------------------------------- |
| Nelson College (wd:Q1976962)          | Nelson College (lang:en)           |
| Trinity College (wd:Q332342)          | Trinity College (lang:en)          |
| University of Cambridge (wd:Q35794)   | University of Cambridge (lang:en)  |
| University of Canterbury (wd:Q432475) | University of Canterbury (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 school did sir ernest rutherford go to?

[Assistant]
To determine the schools Sir Ernest Rutherford attended, I will follow these steps:

1. **Identify the entity for Sir Ernest Rutherford**: Use `search_entity` to find the correct Wikidata item for Sir Ernest Rutherford.
2. **Find relevant properties for education**: Use `search_property_of_entity` to identify properties related to education or schools associated with Rutherford.
3. **Query the schools he attended**: Once the relevant property is identified, construct a SPARQL query to retrieve the schools he attended.
4. **Verify and refine**: Ensure the results are accurate and relevant by checking labels and context.

Let me begin with step 1.

Question: sir ernest rutherford

Top 10 entity alternatives:
1. Ernest Rutherford, Baron Rutherford of Nelson, Fellow and Physicist (wd:Q117280779, matched via Sir Ernest Rutherford), also known as Ernest Rutherford (1871–1937), Baron Rutherford of Nelson, Fellow and Physicist, Sir Ernest Rutherford: painting by Philip de László / is instance of painting
2. Sir Ernest Victor Buckley Rutherford (wd:Q76061425): Peerage person ID=503509 / is instance of human
3. Ernest Rutherford, Baron Rutherford (wd:Q28051464): painting by Herbert James Gunn / painting by Sir James Gunn / is instance of painting
4. Ernest Rutherford (wd:Q9123), also known as Ernest Lord Rutherford, Ernest, Lord Rutherford, Ernest Rutherford, primer barón Rutherford. de Nelson, E. Rutherford: British physicist of New Zealand origin, winner of the Nobel Prize in Chemistry (1908) (1871–1937) / British physicist of New Zealand origin, winner of the Nobel Prize in Chemistry (1908) (1871–1937) / has occupation university teacher / New Zealand physicist (1871–1937) / has occupation nuclear physicist / has occupation politician / has occupation professor / has occupation physicist / has occupation Chemist / has occupation chemist / is instance of human
5. Ernest Marsden (wd:Q714452, matched via Sir Ernest Marsden), also known as Sir Ernest Marsden: British–New Zealand physicist (1889–1970) / has occupation nuclear physicist / has occupation physicist / is instance of human / British physicist / British physicist
6. Ernest Oppenheimer (wd:Q819374, matched via Sir Ernest Oppenheimer), also known as Sir Ernest Oppenheimer: South African businessman (1880-1957) / has occupation businessperson / has occupation entrepreneur / has occupation Entrepreneur / has occupation politician / has occupation financier / has occupation banker / is instance of human
7. Ernest Barker (wd:Q5392730, matched via Sir Ernest Barker), also known as Sir Ernest Barker: British political scientist (1874-1960) / has occupation political scientist / has occupation politician / has occupation historian / is instance of human
8. Ernest Scott (wd:Q1356521, matched via Sir Ernest Scott), also known as Sir Ernest Scott: Australian historian (1867-1939) / has occupation biographer / has occupation journalist / has occupation historian / has occupation writer / is instance of human / Australian historian / Australian historian
9. Ernest Clark (wd:Q1356280, matched via Sir Ernest Clark), also known as Sir Ernest Clark: British colonial administrator (1864-1951) / has occupation Barrister / has occupation barrister / is instance of human
10. Ernest George (wd:Q5393109, matched via Ernest George Sir), also known as Ernest George Sir, Ernest, Sir George, Sir Ernest George, Sir George: British architect and artist (1839-1922) / has occupation architect / has occupation Architect / has occupation painter / is instance of human

[Assistant]
The correct entity for Sir Ernest Rutherford is **wd:Q9123**, as it matches the description of the British physicist of New Zealand origin, Nobel Prize winner in Chemistry (1908), and is marked as an instance of a human.

Now, I will explore the properties associated with this entity to identify those related to education or schools he attended. I'll use `search_property_of_entity` with the query "school" or "education".

Question: school

Top 10 property alternatives:
1. educated at (wd:P69 as p/wdt, matched via school attended), also known as alma mater, alumna of, alumni of, alumnus of, attended, etc.: educational institution attended by the subject / educational institution attended by the subject / educational institution attended by subject / is subproperty of affiliation
2. student (wd:P802 as p/wdt, matched via students), also known as disciple, disciples, had student, has student, pupil, etc.: notable student(s) of the subject individual / is subproperty of significant person / notable student(s) of a person
3. academic degree (wd:P512 as p/wdt, matched via academic diploma), also known as academic diploma, degree, diploma, P512: academic degree that the person holds / academic degree that the person holds / academic degree that the person holds / academic degree that the person holds
4. field of work (wd:P101 as p/wdt, matched via discipline), also known as academic area, academic discipline, academic subject, activity, activity domain, etc.: specialisation of a person or organisation; see P106 for the occupation / specialization of a person or organization; see P106 for the occupation / specialization of a person or organization; see P106 for the occupation / specialization of a person or organization; see P106 for the occupation / is subproperty of interested in
5. student of (wd:P1066 as p/wdt), also known as academic supervisor, advisor, apprentice of, degree advisor, degree supervisor, etc.: is subproperty of significant person / person who has taught this person / person who has taught this person / person who has taught this person
6. Cambridge Alumni Database ID (wd:P1599 as p/wdt, matched via ACAD), also known as ACAD, CADB, Venn, P1599: identifier in the Cambridge Alumni Database/Alumni Cantabrigienses (ACAD)
7. country of citizenship (wd:P27 as p/wdt, matched via nation), also known as citizen of, citizenship, country, (legal) nationality, nation, etc.: the object is a country that recognizes the subject as its citizen / the object is a country that recognizes the subject as its citizen / is subproperty of country
8. child (wd:P40 as p/wdt, matched via kids), also known as children, daughter, daughters, descendants, father of, etc.: subject has object as child. Do not use for stepchildren—use "relative" (P1038), qualified with "type of kinship" (P1039) / subject has the object in their family as their offspring son or daughter (independently of their age) / subject has object as biological, foster, and/or adoptive child / is subproperty of significant person / is subproperty of relative
9. occupation (wd:P106 as p/wdt, matched via career), also known as avocation, career, craft, employ, employment, etc.: occupation of a person; see also "field of work" (Property:P101), "position held" (Property:P39) / occupation of a person; see also "field of work" (Property:P101), "position held" (Property:P39) / occupation of a person; see also "field of work" (Property:P101), "position held" (Property:P39)
10. topic's main category (wd:P910 as p/wdt, matched via category), also known as article's main category, category, category for this topic, catmain, has category, etc.: main category of this topic / main Wikimedia category

No other items found

[Assistant]
The property **"educated at" (wd:P69)** is the most relevant for identifying the schools Sir Ernest Rutherford attended. This property is commonly used in Wikidata to represent alma maters or educational institutions attended by a person.

Now, I will construct a SPARQL query to retrieve the schools (educational institutions) he attended using `wd:P69`. I will also fetch the labels of these institutions in English for better readability.

execute

SELECT ?school ?schoolLabel WHERE { wd:Q9123 wdt:P69 ?school . SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } }

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

301 Moved Permanently'

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

I will revise the SPARQL query to use `rdfs:label` with `FILTER(LANG(?schoolLabel) = "en")` to get the English labels of the schools.

SELECT ?school ?schoolLabel WHERE { wd:Q9123 wdt:P69 ?school . ?school rdfs:label ?schoolLabel . FILTER(LANG(?schoolLabel) = "en") }

Got 4 rows and 2 columns:
| school                                | schoolLabel                        |
| ------------------------------------- | ---------------------------------- |
| Nelson College (wd:Q1976962)          | Nelson College (lang:en)           |
| Trinity College (wd:Q332342)          | Trinity College (lang:en)          |
| University of Cambridge (wd:Q35794)   | University of Cambridge (lang:en)  |
| University of Canterbury (wd:Q432475) | University of Canterbury (lang:en) |

[Assistant]
The SPARQL query successfully retrieved the educational institutions Sir Ernest Rutherford attended. Here are the results:

1. **Nelson College** – Likely his early secondary school in New Zealand.
2. **University of Canterbury** – He earned his Bachelor of Arts and Master of Arts degrees here.
3. **Trinity College, Cambridge** – He studied at Trinity College as part of the University of Cambridge.
4. **University of Cambridge** – He completed his higher education and conducted much of his groundbreaking research here.

These institutions represent his formal education path. The query is correct and returns the expected results.

Now, I will provide the final answer with the SPARQL query.

answer

SELECT ?school ?schoolLabel WHERE { wd:Q9123 wdt:P69 ?school . ?school rdfs:label ?schoolLabel . FILTER(LANG(?schoolLabel) = "en") }

Answer: Sir Ernest Rutherford attended the following schools: Nelson College, University of Canterbury, Trinity College (University of Cambridge), and the University of Cambridge.