PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX ps: <http://www.wikidata.org/prop/statement/>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX pq: <http://www.wikidata.org/prop/qualifier/>
SELECT ?mun ?munLabel ?recentPop ?recentDate ( YEAR( ?recentDate ) AS ?recentYear ) ?pastPop ?pastDate ( YEAR( ?pastDate ) AS ?pastYear ) WHERE {
  ?mun wdt:P31 wd:Q2074737 ; wdt:P131 * wd:Q93366 .
  ?mun rdfs:label ?munLabel
  FILTER ( LANG( ?munLabel ) = "en" ) .
  OPTIONAL {
    SELECT ?mun ( MAX( ?date ) AS ?recentDate ) WHERE {
      ?mun p:P1082 ?s1 .
      ?s1 ps:P1082 ?v1 .
      ?s1 pq:P585 ?date .
    }
    GROUP BY ?mun
  }
  OPTIONAL {
    ?mun p:P1082 ?stmtRecent .
    ?stmtRecent ps:P1082 ?recentPop .
    OPTIONAL {
      ?stmtRecent pq:P585 ?recentDate .
    }
    FILTER ( ! BOUND( ?recentDate ) || ( BOUND( ?recentDate ) && EXISTS {
      ?stmtRecent pq:P585 ?recentDate
    }
    ) )
  }
  OPTIONAL {
    ?mun wdt:P1082 ?directPop .
    FILTER ( ! BOUND( ?recentPop ) ) BIND( ?directPop AS ?recentPop )
  }
  OPTIONAL {
    BIND( YEAR( ?recentDate ) AS ?recentYear_tmp ) BIND( ( ?recentYear_tmp - 10 ) AS ?targetYear )
  }
  OPTIONAL {
    ?mun p:P1082 ?stmtPast .
    ?stmtPast ps:P1082 ?pastPop .
    ?stmtPast pq:P585 ?pastDate .
    FILTER ( BOUND( ?targetYear ) && YEAR( ?pastDate ) = ?targetYear )
  }
}
ORDER BY ?munLabel

Using entities:
- municipality of Spain (wd:Q2074737), also known as Municipality of Spain, municipio de España, Spanish municipality: is subclass of LAU 2 / is subclass of municipality / is subclass of municipio / is subclass of administrative territorial entity of Spain / is subclass of third-order administrative division / administrative territorial entity of Spain
- Biscay (wd:Q93366), also known as Bizkaia, Province of Biscay, Vizcaya: is instance of province of Spain / is instance of Spanish provinces / is instance of Basque historical territory / province of Basque Country, Spain

Using properties:
- population (wd:P1082 as p/ps/wdt), also known as human population, inhabitants, P1082: number of people inhabiting the place; number of people of subject / number of people inhabiting the place; number of people of subject / number of people inhabiting the place; number of people of subject
- located in the administrative territorial entity (wd:P131 as wdt), also known as administrative territorial entity, administrative territory, city, happens in, in, etc.: is subproperty of location / is subproperty of part of / the item is located on the territory of the following administrative entity / the item is located on the territory of the following administrative entity / the item is located on the territory of the following ... the item falls only partially into the administrative entity. / the item is located on the territory of the following ... the item falls only partially into the administrative entity.
- 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
- point in time (wd:P585 as pq), 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

Answer:
Summary of results and query

- I used wd:Q93366 (Biscay / Bizkaia) and the class "municipality of Spain" (wd:Q2074737).
- The query returns all municipalities in Biscay (114 results in the run I executed) with these columns:
  * mun — the municipality IRI (Wikidata Q item)
  * munLabel — English label of the municipality
  * recentPop — the most recent population value (prefers a dated p:P1082 statement; falls back to wdt:P1082 if undated)
  * recentDate — the point-in-time qualifier (pq:P585) of that most recent population statement, when available
  * recentYear — YEAR(recentDate) when recentDate is present
  * pastPop — population value from a p:P1082 statement whose pq:P585 year equals (recentYear - 10), when such a statement exists
  * pastDate and pastYear — the date and its year for that 10-years-prior population, when available

- In the data I retrieved most municipalities had a most-recent population statement dated 2024. The 10-years-prior column (target year = 2014 for those) is present only for municipalities that have a population statement dated in that target year; many municipalities do not have a statement exactly 10 years earlier, so pastPop/pastDate are empty for them.

If you want, I can:
- return the full table (all 114 rows) as CSV/JSON here,
- alter the query to return the second-most-recent population statement instead of strictly the statement from exactly 10 years earlier (that may be more broadly available), or
- change the target-from-year logic (e.g., look for the population nearest to 10 years earlier instead of exact-year match).

Final SPARQL (repeated):

PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX ps: <http://www.wikidata.org/prop/statement/>
PREFIX pq: <http://www.wikidata.org/prop/qualifier/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

SELECT ?mun ?munLabel ?recentPop ?recentDate (YEAR(?recentDate) AS ?recentYear) ?pastPop ?pastDate (YEAR(?pastDate) AS ?pastYear) WHERE {
  ?mun wdt:P31 wd:Q2074737; wdt:P131* wd:Q93366.
  ?mun rdfs:label ?munLabel FILTER(LANG(?munLabel) = "en").

  OPTIONAL {
    SELECT ?mun (MAX(?date) AS ?recentDate) WHERE {
      ?mun p:P1082 ?s1 .
      ?s1 ps:P1082 ?v1 .
      ?s1 pq:P585 ?date .
    } GROUP BY ?mun
  }

  OPTIONAL {
    ?mun p:P1082 ?stmtRecent .
    ?stmtRecent ps:P1082 ?recentPop .
    OPTIONAL { ?stmtRecent pq:P585 ?recentDate . }
    FILTER( !BOUND(?recentDate) || (BOUND(?recentDate) && EXISTS { ?stmtRecent pq:P585 ?recentDate }) )
  }

  OPTIONAL {
    ?mun wdt:P1082 ?directPop .
    FILTER(!BOUND(?recentPop))
    BIND(?directPop AS ?recentPop)
  }

  OPTIONAL {
    BIND(YEAR(?recentDate) AS ?recentYear_tmp)
    BIND((?recentYear_tmp - 10) AS ?targetYear)
  }

  OPTIONAL {
    ?mun p:P1082 ?stmtPast .
    ?stmtPast ps:P1082 ?pastPop .
    ?stmtPast pq:P585 ?pastDate .
    FILTER(BOUND(?targetYear) && YEAR(?pastDate) = ?targetYear)
  }
}
ORDER BY ?munLabel

