PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
SELECT ?person ?personLabel ?dob ?gender ?genderLabel ?age WHERE {
  ?person wdt:P31 wd:Q5 ; wdt:P106 wd:Q10833314 .
  FILTER NOT EXISTS {
    ?person wdt:P570 ?dod .
  }
  ?person wdt:P569 ?dob .
  OPTIONAL {
    ?person wdt:P21 ?gender .
  }
  OPTIONAL {
    ?person rdfs:label ?personLabel .
    FILTER ( LANG( ?personLabel ) = "en" )
  }
  OPTIONAL {
    ?gender rdfs:label ?genderLabel .
    FILTER ( LANG( ?genderLabel ) = "en" )
  }
  BIND( ( YEAR( NOW () ) - YEAR( ?dob ) - IF( ( MONTH( NOW () ) < MONTH( ?dob ) ) || ( MONTH( NOW () ) = MONTH( ?dob ) && DAY( NOW () ) < DAY( ?dob ) ) , 1 , 0 ) ) AS ?age ) FILTER ( ?age < 110 )
}
ORDER BY DESC ( ?age ) ?dob
LIMIT 100

Using entities:
- tennis player (wd:Q10833314): is instance of profession / is subclass of competitive player / is subclass of athlete / is subclass of sportsperson / sportsperson who plays tennis
- human (wd:Q5), also known as human being, humans, individual Homo sapiens, individual human, modern humans, etc.: is instance of class of organisms known by one particular common name / is instance of organisms known by a particular common name / is subclass of mammal / is subclass of natural person / is subclass of omnivore / is subclass of person / is subclass of individual animal / any member of Homo sapiens, unique extant species of the genus Homo / common name of Homo sapiens, unique extant species of the genus Homo / common name of Homo sapiens, unique extant species of the genus Homo / common name of Homo sapiens, unique extant species of the genus Homo, from embryo to adult

Using properties:
- occupation (wd:P106 as wdt), also known as avocation, career, craft, employ, employment, etc.: occupation of a person; see also "field of work" (Property:P101), "position held" (Property:P39) / occupation of a person; see also "field of work" (Property:P101), "position held" (Property:P39) / occupation of a person; see also "field of work" (Property:P101), "position held" (Property:P39)
- sex or gender (wd:P21 as wdt), also known as biological sex, gender, gender expression, gender identity, gender or sex, etc.: 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) / sexual identity of subject: male (Q6581097), female ... (Q43445). Groups of same gender use "subclass of" (P279)
- 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
- date of birth (wd:P569 as wdt), also known as birth date, birthdate, birth year, birthyear, born, etc.: is subproperty of date of foundation or creation / is subproperty of inception / date on which the subject was born / date on which the subject was born / date on which the subject was born
- date of death (wd:P570 as wdt), also known as date of the end, dead, death, death date, deathdate, etc.: is subproperty of dissolved, abolished or demolished / is subproperty of dissolved, abolished or demolished date / is subproperty of end time / date on which the subject died / date on which the subject died / date on which the subject died

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

