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#>
SELECT ?team ?teamLabel ( COUNT( ?final ) AS ?wins ) WHERE {
  ?final wdt:P31 wd:Q842375 ; wdt:P1346 ?team .
  ?team wdt:P31 wd:Q13393265 .
  OPTIONAL {
    ?team rdfs:label ?teamLabel .
    FILTER ( LANG( ?teamLabel ) = 'en' )
  }
}
GROUP BY ?team ?teamLabel
ORDER BY DESC ( ?wins )
LIMIT 10

Using entities:
- basketball team (wd:Q13393265), also known as basket club: is subclass of sports team / is subclass of sport team / collective name of a constituted group of players of basketball
- NBA Finals (wd:Q842375), also known as BAA Finals [1947–49], BAA World Championship Series [1947-49], Basketball Association of America World Championship Series [1947-49], National Basketball Association World Championship Series [until 1987], NBA title, etc.: is instance of recurring sporting event / is subclass of final / championship series of the National Basketball Association, ... Basketball Association World Championship Series through 1987

Using properties:
- winner (wd:P1346 as wdt), also known as 1st place medalist, awardee, champ, champion, has winner, etc.: is subproperty of participating team / is subproperty of participant / 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
- 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 ... instance of mountain; volcanoes form a subclass of mountains / type to which this subject corresponds/belongs. Different ... is an instance of mountain; volcano is a subclass of mountain

Got 10 rows and 3 columns:
| team                               | teamLabel                       | wins         |
| ---------------------------------- | ------------------------------- | ------------ |
| Boston Celtics (wd:Q131371)        | Boston Celtics (lang:en)        | 17 (xsd:int) |
| Los Angeles Lakers (wd:Q121783)    | Los Angeles Lakers (lang:en)    | 16 (xsd:int) |
| Chicago Bulls (wd:Q128109)         | Chicago Bulls (lang:en)         | 6 (xsd:int)  |
| San Antonio Spurs (wd:Q159729)     | San Antonio Spurs (lang:en)     | 5 (xsd:int)  |
| Golden State Warriors (wd:Q157376) | Golden State Warriors (lang:en) | 4 (xsd:int)  |
| Philadelphia 76ers (wd:Q138089)    | Philadelphia 76ers (lang:en)    | 3 (xsd:int)  |
| Detroit Pistons (wd:Q169661)       | Detroit Pistons (lang:en)       | 3 (xsd:int)  |
| New York Knicks (wd:Q131364)       | New York Knicks (lang:en)       | 2 (xsd:int)  |
| Houston Rockets (wd:Q161345)       | Houston Rockets (lang:en)       | 2 (xsd:int)  |
| Milwaukee Bucks (wd:Q169637)       | Milwaukee Bucks (lang:en)       | 2 (xsd:int)  |

Answer: The NBA team with the most championships is the Boston Celtics with 17 titles, followed by the Los Angeles Lakers with 16 titles.

The NBA team with the most championships is the Boston Celtics with 17 titles, followed by the Los Angeles Lakers with 16 titles.

SPARQL query over wikidata:
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#>
SELECT ?team ?teamLabel ( COUNT( ?final ) AS ?wins ) WHERE {
  ?final wdt:P31 wd:Q842375 ; wdt:P1346 ?team .
  ?team wdt:P31 wd:Q13393265 .
  OPTIONAL {
    ?team rdfs:label ?teamLabel .
    FILTER ( LANG( ?teamLabel ) = 'en' )
  }
}
GROUP BY ?team ?teamLabel
ORDER BY DESC ( ?wins )
LIMIT 10

Using entities:
- basketball team (wd:Q13393265), also known as basket club: is subclass of sports team / is subclass of sport team / collective name of a constituted group of players of basketball
- NBA Finals (wd:Q842375), also known as BAA Finals [1947–49], BAA World Championship Series [1947-49], Basketball Association of America World Championship Series [1947-49], National Basketball Association World Championship Series [until 1987], NBA title, etc.: is instance of recurring sporting event / is subclass of final / championship series of the National Basketball Association, ... Basketball Association World Championship Series through 1987

Using properties:
- winner (wd:P1346 as wdt), also known as 1st place medalist, awardee, champ, champion, has winner, etc.: is subproperty of participating team / is subproperty of participant / 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
- 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 ... instance of mountain; volcanoes form a subclass of mountains / type to which this subject corresponds/belongs. Different ... is an instance of mountain; volcano is a subclass of mountain

Execution result:
Got 10 rows and 3 columns:
| team                               | teamLabel                       | wins         |
| ---------------------------------- | ------------------------------- | ------------ |
| Boston Celtics (wd:Q131371)        | Boston Celtics (lang:en)        | 17 (xsd:int) |
| Los Angeles Lakers (wd:Q121783)    | Los Angeles Lakers (lang:en)    | 16 (xsd:int) |
| Chicago Bulls (wd:Q128109)         | Chicago Bulls (lang:en)         | 6 (xsd:int)  |
| San Antonio Spurs (wd:Q159729)     | San Antonio Spurs (lang:en)     | 5 (xsd:int)  |
| Golden State Warriors (wd:Q157376) | Golden State Warriors (lang:en) | 4 (xsd:int)  |
| Philadelphia 76ers (wd:Q138089)    | Philadelphia 76ers (lang:en)    | 3 (xsd:int)  |
| Detroit Pistons (wd:Q169661)       | Detroit Pistons (lang:en)       | 3 (xsd:int)  |
| New York Knicks (wd:Q131364)       | New York Knicks (lang:en)       | 2 (xsd:int)  |
| Houston Rockets (wd:Q161345)       | Houston Rockets (lang:en)       | 2 (xsd:int)  |
| Milwaukee Bucks (wd:Q169637)       | Milwaukee Bucks (lang:en)       | 2 (xsd:int)  |

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

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

