Tutov1/fr: Difference between revisions

From Resistance in Belgium
No edit summary
No edit summary
 
(8 intermediate revisions by the same user not shown)
Line 2: Line 2:


<!--T:1-->
<!--T:1-->
<div style="border:2px; padding:9px; background-color:#158f68;">
<div style="border:2px ;padding:9px; background-color:#158f68;">
<span style="color:#FFFFFF;"><big>1/ Introduction to SPARQL</big></span>
<span style="color:#FFFFFF;"><big>1. Introduction to SPARQL</big></span> </div>
</div>
<br>


<!--T:2-->
<!--T:2-->
Using SPARQL is like being a detective in a vast archive collection. Instead of browsing through each document one by one, you use a query language that lets you instantly retrieve information that matches your criteria.
Using <b>SPARQL</b> is like being a detective in a vast archive collection. Instead of browsing through each document one by one, you use a language that allows you to instantly find the information matching your criteria with a single precise query.


<!--T:3-->
<!--T:3-->
In the context of ''Resistance in Belgium'', SPARQL makes it easier to access data on resistance members: place of birth, residence, official recognition statuses, or affiliation with resistance organizations.
In the context of <i>Resistance in Belgium</i>, SPARQL makes it easier to access data on resistance members: place of birth, residence, official recognition statuses, or affiliation with a resistance organization.


<!--T:4-->
<!--T:4-->
'''With SPARQL, you can:'''
With SPARQL, you can:
* Filter and cross-reference information;
* <b>Filter and cross-reference information</b>;
* Customize your searches with specific criteria;
* <b>Customize your searches</b> with specific criteria;
* Extract precise data without manually browsing thousands of records;
* <b>Extract precise data</b> without going through thousands of records manually;
* Generate visualizations to better interpret your results.
* <b>Generate visualizations</b> to better interpret your results.


<!--T:5-->
<!--T:5-->
This approach gives you valuable autonomy in analyzing the dataset. You can not only extract name lists, but also identify complex relationships, such as individuals affiliated with multiple organizations or holding various recognition statuses.
This approach gives you <b>valuable autonomy</b> when analyzing data from <i>Resistance in Belgium</i>. You can not only extract <b>lists of names</b>, but also identify <b>complex connections</b>, such as members affiliated with multiple organizations or recognized with different statuses.


<!--T:6-->
<!--T:6-->
SPARQL gives you the superpower coveted by researchers everywhere: asking ultra-specific questions and getting answers within milliseconds. Of course, like any superpower, it takes a bit of practice to master. But don’t worry—this tutorial is here to guide you and turn challenges into opportunities. Who said archival research had to be dusty?
SPARQL gives you the <b>superpower every researcher wants</b>: ask an ultra-specific question and see the results appear in milliseconds. Of course, like any superpower, it takes some practice to master. But don’t worry! This tutorial is here to guide you and turn challenges into opportunities… Who said archive research had to be dusty?


<!--T:7-->
<!--T:7-->
<span style="color:#158f68;"><b>Ready to master the force of SPARQL? Let’s go.</b></span>
<b>Ready to master the force of SPARQL? Let’s go!</b>


<!--T:8-->
<!--T:8-->
<div style="border:2px; padding:9px; background-color:#158f68;">
<div style="border:2px ;padding:9px; background-color:#158f68;">
<span style="color:#FFFFFF;"><big>2/ Strategy for Your First Queries</big></span>
<span style="color:#FFFFFF;"><big>2. Strategy for Your First Queries</big></span> </div>
</div>
<br>


<!--T:9-->
<!--T:9-->
Now that you have a general idea of what SPARQL is, here’s a strategy to help you get started with your research.
Now that you have a general idea of what SPARQL is, here’s a strategy to help you start your research.


<!--T:10-->
<!--T:10-->
There are tools that assist in writing SPARQL queries, but to gain autonomy and flexibility, it’s often more effective to start from an existing query and adapt it to your needs.
There are <b>tools to help write SPARQL queries</b>, but to gain <b>autonomy</b> and <b>flexibility</b>, it’s often more effective to start from an <b>existing query</b> and adapt it to your specific needs.


