Extraction des données - Raphix93/2HS2179_militants-pour-la-paix GitHub Wiki

Création de la base de données Allegrograph

Nom de la base de données : ag132kz7jrzck2hf.allegrograph.cloud/repositories/peace/

Nom du ENDPOINT SPARQL : ag132kz7jrzck2hf.allegrograph.cloud/repositories/peace/sparql

Nom du graphe de données : https://github.com/Raphix93/2HS2179_militants-pour-la-paix/blob/main/wikidata/graph/imported-data.md

Droits d'utilisateurs

La base de données dispose de 2 droits d'utilisation distincts :

Users

Le droit "admin" dispose de droits de "superuser" comprenant des droits d'écriture de la base de données. Le droit "anonymous" dispose uniquement de droits de lecture et d'accès à la base pour consultation.


Extraction des données et import dans la base Allegrograph

Ne sont détaillé ici que les requêtes INSERT pour le peuplement de la base de données, pour plus de détail voir les SPARQLBOOKS.

Population

SPARQLBOOK : wikidata_import_population.sparqlbook

Cette requête SPARQL interroge Wikidata pour extraire tous les individus (« instance of » Q5) dont la profession est « militant pacifique » (P106=Q16323111), nés entre 1800 et 2000, puis en calcule l’année de naissance, récupère leur étiquette et leur genre. Elle insère ensuite, dans le graphe Allegrograph désigné nommé par un URI sur GitHub, un ensemble de triplets décrivant pour chacun : l’URI de l’élément, son libellé, son genre et son année de naissance.

PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX bd: <http://www.bigdata.com/rdf#>
PREFIX franzOption_defaultDatasetBehavior: <franz:rdf>

INSERT {

        ### Mon GRAPH
        GRAPH <https://github.com/Raphix93/2HS2179_militants-pour-la-paix/blob/main/wikidata/graph/imported-data.md>
        {?item  rdfs:label ?itemLabel.
           ?item wdt:P21 ?gender.
           ?item wdt:P569 ?year. 
           ?item rdf:type wd:Q5.}
}
        
        WHERE {

        ## note the service address            
        SERVICE <https://query.wikidata.org/sparql>
            {
            {?item wdt:P106 wd:Q16323111} # militants pacifiques
            
          
            ?item wdt:P31 wd:Q5;  # Any instance of a human.
                wdt:P569 ?birthDate;
                wdt:P21 ?gender.
        BIND(xsd:integer(REPLACE(str(?birthDate), "(.*)([0-9]{4})(.*)", "$2")) AS ?year)
        FILTER(?year > 1800  && ?year < 2000) 

        ## Add this clause in order to fill the variable      
        BIND ( ?itemLabel as ?itemLabel)
        SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }   
        }
        }

country of citizenship

SPARQLBOOK : wdt_import_citizenships.sparqlbook

Cette requête SPARQL parcourt le graphe Allegrograph d’importation pour en extraire jusqu’à 10 000 éléments de type humain (wd:Q5). Pour chacun, elle interroge ensuite le service Wikidata afin de récupérer sa citoyenneté (wdt:P27) et insère ces informations (?item wdt:P27 ?citizenship) dans le même graphe.

PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX franzOption_defaultDatasetBehavior: <franz:rdf>


WITH <https://github.com/Raphix93/2HS2179_militants-pour-la-paix/blob/main/wikidata/graph/imported-data.md>
INSERT {?item wdt:P27 ?citizenship.}
WHERE
    {
        ## Find the persons in the imported graph
        {SELECT ?item
        WHERE 
                {?item a wd:Q5.}
        ORDER BY ?item      
        #OFFSET 8000
        #OFFSET 16000
        #OFFSET 24000
        #OFFSET 32000
        LIMIT 10000

        }
        ## 
        SERVICE <https://query.wikidata.org/sparql>
            {
                ?item wdt:P27 ?citizenship.
            }
                
        }

Occupation

SPARQLBOOK : wdt_import_occupations.sparqlbook

Cette requête SPARQL importe de Allegrograph en lots de 10 000 sujets de type humain (wd:Q5), en sélectionnant d’abord ces items via un SELECT. Pour chaque item, elle interroge l’endpoint Wikidata afin de récupérer la propriété P106 (occupation) et son libellé anglais, puis insère dans la base de données Allegrograph les triplets ?item wdt:P106 ?occupation et ?occupation rdfs:label ?occupationLabel.

PREFIX wd:       <http://www.wikidata.org/entity/>
PREFIX wdt:      <http://www.wikidata.org/prop/direct/>
PREFIX rdf:      <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs:     <http://www.w3.org/2000/01/rdf-schema#>
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX bd:       <http://www.bigdata.com/rdf#>
PREFIX franzOption_defaultDatasetBehavior: <franz:rdf>