Available knowledge graphs:
- wikidata at https://qlever.dev/api/wikidata 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. For 'main business' prefer more specific occupation items (e.g., real estate entrepreneur Q7301138) over broad labels like business magnate.
  - Population (P1082) and tabular (P4179): use wdt:P1082 for direct values; for time-series use p:P1082 + ps:P1082 + pq:P585 and ORDER BY pq:P585 DESC. Inspect qualifiers (e.g., 'applies to part') and references (pr:P854) to detect scope. When computing density with area (wdt:P2046) confirm area unit/datatype (usually km²), ensure population and area present and >0, and BIND(?population/?area AS ?density).
  - Spouse nationality: do not rely only on P27. Check the spouse's place of birth (P19) and then the birthplace's country (P17) or admin parents (wdt:P131*). Many pre-unification German spouses appear under historical states—map those to modern countries when needed.
  - For languages on countries: prefer wdt:P37 (official language) and wdt:P2936 (language used). wdt:P1412 (languages spoken/written/signed) is more often used for peoples/individuals and may be empty for countries. Try P37 and P2936 first, then fall back to P1412/P407. Fetch English labels with rdfs:label + FILTER(LANG(?l)='en').
  - When filtering by date of birth (P569) use xsd:dateTime comparisons (e.g. >= "1900-01-01T00:00:00Z"^^xsd:dateTime). Inception (P571) often uses Jan-01 placeholders for year-only dates; inspect p:P571 -> ps:P571 and check qualifiers/references for precision. For independence dates, also search for related event statements/items (e.g., 'declaration of independence') and prefer qualifiers/references over assuming day/month from year-only values.
  - 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.
  - 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: use p:P1082 ?stmt . ?stmt ps:P1082 ?pop . OPTIONAL { ?stmt pq:P585 ?date } . To get the most recent value prefer a subquery to compute MAX(?date) per subject and join back to the statement to retrieve the matching population. Avoid HAVING(MAX(?date)=?date) — QLever can error. Inspect qualifiers/references for scope (city-proper vs metro).
  - wdt:P131* can be expensive and may be incomplete. First try direct wdt:P131 for immediate administrative parent(s). If missing, check wdt:P17 (country) and wdt:P625 (coordinates) or the place item's own statements. Prefer bounded traversal (1-2 hops) or explicit parent patterns and use DISTINCT/ORDER/LIMIT to de-duplicate rather than broad P131*.
  - Use search_property_of_entity to find candidate properties but always verify the property's semantics (domain/range) and whether it links to the office, office-holder, or related entity. Test with a small query before relying on results. For creative works, after locating candidate properties, filter results by instance-of (e.g., films wd:Q11424; board games wd:Q131436) to avoid non-work items.
  - Use search_property_of_entity to find relevant properties. Political parties are modelled inconsistently (P1142, P1313, P463, P39/P106). Fallback: inspect party pages/lists and MEP group memberships; document assumptions. For country government type prefer P122 (basic form of government); P1288 is inconsistent. To exclude historical states filter NOT EXISTS { ?item wdt:P576 ?d }.
  - 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.
  - Place of burial (P119): use wdt:P119 to get the direct burial place. If you need the city, follow P119 / wdt:P131 or check the burial place's wdt:P17 (country) or wdt:P625 (coordinates) if P131 is missing. Use p:P119 / ps:P119 / pq: qualifiers when you need burial-date or scope details and inspect references for source/context.
  - P118 (league/competition) is used inconsistently: sometimes on clubs, sometimes directly on players. When finding clubs use ?club wdt:P118 wd:Q... and verify ?club wdt:P31 wd:Q483394. If P118 returns players, filter by ?item wdt:P31 wd:Q5 to detect humans and avoid false positives. To get current players prefer club→p:P54 statements: ?player p:P54 ?stmt; ?stmt ps:P54 ?club. OPTIONAL{ ?stmt pq:P582 ?end } FILTER(!BOUND(?end)). Verify qualifiers/references and DOBs for plausibility.
  - Querying holders of offices (P39): prefer p:P39 / ps:P39 patterns to access qualifiers. To find current holder use: ?person p:P39 ?stmt. ?stmt ps:P39 wd:Q... . OPTIONAL{ ?stmt pq:P582 ?end } FILTER(!BOUND(?end)). Watch for duplicate statements (re-elections)  use DISTINCT or ORDER BY DESC(?start) LIMIT 1 on pq:P580. Avoid HAVING(MAX(...)=...) on QLever; prefer subqueries with ORDER/LIMIT.
  - Headquarters: use wdt:P159 for org HQs. If P159 gives a building follow that building's wdt:P131* (bounded hops). If P159 points to a place, verify its wdt:P31. Don't rely only on P17 for org-country—also check P159 and P276. Use UNION/nested patterns to cover ?org wdt:P17 wd:Q... OR ?org wdt:P159|wdt:P276 ?place . ?place wdt:P17 wd:Q... or ?place wdt:P131* wd:Q...

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. If a query using SERVICE fails (e.g., HTTP 301 redirect), switch to rdfs:label + FILTER(LANG(...)) and/or schema:name. Language items (e.g., results from P2936) often lack rdfs:label@en; expect many hits without English labels—prefer P37 for official languages or map major languages by known QIDs.
- Practical query patterns: use rdfs:label + FILTER(LANG(...)) for labels. Use wdt:Pxxx for direct values; p:Pxxx/ps:Pxxx/pq:Pxxx for qualifiers. For roles: films use P161 (actor), directors P57; space missions use P1029 (crew). Query reverse and filter by instance-of film (wd:Q11424) or human (wd:Q5). For 'city' classification prefer ?x wdt:P31/wdt:P279* wd:Q515; use wdt:P2046 for area but check units/duplicates.
- When selecting latest qualifier-dated values (e.g., pq:P585 for award year or population), prefer a subquery to compute MAX(date) per subject and join back to get the matching statement/value. Avoid HAVING(MAX(?date)=?date) patterns on QLever (can cause engine errors). Use OPTIONAL for qualifiers when dates may be missing and GROUP_CONCAT for multi-values.
- Use search_entity to resolve names and verify instance-of (e.g., wdt:P31=wd:Q5). Note: search_entity can return class/designation items or noisy matches; constrain with instance-of, or search the related entity (e.g., country) and query its members. Use search_property_of_entity/search_autocomplete as fallback and always confirm P31 programmatically before trusting the top match.
- 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.
- QLever endpoints do not support SERVICE wikibase:label — use rdfs:label + FILTER(LANG(...))='en'. Common SPARQL pitfalls: avoid '||' outside patterns (use UNION), put AND '&&' only inside FILTER, prefer VALUES over IN, and use rdfs:label filters to constrain language. When testing existence prefer FILTER EXISTS { ... } or OPTIONAL { ?s wdt:Pxx ?v . FILTER(?v = wd:Q...) } — writing OPTIONAL { ?s wdt:Pxx wd:Q... } creates no ?v for BOUND(?v). When execute() fails, simplify the query and test with list(...).
- 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. Also verify ambiguous item QIDs (e.g., currencies or template items) by checking rdfs:label and instance-of with list(...) before use.
- 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"). When computing derived metrics (density/rates) confirm unit consistency (area units) and datatypes and do calculations inside SPARQL.
- 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; 'cause of death' -> P509; 'manner of death' -> P1196). 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] Which NBA teams have won the most seasons?