If you want the full table exported here (CSV/JSON) or a version that finds the population nearest to 10 years prior instead of an exact-year match, tell me which format or variant you prefer and I'll produce it.

Summary of results and query

- I used wd:Q93366 (Biscay / Bizkaia) and the class "municipality of Spain" (wd:Q2074737).
- The query returns all municipalities in Biscay (114 results in the run I executed) with these columns:
  * mun — the municipality IRI (Wikidata Q item)
  * munLabel — English label of the municipality
  * recentPop — the most recent population value (prefers a dated p:P1082 statement; falls back to wdt:P1082 if undated)
  * recentDate — the point-in-time qualifier (pq:P585) of that most recent population statement, when available
  * recentYear — YEAR(recentDate) when recentDate is present
  * pastPop — population value from a p:P1082 statement whose pq:P585 year equals (recentYear - 10), when such a statement exists
  * pastDate and pastYear — the date and its year for that 10-years-prior population, when available

- In the data I retrieved most municipalities had a most-recent population statement dated 2024. The 10-years-prior column (target year = 2014 for those) is present only for municipalities that have a population statement dated in that target year; many municipalities do not have a statement exactly 10 years earlier, so pastPop/pastDate are empty for them.

If you want, I can:
- return the full table (all 114 rows) as CSV/JSON here,
- alter the query to return the second-most-recent population statement instead of strictly the statement from exactly 10 years earlier (that may be more broadly available), or
- change the target-from-year logic (e.g., look for the population nearest to 10 years earlier instead of exact-year match).

Final SPARQL (repeated):

PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX ps: <http://www.wikidata.org/prop/statement/>
PREFIX pq: <http://www.wikidata.org/prop/qualifier/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

SELECT ?mun ?munLabel ?recentPop ?recentDate (YEAR(?recentDate) AS ?recentYear) ?pastPop ?pastDate (YEAR(?pastDate) AS ?pastYear) WHERE {
  ?mun wdt:P31 wd:Q2074737; wdt:P131* wd:Q93366.
  ?mun rdfs:label ?munLabel FILTER(LANG(?munLabel) = "en").

  OPTIONAL {
    SELECT ?mun (MAX(?date) AS ?recentDate) WHERE {
      ?mun p:P1082 ?s1 .
      ?s1 ps:P1082 ?v1 .
      ?s1 pq:P585 ?date .
    } GROUP BY ?mun
  }

  OPTIONAL {
    ?mun p:P1082 ?stmtRecent .
    ?stmtRecent ps:P1082 ?recentPop .
    OPTIONAL { ?stmtRecent pq:P585 ?recentDate . }
    FILTER( !BOUND(?recentDate) || (BOUND(?recentDate) && EXISTS { ?stmtRecent pq:P585 ?recentDate }) )
  }

  OPTIONAL {
    ?mun wdt:P1082 ?directPop .
    FILTER(!BOUND(?recentPop))
    BIND(?directPop AS ?recentPop)
  }

  OPTIONAL {
    BIND(YEAR(?recentDate) AS ?recentYear_tmp)
    BIND((?recentYear_tmp - 10) AS ?targetYear)
  }

  OPTIONAL {
    ?mun p:P1082 ?stmtPast .
    ?stmtPast ps:P1082 ?pastPop .
    ?stmtPast pq:P585 ?pastDate .
    FILTER(BOUND(?targetYear) && YEAR(?pastDate) = ?targetYear)
  }
}
ORDER BY ?munLabel

If you want the full table exported here (CSV/JSON) or a version that finds the population nearest to 10 years prior instead of an exact-year match, tell me which format or variant you prefer and I'll produce it.

SPARQL query over wikidata:
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX ps: <http://www.wikidata.org/prop/statement/>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX pq: <http://www.wikidata.org/prop/qualifier/>
SELECT ?mun ?munLabel ?recentPop ?recentDate ( YEAR( ?recentDate ) AS ?recentYear ) ?pastPop ?pastDate ( YEAR( ?pastDate ) AS ?pastYear ) WHERE {
  ?mun wdt:P31 wd:Q2074737 ; wdt:P131 * wd:Q93366 .
  ?mun rdfs:label ?munLabel
  FILTER ( LANG( ?munLabel ) = "en" ) .
  OPTIONAL {
    SELECT ?mun ( MAX( ?date ) AS ?recentDate ) WHERE {
      ?mun p:P1082 ?s1 .
      ?s1 ps:P1082 ?v1 .
      ?s1 pq:P585 ?date .
    }
    GROUP BY ?mun
  }
  OPTIONAL {
    ?mun p:P1082 ?stmtRecent .
    ?stmtRecent ps:P1082 ?recentPop .
    OPTIONAL {
      ?stmtRecent pq:P585 ?recentDate .
    }
    FILTER ( ! BOUND( ?recentDate ) || ( BOUND( ?recentDate ) && EXISTS {
      ?stmtRecent pq:P585 ?recentDate
    }
    ) )
  }
  OPTIONAL {
    ?mun wdt:P1082 ?directPop .
    FILTER ( ! BOUND( ?recentPop ) ) BIND( ?directPop AS ?recentPop )
  }
  OPTIONAL {
    BIND( YEAR( ?recentDate ) AS ?recentYear_tmp ) BIND( ( ?recentYear_tmp - 10 ) AS ?targetYear )
  }
  OPTIONAL {
    ?mun p:P1082 ?stmtPast .
    ?stmtPast ps:P1082 ?pastPop .
    ?stmtPast pq:P585 ?pastDate .
    FILTER ( BOUND( ?targetYear ) && YEAR( ?pastDate ) = ?targetYear )
  }
}
ORDER BY ?munLabel