<!--T:11-->
<!--T:11-->
This approach allows you to:
To help you get started, you can:
* Save time;
* Check out our [https://data.arch.be/wiki/In-depth_search SPARQL query examples];
* Avoid common errors;
* Use <b>artificial intelligence tools</b> that can generate queries based on your needs.
* Personalize your research with precision.


<!--T:12-->
<!--T:12-->
'''To get started, you can:'''
This tutorial will guide you through the basics of <b>SPARQL</b> and help you identify the <b>key elements</b> to adapt an existing query successfully.
* Consult our examples of SPARQL queries;
* Use artificial intelligence tools capable of generating queries based on your needs.


<!--T:13-->
<!--T:13-->
This tutorial will guide you through the basics of SPARQL and teach you how to identify the key elements needed to adapt an existing query effectively.
<div style="border:2px ;padding:9px; background-color:#158f68;">
<span style="color:#FFFFFF;"><big>3. The Basics of a SPARQL Query</big></span> </div>
<br>


<!--T:14-->
<!--T:14-->
<div style="border:2px; padding:9px; background-color:#158f68;">
A SPARQL query is made up of a few essential elements. Here are the two main ones:
<span style="color:#FFFFFF;"><big>3/ The Basics of a SPARQL Query</big></span>
 
</div>
* <span style="color:#158f68;"><b>SELECT</b></span>: this clause lets you <b>choose which information to display</b> in the results. You specify here which elements you want to see.
* <span style="color:#158f68;"><b>WHERE</b></span>: this clause allows you to <b>filter the data</b> by defining precise criteria. This is where you describe the conditions the data must meet.


<!--T:15-->
<!--T:15-->
A SPARQL query is built around two essential components:
📝 <b>Simple Example</b>
 
* '''SELECT''' – defines which information to display in the results.
* '''WHERE''' – filters the data by setting specific conditions that the results must meet.


<!--T:16-->
<!--T:16-->
'''Simple Example'''
Here is a query that extracts the first and last names of people in the database.
 
Lines starting with <code>#</code> are <b>comments</b> to explain each part of the query.
<!--T:17-->
Here’s a query that retrieves the first and last names of people in the database. Lines starting with <code>#</code> are comments to help explain each part of the query.


<syntaxhighlight lang="sparql">
<syntaxhighlight lang="sparql">
SELECT ?nom ?prenom
SELECT ?lastName ?firstName
WHERE {
WHERE {
   ?personne wdt:P1 wd:Q2 ;   # Selects people
   ?person wdt:P1 wd:Q2 ;     # Selects individuals
            wdt:P3 ?nom ;   # Retrieves last name
          wdt:P3 ?lastName ; # Retrieves the last name
            wdt:P2 ?prenom . # Retrieves first name
          wdt:P2 ?firstName .# Retrieves the first name
}
}
</syntaxhighlight>
</syntaxhighlight>
<!--T:17-->
<b>Explanation of the example:</b>
<ol>
<li><code>SELECT ?lastName ?firstName</code>:<br>
Indicates that we want to display the values of the <code>?lastName</code> and <code>?firstName</code> variables in the results.</li>
<li><code>WHERE { ... }</code>:<br>
Describes the structure and conditions of the query:
<ul>
<li><code>?person wdt:P1 wd:Q2</code>: selects items that are human beings (P1 = item type, Q2 = person).</li>
<li><code>wdt:P3 ?lastName</code>: associates the last name with the variable <code>?lastName</code> (P3).</li>
<li><code>wdt:P2 ?firstName</code>: associates the first name with the variable <code>?firstName</code> (P2).</li>
</ul>
</li>
</ol>


<!--T:18-->
<!--T:18-->
'''Explanation:'''
You now know the <b>basics of all SPARQL queries</b>. You’ll be able to adapt them to your needs by easily selecting the variables to use and by adding <b>filters</b>, <b>additional columns</b>, or <b>advanced options</b>.
1. <code>SELECT ?nom ?prenom</code>: specifies that we want to display the values of the <code>?nom</code> and <code>?prenom</code> variables.
2. <code>WHERE { ... }</code>: defines the conditions the data must meet to be included in the results.


<!--T:19-->
<!--T:19-->
'''Line-by-line breakdown:'''
<div style="border:2px ;padding:9px; background-color:#158f68;">
* <code>?personne wdt:P1 wd:Q2</code>: selects items classified as human beings (P1 = item type, Q2 = person).
<span style="color:#FFFFFF;"><big>4. The Trick That Makes All the Difference</big></span> </div>
* <code>wdt:P3 ?nom</code>: retrieves the last name of the person.
<br>
* <code>wdt:P2 ?prenom</code>: retrieves the first name of the person.


<!--T:20-->
<!--T:20-->
You now know the foundation of any SPARQL query. You’ll be able to adapt them to your needs by selecting the right variables and adding filters, extra columns, or advanced options.
When writing a SPARQL query, it can be tedious to remember numeric identifiers for municipalities, recognition statuses, or resistance organizations. 
Fortunately, an <b>auto-completion feature</b> is available to simplify the process.
 
<!--T:21-->
<ul>
<li><b>Pro tip</b>: Press <b>Ctrl + Space</b> while typing a property or a value. 
This allows you to <b>search for terms in your language</b> instead of relying on numeric identifiers.</li>
</ul>
 
<!--T:22-->
<b>Example:</b><br> 
If you're searching for a municipality like <b>Anderlecht</b>, instead of memorizing its identifier (e.g. <code>wd:Q102</code>), press <b>Ctrl + Space</b> and start typing "Anderlecht" — the editor will automatically suggest the correct identifier.
 
<!--T:23-->
This method helps you <b>save time</b> and <b>avoid errors</b> when entering identifiers.
 
<!--T:24-->
<div style="border:2px ;padding:9px; background-color:#158f68;">
<span style="color:#FFFFFF;"><big>5. Displaying Labels in Your Preferred Language</big></span> </div>
<br>
 
<!--T:25-->
When querying a Wikibase dataset with SPARQL, the results may sometimes display <b>identifiers</b> (e.g. <code>Q102</code>) instead of explicit text (e.g. <code>Anderlecht</code>). To make the results more readable, you can retrieve the <b>labels</b> (i.e., names) in the language of your choice (French, Dutch, German, or English). 
Simply use <code>SERVICE wikibase:label</code> at the end of your query to display values in your preferred language.
 
<!--T:26-->
<b>How to do it?</b><br> 
Add the <code>wikibase:label</code> service to your query. Here is a simple example that retrieves people’s names along with their place of residence, with labels displayed in French:
 
<syntaxhighlight lang="sparql">
SELECT ?person ?personLabel ?residence ?residenceLabel
WHERE {
  ?person wdt:P1 wd:Q2 .              # Select human entities
  ?person wdt:P7 wd:Q102 .            # Residence (P7) = Anderlecht (Q102)
  SERVICE wikibase:label {          # Service to retrieve labels
    bd:serviceParam wikibase:language "fr" . # Language preference: French
  }
}
</syntaxhighlight>
 
<!--T:27-->
<b>Quick explanation</b> 
<ul>
<li><code>SERVICE wikibase:label</code>: activates the label retrieval service.</li>
<li><code>bd:serviceParam wikibase:language "fr"</code>: sets the label language (replace <code>"fr"</code> with <code>"en"</code>, <code>"nl"</code>, <code>"de"</code>, etc. as needed).</li>
</ul>
 
<!--T:28-->
<b>Using AUTO_LANGUAGE</b><br> 
To automatically show labels in the language set by your browser or user preferences, use <code>AUTO_LANGUAGE</code>:
 
<syntaxhighlight lang="sparql">
bd:serviceParam wikibase:language "[AUTO_LANGUAGE],fr,en".
</syntaxhighlight>
 
<!--T:29-->
<b>Tips</b> 
<ul>
<li>To automatically display labels in your browser or user’s preferred language, use: 
<code>bd:serviceParam wikibase:language "[AUTO_LANGUAGE],fr,en"</code></li>
 
<li>You can also prioritize multiple languages. 
For example, to display labels in French and fall back to English if unavailable: 
<code>bd:serviceParam wikibase:language "fr,en,[AUTO_LANGUAGE]"</code></li>
</ul>
 
<!--T:30-->
<div style="border:2px ;padding:9px; background-color:#158f68;">
<span style="color:#FFFFFF;"><big>6. Adding Additional Information</big></span> </div>
<br>
 
<!--T:31-->
To enrich your results, you can add multiple columns containing additional information, such as residence, date of birth, or other relevant details. 
To get inspired: check out the [https://data.arch.be/wiki/Special:ListProperties list of properties] or see how data is modeled using an example, like [https://data.arch.be/wiki/Item:Q6793 Andrée De Jongh].
 
<!--T:32-->
<b>Adding simple columns</b><br> 
Just include the properties that correspond to the information you want to extract.
 
<b>Example</b>: Add the residence and date of birth of individuals.
 
<syntaxhighlight lang="sparql">
SELECT ?person ?personLabel ?residenceLabel ?birthDate
WHERE {
  ?person wdt:P7 ?residence .        # P7: Residence
  ?person wdt:P67 ?birthDate .      # P67: Date of birth
 
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],fr" }
}
</syntaxhighlight>
 
<!--T:33-->
<b>Making a column optional with <code>OPTIONAL</code></b><br> 
If some information might be missing, use <code>OPTIONAL</code> to avoid limiting the results. 
Adding <code>OPTIONAL</code> lets you retrieve results even if a column is empty.
 
<b>Example</b>: Add date of birth only if the information is available.
 
<syntaxhighlight lang="sparql">
SELECT ?person ?personLabel ?residenceLabel ?birthDate
WHERE {
  ?person wdt:P7 ?residence .        # P7: Residence
 
  OPTIONAL { ?person wdt:P67 ?birthDate . }  # P67: Optional date of birth
 
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],fr" }
}
</syntaxhighlight>
 