[Assistant]
To determine which NBA teams have won the most seasons (i.e., championships), I need to find information about NBA championship wins. This involves identifying:

1. The entity representing the NBA (National Basketball Association).
2. The property that links teams to their championship wins.
3. The entities representing NBA teams and their championship counts.

### Step 1: Search for the NBA entity
I'll start by searching for the NBA entity in Wikidata.

Question: NBA

Top 10 entity alternatives:
1. National Basketball Association (wd:Q155223, matched via NBA), also known as BAA, Basketball Association of America, National Basketball Assn., Nat'l Basketball Assn., NBA: North American professional basketball league / is instance of professional sports league / is instance of basketball association / is instance of basketball league / is instance of online database
2. National Book Award (wd:Q572316, matched via NBA), also known as American National Book Award, American NBA, ANBA, NBA: United States literary award in five categories / is instance of literary award / is subclass of prize / is subclass of award
3. New Barnet railway station (wd:Q1217434, matched via NBA), also known as NBA, New Barnet Station: railway station in New Barnet, London Borough of Barnet, England, UK / railway station in the United Kingdom / railway station in the United Kingdom / is instance of railway station / is instance of train station
4. Niger Basin Authority (wd:Q1162546, matched via NBA), also known as ABN, Autorite du Bassin du Niger, Autorité du Bassin du Niger, NBA: is instance of intergovernmental organisation / is instance of intergovernmental organization / intergovernmental organisation in West Africa
5. Sybil (wd:Q2915054, matched via NBA), also known as NBA: 1973 book Sybil. The True Story of A Woman Possessed By 16 Separaste Personalities. / is instance of written work
6. Nba Saghru (wd:Q3874050, matched via NBA), also known as NBA: Moroccan singer-songwriter, poet and painter (1982-2011) / has occupation singer-songwriter / has occupation painter / is instance of human / has occupation poet
7. National Biodiversity Authority (wd:Q5054185, matched via NBA), also known as NBA: is instance of government organization / is instance of government organisation / government agency in India
8. .nba (wd:Q26980848): is instance of sponsored top-level domain
9. Namibia Sports Commission (wd:Q1490962, matched via NBA), also known as Namibia Sport Commision, Namibia Sport Commission, Namibia Sports Commission*, NBA: Umbrella organization of all sports associations in Namibia / is subclass of sports governing body / is instance of organization / is instance of organisation
10. Royal Netherlands Institute of Chartered Accountants (wd:Q1827284, matched via NBA), also known as NBA: Dutch professional body for accountants / is instance of regulatory college

[Assistant]
The correct entity for the National Basketball Association is `wd:Q155223`. Now, I need to find the property that links NBA teams to their championship wins.

### Step 2: Search for properties related to championships or wins
I'll search for properties related to "championship" or "win" to find the correct one.

Question: championship

Top 10 property alternatives:
1. winner (wd:P1346 as psn/pq/prn/p/pqn/psv/pr/ps/pqv/wdtn/wdt/prv, matched via champion), 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
2. points for (wd:P1358 as psn/pq/prn/p/pqn/psv/pr/ps/pqv/wdtn/wdt/prv, matched via championship points), also known as championship points, competition points, league points, pf, points, etc.: number of points in a league table or decathlon. (Use P1351 for goals/points in a match)
3. Championat ID (wd:P10800 as psn/pq/prn/p/pqn/psv/pr/ps/pqv/wdtn/wdt/prv, matched via championat.com/), also known as championat.com/, Championat.com ID, Championat.com identifier, Championat identifier, https://www.championat.com/, etc.: identifier of a team, sports facility, or player on the Championat website
4. league or competition (wd:P118 as psn/pq/prn/p/pqn/psv/pr/ps/pqv/wdtn/wdt/prv, matched via tournament), also known as competition, cup, division, sports league, tournament, etc.: league or competition in which team or player has played, or in which an event occurs / is subproperty of participant in / league in which the team plays / league in which the team plays
5. competition won (wd:P2522 as psn/pq/prn/p/pqn/psv/pr/ps/pqv/wdtn/wdt/prv, matched via winner of), also known as victory, winner of, won, won event, P2522: competition or sports event won by the subject / is subproperty of participant in
6. award received (wd:P166 as psn/pq/prn/p/pqn/psv/pr/ps/pqv/wdtn/wdt/prv, matched via winner of), also known as award, awarded, awards, awards received, award won, etc.: award or recognition received by a person, organisation or creative work / award or recognition received by a person, organization or creative work / award or recognition received by a person, organization or creative work / awards received by a person, organisation or creative work
7. competition class (wd:P2094 as psn/pq/prn/p/pqn/psv/pr/ps/pqv/wdtn/wdt/prv), also known as class for competition, compclass, disability sport classifications, qualification class, qualifies for, etc.: official classification by a regulating body under which the ... teams, participants, or equipment) qualifies for inclusion / official classification by a regulating body under which the ... teams, participants, or equipment) qualifies for inclusion
8. sport (wd:P641 as psn/pq/prn/p/pqn/psv/pr/ps/pqv/wdtn/wdt/prv), also known as play, plays, sport played, sports, P641: sport that the subject participates or participated in or is associated with / sport or discipline in which the entity participates or belongs to
9. number of matches played/races/starts (wd:P1350 as psn/pq/prn/p/pqn/psv/pr/ps/pqv/wdtn/wdt/prv, matched via races), also known as appearances, caps, games pitched, games played, gp, etc.: matches or games a player or a team played during an event. ... a player officially appeared in during the whole career. / matches or games a player or a team played during an event. ... a player officially appeared in during the whole career. / by a sports team
10. sports discipline competed in (wd:P2416 as psn/pq/prn/p/pqn/psv/pr/ps/pqv/wdtn/wdt/prv, matched via sports event), also known as discipline of sport, event in sports, sport discipline, sport discipline competed in, sport disciplines competed in, etc.: discipline an athlete competed in within a sport / is subproperty of field of work