Using entities:
- municipality of Spain (wd:Q2074737), also known as Municipality of Spain, municipio de España, Spanish municipality: is subclass of LAU 2 / is subclass of municipality / is subclass of municipio / is subclass of administrative territorial entity of Spain / is subclass of third-order administrative division / administrative territorial entity of Spain
- Biscay (wd:Q93366), also known as Bizkaia, Province of Biscay, Vizcaya: is instance of province of Spain / is instance of Spanish provinces / is instance of Basque historical territory / province of Basque Country, Spain

Using properties:
- population (wd:P1082 as p/ps/wdt), also known as human population, inhabitants, P1082: number of people inhabiting the place; number of people of subject / number of people inhabiting the place; number of people of subject / number of people inhabiting the place; number of people of subject
- located in the administrative territorial entity (wd:P131 as wdt), also known as administrative territorial entity, administrative territory, city, happens in, in, etc.: is subproperty of location / is subproperty of part of / the item is located on the territory of the following administrative entity / the item is located on the territory of the following administrative entity / the item is located on the territory of the following ... the item falls only partially into the administrative entity. / the item is located on the territory of the following ... the item falls only partially into the administrative entity.
- 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
- point in time (wd:P585 as pq), 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

Execution result:
Got 114 rows and 8 columns, showing the first 5 and last 5 rows below:
| mun                                             | munLabel                                    | recentPop           | recentDate                          | recentYear     | pastPop | pastDate | pastYear |
| ----------------------------------------------- | ------------------------------------------- | ------------------- | ----------------------------------- | -------------- | ------- | -------- | -------- |
| Abadiño (wd:Q744893)                            | Abadiño (lang:en)                           | 7742 (xsd:decimal)  | 2024-01-01T00:00:00Z (xsd:dateTime) | 2024 (xsd:int) |         |          |          |
| Abanto y Ciérvana-Abanto Zierbena (wd:Q1242411) | Abanto y Ciérvana-Abanto Zierbena (lang:en) | 9409 (xsd:decimal)  | 2024-01-01T00:00:00Z (xsd:dateTime) | 2024 (xsd:int) |         |          |          |
| Ajangiz (wd:Q1228043)                           | Ajangiz (lang:en)                           | 475 (xsd:decimal)   | 2024-01-01T00:00:00Z (xsd:dateTime) | 2024 (xsd:int) |         |          |          |
| Alonsotegi (wd:Q927978)                         | Alonsotegi (lang:en)                        | 3020 (xsd:decimal)  | 2024-01-01T00:00:00Z (xsd:dateTime) | 2024 (xsd:int) |         |          |          |
| Amorebieta-Etxano (wd:Q474080)                  | Amorebieta-Etxano (lang:en)                 | 19678 (xsd:decimal) | 2024-01-01T00:00:00Z (xsd:dateTime) | 2024 (xsd:int) |         |          |          |
| ...                                             | ...                                         | ...                 | ...                                 | ...            | ...     | ...      | ...      |
| Zaratamo (wd:Q1227189)                          | Zaratamo (lang:en)                          | 1611 (xsd:decimal)  | 2024-01-01T00:00:00Z (xsd:dateTime) | 2024 (xsd:int) |         |          |          |
| Zeanuri (wd:Q169332)                            | Zeanuri (lang:en)                           | 1250 (xsd:decimal)  | 2024-01-01T00:00:00Z (xsd:dateTime) | 2024 (xsd:int) |         |          |          |
| Zeberio (wd:Q594280)                            | Zeberio (lang:en)                           | 1081 (xsd:decimal)  | 2024-01-01T00:00:00Z (xsd:dateTime) | 2024 (xsd:int) |         |          |          |
| Zierbena (wd:Q1542223)                          | Zierbena (lang:en)                          | 1493 (xsd:decimal)  | 2024-01-01T00:00:00Z (xsd:dateTime) | 2024 (xsd:int) |         |          |          |
| Ziortza-Bolibar (wd:Q1247479)                   | Ziortza-Bolibar (lang:en)                   | 409 (xsd:decimal)   | 2024-01-01T00:00:00Z (xsd:dateTime) | 2024 (xsd:int) |         |          |          |

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

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

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

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

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

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

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

[User] What are the municipalities of Spain located in Biscay, along with their most recent population and the year of that population data, and if available, the population and year of the population data from 10 years prior?

[Assistant]
Step 1 — I'll search Wikidata for the entity corresponding to the province "Biscay" (also known as Bizkaia) to get its QID. I'll verify it's an administrative division in Spain (instance of province). I'll use search_entity.

Question: Biscay