<!--T:34-->
<b>Tip</b>: To combine multiple values into a single column (for example, to “concatenate” membership in multiple resistance organizations), use <code>CONCAT</code>. 
This allows grouping the data into a single cell while keeping one result row per person.
To explore this function and its variants, refer to the SPARQL documentation available online.
 
<!--T:35-->
<div style="border:2px ;padding:9px; background-color:#158f68;">
<span style="color:#FFFFFF;"><big>7. Limiting the Number of Results</big></span> </div>
<br>
 
<!--T:36-->
To reduce the number of results displayed (especially if you’re testing a query with many columns), add the <code><b>LIMIT</b></code> clause to your query.
 
<b>Example</b>: Show only the first 10 results.
 
<syntaxhighlight lang="sparql">
SELECT ?person ?personLabel ?birthDate
WHERE {
  ?person wdt:P67 ?birthDate .
 
  SERVICE wikibase:label {
    bd:serviceParam wikibase:language "[AUTO_LANGUAGE],fr"
  }
}
LIMIT 10
</syntaxhighlight>
 
<!--T:37-->
<div style="border:2px ;padding:9px; background-color:#158f68;">
<span style="color:#FFFFFF;"><big>8. Sorting the Results</big></span> </div>
<br>
 
<!--T:38-->
To sort results by a specific column, use the <code><b>ORDER BY</b></code> clause. 
By default, the sorting is ascending (<code><b>ASC</b></code>), but you can also specify descending order using <code><b>DESC</b></code>.
 