[Assistant]
The most relevant property for "championship won" is `wdt:P2522` (competition won). This property links an entity (e.g., a team) to the competition it won.

Now, I need to find NBA teams that have won the NBA championship. I'll first check if the NBA championship has a specific item in Wikidata.

### Step 3: Search for the NBA championship entity
I'll search for "NBA championship" to find its Wikidata item.

Question: NBA championship

Top 10 entity alternatives:
1. NBA Championship ring (wd:Q18156668), also known as The NBA Championship: Championship ring for winning the NBA Finals / is instance of final
2. Larry O'Brien Championship Trophy (wd:Q31736, matched via Larry O'Brien NBA Championship Trophy), also known as Larry O'Brien NBA Championship Trophy: is instance of sports award / basketball trophy
3. 1983 NBA World Championship Series (wd:Q2886405), also known as 1983 National Basketball Association Finals, 1983 National Basketball Association World Championship Series, 1983 NBA Finals, Showdown '83: 1983 basketball championship series / is instance of NBA Finals
4. 1947 BAA World Championship Series (wd:Q3072443, matched via 1947 NBA World Championship Series), also known as 1947 BAA Finals, 1947 Basketball Association of America Finals, 1947 Basketball Association of America World Championship Series, 1947 National Basketball Association Finals, 1947 National Basketball Association World Championship Series, etc.: basketball championship series, 1st annual Basketball Association of America finale; officially the 1st annual NBA finale / is instance of NBA Finals
5. 1957 NBA World Championship Series (wd:Q3072448), also known as 1957 National Basketball Association Finals, 1957 National Basketball Association World Championship Series, 1957 NBA Finals: 1957 basketball championship series / is instance of NBA Finals
6. 1984 NBA World Championship Series (wd:Q3072477), also known as 1984 National Basketball Association Finals, 1984 National Basketball Association World Championship Series, 1984 NBA Finals, Showdown '84: 1984 basketball championship series / is instance of NBA Finals
7. 1985 NBA World Championship Series (wd:Q3072478), also known as 1985 National Basketbal Association World Championship Series, 1985 National Basketball Association Finals, 1985 NBA Finals: 1985 basketball championship series / is instance of NBA Finals
8. 1986 NBA World Championship Series (wd:Q3072479), also known as 1986 National Basketball Association Finals, 1986 National Basketball Association World Championship Series, 1986 NBA Finals: 1986 basketball championship series / is instance of NBA Finals
9. 1987 NBA World Championship Series (wd:Q3072482), also known as 1987 National Basketball Association Finals, 1987 National Basketball Association World Championship Series, 1987 NBA Finals: 1987 basketball championship series / is instance of NBA Finals
10. 1979 NBA World Championship Series (wd:Q4578767), also known as 1979 National Basketball Association Finals, 1979 National Basketball Association World Championship Series, 1979 NBA Finals: 1979 basketball championship series / is instance of NBA Finals

[Assistant]
The NBA Championship is represented by the trophy (`wd:Q31736`) and individual finals (e.g., `wd:Q2886405` for 1983). However, the property `wdt:P2522` (competition won) is used to link teams to the specific finals they won (e.g., 1983 NBA Finals).

To find the teams with the most championships, I need to:
1. Find all NBA teams that have won the NBA Finals (using `wdt:P2522` with the finals as objects).
2. Count the number of championships per team.
3. Order by the count in descending order to find the team(s) with the most wins.

I'll construct a SPARQL query to:
- Find all teams (`wdt:P31 wd:Q483394` for sports team) that have won an NBA Finals (`wdt:P2522` with an object that is an instance of `wd:Q11424` (NBA Finals)).
- Count the number of wins per team.
- Order by count descending.

Let me write and execute the query.

execute

SELECT ?team ?teamLabel (COUNT(?final) AS ?wins) WHERE {
  ?team wdt:P31 wd:Q483394 ; # is a sports team
        wdt:P2522 ?final .    # won a competition
  ?final wdt:P31 wd:Q11424 .   # is an NBA Finals
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
} GROUP BY ?team ?teamLabel ORDER BY DESC(?wins) LIMIT 10

[Assistant]
The query returned no results, which suggests that either:
1. The property `wdt:P2522` is not used to link teams to NBA Finals, or
2. The NBA Finals are not correctly classified as `wd:Q11424` (which is "basketball championship series" — a general class).

Let me verify the classification of the NBA Finals. I'll check the instance-of (`P31`) of one of the NBA Finals items (e.g., `wd:Q2886405` for 1983 NBA Finals) to see what its type is.

list

wd:Q2886405

[Assistant]
Ah! The 1983 NBA Finals is an instance of `wd:Q842375` (NBA Finals), not `wd:Q11424` (basketball championship series). So I need to use `wd:Q842375` as the correct class for NBA Finals.

Let me update the query to use `wd:Q842375` instead of `wd:Q11424`.

Also, I notice that `SERVICE wikibase:label` is not supported in QLever. I'll remove it and instead fetch labels manually using `rdfs:label` with language filter.

Let me rewrite the query:

execute

SELECT ?team ?teamLabel (COUNT(?final) AS ?wins) WHERE {
  ?team wdt:P31 wd:Q483394 ; # is a sports team
        wdt:P2522 ?final .    # won a competition
  ?final wdt:P31 wd:Q842375 .  # is an NBA Finals
  OPTIONAL { ?team rdfs:label ?teamLabel . FILTER(LANG(?teamLabel) = 'en') }
} GROUP BY ?team ?teamLabel ORDER BY DESC(?wins) LIMIT 10