Top 10 entity alternatives:
1. Biscay (wd:Q93366), also known as Bizkaia, Province of Biscay, Vizcaya: is instance of Basque historical territory / province of Basque Country, Spain / is instance of Spanish provinces / is instance of province of Spain
2. Biscay (wd:Q2231801), also known as Biscay, Minnesota, Biscay, MN: human settlement in McLeod County, Minnesota, United States of America / is instance of city in the United States / is instance of city of the United States
3. Andrea del Brescianino (wd:Q2846393, matched via Biscay), also known as Andrea Brescianino, Andrea del Piccinelli, Andrea Piccinelli, Andrea Picinelli gen. Andrea Del Brescianino, Biscay, etc.: Italian painter (1487–1525) / has occupation painter / is instance of human / Italian painter / Italian painter
4. Balthasar Beschey (wd:Q2881605, matched via Biscay), also known as Bachai, Baltasar Beschey, Balt. Beschey, Balt. Besschey, Balt. Bisschey, etc.: Flemish painter (1708-1776) / has occupation painter / is instance of human
5. Biscay (wd:Q4917218): is instance of electoral district of the Spanish Congress / Congress of Deputies constituency
6. Biscay (wd:Q2904600), also known as Bizkai: is instance of commune of France / former commune in France
7. Biscay (wd:Q28452115): Basque Parliament constituency / is instance of electoral unit / is instance of constituency / is instance of riding
8. Biscay (wd:Q58214031), also known as Biscay (Senate constituency): is instance of constituency of the Senate of Spain / Senate constituency in Spain
9. Biscay (wd:Q4917221): Australian-bred Thoroughbred racehorse / is instance of horse / is instance of Horse
10. Biscay (wd:Q75135299): is instance of family name / is instance of surname / family name / family name / surname

[Assistant]
Now I'll search for the item corresponding to "municipality of Spain" to identify the appropriate instance-of value to match municipalities. I'll use search_entity for "municipality of Spain".

Question: municipality of Spain

Top 10 entity alternatives:
1. municipality of Spain (wd:Q2074737), also known as Municipality of Spain, municipio de España, Spanish municipality: is subclass of administrative territorial entity of Spain / is subclass of third-order administrative division / administrative territorial entity of Spain / is subclass of municipality / is subclass of municipio / is subclass of LAU 2
2. former municipality of Spain (wd:Q55863584): is subclass of former administrative territorial entity / is subclass of municipality of Spain / is subclass of former municipality
3. Spain (wd:Q29, matched via Kingdom of Spain), also known as Kingdom of Spain: country in southwestern Europe with territories in Africa / constitutional monarchy in Southwest Europe / constitutional monarchy in Southwest Europe / is instance of Mediterranean country / is instance of sovereign state / is instance of country / is instance of realm
4. Shanghai (wd:Q8686, matched via Municipality of Shanghai), also known as Hu, Municipality of Shanghai, Pearl of the Orient, Shanghae, Shang-hai, etc.: is instance of Economic and Technological Development Zones / is instance of direct-administered municipality / provincial-level municipality in China / is instance of national central city / is instance of largest city / is instance of global city / is instance of metropolis / is instance of Metropolis / is instance of port city / is instance of big city / is instance of megacity
5. Tianjin (wd:Q11736, matched via Municipality of Tianjin), also known as Municipality of Tianjin, Tianjin Municipality, Tien-tsin, Tientsin: is instance of Economic and Technological Development Zones / is instance of direct-administered municipality / is instance of national central city / is instance of port city / is instance of big city / is instance of megacity / municipality of China / is instance of city
6. Córdoba (wd:Q5818, matched via Municipality of Cordova), also known as Cordoba, Cordova, Cordova municipality, Municipality of Cordova: municipality in the province of Córdoba, Spain / is instance of municipality of Spain / city in Andalusia, southern Spain
7. Port of Spain (wd:Q39178), also known as Cumucurapo, Port-of-Spain, Puerto España: is instance of regional corporation or municipality of Trinidad and Tobago / is instance of political territorial entity / capital of Trinidad and Tobago / is instance of city
8. Anchorage (wd:Q39450, matched via Municipality of Anchorage), also known as Anchorage, Alaska, Municipality of Anchorage, The City of Lights and Flowers: consolidated city-borough in Alaska, United States of America / is instance of city in the United States / is instance of city of the United States / is instance of consolidated city-county / is instance of big city
9. Toledo (wd:Q5836, matched via Municipality of Toledo), also known as Municipality of Toledo, Toledo, Castile-La Mancha, Toledo municipality, Toledo Municipality, Toledo, Spain: is instance of municipality of Spain / municipality in central Spain / municipality in central Spain / municipality in central Spain / is instance of city
10. Nijmegen (wd:Q47887, matched via Municipality of Nijmegen), also known as Gemeente Nijmegen, Municipality of Nijmegen, Nimeguen: is instance of municipality of the Netherlands / municipality in Gelderland, Netherlands / is instance of government department / is instance of government agency

[Assistant]
I'll run a simple query to list municipalities (instance of 'municipality of Spain') that have Biscay (wd:Q93366) somewhere in their administrative hierarchy (wdt:P131*). This verifies the set of municipalities I'll work on. I'll request English labels.

execute

SELECT ?mun ?munLabel WHERE {
  ?mun wdt:P31 wd:Q2074737; wdt:P131* wd:Q93366.
  ?mun rdfs:label ?munLabel FILTER(LANG(?munLabel) = "en").
} ORDER BY ?munLabel

Got 114 rows and 2 columns, showing the first 5 and last 5 rows below:
| mun                                             | munLabel                                    |
| ----------------------------------------------- | ------------------------------------------- |
| Abadiño (wd:Q744893)                            | Abadiño (lang:en)                           |
| Abanto y Ciérvana-Abanto Zierbena (wd:Q1242411) | Abanto y Ciérvana-Abanto Zierbena (lang:en) |
| Ajangiz (wd:Q1228043)                           | Ajangiz (lang:en)                           |
| Alonsotegi (wd:Q927978)                         | Alonsotegi (lang:en)                        |
| Amorebieta-Etxano (wd:Q474080)                  | Amorebieta-Etxano (lang:en)                 |
| ...                                             | ...                                         |
| Zaratamo (wd:Q1227189)                          | Zaratamo (lang:en)                          |
| Zeanuri (wd:Q169332)                            | Zeanuri (lang:en)                           |
| Zeberio (wd:Q594280)                            | Zeberio (lang:en)                           |
| Zierbena (wd:Q1542223)                          | Zierbena (lang:en)                          |
| Ziortza-Bolibar (wd:Q1247479)                   | Ziortza-Bolibar (lang:en)                   |