Explanation: I attempted to execute a SPARQL query on the local Wikidata endpoint (http://localhost:7001) to retrieve the 100 oldest living tennis players, including their dates of birth, genders, and computed ages, ordered by age descending and excluding ages >= 110. Both execution attempts timed out with a read timeout from the HTTP connection to the endpoint. Because the endpoint did not return results, I cannot verify or return the query results here. The query itself is ready and should produce the requested information when run against a functioning Wikidata SPARQL endpoint.

I attempted to execute a SPARQL query on the local Wikidata endpoint (http://localhost:7001) to retrieve the 100 oldest living tennis players, including their dates of birth, genders, and computed ages, ordered by age descending and excluding ages >= 110. Both execution attempts timed out with a read timeout from the HTTP connection to the endpoint. Because the endpoint did not return results, I cannot verify or return the query results here. The query itself is ready and should produce the requested information when run against a functioning Wikidata SPARQL endpoint.

SPARQL query over wikidata:
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
SELECT ?person ?personLabel ?dob ?gender ?genderLabel ?age WHERE {
  ?person wdt:P31 wd:Q5 ; wdt:P106 wd:Q10833314 .
  FILTER NOT EXISTS {
    ?person wdt:P570 ?dod .
  }
  ?person wdt:P569 ?dob .
  OPTIONAL {
    ?person wdt:P21 ?gender .
  }
  OPTIONAL {
    ?person rdfs:label ?personLabel .
    FILTER ( LANG( ?personLabel ) = "en" )
  }
  OPTIONAL {
    ?gender rdfs:label ?genderLabel .
    FILTER ( LANG( ?genderLabel ) = "en" )
  }
  BIND( ( YEAR( NOW () ) - YEAR( ?dob ) - IF( ( MONTH( NOW () ) < MONTH( ?dob ) ) || ( MONTH( NOW () ) = MONTH( ?dob ) && DAY( NOW () ) < DAY( ?dob ) ) , 1 , 0 ) ) AS ?age ) FILTER ( ?age < 110 )
}
ORDER BY DESC ( ?age ) ?dob
LIMIT 100

Using entities:
- tennis player (wd:Q10833314): is instance of profession / is subclass of competitive player / is subclass of athlete / is subclass of sportsperson / sportsperson who plays tennis
- human (wd:Q5), also known as human being, humans, individual Homo sapiens, individual human, modern humans, etc.: is instance of class of organisms known by one particular common name / is instance of organisms known by a particular common name / is subclass of mammal / is subclass of natural person / is subclass of omnivore / is subclass of person / is subclass of individual animal / any member of Homo sapiens, unique extant species of the genus Homo / common name of Homo sapiens, unique extant species of the genus Homo / common name of Homo sapiens, unique extant species of the genus Homo / common name of Homo sapiens, unique extant species of the genus Homo, from embryo to adult

Using properties:
- occupation (wd:P106 as wdt), also known as avocation, career, craft, employ, employment, etc.: occupation of a person; see also "field of work" (Property:P101), "position held" (Property:P39) / occupation of a person; see also "field of work" (Property:P101), "position held" (Property:P39) / occupation of a person; see also "field of work" (Property:P101), "position held" (Property:P39)
- sex or gender (wd:P21 as wdt), also known as biological sex, gender, gender expression, gender identity, gender or sex, etc.: 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) / sexual identity of subject: male (Q6581097), female ... (Q43445). Groups of same gender use "subclass of" (P279)
- 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
- date of birth (wd:P569 as wdt), also known as birth date, birthdate, birth year, birthyear, born, etc.: is subproperty of date of foundation or creation / is subproperty of inception / date on which the subject was born / date on which the subject was born / date on which the subject was born
- date of death (wd:P570 as wdt), also known as date of the end, dead, death, death date, deathdate, etc.: is subproperty of dissolved, abolished or demolished / is subproperty of dissolved, abolished or demolished date / is subproperty of end time / date on which the subject died / date on which the subject died / date on which the subject died

Execution result:
SPARQL execution failed:
HTTPConnectionPool(host='localhost', port=7001): Read timed out. (read timeout=30)

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

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

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

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

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

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

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

[User] Who are the 100 oldest living tennis players? Include their dates of birth, genders, and ages, and order by age in descending order. Exclude those who are 110 years old or older.

[Assistant]
I'll first search Wikidata for the entity representing "tennis player" to get the correct QID. Then I'll build a SPARQL query that finds humans (P31 = Q5) with occupation (P106) = tennis player, who are living (no P570 date of death), retrieving their date of birth (P569), gender (P21), and computing age relative to NOW(). I'll filter out ages >= 110, order by age descending, and limit to 100. I'll run intermediate searches/queries to confirm identifiers and results.

Question: tennis player

Top 10 entity alternatives:
1. tennis player (wd:Q10833314): is subclass of competitive player / sportsperson who plays tennis / is subclass of sportsperson / is instance of profession / is subclass of athlete
2. Tennis Player (wd:Q106774483): painting by James Edward Davis (Princeton y1968-147) / is instance of painting
3. Tennis Player (wd:Q106776651): painting by James Edward Davis (Princeton y1968-145) / is instance of painting
4. Tennis Player (wd:Q106776580): painting by James Edward Davis (Princeton y1968-146) / is instance of painting
5. Tennis Player (wd:Q106767186): painting by James Edward Davis / is instance of painting
6. Chee-Meng Jimmy Liew (wd:Q27579542, matched via Tennis player), also known as Tennis player: has occupation chess player / is instance of human / chess player
7. Tennis player (wd:Q50648121): painting by Roy De maistre / painting by Roy De Maistre / is instance of painting
8. table tennis player (wd:Q13382519), also known as ping-pong player, table tennis athlete: sportsperson taking part in table tennis competitions / sportsperson taking part in table tennis competitions / sportsperson taking part in table tennis competitions / is subclass of competitive player / is subclass of sportsperson / is instance of profession / is subclass of athlete
9. amateur tennis player (wd:Q48995125), also known as amateur tennis players: is subclass of tennis player / is instance of occupation
10. soft tennis player (wd:Q130482100): is subclass of tennis player / is instance of occupation

[Assistant]
I'll run a SPARQL query that finds humans with occupation "tennis player" (Q10833314), ensures they have no date of death (so are living), retrieves date of birth and gender, computes age using YEAR/MONTH/DAY against NOW(), filters out age >= 110, orders by age descending, and limits to 100. I will now execute that query on Wikidata.

execute

PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>

SELECT ?person ?personLabel ?dob ?gender ?genderLabel ?age WHERE {
  ?person wdt:P31 wd:Q5;         # instance of human
          wdt:P106 wd:Q10833314. # occupation: tennis player
  FILTER NOT EXISTS { ?person wdt:P570 ?dod. } # no date of death -> living
  ?person wdt:P569 ?dob.                          # date of birth
  OPTIONAL { ?person wdt:P21 ?gender. }
  # labels
  OPTIONAL { ?person rdfs:label ?personLabel. FILTER(LANG(?personLabel) = "en") }
  OPTIONAL { ?gender rdfs:label ?genderLabel. FILTER(LANG(?genderLabel) = "en") }

  # compute age in years precisely
  BIND( (YEAR(NOW()) - YEAR(?dob) -
         IF(
           (MONTH(NOW()) < MONTH(?dob)) ||
           (MONTH(NOW()) = MONTH(?dob) && DAY(NOW()) < DAY(?dob)),
           1, 0
         )
        ) AS ?age )
  FILTER(?age < 110)
}
ORDER BY DESC(?age) ?dob
LIMIT 100

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

[Assistant]
Retrying the same SPARQL query (endpoint timed out on first attempt). I'm trying again to get the results.

PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>

SELECT ?person ?personLabel ?dob ?gender ?genderLabel ?age WHERE {
  ?person wdt:P31 wd:Q5;         # instance of human
          wdt:P106 wd:Q10833314. # occupation: tennis player
  FILTER NOT EXISTS { ?person wdt:P570 ?dod. } # no date of death -> living
  ?person wdt:P569 ?dob.                          # date of birth
  OPTIONAL { ?person wdt:P21 ?gender. }
  # labels
  OPTIONAL { ?person rdfs:label ?personLabel. FILTER(LANG(?personLabel) = "en") }
  OPTIONAL { ?gender rdfs:label ?genderLabel. FILTER(LANG(?genderLabel) = "en") }

  # compute age in years precisely
  BIND( (YEAR(NOW()) - YEAR(?dob) -
         IF(
           (MONTH(NOW()) < MONTH(?dob)) ||
           (MONTH(NOW()) = MONTH(?dob) && DAY(NOW()) < DAY(?dob)),
           1, 0
         )
        ) AS ?age )
  FILTER(?age < 110)
}
ORDER BY DESC(?age) ?dob
LIMIT 100

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

[Assistant]
The Wikidata SPARQL endpoint timed out when executing the final query (two attempts). I'll stop and return a detailed explanation and the best SPARQL query I prepared so you can run it directly when the endpoint is accessible.

cancel

Explanation: I attempted to execute a SPARQL query on the local Wikidata endpoint (http://localhost:7001) to retrieve the 100 oldest living tennis players, including their dates of birth, genders, and computed ages, ordered by age descending and excluding ages >= 110. Both execution attempts timed out with a read timeout from the HTTP connection to the endpoint. Because the endpoint did not return results, I cannot verify or return the query results here. The query itself is ready and should produce the requested information when run against a functioning Wikidata SPARQL endpoint.

PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>

SELECT ?person ?personLabel ?dob ?gender ?genderLabel ?age WHERE {
  ?person wdt:P31 wd:Q5;         # instance of human
          wdt:P106 wd:Q10833314. # occupation: tennis player
  FILTER NOT EXISTS { ?person wdt:P570 ?dod. } # no date of death -> living
  ?person wdt:P569 ?dob.                          # date of birth
  OPTIONAL { ?person wdt:P21 ?gender. }
  # labels
  OPTIONAL { ?person rdfs:label ?personLabel. FILTER(LANG(?personLabel) = "en") }
  OPTIONAL { ?gender rdfs:label ?genderLabel. FILTER(LANG(?genderLabel) = "en") }

  # compute age in years precisely
  BIND( (YEAR(NOW()) - YEAR(?dob) -
         IF(
           (MONTH(NOW()) < MONTH(?dob)) ||
           (MONTH(NOW()) = MONTH(?dob) && DAY(NOW()) < DAY(?dob)),
           1, 0
         )
        ) AS ?age )
  FILTER(?age < 110)
}
ORDER BY DESC(?age) ?dob
LIMIT 100


PREFIX pq: <http://www.wikidata.org/prop/qualifier/>
PREFIX ps: <http://www.wikidata.org/prop/statement/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX wd: <http://www.wikidata.org/entity/>
SELECT DISTINCT ?person ?personLabel ?position ?positionLabel WHERE {
  ?person wdt:P31 wd:Q5 .
  ?person p:P39 ?stmt .
  ?stmt ps:P39 ?position .
  ?stmt pq:P748 wd:Q22686 .
  OPTIONAL {
    ?person rdfs:label ?personLabel .
    FILTER ( LANG( ?personLabel ) = "en" )
  }
  OPTIONAL {
    ?position rdfs:label ?positionLabel .
    FILTER ( LANG( ?positionLabel ) = "en" )
  }
}
ORDER BY ?personLabel

Using entities:
- Donald Trump (wd:Q22686), also known as DJT, Donald John Trump, Donald J. Trump, Mr Trump, POTUS 45, etc.: has occupation television producer / has occupation writer / has occupation businessperson / has occupation chief executive officer / has occupation investor / has occupation real estate entrepreneur / has occupation politician / has occupation business magnate / has occupation Business magnate / has occupation film producer / has occupation entrepreneur / has occupation Entrepreneur / has occupation merchant / has occupation game show host / has occupation Film producer / has occupation actor / is instance of human / 45th president of the United States of America / president of the United States (2017–2021, 2025–present) / president of the United States (2017–2021, 2025–present)
- human (wd:Q5), also known as human being, humans, individual Homo sapiens, individual human, modern humans, etc.: is instance of class of organisms known by one particular common name / is instance of organisms known by a particular common name / is subclass of mammal / is subclass of natural person / is subclass of omnivore / is subclass of person / is subclass of individual animal / any member of Homo sapiens, unique extant species of the genus Homo / common name of Homo sapiens, unique extant species of the genus Homo / common name of Homo sapiens, unique extant species of the genus Homo / common name of Homo sapiens, unique extant species of the genus Homo, from embryo to adult

Using properties:
- instance of (wd:P31 as wdt), also known as example of, has type, is a, is an, is of type, etc.: that class of which this subject is a particular example and ... a subclass of mountain (and an instance of volcanic landform) / type to which this subject corresponds/belongs. Different ... and the volcano is a type (instance) of volcanic landform
- position held (wd:P39 as p/ps), also known as function, held position, holds position, job, office held, etc.: subject currently or formerly holds the object position or public office / subject currently or formerly holds the object position or public office / subject currently or formerly holds the object position or public office / subject currently or formerly holds the object position or public office
- appointed by (wd:P748 as pq), also known as named by, P748: who appointed the person to the office, can be used as a qualifier

Got 90 rows and 4 columns, showing the first 5 and last 5 rows below:
| person                               | personLabel                     | position                                                                           | positionLabel                                                                |
| ------------------------------------ | ------------------------------- | ---------------------------------------------------------------------------------- | ---------------------------------------------------------------------------- |
| Adam S. Boehler (wd:Q79484036)       | Adam S. Boehler (lang:en)       | chief executive officer (wd:Q484876)                                               | chief executive officer (lang:en)                                            |
| Alex Azar (wd:Q4716651)              | Alex Azar (lang:en)             | United States Secretary of Health and Human Services (wd:Q2305968)                 | United States Secretary of Health and Human Services (lang:en)               |
| Alex N. Wong (wd:Q51884812)          | Alex N. Wong (lang:en)          | Deputy National Security Advisor (wd:Q5261055)                                     | Deputy National Security Advisor (lang:en)                                   |
| Allison Jones Rushing (wd:Q56284201) | Allison Jones Rushing (lang:en) | Judge of the United States Court of Appeals for the Fourth Circuit (wd:Q117838060) | Judge of the United States Court of Appeals for the Fourth Circuit (lang:en) |
| Alyssa Farah Griffin (wd:Q86419354)  | Alyssa Farah Griffin (lang:en)  | White House Director of Strategic Communications (wd:Q28450497)                    | White House Director of Strategic Communications (lang:en)                   |
| ...                                  | ...                             | ...                                                                                | ...                                                                          |
| Steve Goldstein (wd:Q44133885)       | Steve Goldstein (lang:en)       | Under Secretary of State for Public Diplomacy and Public Affairs (wd:Q3965299)     | Under Secretary of State for Public Diplomacy and Public Affairs (lang:en)   |
| Steve Witkoff (wd:Q16189572)         | Steve Witkoff (lang:en)         | United States Special Envoy for Middle East Peace (wd:Q127869087)                  | United States Special Envoy for Middle East Peace (lang:en)                  |
| Susie Wiles (wd:Q113560461)          | Susie Wiles (lang:en)           | White House Chief of Staff (wd:Q786242)                                            | White House Chief of Staff (lang:en)                                         |
| Tammy Bruce (wd:Q541912)             | Tammy Bruce (lang:en)           | Spokesperson for the United States Department of State (wd:Q17279657)              | Spokesperson for the United States Department of State (lang:en)             |
| Tulsi Gabbard (wd:Q32620)            | Tulsi Gabbard (lang:en)         | Director of National Intelligence (wd:Q1154057)                                    | Director of National Intelligence (lang:en)                                  |

Answer: I ran the query above and found 90 human items whose position-held (P39) statements include the qualifier "appointed by" (P748) with Donald Trump (wd:Q22686). The query returns each person IRI and the position IRI they were appointed to, plus English labels when available. Example rows include Alex Azar — United States Secretary of Health and Human Services; Allison Jones Rushing — Judge of the United States Court of Appeals for the Fourth Circuit; Alyssa Farah Griffin — White House Director of Strategic Communications; Susie Wiles — White House Chief of Staff; and others. Run the query against Wikidata to get the full list of persons and positions.

I ran the query above and found 90 human items whose position-held (P39) statements include the qualifier "appointed by" (P748) with Donald Trump (wd:Q22686). The query returns each person IRI and the position IRI they were appointed to, plus English labels when available. Example rows include Alex Azar — United States Secretary of Health and Human Services; Allison Jones Rushing — Judge of the United States Court of Appeals for the Fourth Circuit; Alyssa Farah Griffin — White House Director of Strategic Communications; Susie Wiles — White House Chief of Staff; and others. Run the query against Wikidata to get the full list of persons and positions.

SPARQL query over wikidata:
PREFIX pq: <http://www.wikidata.org/prop/qualifier/>
PREFIX ps: <http://www.wikidata.org/prop/statement/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX wd: <http://www.wikidata.org/entity/>
SELECT DISTINCT ?person ?personLabel ?position ?positionLabel WHERE {
  ?person wdt:P31 wd:Q5 .
  ?person p:P39 ?stmt .
  ?stmt ps:P39 ?position .
  ?stmt pq:P748 wd:Q22686 .
  OPTIONAL {
    ?person rdfs:label ?personLabel .
    FILTER ( LANG( ?personLabel ) = "en" )
  }
  OPTIONAL {
    ?position rdfs:label ?positionLabel .
    FILTER ( LANG( ?positionLabel ) = "en" )
  }
}
ORDER BY ?personLabel

Using entities:
- Donald Trump (wd:Q22686), also known as DJT, Donald John Trump, Donald J. Trump, Mr Trump, POTUS 45, etc.: has occupation television producer / has occupation writer / has occupation businessperson / has occupation chief executive officer / has occupation investor / has occupation real estate entrepreneur / has occupation politician / has occupation business magnate / has occupation Business magnate / has occupation film producer / has occupation entrepreneur / has occupation Entrepreneur / has occupation merchant / has occupation game show host / has occupation Film producer / has occupation actor / is instance of human / 45th president of the United States of America / president of the United States (2017–2021, 2025–present) / president of the United States (2017–2021, 2025–present)
- human (wd:Q5), also known as human being, humans, individual Homo sapiens, individual human, modern humans, etc.: is instance of class of organisms known by one particular common name / is instance of organisms known by a particular common name / is subclass of mammal / is subclass of natural person / is subclass of omnivore / is subclass of person / is subclass of individual animal / any member of Homo sapiens, unique extant species of the genus Homo / common name of Homo sapiens, unique extant species of the genus Homo / common name of Homo sapiens, unique extant species of the genus Homo / common name of Homo sapiens, unique extant species of the genus Homo, from embryo to adult

Using properties:
- instance of (wd:P31 as wdt), also known as example of, has type, is a, is an, is of type, etc.: that class of which this subject is a particular example and ... a subclass of mountain (and an instance of volcanic landform) / type to which this subject corresponds/belongs. Different ... and the volcano is a type (instance) of volcanic landform
- position held (wd:P39 as p/ps), also known as function, held position, holds position, job, office held, etc.: subject currently or formerly holds the object position or public office / subject currently or formerly holds the object position or public office / subject currently or formerly holds the object position or public office / subject currently or formerly holds the object position or public office
- appointed by (wd:P748 as pq), also known as named by, P748: who appointed the person to the office, can be used as a qualifier

Execution result:
Got 90 rows and 4 columns, showing the first 5 and last 5 rows below:
| person                               | personLabel                     | position                                                                           | positionLabel                                                                |
| ------------------------------------ | ------------------------------- | ---------------------------------------------------------------------------------- | ---------------------------------------------------------------------------- |
| Adam S. Boehler (wd:Q79484036)       | Adam S. Boehler (lang:en)       | chief executive officer (wd:Q484876)                                               | chief executive officer (lang:en)                                            |
| Alex Azar (wd:Q4716651)              | Alex Azar (lang:en)             | United States Secretary of Health and Human Services (wd:Q2305968)                 | United States Secretary of Health and Human Services (lang:en)               |
| Alex N. Wong (wd:Q51884812)          | Alex N. Wong (lang:en)          | Deputy National Security Advisor (wd:Q5261055)                                     | Deputy National Security Advisor (lang:en)                                   |
| Allison Jones Rushing (wd:Q56284201) | Allison Jones Rushing (lang:en) | Judge of the United States Court of Appeals for the Fourth Circuit (wd:Q117838060) | Judge of the United States Court of Appeals for the Fourth Circuit (lang:en) |
| Alyssa Farah Griffin (wd:Q86419354)  | Alyssa Farah Griffin (lang:en)  | White House Director of Strategic Communications (wd:Q28450497)                    | White House Director of Strategic Communications (lang:en)                   |
| ...                                  | ...                             | ...                                                                                | ...                                                                          |
| Steve Goldstein (wd:Q44133885)       | Steve Goldstein (lang:en)       | Under Secretary of State for Public Diplomacy and Public Affairs (wd:Q3965299)     | Under Secretary of State for Public Diplomacy and Public Affairs (lang:en)   |
| Steve Witkoff (wd:Q16189572)         | Steve Witkoff (lang:en)         | United States Special Envoy for Middle East Peace (wd:Q127869087)                  | United States Special Envoy for Middle East Peace (lang:en)                  |
| Susie Wiles (wd:Q113560461)          | Susie Wiles (lang:en)           | White House Chief of Staff (wd:Q786242)                                            | White House Chief of Staff (lang:en)                                         |
| Tammy Bruce (wd:Q541912)             | Tammy Bruce (lang:en)           | Spokesperson for the United States Department of State (wd:Q17279657)              | Spokesperson for the United States Department of State (lang:en)             |
| Tulsi Gabbard (wd:Q32620)            | Tulsi Gabbard (lang:en)         | Director of National Intelligence (wd:Q1154057)                                    | Director of National Intelligence (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 were the people appointed by Donald Trump, and which position was this for each person?

[Assistant]
I'll first locate the Wikidata item for Donald Trump and then search for properties related to "appointed by" or "nominated by" so I can find statements that indicate a person was appointed by him. I'll start by searching for Donald Trump, then look for relevant properties like "appointed by" or "nominated by".

Question: Donald Trump

Top 10 entity alternatives:
1. Donald Trump (wd:Q22686), also known as DJT, Donald John Trump, Donald J. Trump, Mr Trump, POTUS 45, etc.: president of the United States (2017–2021, 2025–present) / president of the United States (2017–2021, 2025–present) / 45th president of the United States of America / has occupation real estate entrepreneur / has occupation chief executive officer / has occupation television producer / has occupation Business magnate / has occupation business magnate / has occupation businessperson / has occupation game show host / has occupation film producer / has occupation Film producer / has occupation entrepreneur / has occupation Entrepreneur / has occupation politician / has occupation investor / has occupation merchant / has occupation writer / has occupation actor / is instance of human
2. Donald Trump (wd:Q27947481), also known as Donald L. Trump, Donald Lynn "Skip" Trump, Donald Lynn Trump, Dr. Donald L. Trump, Skip Trump, etc.: has occupation executive officer / has occupation oncologist / has occupation executive / has occupation physician / is instance of human / American physician
3. Donald Trump (wd:Q5295230): 2011 song by Mac Miller / is instance of single / is instance of song
4. Donald Trump (wd:Q23001025): segment of an episode of Last Week Tonight / is instance of television segment
5. Donald Trump III (wd:Q23000825, matched via Donald Trump), also known as Donald John Trump, Donald John Trump III, Donald J. Trump, Donald J. Trump III, Donald Trump: son of Donald Trump Jr. (born 2009) / is instance of human
6. Donald Trump (wd:Q104421475): character Donald Trump in Anthony Davis's opera The Central Park Five / is instance of operatic character / is instance of fictional human
7. Donald Trump Jr. (wd:Q3713655), also known as DJTJ, Donald John "Don" Trump Jr., Donald John Trump Jr., Donald John Trump, Jr., Donald J. Trump Jr., etc.: American businessman and reality television personality (born 1977) / has occupation television presenter / has occupation businessperson / has occupation Entrepreneur / has occupation entrepreneur / is instance of human
8. second impeachment of Donald Trump (wd:Q104713215, matched via Donald Trump Impeachment), also known as 2021 efforts to remove Donald Trump from office, 2021 impeachment of Donald Trump, 2nd impeachment of Donald Trump, Donald J. Trump Impeachment, Donald Trump Impeachment, etc.: is instance of Impeachments of presidents of the United States / is instance of United States presidential impeachment / 2021 United States presidential impeachment / is instance of Impeachment / is instance of impeachment
9. second inauguration of Donald Trump (wd:Q126616223, matched via Donald Trump inauguration), also known as 2025 United States presidential inauguration, 2nd inauguration of Donald Trump, Donald Trump inauguration, inauguration of Donald Trump, second Donald Trump inauguration, etc.: is instance of United States presidential inauguration / 2025 United States presidential inauguration
10. first presidency of Donald Trump (wd:Q27809653, matched via Donald Trump I), also known as Donald Trump I, First Donald Trump Administration, First Donald Trump presidency, First presidency of Donald Trump, First Trump presidency: U.S. presidential administration from 2017 to 2021 / is instance of presidential term

[Assistant]
I'll search for properties matching phrases like "appointed", "appointed by", and "nominated by" to find appropriate Wikidata properties used to record who appointed someone (these might be qualifiers on position-held statements or standalone properties).

Question: appointed

Top 10 property alternatives:
1. ratified by (wd:P6193 as pq/pqn/prv/ps/psn/pqv/prn/wdt/psv/wdtn/pr/p, matched via approval), also known as acceptance, accession, approval, ratification, P6193: used to specify that a treaty has been ratified by a given state or subject of international law
2. model (wd:P2634 as pq/pqn/prv/ps/psn/pqv/prn/wdt/psv/wdtn/pr/p, matched via posed), also known as artist's model, modelled after, posed, sitter, P2634: person who appears in an artwork or photograph, in the role of an artist's model, rather than subject
3. candidate (wd:P726 as pq/pqn/prv/ps/psn/pqv/prn/wdt/psv/wdtn/pr/p), also known as candidate in this election, election has candidate, electoral candidate, has election candidate, P726: person or party that is an option for an office in this election / person or party that is an option for an office in an election / is subproperty of participant
4. successful candidate (wd:P991 as pq/pqn/prv/ps/psn/pqv/prn/wdt/psv/wdtn/pr/p, matched via elected), also known as elected, elected candidate, elected person, election winner, election won by, etc.: person(s) or political organization(s) elected after the election / is subproperty of candidate / is subproperty of winner
5. dissolved, abolished or demolished date (wd:P576 as pq/pqn/prv/ps/psn/pqv/prn/wdt/psv/wdtn/pr/p, matched via ended), also known as abolished, abolishment date, ceased date, ceased on, ceased publication, etc.: point in time at which the subject (organisation, building) ...  "discontinued date" (P2669) for stopping a product / date or point in time on which the organisation was dissolved/disappeared or the building demolished / is subproperty of end time
6. located in/on physical feature (wd:P706 as pq/pqn/prv/ps/psn/pqv/prn/wdt/psv/wdtn/pr/p, 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. point in time (wd:P585 as pq/pqn/prv/ps/psn/pqv/prn/wdt/psv/wdtn/pr/p, matched via on), also known as as of, at time, by date, date, during, etc.: date something took place, existed or a statement was true; for providing time use the "refine date" property (P4241) / time and date something took place, existed or a statement was true / time and date something took place, existed or a statement was true / time and date something took place, existed or a statement was true
8. educated at (wd:P69 as pq/pqn/prv/ps/psn/pqv/prn/wdt/psv/wdtn/pr/p, matched via 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
9. participant in (wd:P1344 as pq/pqn/prv/ps/psn/pqv/prn/wdt/psv/wdtn/pr/p, matched via attended), also known as attended, competed in, competes in, participant of, participant of event, etc.: event in which a person or organisation was/is a participant; inverse of P710 or P1923 / event in which a person or organization was/is a participant; inverse of P710 or P1923 / is subproperty of significant event / is subproperty of part of
10. number of wins (wd:P1355 as pq/pqn/prv/ps/psn/pqv/prn/wdt/psv/wdtn/pr/p, matched via won), also known as games won, matches won, match victories, sporting wins, victories, etc.: number of sporting matches, games or events won

[Assistant]
I'll search for "nominated" and "appointed by" as alternative queries to find properties used for appointment relationships (they might be expressed as qualifiers on position-held statements, e.g., "nominated by" or "appointed by").

Question: nominated

Top 10 property alternatives:
1. nominated by (wd:P4353 as pq/pqn/prv/ps/psn/pqv/prn/wdt/psv/wdtn/pr/p), also known as P4353: who nominated a person for an office or award; can be used as a qualifier
2. nominated for (wd:P1411 as pq/pqn/prv/ps/psn/pqv/prn/wdt/psv/wdtn/pr/p), also known as finalist for, finalist for award, have nomination to, nominated for award, nomination received, etc.: award nomination received by a person, organisation or creative work (inspired from "award received" (Property:P166)) / award nomination received by a person, organisation or creative work (inspired from "award received" (Property:P166))
3. successful candidate (wd:P991 as pq/pqn/prv/ps/psn/pqv/prn/wdt/psv/wdtn/pr/p, matched via elected), also known as elected, elected candidate, elected person, election winner, election won by, etc.: person(s) or political organization(s) elected after the election / is subproperty of candidate / is subproperty of winner
4. winner (wd:P1346 as pq/pqn/prv/ps/psn/pqv/prn/wdt/psv/wdtn/pr/p, matched via nominee), also known as 1st place medalist, awardee, champ, champion, has winner, etc.: winner of a competition or similar event, not to be used for ... qualified with "for work" (P1686)) or for wars or battles / winner of an event - do not use for awards (use P166 instead), nor for wars or battles / is subproperty of participating team / is subproperty of participant
5. nominee (wd:P2453 as pq/pqn/prv/ps/psn/pqv/prn/wdt/psv/wdtn/pr/p), also known as award nominee, P2453: qualifier used with “nominated for” to specify which person or organization was nominated
6. candidate (wd:P726 as pq/pqn/prv/ps/psn/pqv/prn/wdt/psv/wdtn/pr/p), also known as candidate in this election, election has candidate, electoral candidate, has election candidate, P726: person or party that is an option for an office in this election / person or party that is an option for an office in an election / is subproperty of participant
7. candidacy in election (wd:P3602 as pq/pqn/prv/ps/psn/pqv/prn/wdt/psv/wdtn/pr/p, matched via candidate in), also known as candidate in, candidate in election, election candidacy, ran in election, running in election, etc.: election where the subject is a candidate / election where the subject is a candidate / is subproperty of participant in
8. for work (wd:P1686 as pq/pqn/prv/ps/psn/pqv/prn/wdt/psv/wdtn/pr/p, matched via nominated for work), also known as awarded for work, citation for award, for their work on, nominated for work, P1686: qualifier of award received (P166) to specify the work that an award was given to the creator for / qualifier of award received (P166) to specify the work that an award was given to the creator for
9. appointed by (wd:P748 as pq/pqn/prv/ps/psn/pqv/prn/wdt/psv/wdtn/pr/p), also known as named by, P748: who appointed the person to the office, can be used as a qualifier
10. elected in (wd:P2715 as pq/pqn/prv/ps/psn/pqv/prn/wdt/psv/wdtn/pr/p), also known as election, re-elected in, P2715: qualifier for statements in position held to link the ... from, or re-election in which the position was confirmed / election in which a person gained a position (as qualifier), or a position or legislative term is/was elected (as main value)

[Assistant]
Plan:
- Query humans (?person wdt:P31 wd:Q5) with a position-held statement (p:P39) where the statement's main value is a position (ps:P39 ?position) and the statement has the qualifier appointed by (pq:P748) with Donald Trump (wd:Q22686).
- Return person and position IRIs and English labels.

Now I'll run a SPARQL query to find people appointed by Donald Trump and the position for each appointment.

execute

SELECT DISTINCT ?person ?personLabel ?position ?positionLabel WHERE {
  ?person wdt:P31 wd:Q5 .
  ?person p:P39 ?stmt .
  ?stmt ps:P39 ?position .
  ?stmt pq:P748 wd:Q22686 .
  OPTIONAL { ?person rdfs:label ?personLabel . FILTER(LANG(?personLabel) = "en") }
  OPTIONAL { ?position rdfs:label ?positionLabel . FILTER(LANG(?positionLabel) = "en") }
}
ORDER BY ?personLabel

Got 90 rows and 4 columns, showing the first 5 and last 5 rows below:
| person                               | personLabel                     | position                                                                           | positionLabel                                                                |
| ------------------------------------ | ------------------------------- | ---------------------------------------------------------------------------------- | ---------------------------------------------------------------------------- |
| Adam S. Boehler (wd:Q79484036)       | Adam S. Boehler (lang:en)       | chief executive officer (wd:Q484876)                                               | chief executive officer (lang:en)                                            |
| Alex Azar (wd:Q4716651)              | Alex Azar (lang:en)             | United States Secretary of Health and Human Services (wd:Q2305968)                 | United States Secretary of Health and Human Services (lang:en)               |
| Alex N. Wong (wd:Q51884812)          | Alex N. Wong (lang:en)          | Deputy National Security Advisor (wd:Q5261055)                                     | Deputy National Security Advisor (lang:en)                                   |
| Allison Jones Rushing (wd:Q56284201) | Allison Jones Rushing (lang:en) | Judge of the United States Court of Appeals for the Fourth Circuit (wd:Q117838060) | Judge of the United States Court of Appeals for the Fourth Circuit (lang:en) |
| Alyssa Farah Griffin (wd:Q86419354)  | Alyssa Farah Griffin (lang:en)  | White House Director of Strategic Communications (wd:Q28450497)                    | White House Director of Strategic Communications (lang:en)                   |
| ...                                  | ...                             | ...                                                                                | ...                                                                          |
| Steve Goldstein (wd:Q44133885)       | Steve Goldstein (lang:en)       | Under Secretary of State for Public Diplomacy and Public Affairs (wd:Q3965299)     | Under Secretary of State for Public Diplomacy and Public Affairs (lang:en)   |
| Steve Witkoff (wd:Q16189572)         | Steve Witkoff (lang:en)         | United States Special Envoy for Middle East Peace (wd:Q127869087)                  | United States Special Envoy for Middle East Peace (lang:en)                  |
| Susie Wiles (wd:Q113560461)          | Susie Wiles (lang:en)           | White House Chief of Staff (wd:Q786242)                                            | White House Chief of Staff (lang:en)                                         |
| Tammy Bruce (wd:Q541912)             | Tammy Bruce (lang:en)           | Spokesperson for the United States Department of State (wd:Q17279657)              | Spokesperson for the United States Department of State (lang:en)             |
| Tulsi Gabbard (wd:Q32620)            | Tulsi Gabbard (lang:en)         | Director of National Intelligence (wd:Q1154057)                                    | Director of National Intelligence (lang:en)                                  |

[Assistant]
I'll finalize by returning the final SPARQL query I executed and a short summary of the results (number of rows and what the query returns).

answer

SELECT DISTINCT ?person ?personLabel ?position ?positionLabel WHERE {
  ?person wdt:P31 wd:Q5 .
  ?person p:P39 ?stmt .
  ?stmt ps:P39 ?position .
  ?stmt pq:P748 wd:Q22686 .
  OPTIONAL { ?person rdfs:label ?personLabel . FILTER(LANG(?personLabel) = "en") }
  OPTIONAL { ?position rdfs:label ?positionLabel . FILTER(LANG(?positionLabel) = "en") }
}
ORDER BY ?personLabel

Answer: I ran the query above and found 90 human items whose position-held (P39) statements include the qualifier "appointed by" (P748) with Donald Trump (wd:Q22686). The query returns each person IRI and the position IRI they were appointed to, plus English labels when available. Example rows include Alex Azar — United States Secretary of Health and Human Services; Allison Jones Rushing — Judge of the United States Court of Appeals for the Fourth Circuit; Alyssa Farah Griffin — White House Director of Strategic Communications; Susie Wiles — White House Chief of Staff; and others. Run the query against Wikidata to get the full list of persons and positions.