[Assistant]
Still no results. This suggests that `wdt:P2522` (competition won) may not be the correct property to link teams to NBA Finals. Let me investigate further.

I'll check what properties are used on an NBA team that has won championships — for example, the Boston Celtics, who have won many championships.

Let me search for the Boston Celtics entity.

Question: Boston Celtics

Top 10 entity alternatives:
1. Boston Celtics (wd:Q131371), also known as Celtics, Celts, C's, Green and White: NBA team based in Boston; tied with most NBA Championships / NBA team based in Boston; tied with most NBA Championships / NBA team based in Boston; tied with most NBA Championships / is instance of basketball team
2. history of the Boston Celtics (wd:Q5869142, matched via Boston Celtics history), also known as Boston Celtics history, the Boston Celtics history: is instance of aspect of history / The Celtics are an NBA franchise
3. 2018–19 Boston Celtics season (wd:Q54866896): season of National Basketball Association team the Boston Celtics / is instance of basketball team season
4. 2021–22 Boston Celtics season (wd:Q107723060): NBA professional basketball team season / is instance of basketball team season
5. 2022–23 Boston Celtics season (wd:Q112724824): NBA professional basketball team season / is instance of basketball team season
6. 2007–08 Boston Celtics season (wd:Q1018115), also known as NBA Champions 2007-08: The season of the Boston Celtics that happened between 2007 and 2008. / is instance of basketball team season
7. 2017–18 Boston Celtics season (wd:Q30641899): season of National Basketball Association team the Boston Celtics / is instance of basketball team season
8. 1956–57 Boston Celtics season (wd:Q3465057): NBA basketball team season (Season champions) / is instance of basketball team season
9. 2004–05 Boston Celtics season (wd:Q3643007): season of National Basketball Association team the Boston Celtics / is instance of basketball team season / is instance of sports season
10. 1946–47 Boston Celtics season (wd:Q3642957): season of National Basketball Association team the Boston Celtics / is instance of basketball team season

[Assistant]
The Boston Celtics are `wd:Q131371`. Now, I'll check what properties are used on this entity to indicate championship wins.

I'll list the triples for the Boston Celtics to see if there's a property indicating championship wins.

list

wd:Q131371

Got 450 rows and 3 columns, showing the first 10 rows below:
| subject                     | property                    | object                                      |
| --------------------------- | --------------------------- | ------------------------------------------- |
| Boston Celtics (wd:Q131371) | instance of (wdt:P31)       | basketball team (wd:Q13393265)              |
| Boston Celtics (wd:Q131371) | country (wdt:P17)           | United States (wd:Q30)                      |
| Boston Celtics (wd:Q131371) | Commons category (wdt:P373) | Boston Celtics                              |
| Boston Celtics (wd:Q131371) | part of (wdt:P361)          | Atlantic Division (wd:Q638908)              |
| Boston Celtics (wd:Q131371) | Freebase ID (wdt:P646)      | /m/0bwjj                                    |
| Boston Celtics (wd:Q131371) | inception (wdt:P571)        | 1946-01-01T00:00:00Z (xsd:dateTime)         |
| Boston Celtics (wd:Q131371) | VIAF cluster ID (wdtn:P214) | <http://viaf.org/viaf/59149842027902842392> |
| Boston Celtics (wd:Q131371) | sport (wdt:P641)            | basketball (wd:Q5372)                       |
| Boston Celtics (wd:Q131371) | official website (wdt:P856) | <http://www.celtics.com/>                   |
| Boston Celtics (wd:Q131371) | ISNI (wdt:P213)             | 0000000085939623                            |
| ...                         | ...                         | ...                                         |

[Assistant]
I don't see any direct property linking the Boston Celtics to their championship wins. This suggests that championship wins are not stored directly on the team entity, but rather on the individual NBA Finals events, with the winning team as the winner.

Let me check the properties of one of the NBA Finals items, like the 1983 NBA Finals (`wd:Q2886405`), to see how the winner is recorded.

wd:Q2886405

Got 54 rows and 3 columns, showing the first 10 rows below:
| subject                                          | property                    | object                                                                                |
| ------------------------------------------------ | --------------------------- | --------------------------------------------------------------------------------------------------------------------------------- |
| 1983 NBA World Championship Series (wd:Q2886405) | instance of (wdt:P31)       | NBA Finals (wd:Q842375)                                                                                |
| 1983 NBA World Championship Series (wd:Q2886405) | country (wdt:P17)           | United States (wd:Q30)                                                                                |
| 1983 NBA World Championship Series (wd:Q2886405) | Commons category (wdt:P373) | 1983 NBA Finals                                                                                |
| 1983 NBA World Championship Series (wd:Q2886405) | image (wdt:P18)             | <http://commons.wikimedia.org/wiki/Special:FilePath/Official%20Scorer%27s%20Report%20-%20Game%204%20of%201983%20NBA%20Finals.jpg> |
| 1983 NBA World Championship Series (wd:Q2886405) | Freebase ID (wdt:P646)      | /m/08x9y4                                                                                |
| 1983 NBA World Championship Series (wd:Q2886405) | location (wdt:P276)         | Spectrum (wd:Q2085822)                                                                                |
| 1983 NBA World Championship Series (wd:Q2886405) | sport (wdt:P641)            | basketball (wd:Q5372)                                                                                |
| 1983 NBA World Championship Series (wd:Q2886405) | official name (wdt:P1448)   | 1983 National Basketball Association World Championship Series (lang:en)                                                          |
| 1983 NBA World Championship Series (wd:Q2886405) | follows (wdt:P155)          | 1982 NBA World Championship Series (wd:Q4580529)                                                                                |
| 1983 NBA World Championship Series (wd:Q2886405) | followed by (wdt:P156)      | 1984 NBA World Championship Series (wd:Q3072477)                                                                                |
| ...                                              | ...                         | ...                                                                                |

[Assistant]
I still don't see the winning team. This suggests that the winner might be stored as a qualifier or in a different way. Let me check if the winner is stored using the `wdt:P1346` property, which is "winner" (used for competitions).

Let me check if `wdt:P1346` is used on the 1983 NBA Finals.

wd:Q2886405