[Assistant]
I'll run a SPARQL query that:
- finds all items that are instance of "municipality of Spain" and have Biscay (wd:Q93366) in their administrative chain (wdt:P131*),
- obtains the most recent population statement date by MAX(pq:P585) per municipality (via a subquery),
- retrieves the population value for that most recent dated statement (or falls back to wdt:P1082 if no dated statements),
- computes the target year = recent year - 10 (when recent year is available) and looks for a population statement whose date has that year,
- returns municipality IRI, English label, recent population and date, and the 10-years-prior population and date (if present).

I'll execute the query now to get the actual results.

PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX ps: <http://www.wikidata.org/prop/statement/>
PREFIX pq: <http://www.wikidata.org/prop/qualifier/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

SELECT ?mun ?munLabel ?recentPop ?recentDate ?recentYear ?pastPop ?pastDate ?pastYear WHERE {
  ?mun wdt:P31 wd:Q2074737; wdt:P131* wd:Q93366.
  ?mun rdfs:label ?munLabel FILTER(LANG(?munLabel) = "en").

  # subquery to get the most recent population date (if any) per municipality
  OPTIONAL {
    SELECT ?mun (MAX(?date) AS ?recentDate) WHERE {
      ?mun p:P1082 ?s1 .
      ?s1 ps:P1082 ?v1 .
      ?s1 pq:P585 ?date .
    } GROUP BY ?mun
  }

  # Try to get the population value from the statement that has the most recent date
  OPTIONAL {
    ?mun p:P1082 ?stmtRecent .
    ?stmtRecent ps:P1082 ?recentPop .
    OPTIONAL { ?stmtRecent pq:P585 ?recentDate . }
    # If ?recentDate from subquery is bound, ensure this statement matches it
    FILTER( !BOUND(?recentDate) || (BOUND(?recentDate) && EXISTS { ?stmtRecent pq:P585 ?recentDate }) )
  }

  # Fallback: if we didn't get a dated recentPop, use the direct quick value wdt:P1082 (may be undated)
  OPTIONAL {
    ?mun wdt:P1082 ?directPop .
    FILTER(!BOUND(?recentPop))
    BIND(?directPop AS ?recentPop)
  }

  # if we have a recentDate, compute recentYear and targetYear (recentYear - 10)
  OPTIONAL {
    BIND(YEAR(?recentDate) AS ?recentYear)
    BIND((?recentYear - 10) AS ?targetYear)
  }

  # find a population statement whose date has year = targetYear
  OPTIONAL {
    ?mun p:P1082 ?stmtPast .
    ?stmtPast ps:P1082 ?pastPop .
    ?stmtPast pq:P585 ?pastDate .
    FILTER(BOUND(?targetYear) && YEAR(?pastDate) = ?targetYear)
    BIND(YEAR(?pastDate) AS ?pastYear)
  }
}
ORDER BY ?munLabel

[Assistant]
I'll run a refined query that explicitly projects YEAR(?recentDate) and YEAR(?pastDate) in the SELECT list so the year columns are filled when dates are present.

PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX ps: <http://www.wikidata.org/prop/statement/>
PREFIX pq: <http://www.wikidata.org/prop/qualifier/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

SELECT ?mun ?munLabel ?recentPop ?recentDate (YEAR(?recentDate) AS ?recentYear) ?pastPop ?pastDate (YEAR(?pastDate) AS ?pastYear) WHERE {
  ?mun wdt:P31 wd:Q2074737; wdt:P131* wd:Q93366.
  ?mun rdfs:label ?munLabel FILTER(LANG(?munLabel) = "en").

  OPTIONAL {
    SELECT ?mun (MAX(?date) AS ?recentDate) WHERE {
      ?mun p:P1082 ?s1 .
      ?s1 ps:P1082 ?v1 .
      ?s1 pq:P585 ?date .
    } GROUP BY ?mun
  }

  OPTIONAL {
    ?mun p:P1082 ?stmtRecent .
    ?stmtRecent ps:P1082 ?recentPop .
    OPTIONAL { ?stmtRecent pq:P585 ?recentDate . }
    FILTER( !BOUND(?recentDate) || (BOUND(?recentDate) && EXISTS { ?stmtRecent pq:P585 ?recentDate }) )
  }

  OPTIONAL {
    ?mun wdt:P1082 ?directPop .
    FILTER(!BOUND(?recentPop))
    BIND(?directPop AS ?recentPop)
  }

  OPTIONAL {
    BIND(YEAR(?recentDate) AS ?recentYear_tmp)
    BIND((?recentYear_tmp - 10) AS ?targetYear)
  }

  OPTIONAL {
    ?mun p:P1082 ?stmtPast .
    ?stmtPast ps:P1082 ?pastPop .
    ?stmtPast pq:P585 ?pastDate .
    FILTER(BOUND(?targetYear) && YEAR(?pastDate) = ?targetYear)
  }
}
ORDER BY ?munLabel

[Assistant]
I will finalize by returning the SPARQL I used and a brief summary of the results (number of municipalities and what the query returns). Then I'll stop.

answer

PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX ps: <http://www.wikidata.org/prop/statement/>
PREFIX pq: <http://www.wikidata.org/prop/qualifier/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

