Tutov1/fr: Difference between revisions

From Resistance in Belgium
No edit summary
No edit summary
Line 67: Line 67:


<!--T:17-->
<!--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.
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 last name
            wdt:P2 ?prenom . # Retrieves first name
          wdt:P2 ?firstName .# Retrieves first name
}
}
</syntaxhighlight>
</syntaxhighlight>
Line 80: Line 81:
<!--T:18-->
<!--T:18-->
'''Explanation:'''
'''Explanation:'''
1. <code>SELECT ?nom ?prenom</code>: specifies that we want to display the values of the <code>?nom</code> and <code>?prenom</code> variables.
1. <code>SELECT ?lastName ?firstName</code>: specifies that we want to display the values of the <code>?lastName</code> and <code>?firstName</code> variables.
2. <code>WHERE { ... }</code>: defines the conditions the data must meet to be included in the results.
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:'''
'''Line-by-line breakdown:'''
* <code>?personne wdt:P1 wd:Q2</code>: selects items classified as human beings (P1 = item type, Q2 = person).
* <code>?person wdt:P1 wd:Q2</code>: selects items classified as human beings (P1 = item type, Q2 = person).
* <code>wdt:P3 ?nom</code>: retrieves the last name of the person.
* <code>wdt:P3 ?lastName</code>: retrieves the person’s last name.
* <code>wdt:P2 ?prenom</code>: retrieves the first name of the person.
* <code>wdt:P2 ?firstName</code>: retrieves the person’s first name.


<!--T:20-->
<!--T:20-->

Revision as of 12:15, 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 query language that lets you instantly retrieve information that matches your criteria.

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.

With SPARQL, you can:

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

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.

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?

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 get started with your research.

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.

This approach allows you to:

  • Save time;
  • Avoid common errors;
  • Personalize your research with precision.

To get started, you can:

  • Consult our examples of SPARQL queries;
  • Use artificial intelligence tools capable of generating queries based on your needs.

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.

3/ The Basics of a SPARQL Query


A SPARQL query is built around two essential components:

  • SELECT – defines which information to display in the results.
  • WHERE – filters the data by setting specific conditions that the results must meet.

Simple Example

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

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

Explanation: 1. SELECT ?lastName ?firstName: specifies that we want to display the values of the ?lastName and ?firstName variables. 2. WHERE { ... }: defines the conditions the data must meet to be included in the results.

Line-by-line breakdown:

  • ?person wdt:P1 wd:Q2: selects items classified as human beings (P1 = item type, Q2 = person).
  • wdt:P3 ?lastName: retrieves the person’s last name.
  • wdt:P2 ?firstName: retrieves the person’s first name.

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.