[Assistant]
Perfect! The winner of the 1983 NBA Finals is stored using `wdt:P1346` (winner), and it links to the Philadelphia 76ers (`wd:Q138089`).

So the correct approach is:
- Use `wdt:P1346` (winner) on items that are instances of `wd:Q842375` (NBA Finals).
- The winner is an NBA team (instance of `wd:Q13393265` or `wd:Q483394` — I'll check both).

Let me verify the team type:

wd:Q138089

[Assistant]
The Philadelphia 76ers are an instance of `wd:Q13393265` (basketball team). So I'll use that as the team type.

Now I can construct the correct SPARQL query:
- Find all NBA Finals (`wdt:P31 wd:Q842375`).
- Get their winner (`wdt:P1346`).
- Filter winners to be basketball teams (`wdt:P31 wd:Q13393265`).
- Count the number of wins per team.
- Order by count descending.

I'll write the query without `SERVICE wikibase:label` and use `rdfs:label` instead.

execute

SELECT ?team ?teamLabel (COUNT(?final) AS ?wins) WHERE {
  ?final wdt:P31 wd:Q842375 ;           # is an NBA Finals
         wdt:P1346 ?team .              # has a winner
  ?team wdt:P31 wd:Q13393265 .          # is a basketball team
  OPTIONAL { ?team rdfs:label ?teamLabel . FILTER(LANG(?teamLabel) = 'en') }
} GROUP BY ?team ?teamLabel ORDER BY DESC(?wins) LIMIT 10

Got 10 rows and 3 columns:
| team                               | teamLabel                       | wins         |
| ---------------------------------- | ------------------------------- | ------------ |
| Boston Celtics (wd:Q131371)        | Boston Celtics (lang:en)        | 17 (xsd:int) |
| Los Angeles Lakers (wd:Q121783)    | Los Angeles Lakers (lang:en)    | 16 (xsd:int) |
| Chicago Bulls (wd:Q128109)         | Chicago Bulls (lang:en)         | 6 (xsd:int)  |
| San Antonio Spurs (wd:Q159729)     | San Antonio Spurs (lang:en)     | 5 (xsd:int)  |
| Golden State Warriors (wd:Q157376) | Golden State Warriors (lang:en) | 4 (xsd:int)  |
| Philadelphia 76ers (wd:Q138089)    | Philadelphia 76ers (lang:en)    | 3 (xsd:int)  |
| Detroit Pistons (wd:Q169661)       | Detroit Pistons (lang:en)       | 3 (xsd:int)  |
| New York Knicks (wd:Q131364)       | New York Knicks (lang:en)       | 2 (xsd:int)  |
| Houston Rockets (wd:Q161345)       | Houston Rockets (lang:en)       | 2 (xsd:int)  |
| Milwaukee Bucks (wd:Q169637)       | Milwaukee Bucks (lang:en)       | 2 (xsd:int)  |

[Assistant]
The query has returned the correct results! The Boston Celtics have won the most NBA championships with 17 titles, followed by the Los Angeles Lakers with 16.

### Final Answer:
The NBA team with the most championships is the **Boston Celtics** with 17 titles, followed by the **Los Angeles Lakers** with 16.

Here is the final SPARQL query:
```sparql
SELECT ?team ?teamLabel (COUNT(?final) AS ?wins) WHERE {
  ?final wdt:P31 wd:Q842375 ;           # is an NBA Finals
         wdt:P1346 ?team .              # has a winner
  ?team wdt:P31 wd:Q13393265 .          # is a basketball team
  OPTIONAL { ?team rdfs:label ?teamLabel . FILTER(LANG(?teamLabel) = 'en') }
} GROUP BY ?team ?teamLabel ORDER BY DESC(?wins) LIMIT 10
```

I'll now provide the answer.

answer

SELECT ?team ?teamLabel (COUNT(?final) AS ?wins) WHERE {
  ?final wdt:P31 wd:Q842375 ;           # is an NBA Finals
         wdt:P1346 ?team .              # has a winner
  ?team wdt:P31 wd:Q13393265 .          # is a basketball team
  OPTIONAL { ?team rdfs:label ?teamLabel . FILTER(LANG(?teamLabel) = 'en') }
} GROUP BY ?team ?teamLabel ORDER BY DESC(?wins) LIMIT 10

Answer: The NBA team with the most championships is the Boston Celtics with 17 titles, followed by the Los Angeles Lakers with 16 titles.


PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
SELECT ?height WHERE {
  wd:Q4176 wdt:P2048 ?height
}

Using entities:
- Cologne Cathedral (wd:Q4176), also known as High Cathedral of St. Peter: is instance of church / is instance of church building / is instance of Catholic cathedral / is instance of tourist attraction / Roman-Catholic cathedral in Cologne, Germany

Using properties:
- height (wd:P2048 as wdt), also known as depth over terrain, heighth, size, P2048: is subproperty of length / vertical dimension of an entity / vertical length of an entity

Answer: The height of the Cologne Cathedral is 157.0 meters.

The height of the Cologne Cathedral is 157.0 meters.

SPARQL query over wikidata:
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
SELECT ?height WHERE {
  wd:Q4176 wdt:P2048 ?height
}

Using entities:
- Cologne Cathedral (wd:Q4176), also known as High Cathedral of St. Peter: is instance of church / is instance of church building / is instance of Catholic cathedral / is instance of tourist attraction / Roman-Catholic cathedral in Cologne, Germany

Using properties:
- height (wd:P2048 as wdt), also known as depth over terrain, heighth, size, P2048: is subproperty of length / vertical dimension of an entity / vertical length of an entity

Execution result:
Got 1 row and 1 column:
| height              |
| ------------------- |
| 157.0 (xsd:decimal) |

[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 https://qlever.dev/api/wikidata 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. For 'main business' prefer more specific occupation items (e.g., real estate entrepreneur Q7301138) over broad labels like business magnate.
  - Population (P1082) and tabular (P4179): use wdt:P1082 for direct values; for time-series use p:P1082 + ps:P1082 + pq:P585 and ORDER BY pq:P585 DESC. Inspect qualifiers (e.g., 'applies to part') and references (pr:P854) to detect scope. When computing density with area (wdt:P2046) confirm area unit/datatype (usually km²), ensure population and area present and >0, and BIND(?population/?area AS ?density).
  - Spouse nationality: do not rely only on P27. Check the spouse's place of birth (P19) and then the birthplace's country (P17) or admin parents (wdt:P131*). Many pre-unification German spouses appear under historical states—map those to modern countries when needed.
  - For languages on countries: prefer wdt:P37 (official language) and wdt:P2936 (language used). wdt:P1412 (languages spoken/written/signed) is more often used for peoples/individuals and may be empty for countries. Try P37 and P2936 first, then fall back to P1412/P407. Fetch English labels with rdfs:label + FILTER(LANG(?l)='en').
  - When filtering by date of birth (P569) use xsd:dateTime comparisons (e.g. >= "1900-01-01T00:00:00Z"^^xsd:dateTime). Inception (P571) often uses Jan-01 placeholders for year-only dates; inspect p:P571 -> ps:P571 and check qualifiers/references for precision. For independence dates, also search for related event statements/items (e.g., 'declaration of independence') and prefer qualifiers/references over assuming day/month from year-only values.
  - 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.
  - 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: use p:P1082 ?stmt . ?stmt ps:P1082 ?pop . OPTIONAL { ?stmt pq:P585 ?date } . To get the most recent value prefer a subquery to compute MAX(?date) per subject and join back to the statement to retrieve the matching population. Avoid HAVING(MAX(?date)=?date) — QLever can error. Inspect qualifiers/references for scope (city-proper vs metro).
  - wdt:P131* can be expensive and may be incomplete. First try direct wdt:P131 for immediate administrative parent(s). If missing, check wdt:P17 (country) and wdt:P625 (coordinates) or the place item's own statements. Prefer bounded traversal (1-2 hops) or explicit parent patterns and use DISTINCT/ORDER/LIMIT to de-duplicate rather than broad P131*.
  - Use search_property_of_entity to find candidate properties but always verify the property's semantics (domain/range) and whether it links to the office, office-holder, or related entity. Test with a small query before relying on results. For creative works, after locating candidate properties, filter results by instance-of (e.g., films wd:Q11424; board games wd:Q131436) to avoid non-work items.
  - Use search_property_of_entity to find relevant properties. Political parties are modelled inconsistently (P1142, P1313, P463, P39/P106). Fallback: inspect party pages/lists and MEP group memberships; document assumptions. For country government type prefer P122 (basic form of government); P1288 is inconsistent. To exclude historical states filter NOT EXISTS { ?item wdt:P576 ?d }.
  - 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.
  - Place of burial (P119): use wdt:P119 to get the direct burial place. If you need the city, follow P119 / wdt:P131 or check the burial place's wdt:P17 (country) or wdt:P625 (coordinates) if P131 is missing. Use p:P119 / ps:P119 / pq: qualifiers when you need burial-date or scope details and inspect references for source/context.
  - P118 (league/competition) is used inconsistently: sometimes on clubs, sometimes directly on players. When finding clubs use ?club wdt:P118 wd:Q... and verify ?club wdt:P31 wd:Q483394. If P118 returns players, filter by ?item wdt:P31 wd:Q5 to detect humans and avoid false positives. To get current players prefer club→p:P54 statements: ?player p:P54 ?stmt; ?stmt ps:P54 ?club. OPTIONAL{ ?stmt pq:P582 ?end } FILTER(!BOUND(?end)). Verify qualifiers/references and DOBs for plausibility.
  - Querying holders of offices (P39): prefer p:P39 / ps:P39 patterns to access qualifiers. To find current holder use: ?person p:P39 ?stmt. ?stmt ps:P39 wd:Q... . OPTIONAL{ ?stmt pq:P582 ?end } FILTER(!BOUND(?end)). Watch for duplicate statements (re-elections)  use DISTINCT or ORDER BY DESC(?start) LIMIT 1 on pq:P580. Avoid HAVING(MAX(...)=...) on QLever; prefer subqueries with ORDER/LIMIT.
  - Headquarters: use wdt:P159 for org HQs. If P159 gives a building follow that building's wdt:P131* (bounded hops). If P159 points to a place, verify its wdt:P31. Don't rely only on P17 for org-country—also check P159 and P276. Use UNION/nested patterns to cover ?org wdt:P17 wd:Q... OR ?org wdt:P159|wdt:P276 ?place . ?place wdt:P17 wd:Q... or ?place wdt:P131* wd:Q...

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. If a query using SERVICE fails (e.g., HTTP 301 redirect), switch to rdfs:label + FILTER(LANG(...)) and/or schema:name. Language items (e.g., results from P2936) often lack rdfs:label@en; expect many hits without English labels—prefer P37 for official languages or map major languages by known QIDs.
- Practical query patterns: use rdfs:label + FILTER(LANG(...)) for labels. Use wdt:Pxxx for direct values; p:Pxxx/ps:Pxxx/pq:Pxxx for qualifiers. For roles: films use P161 (actor), directors P57; space missions use P1029 (crew). Query reverse and filter by instance-of film (wd:Q11424) or human (wd:Q5). For 'city' classification prefer ?x wdt:P31/wdt:P279* wd:Q515; use wdt:P2046 for area but check units/duplicates.
- When selecting latest qualifier-dated values (e.g., pq:P585 for award year or population), prefer a subquery to compute MAX(date) per subject and join back to get the matching statement/value. Avoid HAVING(MAX(?date)=?date) patterns on QLever (can cause engine errors). Use OPTIONAL for qualifiers when dates may be missing and GROUP_CONCAT for multi-values.
- Use search_entity to resolve names and verify instance-of (e.g., wdt:P31=wd:Q5). Note: search_entity can return class/designation items or noisy matches; constrain with instance-of, or search the related entity (e.g., country) and query its members. Use search_property_of_entity/search_autocomplete as fallback and always confirm P31 programmatically before trusting the top match.
- 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.
- QLever endpoints do not support SERVICE wikibase:label — use rdfs:label + FILTER(LANG(...))='en'. Common SPARQL pitfalls: avoid '||' outside patterns (use UNION), put AND '&&' only inside FILTER, prefer VALUES over IN, and use rdfs:label filters to constrain language. When testing existence prefer FILTER EXISTS { ... } or OPTIONAL { ?s wdt:Pxx ?v . FILTER(?v = wd:Q...) } — writing OPTIONAL { ?s wdt:Pxx wd:Q... } creates no ?v for BOUND(?v). When execute() fails, simplify the query and test with list(...).
- 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. Also verify ambiguous item QIDs (e.g., currencies or template items) by checking rdfs:label and instance-of with list(...) before use.
- 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"). When computing derived metrics (density/rates) confirm unit consistency (area units) and datatypes and do calculations inside SPARQL.
- 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; 'cause of death' -> P509; 'manner of death' -> P1196). 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] How high is the Cologne Cathedral ?