SELECT ?mun ?munLabel ?recentPop ?recentDate (YEAR(?recentDate) AS ?recentYear) ?pastPop ?pastDate (YEAR(?pastDate) AS ?pastYear) WHERE {
  ?mun wdt:P31 wd:Q2074737; wdt:P131* wd:Q93366.
  ?mun rdfs:label ?munLabel FILTER(LANG(?munLabel) = "en").

  OPTIONAL {
    SELECT ?mun (MAX(?date) AS ?recentDate) WHERE {
      ?mun p:P1082 ?s1 .
      ?s1 ps:P1082 ?v1 .
      ?s1 pq:P585 ?date .
    } GROUP BY ?mun
  }

  OPTIONAL {
    ?mun p:P1082 ?stmtRecent .
    ?stmtRecent ps:P1082 ?recentPop .
    OPTIONAL { ?stmtRecent pq:P585 ?recentDate . }
    FILTER( !BOUND(?recentDate) || (BOUND(?recentDate) && EXISTS { ?stmtRecent pq:P585 ?recentDate }) )
  }

  OPTIONAL {
    ?mun wdt:P1082 ?directPop .
    FILTER(!BOUND(?recentPop))
    BIND(?directPop AS ?recentPop)
  }

  OPTIONAL {
    BIND(YEAR(?recentDate) AS ?recentYear_tmp)
    BIND((?recentYear_tmp - 10) AS ?targetYear)
  }

  OPTIONAL {
    ?mun p:P1082 ?stmtPast .
    ?stmtPast ps:P1082 ?pastPop .
    ?stmtPast pq:P585 ?pastDate .
    FILTER(BOUND(?targetYear) && YEAR(?pastDate) = ?targetYear)
  }
}
ORDER BY ?munLabel

Answer:
Summary of results and query

- I used wd:Q93366 (Biscay / Bizkaia) and the class "municipality of Spain" (wd:Q2074737).
- The query returns all municipalities in Biscay (114 results in the run I executed) with these columns:
  * mun — the municipality IRI (Wikidata Q item)
  * munLabel — English label of the municipality
  * recentPop — the most recent population value (prefers a dated p:P1082 statement; falls back to wdt:P1082 if undated)
  * recentDate — the point-in-time qualifier (pq:P585) of that most recent population statement, when available
  * recentYear — YEAR(recentDate) when recentDate is present
  * pastPop — population value from a p:P1082 statement whose pq:P585 year equals (recentYear - 10), when such a statement exists
  * pastDate and pastYear — the date and its year for that 10-years-prior population, when available

- In the data I retrieved most municipalities had a most-recent population statement dated 2024. The 10-years-prior column (target year = 2014 for those) is present only for municipalities that have a population statement dated in that target year; many municipalities do not have a statement exactly 10 years earlier, so pastPop/pastDate are empty for them.

If you want, I can:
- return the full table (all 114 rows) as CSV/JSON here,
- alter the query to return the second-most-recent population statement instead of strictly the statement from exactly 10 years earlier (that may be more broadly available), or
- change the target-from-year logic (e.g., look for the population nearest to 10 years earlier instead of exact-year match).

Final SPARQL (repeated):

PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX ps: <http://www.wikidata.org/prop/statement/>
PREFIX pq: <http://www.wikidata.org/prop/qualifier/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

SELECT ?mun ?munLabel ?recentPop ?recentDate (YEAR(?recentDate) AS ?recentYear) ?pastPop ?pastDate (YEAR(?pastDate) AS ?pastYear) WHERE {
  ?mun wdt:P31 wd:Q2074737; wdt:P131* wd:Q93366.
  ?mun rdfs:label ?munLabel FILTER(LANG(?munLabel) = "en").

  OPTIONAL {
    SELECT ?mun (MAX(?date) AS ?recentDate) WHERE {
      ?mun p:P1082 ?s1 .
      ?s1 ps:P1082 ?v1 .
      ?s1 pq:P585 ?date .
    } GROUP BY ?mun
  }

  OPTIONAL {
    ?mun p:P1082 ?stmtRecent .
    ?stmtRecent ps:P1082 ?recentPop .
    OPTIONAL { ?stmtRecent pq:P585 ?recentDate . }
    FILTER( !BOUND(?recentDate) || (BOUND(?recentDate) && EXISTS { ?stmtRecent pq:P585 ?recentDate }) )
  }

  OPTIONAL {
    ?mun wdt:P1082 ?directPop .
    FILTER(!BOUND(?recentPop))
    BIND(?directPop AS ?recentPop)
  }

  OPTIONAL {
    BIND(YEAR(?recentDate) AS ?recentYear_tmp)
    BIND((?recentYear_tmp - 10) AS ?targetYear)
  }

  OPTIONAL {
    ?mun p:P1082 ?stmtPast .
    ?stmtPast ps:P1082 ?pastPop .
    ?stmtPast pq:P585 ?pastDate .
    FILTER(BOUND(?targetYear) && YEAR(?pastDate) = ?targetYear)
  }
}
ORDER BY ?munLabel

If you want the full table exported here (CSV/JSON) or a version that finds the population nearest to 10 years prior instead of an exact-year match, tell me which format or variant you prefer and I'll produce it.


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 DISTINCT ?person ?personLabel WHERE {
  ?person wdt:P734 wd:Q37069298 ; wdt:P31 wd:Q5 .
  ?person rdfs:label ?l .
  FILTER ( REGEX( ?l , "Bertha" , "i" ) ) .
  OPTIONAL {
    ?person rdfs:label ?personLabel .
    FILTER ( LANG( ?personLabel ) = "en" )
  }
}
LIMIT 100

Using entities:
- Krupp (wd:Q37069298): is instance of family name / is instance of surname / family name / family name / surname
- 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
- family name (wd:P734 as wdt), also known as clan name, last name, surname, P734: is subproperty of name / last name or family name of a person / part of full name of person / part of full name of person

Got 2 rows and 2 columns:
| person                          | personLabel               |
| ------------------------------- | ------------------------- |
| Bertha Eichhoff (wd:Q114505809) | Bertha Eichhoff (lang:en) |
| Bertha Krupp (wd:Q66505)        | Bertha Krupp (lang:en)    |

Answer:
The query returns two human items with family name wd:Q37069298 (Krupp) whose label contains "Bertha":