<b>Example</b>: Sort results by birth date in ascending order.
 
<syntaxhighlight lang="sparql">
SELECT ?person ?personLabel ?birthDate
WHERE {
  ?person wdt:P67 ?birthDate .
 
  SERVICE wikibase:label {
    bd:serviceParam wikibase:language "[AUTO_LANGUAGE],fr"
  }
}
ORDER BY ASC(?birthDate)
</syntaxhighlight>
 
<!--T:39-->
<div style="border:2px ;padding:9px; background-color:#158f68;">
<span style="color:#FFFFFF;"><big>9. Adding Filters</big></span> </div>
<br>
 
<!--T:40-->
Filters allow you to refine your results by adding specific criteria to your query.
They are useful for <b>combining multiple conditions</b> or excluding certain values.
 
<!--T:41-->
📝 <b>Simple example without filter</b>
 
To select individuals matching a basic criterion—like “residing in Anderlecht”—you can write:
 
<syntaxhighlight lang="sparql">
?person wdt:P4 wd:Q102 .  # Selects individuals residing in Anderlecht
</syntaxhighlight>
 
<!--T:42-->
<b>Using <code>FILTER</code> for specific conditions</b><br> 
If you want to narrow your results even more, use <code>FILTER</code>. 
This allows you to combine multiple conditions. 
For example: select individuals living in Anderlecht and born after January 1st, 1920 
([https://tinyurl.com/26b2wdxc Link to test the query]).
 
<syntaxhighlight lang="sparql">
SELECT ?person ?personLabel ?residenceLabel ?birthDate
WHERE {
  # Select residence and birth date of the person
  ?person wdt:P7 ?residence .        # P7: Residence
  ?person wdt:P67 ?birthDate .      # P67: Date of birth
 
  # Filter for people living in Anderlecht (wd:Q102) and born after Jan 1, 1920
  FILTER(?residence = wd:Q102 && ?birthDate >= "1920-01-01T00:00:00Z"^^xsd:dateTime)
 
  # Use the label service for readable output
  SERVICE wikibase:label {
    bd:serviceParam wikibase:language "[AUTO_LANGUAGE],fr"
  }
}
</syntaxhighlight>
 
<!--T:43-->
<b>Advanced usage</b>: 
It’s also possible to use <code>FILTER NOT EXISTS</code> for more complex exclusions. 
This allows you to filter out results that meet a specific condition. 
You can explore this functionality further in advanced SPARQL resources.
 
<!--T:44-->
<div style="border:2px ;padding:9px; background-color:#158f68;">
<span style="color:#FFFFFF;"><big>10. Visualizing Your Results</big></span> </div>
<br>
 
<!--T:45-->
To create charts from your SPARQL queries, you have two options:
 
* Use the features of the <i>Query Service</i>: visualize the data in the form of tables, maps, bar charts, and timelines. For more details, see [https://www.wikidata.org/wiki/Wikidata:SPARQL_query_service/Wikidata_Query_Help/Result_Views the Wikidata documentation].
* Export the data and use other tools: you can export your results in CSV or TSV format, and then process them with data visualization tools.
 
<!--T:46-->
<div style="border:2px ;padding:9px; background-color:#158f68;">
<span style="color:#FFFFFF;"><big>11. Federated Queries</big></span> </div>
<br>
 
<!--T:47-->
<b>Advanced feature</b>: If you want to query multiple databases at once to enrich your results, you can use <b>federated queries</b>. 
For an example, see [https://data.arch.be/wiki/In-depth_search#%3E_Enriching_data_on_resistance_members_using_external_sources_(federated_query) this sample query], which extracts information from <i>Resistance in Belgium</i> and combines it with data from external sources (e.g., Wikidata).
 
<!--T:48-->
<div style="border:2px ;padding:9px; background-color:#158f68;">
<span style="color:#FFFFFF;"><big>12. Saving and Sharing Your Queries</big></span> </div>
<br>
 
<!--T:49-->
After running a SPARQL query, you can save and share its link. 
Click the <b>“Link”</b> tab above the results to generate a <b>Tiny URL</b> (a short link) that’s easy to copy and share. 
This allows others to run the same query directly, with no extra effort.
 
<!--T:50-->
<div style="border:2px ;padding:9px; background-color:#158f68;">
<span style="color:#FFFFFF;"><big>13. Downloading the Results</big></span> </div>
<br>
 
<!--T:51-->
After executing a query, use the <b>“Download”</b> tab (located on the right above the results) to export the data in different formats: 
<b>CSV</b> (compatible with LibreOffice Calc or Excel), <b>TSV</b>, or <b>JSON</b>.
 
<!--T:52-->
<b>Best practice</b>: Save the file with a clear name that reflects your search criteria to make it easier to reuse later.
 
<!--T:53-->
<div style="border:2px ;padding:9px; background-color:#158f68;">
<span style="color:#FFFFFF;"><big>14. Additional Resources</big></span> </div>
<br>
 
<!--T:54-->
To deepen your knowledge and create more advanced queries, here are some useful resources:
 
<ul>
<li><b>List of properties</b> used to describe resistance members:<br>
[https://data.arch.be/wiki/Special:ListProperties https://data.arch.be/wiki/Special:ListProperties]</li>
 
<li><b>Example profile of an individual</b> (e.g. Andrée De Jongh):<br> 
[https://data.arch.be/wiki/Item:Q6793 https://data.arch.be/wiki/Item:Q6793]</li>
 
<li><b>Sample of nine SPARQL queries</b> organized by complexity level:<br> 
[https://data.arch.be/wiki/In-depth_search/fr https://data.arch.be/wiki/In-depth_search/fr]</li>
 
<li><b>FAQ</b> to understand the context and content of the available data:<br>
[https://data.arch.be/wiki/FAQ/en https://data.arch.be/wiki/FAQ/en]</li>
</ul>
 
<!--T:55-->
<b>External Resources</b><br> 
We also encourage you to consult external resources, such as <b>Wikidata tutorials</b>, which offer excellent introductions to SPARQL queries. 
Although these examples use the same software (Wikibase) as this project, note that the data and query structure are specific to Wikidata and do not apply directly to the content of <i>Resistance in Belgium</i>.
 
* [https://wdqs-tutorial.toolforge.org/ '''Wikidata Query Service Tutorial (interactive)''']: An interactive tutorial for beginners to explore SPARQL queries practically. <i>(Resource in English)</i>.
* [https://www.wikidata.org/wiki/Wikidata:SPARQL_query_service/A_gentle_introduction_to_the_Wikidata_Query_Service '''A gentle introduction to the Wikidata Query Service''']: A simple step-by-step guide to understand the interface and write queries.
* [https://www.wikidata.org/wiki/Wikidata:SPARQL_tutorial '''Wikidata:SPARQL Tutorial''']: A detailed and structured SPARQL guide for those who want to deepen their query writing.
* <b>AI-powered tools</b> that can assist you in writing queries.


</translate>
</translate>

Latest revision as of 14:41, 1 April 2025

1. Introduction to SPARQL


Using SPARQL is like being a detective in a vast archive collection. Instead of browsing through each document one by one, you use a language that allows you to instantly find the information matching your criteria with a single precise query.

In the context of Resistance in Belgium, SPARQL makes it easier to access data on resistance members: place of birth, residence, official recognition statuses, or affiliation with a resistance organization.

With SPARQL, you can:

  • Filter and cross-reference information;
  • Customize your searches with specific criteria;
  • Extract precise data without going through thousands of records manually;
  • Generate visualizations to better interpret your results.

This approach gives you valuable autonomy when analyzing data from Resistance in Belgium. You can not only extract lists of names, but also identify complex connections, such as members affiliated with multiple organizations or recognized with different statuses.

SPARQL gives you the superpower every researcher wants: ask an ultra-specific question and see the results appear in milliseconds. Of course, like any superpower, it takes some practice to master. But don’t worry! This tutorial is here to guide you and turn challenges into opportunities… Who said archive research had to be dusty?

Ready to master the force of SPARQL? Let’s go!

2. Strategy for Your First Queries


Now that you have a general idea of what SPARQL is, here’s a strategy to help you start your research.

There are tools to help write SPARQL queries, but to gain autonomy and flexibility, it’s often more effective to start from an existing query and adapt it to your specific needs.

To help you get started, you can:

  • Check out our SPARQL query examples;
  • Use artificial intelligence tools that can generate queries based on your needs.

This tutorial will guide you through the basics of SPARQL and help you identify the key elements to adapt an existing query successfully.

3. The Basics of a SPARQL Query


A SPARQL query is made up of a few essential elements. Here are the two main ones:

  • SELECT: this clause lets you choose which information to display in the results. You specify here which elements you want to see.
  • WHERE: this clause allows you to filter the data by defining precise criteria. This is where you describe the conditions the data must meet.

📝 Simple Example

Here is a query that extracts the first and last names of people in the database. Lines starting with # are comments to explain each part of the query.

SELECT ?lastName ?firstName
WHERE {
  ?person wdt:P1 wd:Q2 ;      # Selects individuals
          wdt:P3 ?lastName ; # Retrieves the last name
          wdt:P2 ?firstName .# Retrieves the first name
}

Explanation of the example:

  1. SELECT ?lastName ?firstName:
    Indicates that we want to display the values of the ?lastName and ?firstName variables in the results.
  2. WHERE { ... }:
    Describes the structure and conditions of the query:
    • ?person wdt:P1 wd:Q2: selects items that are human beings (P1 = item type, Q2 = person).
    • wdt:P3 ?lastName: associates the last name with the variable ?lastName (P3).
    • wdt:P2 ?firstName: associates the first name with the variable ?firstName (P2).

You now know the basics of all SPARQL queries. You’ll be able to adapt them to your needs by easily selecting the variables to use and by adding filters, additional columns, or advanced options.

4. The Trick That Makes All the Difference


When writing a SPARQL query, it can be tedious to remember numeric identifiers for municipalities, recognition statuses, or resistance organizations. Fortunately, an auto-completion feature is available to simplify the process.

  • Pro tip: Press Ctrl + Space while typing a property or a value. This allows you to search for terms in your language instead of relying on numeric identifiers.

Example:
If you're searching for a municipality like Anderlecht, instead of memorizing its identifier (e.g. wd:Q102), press Ctrl + Space and start typing "Anderlecht" — the editor will automatically suggest the correct identifier.

This method helps you save time and avoid errors when entering identifiers.

5. Displaying Labels in Your Preferred Language


When querying a Wikibase dataset with SPARQL, the results may sometimes display identifiers (e.g. Q102) instead of explicit text (e.g. Anderlecht). To make the results more readable, you can retrieve the labels (i.e., names) in the language of your choice (French, Dutch, German, or English). Simply use SERVICE wikibase:label at the end of your query to display values in your preferred language.

How to do it?
Add the wikibase:label service to your query. Here is a simple example that retrieves people’s names along with their place of residence, with labels displayed in French:

SELECT ?person ?personLabel ?residence ?residenceLabel
WHERE {
  ?person wdt:P1 wd:Q2 .              # Select human entities
  ?person wdt:P7 wd:Q102 .            # Residence (P7) = Anderlecht (Q102)
  SERVICE wikibase:label {           # Service to retrieve labels
    bd:serviceParam wikibase:language "fr" . # Language preference: French
  }
}

Quick explanation

  • SERVICE wikibase:label: activates the label retrieval service.
  • bd:serviceParam wikibase:language "fr": sets the label language (replace "fr" with "en", "nl", "de", etc. as needed).

Using AUTO_LANGUAGE
To automatically show labels in the language set by your browser or user preferences, use AUTO_LANGUAGE:

bd:serviceParam wikibase:language "[AUTO_LANGUAGE],fr,en".

Tips

  • To automatically display labels in your browser or user’s preferred language, use: bd:serviceParam wikibase:language "[AUTO_LANGUAGE],fr,en"
  • You can also prioritize multiple languages. For example, to display labels in French and fall back to English if unavailable: bd:serviceParam wikibase:language "fr,en,[AUTO_LANGUAGE]"
6. Adding Additional Information


To enrich your results, you can add multiple columns containing additional information, such as residence, date of birth, or other relevant details. To get inspired: check out the list of properties or see how data is modeled using an example, like Andrée De Jongh.

Adding simple columns
Just include the properties that correspond to the information you want to extract.

Example: Add the residence and date of birth of individuals.

SELECT ?person ?personLabel ?residenceLabel ?birthDate
WHERE {
  ?person wdt:P7 ?residence .        # P7: Residence
  ?person wdt:P67 ?birthDate .       # P67: Date of birth

  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],fr" }
}

Making a column optional with OPTIONAL
If some information might be missing, use OPTIONAL to avoid limiting the results. Adding OPTIONAL lets you retrieve results even if a column is empty.

Example: Add date of birth only if the information is available.

SELECT ?person ?personLabel ?residenceLabel ?birthDate
WHERE {
  ?person wdt:P7 ?residence .        # P7: Residence

  OPTIONAL { ?person wdt:P67 ?birthDate . }  # P67: Optional date of birth

  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],fr" }
}

Tip: To combine multiple values into a single column (for example, to “concatenate” membership in multiple resistance organizations), use CONCAT. This allows grouping the data into a single cell while keeping one result row per person. To explore this function and its variants, refer to the SPARQL documentation available online.

7. Limiting the Number of Results


To reduce the number of results displayed (especially if you’re testing a query with many columns), add the LIMIT clause to your query.

Example: Show only the first 10 results.

SELECT ?person ?personLabel ?birthDate
WHERE {
  ?person wdt:P67 ?birthDate .

  SERVICE wikibase:label {
    bd:serviceParam wikibase:language "[AUTO_LANGUAGE],fr"
  }
}
LIMIT 10
8. Sorting the Results


To sort results by a specific column, use the ORDER BY clause. By default, the sorting is ascending (ASC), but you can also specify descending order using DESC.

Example: Sort results by birth date in ascending order.

SELECT ?person ?personLabel ?birthDate
WHERE {
  ?person wdt:P67 ?birthDate .

  SERVICE wikibase:label {
    bd:serviceParam wikibase:language "[AUTO_LANGUAGE],fr"
  }
}
ORDER BY ASC(?birthDate)
9. Adding Filters


Filters allow you to refine your results by adding specific criteria to your query. They are useful for combining multiple conditions or excluding certain values.

📝 Simple example without filter

To select individuals matching a basic criterion—like “residing in Anderlecht”—you can write:

?person wdt:P4 wd:Q102 .  # Selects individuals residing in Anderlecht

Using FILTER for specific conditions
If you want to narrow your results even more, use FILTER. This allows you to combine multiple conditions. For example: select individuals living in Anderlecht and born after January 1st, 1920 (Link to test the query).

SELECT ?person ?personLabel ?residenceLabel ?birthDate
WHERE {
  # Select residence and birth date of the person
  ?person wdt:P7 ?residence .        # P7: Residence
  ?person wdt:P67 ?birthDate .       # P67: Date of birth

  # Filter for people living in Anderlecht (wd:Q102) and born after Jan 1, 1920
  FILTER(?residence = wd:Q102 && ?birthDate >= "1920-01-01T00:00:00Z"^^xsd:dateTime)

  # Use the label service for readable output
  SERVICE wikibase:label {
    bd:serviceParam wikibase:language "[AUTO_LANGUAGE],fr"
  }
}

Advanced usage: It’s also possible to use FILTER NOT EXISTS for more complex exclusions. This allows you to filter out results that meet a specific condition. You can explore this functionality further in advanced SPARQL resources.

10. Visualizing Your Results


To create charts from your SPARQL queries, you have two options:

  • Use the features of the Query Service: visualize the data in the form of tables, maps, bar charts, and timelines. For more details, see the Wikidata documentation.
  • Export the data and use other tools: you can export your results in CSV or TSV format, and then process them with data visualization tools.
11. Federated Queries


Advanced feature: If you want to query multiple databases at once to enrich your results, you can use federated queries. For an example, see this sample query, which extracts information from Resistance in Belgium and combines it with data from external sources (e.g., Wikidata).

12. Saving and Sharing Your Queries


After running a SPARQL query, you can save and share its link. Click the “Link” tab above the results to generate a Tiny URL (a short link) that’s easy to copy and share. This allows others to run the same query directly, with no extra effort.

13. Downloading the Results


After executing a query, use the “Download” tab (located on the right above the results) to export the data in different formats: CSV (compatible with LibreOffice Calc or Excel), TSV, or JSON.

Best practice: Save the file with a clear name that reflects your search criteria to make it easier to reuse later.

14. Additional Resources


To deepen your knowledge and create more advanced queries, here are some useful resources:

External Resources
We also encourage you to consult external resources, such as Wikidata tutorials, which offer excellent introductions to SPARQL queries. Although these examples use the same software (Wikibase) as this project, note that the data and query structure are specific to Wikidata and do not apply directly to the content of Resistance in Belgium.