[Assistant]
To determine the height of the Cologne Cathedral, I need to find the relevant property that stores the height of buildings in Wikidata.

Step 1: Search for the entity "Cologne Cathedral" to confirm its Wikidata identifier.

Question: Cologne Cathedral

Top 10 entity alternatives:
1. Cologne Cathedral (wd:Q4176), also known as High Cathedral of St. Peter: Roman-Catholic cathedral in Cologne, Germany / is instance of tourist attraction / is instance of Catholic cathedral / is instance of church building / is instance of church
2. Cologne Cathedral (wd:Q20891184): painting by Oskar Kokoschka / painting by Oskar Kokoschka / is instance of painting
3. Cologne Cathedral Seal (wd:Q1795817): part of Cologne Cathedral
4. Baptistry Cologne Cathedral (wd:Q106498805): is instance of church building / is instance of church
5. Cologne Cathedral, 1869 (wd:Q119111134): painting by James Webb (1835–1895), Bristol Museum & Art Gallery / is instance of painting
6. Finials of Cologne Cathedral (wd:Q1408999): is instance of Work of art / is instance of work of art / cologne cathedral
7. Bells of Cologne Cathedral (wd:Q1795814): is instance of church bell
8. Organs of Cologne Cathedral (wd:Q7102106), also known as Organs in Cologne Cathedral: is instance of set
9. The Beggar from Cologne Cathedral (wd:Q15241065, matched via Beggar from Cologne Cathedral), also known as Beggar from Cologne Cathedral: 1927 film by Rolf Randolf / is instance of film
10. Surroundings of Cologne Cathedral (wd:Q65233962): is instance of pedestrian zone / cologne Cathedral surroundings