- wd:Q66505 — Bertha Krupp (English label: "Bertha Krupp")
- wd:Q114505809 — Bertha Eichhoff (English label: "Bertha Eichhoff")

The query returns two human items with family name wd:Q37069298 (Krupp) whose label contains "Bertha":

- wd:Q66505 — Bertha Krupp (English label: "Bertha Krupp")
- wd:Q114505809 — Bertha Eichhoff (English label: "Bertha Eichhoff")

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 DISTINCT ?person ?personLabel WHERE {
  ?person wdt:P734 wd:Q37069298 ; wdt:P31 wd:Q5 .
  ?person rdfs:label ?l .
  FILTER ( REGEX( ?l , "Bertha" , "i" ) ) .
  OPTIONAL {
    ?person rdfs:label ?personLabel .
    FILTER ( LANG( ?personLabel ) = "en" )
  }
}
LIMIT 100

Using entities:
- Krupp (wd:Q37069298): is instance of family name / is instance of surname / family name / family name / surname
- 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
- family name (wd:P734 as wdt), also known as clan name, last name, surname, P734: is subproperty of name / last name or family name of a person / part of full name of person / part of full name of person

Execution result:
Got 2 rows and 2 columns:
| person                          | personLabel               |
| ------------------------------- | ------------------------- |
| Bertha Eichhoff (wd:Q114505809) | Bertha Eichhoff (lang:en) |
| Bertha Krupp (wd:Q66505)        | Bertha Krupp (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 has the family name Krupp (the QID Q37069298) and also have "Bertha" somewhere in their label?

[Assistant]
I'll first verify the Wikidata property for "family name" (to avoid assuming a property id). I'll search for the property whose label matches "family name". Then I'll inspect the item Q37069298 to confirm it's the Krupp family-name item and to see its labels. After that I'll build and run a SPARQL query to find human items with that family name and whose label contains "Bertha". I'll start by searching for the property.

Question: family name

Top 10 property alternatives:
1. family name (wd:P734 as pr/psn/wdtn/ps/prn/p/pq/pqv/wdt/prv/psv/pqn), also known as clan name, last name, surname, P734: last name or family name of a person / part of full name of person / part of full name of person / is subproperty of name
2. infix (wd:P7377 as pr/psn/wdtn/ps/prn/p/pq/pqv/wdt/prv/psv/pqn, matched via family name affix), also known as family name affix, family name prefix, P7377: component of Dutch family name or similar of other languages, ... Note differences in capitalization and affixation (spaces)
3. family name identical to this given name (wd:P1533 as pr/psn/wdtn/ps/prn/p/pq/pqv/wdt/prv/psv/pqn, matched via corresponding family name), also known as corresponding family name, corresponding surname, family name identical to this first name, last name identical to this first name, related family name, etc.: last name that is the same as a given first name. Use on items for given names / last name that is the same as a given first name. Use on items for given names / last name that is the same as a given first name. Use on items for given names / is subproperty of different from
4. author last names (wd:P9688 as pr/psn/wdtn/ps/prn/p/pq/pqv/wdt/prv/psv/pqn, matched via last name), also known as author last name, last name, last names, surname, surnames, etc.: qualifier to provide string representation of family or ... in a bibliographic reference file (for example BibTeX) / is subproperty of family name / is subproperty of surname
5. Philippine middle name (wd:P12330 as pr/psn/wdtn/ps/prn/p/pq/pqv/wdt/prv/psv/pqn, matched via maternal family name), also known as Filipino maternal family name, Filipino maternal surname, Filipino middle name, maternal family name, maternal surname, etc.: maternal surname generally placed in the middle of this person's name / is subproperty of name
6. generational suffix (wd:P8017 as pr/psn/wdtn/ps/prn/p/pq/pqv/wdt/prv/psv/pqn, matched via family suffix), also known as age suffix, family suffix, Jr., Junior, Senior, etc.: suffix used in name
7. second family name in Spanish name (wd:P1950 as pr/psn/wdtn/ps/prn/p/pq/pqv/wdt/prv/psv/pqn, matched via second family name), also known as maternal family name in Spanish name, second family name, second Spanish name, second surname, second surname in Spanish name, etc.: second (generally maternal) family name in Spanish names (do not use for other double barrelled names) and in some French names. / second (generally maternal) family name in Spanish names (do not use for other double barrelled names) / second (generally maternal) surname in Spanish names (do not use for other double barrelled names) / is subproperty of family name / is subproperty of surname
8. surname for other gender (wd:P5278 as pr/psn/wdtn/ps/prn/p/pq/pqv/wdt/prv/psv/pqn, matched via female surname), also known as family name for other gender, female surname, gender inflection of family name, gender inflection of matronymic, gender inflection of patronymic, etc.: gender inflection of surname, patronymic or matronymic
9. birth name (wd:P1477 as pr/psn/wdtn/ps/prn/p/pq/pqv/wdt/prv/psv/pqn, matched via birthname), also known as birthname, bn, bname, born as, full birth name, etc.: full name of a person at birth, if different from their ... John Peter Doe for Joe Doe, Ann Smith for Ann Miller) / full name of a person at birth, if different from their current, generally used name / full name of a person at birth, if different from their current name / is subproperty of name
10. author given names (wd:P9687 as pr/psn/wdtn/ps/prn/p/pq/pqv/wdt/prv/psv/pqn, matched via first name), also known as author first name, author first names, first name, given name, given names, etc.: qualifier for string representation of given or secondary ... in a bibliographic reference file (for example BibTeX) / is subproperty of given name

[Assistant]
Now I'll inspect the item Q37069298 to confirm it's the Krupp family name and to see labels/statements. I will list triples with that subject.

list

wd:Q37069298