WITH <https://github.com/Raphix93/2HS2179_militants-pour-la-paix/blob/main/wikidata/graph/imported-data.md>
INSERT {
  ?item wdt:P106       ?occupation .
  ?occupation rdfs:label ?occupationLabel .
}
WHERE {
  ## 1) On sélectionne d’abord, DANS LE GRAPHE LOCAL (importé), les 10 000 premiers sujets de type wd:Q5
  GRAPH <https://github.com/Raphix93/2HS2179_militants-pour-la-paix/blob/main/wikidata/graph/imported-data.md> {
    {
      SELECT ?item
      WHERE {
        ?item rdf:type wd:Q5 .
      }
      ORDER BY ?item
      OFFSET 0     # → à remplacer par 0, 10000, 20000 selon l’étape
      LIMIT 10000
    }
  }

  ## 2) Pour chaque ?item ainsi obtenu, on interroge l’endpoint Wikidata pour récupérer P106
  SERVICE <https://query.wikidata.org/sparql> {
    ?item wdt:P106 ?occupation .
    SERVICE wikibase:label {
      bd:serviceParam wikibase:language "en" .
      # Cela crée automatiquement ?occupationLabel (le label anglais de ?occupation)
    }
  }
}

Fields

SPARQLBOOK : wdt_import_fields.sparqlbook

Cette requête SPARQL parcourt tout d’abord le graphe Allegrograph pour identifier tous les éléments de type « humain » (wd:Q5), puis pour chacun interroge l’endpoint Wikidata afin de récupérer la propriété P101 (domaine d’activité) et son libellé en anglais. Elle insère ensuite dans le même graphe local les triplets ?item wdt:P101 ?field et ?field rdfs:label ?fieldLabel.

PREFIX wd:       <http://www.wikidata.org/entity/>
PREFIX wdt:      <http://www.wikidata.org/prop/direct/>
PREFIX rdf:      <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs:     <http://www.w3.org/2000/01/rdf-schema#>
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX bd:       <http://www.bigdata.com/rdf#>
PREFIX franzOption_defaultDatasetBehavior: <franz:rdf>

WITH <https://github.com/Raphix93/2HS2179_militants-pour-la-paix/blob/main/wikidata/graph/imported-data.md>
INSERT {
  ?item  wdt:P101  ?field .
  ?field rdfs:label ?fieldLabel .
}
WHERE {
  ## 1) On puise dans le graphe local pour trouver toutes les personnes (Q5)
  GRAPH <https://github.com/Raphix93/2HS2179_militants-pour-la-paix/blob/main/wikidata/graph/imported-data.md> {
    ?item rdf:type wd:Q5 .
  }

  ## 2) Pour chaque ?item détecté, on interroge Wikidata pour récupérer P101 et son label
  SERVICE <https://query.wikidata.org/sparql> {
    ?item wdt:P101 ?field .
    BIND (?fieldLabel as ?fieldLabel)
    SERVICE wikibase:label {
      bd:serviceParam wikibase:language "en" .
      # cela crée automatiquement ?fieldLabel = le label anglais de ?field
    }
  }
}

Relationship to organisation

SPARQLBOOK : wdt_import_relationships_to_organisations.sparqlbook

Employer

Cette requête SPARQL extrait par lots de 10 000 personnes (wd:Q5) depuis Allegrograph, interroge Wikidata pour récupérer leur affiliation professionnelle (P108) ainsi que le libellé anglais de chaque organisation, puis insère dans le même graphe les triplets ?item wdt:P108 ?organisation et ?organisation rdfs:label ?organisationLabel. Elle enrichit ainsi le graphe en associant à chaque individu son employeur et son nom en anglais.

PREFIX franzOption_defaultDatasetBehavior: <franz:rdf>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX bd: <http://www.bigdata.com/rdf#>

WITH <https://github.com/Raphix93/2HS2179_militants-pour-la-paix/blob/main/wikidata/graph/imported-data.md>
INSERT {
    ?item wdt:P108 ?organisation .
    ?organisation rdfs:label ?organisationLabel .
}
WHERE {
    {
        SELECT ?item
        WHERE {
            ?item a wd:Q5 .
        }
        ORDER BY ?item
        OFFSET 10000         # à adapter : 0, 10000, 20000, etc.
        LIMIT 10000
    }
    
    SERVICE <https://query.wikidata.org/sparql> {
        ?item wdt:P108 ?organisation .
        SERVICE wikibase:label { 
            bd:serviceParam wikibase:language "en" .
            ?organisation rdfs:label ?organisationLabel .
        }
    }
}