[Assistant]
The primary entity for the Cologne Cathedral is wd:Q4176. Now, I need to find the property that represents the height of a building.

Step 2: Search for properties related to "height" to identify the correct property.

Question: height

Top 10 property alternatives:
1. clearance (wd:P2793 as psn/pq/prn/p/pqn/psv/pr/ps/pqv/wdtn/wdt/prv, matched via height), also known as air draft, air draught, bridge height, clearance below, deck height, etc.: distance between surface under bridge and bottom of a bridge deck / distance between surface and bottom of a bridge deck
2. height (wd:P2048 as psn/pq/prn/p/pqn/psv/pr/ps/pqv/wdtn/wdt/prv), also known as depth over terrain, heighth, size, P2048: vertical dimension of an entity / vertical length of an entity / is subproperty of length
3. elevation above sea level (wd:P2044 as psn/pq/prn/p/pqn/psv/pr/ps/pqv/wdtn/wdt/prv, matched via height), also known as altitude, AMSL, EASL, elevation, elevation above mean sea level, etc.: height of the item (geographical object) as measured relative to sea level / height of the item as measured relative to sea level / height of the item as measured relative to sea level
4. highest point (wd:P610 as psn/pq/prn/p/pqn/psv/pr/ps/pqv/wdtn/wdt/prv), also known as elevation of highest point, extreme point highest, highest peak, pinnacle, summit, etc.: point with the highest elevation in the country, region, city, town, or area / point with highest elevation in the country, region, city or area / point with highest elevation in a region or path / is subproperty of has part(s) / is subproperty of has part
5. ride height (wd:P8594 as psn/pq/prn/p/pqn/psv/pr/ps/pqv/wdtn/wdt/prv), also known as ground clearance, P8594: ground clearance of vehicle or distance between the base of a vehicle tire and the lowest point
6. number of hits (wd:P9184 as psn/pq/prn/p/pqn/psv/pr/ps/pqv/wdtn/wdt/prv, matched via H), also known as career hits, career hits total, career total hits, H, hits, etc.: number of hits earned in a baseball career or game(s)
7. entry height (wd:P13238 as psn/pq/prn/p/pqn/psv/pr/ps/pqv/wdtn/wdt/prv), also known as P13238: height of the entrance above ground level for boarding vehicles
8. maximum operating altitude (wd:P2254 as psn/pq/prn/p/pqn/psv/pr/ps/pqv/wdtn/wdt/prv, matched via maximum altitude), also known as ceiling, maximum altitude, service ceiling, P2254: ceiling or maximum density altitude at which an aircraft can operate / is subproperty of elevation above sea level
9. precipitation height (wd:P3036 as psn/pq/prn/p/pqn/psv/pr/ps/pqv/wdtn/wdt/prv, matched via snow height), also known as amount of precipitation, amount of rain, amount of snow, precipitation amount, rain amount, etc.: maximum height of snow or rain during an event or space of time / maximum height of snow or rain during an event or space of time
10. director / manager (wd:P1037 as psn/pq/prn/p/pqn/psv/pr/ps/pqv/wdtn/wdt/prv, matched via head), also known as boss, chief, director, director general, general manager, etc.: person who manages any kind of group or organisation / is subproperty of significant person / person who manages any kind of group / person who manages any kind of group

[Assistant]
The property for height is P2048. Now, I will query the height of the Cologne Cathedral (wd:Q4176) using this property.

execute

SELECT ?height WHERE { wd:Q4176 wdt:P2048 ?height }

[Assistant]
The height of the Cologne Cathedral is 157.0 meters.

I now have the answer and can provide the final SPARQL query and response.

answer

SELECT ?height WHERE { wd:Q4176 wdt:P2048 ?height }

Answer: The height of the Cologne Cathedral is 157.0 meters.