Got 168 rows and 3 columns, showing the first 10 rows below:
| subject              | property                                 | object                                         |
| -------------------- | ---------------------------------------- | ---------------------------------------------- |
| Krupp (wd:Q37069298) | instance of (wdt:P31)                    | family name (wd:Q101352)                       |
| Krupp (wd:Q37069298) | Commons category (wdt:P373)              | Krupp (surname)                                |
| Krupp (wd:Q37069298) | native label (wdt:P1705)                 | Krupp (lang:mul)                               |
| Krupp (wd:Q37069298) | different from (wdt:P1889)               | wd:Q235217                                     |
| Krupp (wd:Q37069298) | writing system (wdt:P282)                | Latin script (wd:Q8229)                        |
| Krupp (wd:Q37069298) | FactGrid item ID (wdtn:P8168)            | <https://database.factgrid.de/entity/Q1012025> |
| Krupp (wd:Q37069298) | Cologne phonetics (wdt:P3879)            | 471                                            |
| Krupp (wd:Q37069298) | Soundex (wdt:P3878)                      | K610                                           |
| Krupp (wd:Q37069298) | Geneanet family name ID (wdt:P9644)      | KRUPP                                          |
| Krupp (wd:Q37069298) | Wolfram Language entity code (wdt:P4839) | Entity["Surname", "Krupp"]                     |
| ...                  | ...                                      | ...                                            |

[Assistant]
I'll run a SPARQL query that finds human items with family name P734 = Q37069298 and whose rdfs:label contains "Bertha" (case-insensitive). The query will return the item IRIs and labels (English label if available plus the matched rdfs:label).

execute

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT DISTINCT ?person ?personLabel ?matchedLabel WHERE {
  ?person wdt:P734 wd:Q37069298 ;
          wdt:P31 wd:Q5 .
  ?person rdfs:label ?matchedLabel .
  FILTER(REGEX(?matchedLabel, "Bertha", "i")) .
  OPTIONAL { ?person rdfs:label ?personLabel . FILTER(LANG(?personLabel) = "en") }
}
ORDER BY ?person

Got 20 rows and 3 columns, showing the first 5 and last 5 rows below:
| person                          | personLabel               | matchedLabel                                  |
| ------------------------------- | ------------------------- | --------------------------------------------- |
| Bertha Eichhoff (wd:Q114505809) | Bertha Eichhoff (lang:en) | Bertha Eichhoff (lang:en)                     |
| Bertha Eichhoff (wd:Q114505809) | Bertha Eichhoff (lang:en) | Bertha Eichhoff (lang:de)                     |
| Bertha Krupp (wd:Q66505)        | Bertha Krupp (lang:en)    | Bertha Krupp von Bohlen und Halbach (lang:sv) |
| Bertha Krupp (wd:Q66505)        | Bertha Krupp (lang:en)    | Bertha Krupp von Bohlen und Halbach (lang:nb) |
| Bertha Krupp (wd:Q66505)        | Bertha Krupp (lang:en)    | Bertha Krupp von Bohlen und Halbach (lang:fi) |
| ...                             | ...                       | ...                                           |
| Bertha Krupp (wd:Q66505)        | Bertha Krupp (lang:en)    | Bertha Krupp (lang:eu)                        |
| Bertha Krupp (wd:Q66505)        | Bertha Krupp (lang:en)    | Bertha Krupp (lang:es)                        |
| Bertha Krupp (wd:Q66505)        | Bertha Krupp (lang:en)    | Bertha Krupp (lang:en)                        |
| Bertha Krupp (wd:Q66505)        | Bertha Krupp (lang:en)    | Bertha Krupp (lang:ca)                        |
| Bertha Krupp (wd:Q66505)        | Bertha Krupp (lang:en)    | Bertha Krupp (lang:ast)                       |

[Assistant]
I'll run a deduplicated query that returns distinct person IRIs and their English label (if present) for humans with family name Q37069298 and any rdfs:label containing "Bertha". This avoids multiple rows per language label.

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT DISTINCT ?person ?personLabel WHERE {
  ?person wdt:P734 wd:Q37069298 ;
          wdt:P31 wd:Q5 .
  OPTIONAL { ?person rdfs:label ?personLabel . FILTER(LANG(?personLabel) = "en") }
  FILTER(EXISTS { ?person rdfs:label ?l FILTER(REGEX(?l, "Bertha", "i")) })
}
ORDER BY ?person

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

[Assistant]
Retrying a deduplicated query with a LIMIT to avoid timeouts.

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT DISTINCT ?person ?personLabel WHERE {
  ?person wdt:P734 wd:Q37069298 ;
          wdt:P31 wd:Q5 .
  ?person rdfs:label ?l .
  FILTER(REGEX(?l, "Bertha", "i")) .
  OPTIONAL { ?person rdfs:label ?personLabel . FILTER(LANG(?personLabel) = "en") }
}
LIMIT 100

Got 2 rows and 2 columns:
| person                          | personLabel               |
| ------------------------------- | ------------------------- |
| Bertha Eichhoff (wd:Q114505809) | Bertha Eichhoff (lang:en) |
| Bertha Krupp (wd:Q66505)        | Bertha Krupp (lang:en)    |

[Assistant]
Final SPARQL (deduplicated, limited) and the answer below are based on the query results I obtained.

answer

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT DISTINCT ?person ?personLabel WHERE {
  ?person wdt:P734 wd:Q37069298 ;
          wdt:P31 wd:Q5 .
  ?person rdfs:label ?l .
  FILTER(REGEX(?l, "Bertha", "i")) .
  OPTIONAL { ?person rdfs:label ?personLabel . FILTER(LANG(?personLabel) = "en") }
}
LIMIT 100

Answer:
The query returns two human items with family name wd:Q37069298 (Krupp) whose label contains "Bertha":

- wd:Q66505 — Bertha Krupp (English label: "Bertha Krupp")
- wd:Q114505809 — Bertha Eichhoff (English label: "Bertha Eichhoff")