Membership

Cette requête SPARQL parcourt Allegrograph par segments de 10 000 sujets de type humain (wd:Q5), interroge ensuite l’endpoint Wikidata pour récupérer pour chacun la propriété « membre de » (P463) et le libellé anglais de l’organisation. Elle insère enfin dans le même graphe les triplets ?item wdt:P463 ?organisation et ?organisation rdfs:label ?organisationLabel. De cette manière le graphe est enrichi avec l’appartenance organisationnelle de chaque individu.

PREFIX franzOption_defaultDatasetBehavior: <franz:rdf>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX bd: <http://www.bigdata.com/rdf#>

WITH <https://github.com/Raphix93/2HS2179_militants-pour-la-paix/blob/main/wikidata/graph/imported-data.md>
INSERT {
  ?item wdt:P463 ?organisation .
  ?organisation rdfs:label ?organisationLabel .
}
WHERE {
  {
    SELECT ?item
    WHERE {
      ?item a wd:Q5 .
    }
    ORDER BY ?item
    OFFSET 0   # ← À modifier pour chaque segment (0 / 10000 / 20000 / 30000)
    LIMIT 10000
  }

  SERVICE <https://query.wikidata.org/sparql> {
    ?item wdt:P463 ?organisation .
    SERVICE wikibase:label {
      bd:serviceParam wikibase:language "en" .
      ?organisation rdfs:label ?organisationLabel .
    }
  }
}

Educated at

Cette requête SPARQL sélectionne un segment de 10 000 personnes (wd:Q5) à partir d'Allegrograph, puis interroge l’endpoint Wikidata pour récupérer leur propriété « educated at » (P69) et le libellé anglais de l’établissement. Elle insère enfin dans le même graphe les triplets ?item wdt:P69 ?organisation et ?organisation rdfs:label ?organisationLabel. Ainsi, chaque individu du lot se voit associé à son institution de formation et à son nom en anglais.

PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX bd: <http://www.bigdata.com/rdf#>
PREFIX franzOption_defaultDatasetBehavior: <franz:rdf>

WITH <https://github.com/Raphix93/2HS2179_militants-pour-la-paix/blob/main/wikidata/graph/imported-data.md>
INSERT {?item wdt:P69 ?organisation.
         ?organisation rdfs:label ?organisationLabel}
WHERE
    {
        ## Find the persons in the imported graph
        {SELECT ?item
        WHERE 
                {?item a wd:Q5.}
        ORDER BY ?item      
        #OFFSET 10000
        #OFFSET 20000
        OFFSET 30000
        LIMIT 10000

        }
        ## 
        SERVICE <https://query.wikidata.org/sparql>
            {
                # educated at
                ?item wdt:P69 ?organisation.
                BIND (?organisationLabel as ?organisationLabel)
                SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } 
            }
                
        } 

Birth Place

SPARQLBOOK : wdt_import_birth_places.sparqlbook

Cette requête SPARQL enrichit le graphe Allegrograph en y ajoutant, pour chaque personne (wd:Q5) déjà importée, sa localité de naissance (P19) et le libellé anglais de ce lieu. Elle inscrit dans le graphe un triplet liant l’item à son lieu de naissance, puis décrit ce lieu avec son rdfs:label et le classe sdh:C13.

PREFIX wd:    <http://www.wikidata.org/entity/>
PREFIX wdt:   <http://www.wikidata.org/prop/direct/>
PREFIX rdfs:  <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rdf:   <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX bd:    <http://www.bigdata.com/rdf#>
PREFIX sdh:   <https://sdhss.org/ontology/core/>
PREFIX franzOption_defaultDatasetBehavior: <franz:rdf>

INSERT {
  GRAPH <https://github.com/Raphix93/2HS2179_militants-pour-la-paix/blob/main/wikidata/graph/imported-data.md> {
    ?item     wdt:P19       ?birthPlace .
    ?birthPlace
              rdfs:label    ?birthPlaceLabel ;
              rdf:type      sdh:C13 .
  }
}
WHERE {
  GRAPH <https://github.com/Raphix93/2HS2179_militants-pour-la-paix/blob/main/wikidata/graph/imported-data.md> {
    {
      SELECT ?item
      WHERE { ?item a wd:Q5. }
      ORDER BY ?item
      OFFSET 0
    }
  }
  
  SERVICE <https://query.wikidata.org/sparql> {
    ?item wdt:P19 ?birthPlace .
    # Récupération du label anglais
    SERVICE wikibase:label {
      bd:serviceParam wikibase:language "en" .
      # wikibase:label déclare automatiquement ?birthPlaceLabel
    }
  }
}
⚠️ **GitHub.com Fallback** ⚠️