Skip to content
Snippets Groups Projects
Commit 23311b68 authored by Emmanuel Raviart's avatar Emmanuel Raviart
Browse files

Améliore le moissonneur des accords internationaux pour prendre en compte l'ensemble des accords

parent 02b42812
Branches
No related tags found
No related merge requests found
import {
Audit,
auditArray,
auditChain,
auditEmptyToNull,
auditFunction,
......@@ -27,18 +26,20 @@ type BilateralTreaty = TreatyBase & {
"Type de traité":
| "BILATERAL"
| "BILATERAL - Accord entre Etats"
| "BILATERAL - ACCORD INTERGOUVERNEMENTAL"
| "BILATERAL - Accord intergouvernemental"
| "BILATERAL - Arrangement Administratif"
| "BILATERAL - Arrangement administratif"
| "BILATERAL - Autre"
| "BILATERAL - AUTRE ACCORD"
| "BILATERAL - Autre accord"
| "BILATERAL - Procès-verbal"
"Date de fin de vigueur"?: string
"Certificat ONU"?: string
Enregistrement?: string
}
type EuropeanAgreement = TreatyBase & {
"Type de traité":
| "EUROPEEN"
| "EUROPEEN - Accord entre Etats"
| "EUROPEEN - Accord intergouvernemental"
| "EUROPEEN - Autre"
......@@ -57,8 +58,6 @@ type MultilateralTreaty = TreatyBase & {
| "MULTILATERAL - Autre accord"
"Date de fin de vigueur"?: string
"Etat des ratifications"?: string
"Certificat ONU"?: string
Enregistrement?: string
}
type Treaty = BilateralTreaty | EuropeanAgreement | MultilateralTreaty
......@@ -66,16 +65,20 @@ type Treaty = BilateralTreaty | EuropeanAgreement | MultilateralTreaty
type TreatyBase = {
Numéro: string
Titre: string
"Titre (DE)"?: string
"Titre (EN)"?: string
"Titre (SP)"?: string
"Type de traité": TreatyType
"Date d'adoption"?: string
"Entré(e) en vigueur le"?: string
"Ce traité n'est plus en vigueur."?: boolean
"Date de fin de vigueur"?: string
"Ce traité n'est plus en vigueur"?: boolean
"Signé(e) par la France, le"?: string
"Signataire(s) français"?: string
"Signé par l', le, la, les"?: string
"Lieu d'adoption ou de signature"?: string
"Ratification par la France"?: string[]
"Ratification par la France"?: string
"Entré(e) en vigueur en France"?: string
Dépositaire?: string
"Accéder au site du dépositaire"?: string
Parties?: string
......@@ -86,9 +89,13 @@ type TreatyBase = {
"Texte et annexe(s)"?: string
"Conditions d'entrée en vigueur"?: string
"Conditions de durée"?: string
"Dénonciation par la France"?: string
"Publication au JORF"?: string
"Publication autre que JORF"?: string
Rectificatif?: string
"Certificat ONU"?: string
// Enregistrement du traité à l'ONU
Enregistrement?: string
Pièces: { [id: string]: string }
Bibliographie?: string
"Contenu du dossier"?: string
......@@ -100,6 +107,10 @@ type TreatyListItem = Record<Label, string>
type TreatyType = (typeof treatyTypes)[number]
const denonciationParLaFranceRegExp =
/^Dénonciation par la France au ([0123]\d\/[01]?\d\/\d{1,4})$/
const entreeEnVigueurEnFranceRegExp =
/^Entré\(e\) en vigueur en France, le ([0123]\d\/[01]?\d\/\d{1,4})$/
const frenchDateRegExp = /^[0123]\d\/[01]?\d\/\d{1,4}$/
const labels = [
"Numéro",
......@@ -108,21 +119,25 @@ const labels = [
"Date d'adoption",
"Type d'accord",
] as const
const pieceNumberRegExp = /^TRA\d{8}\/[\dA-Za-z]+$/
const pieceRegExp = /^Pièce n° (TRA\d{8}\/[\dA-Za-z]+)$/
const pieceNumberRegExp = /^[-\/\dA-Za-z]+( [A-Z])?$/
const pieceRegExp = /^Pièce n° ([-\/\dA-Za-z]+( [A-Z])?)$/
const treatyBaseKeys = [
"Numéro",
"Titre",
"Titre (DE)",
"Titre (EN)",
"Titre (SP)",
"Type de traité",
"Date d'adoption",
"Entré(e) en vigueur le",
"Ce traité n'est plus en vigueur.",
"Date de fin de vigueur",
"Ce traité n'est plus en vigueur",
"Signé(e) par la France, le",
"Signataire(s) français",
"Signé par l', le, la, les",
"Lieu d'adoption ou de signature",
"Ratification par la France",
"Entré(e) en vigueur en France",
"Dépositaire",
"Accéder au site du dépositaire",
"Parties",
......@@ -133,9 +148,12 @@ const treatyBaseKeys = [
"Texte et annexe(s)",
"Conditions d'entrée en vigueur",
"Conditions de durée",
"Dénonciation par la France",
"Publication au JORF",
"Publication autre que JORF",
"Rectificatif",
"Certificat ONU",
"Enregistrement",
"Pièces",
"Bibliographie",
"Contenu du dossier",
......@@ -145,11 +163,15 @@ const treatyBaseKeys = [
const treatyTypes = [
"BILATERAL",
"BILATERAL - Accord entre Etats",
"BILATERAL - ACCORD INTERGOUVERNEMENTAL",
"BILATERAL - Accord intergouvernemental",
"BILATERAL - Arrangement Administratif",
"BILATERAL - Arrangement administratif",
"BILATERAL - Autre",
"BILATERAL - AUTRE ACCORD",
"BILATERAL - Autre accord",
"BILATERAL - Procès-verbal",
"EUROPEEN",
"EUROPEEN - Accord entre Etats",
"EUROPEEN - Accord intergouvernemental",
"EUROPEEN - Autre",
......@@ -243,7 +265,11 @@ async function downloadTreaties({
),
)
).filter((row) => {
if (row.length === 2 && row[0] === "" && ["", "\n"].includes(row[1])) {
if (
row.length === 2 &&
row[0] === "" &&
["", "\n", "Enregistrement du Traité à l'ONU"].includes(row[1])
) {
return false
}
if (
......@@ -298,12 +324,16 @@ async function downloadTreaties({
const keys = new Set<string>()
let lastKey: string | undefined = undefined
for (const [index, [key, value]] of rows.entries()) {
if (key === "" && value !== "Ce traité n'est plus en vigueur.") {
if (lastKey === undefined) {
errors[index] = `Continuation line without previous field`
} else if (lastKey !== "Ratification par la France") {
if (key === "") {
if (
value !== "Ce traité n'est plus en vigueur." &&
value.match(denonciationParLaFranceRegExp) === null &&
value.match(entreeEnVigueurEnFranceRegExp) === null
) {
errors[index] =
`Continuation line for unexpected field: ${lastKey}`
lastKey === undefined
? `Continuation line without previous field`
: `Continuation line for unexpected field: ${lastKey}`
}
continue
}
......@@ -322,19 +352,25 @@ async function downloadTreaties({
for (const [key, value] of rows) {
if (key === "") {
if (value === "Ce traité n'est plus en vigueur.") {
treaty["Ce traité n'est plus en vigueur."] = true
treaty["Ce traité n'est plus en vigueur"] = true
} else {
const match = value.match(denonciationParLaFranceRegExp)
if (match !== null) {
treaty["Dénonciation par la France"] = match[1]
} else {
const match = value.match(entreeEnVigueurEnFranceRegExp)
if (match !== null) {
treaty["Entré(e) en vigueur en France"] = match[1]
} else {
;(treaty[lastKey!] as string[]).push(value)
throw new Error(`Unexpected value with blank key: ${value}`)
}
}
}
} else {
lastKey = key
if (key === "Ratification par la France") {
treaty[key] = [value]
} else {
treaty[key] = value
}
}
}
return treaty
}),
auditFunction((treaty: { [key: string]: unknown }) => {
......@@ -354,22 +390,20 @@ async function downloadTreaties({
auditPartial({
Numéro: auditSetNullish(treatyId),
Titre: auditSetNullish(title),
"Titre (DE)": [auditTrimString, auditEmptyToNull],
"Titre (EN)": [auditTrimString, auditEmptyToNull],
"Titre (SP)": [auditTrimString, auditEmptyToNull],
"Type de traité": [auditOptions(treatyTypes), auditRequire],
"Date d'adoption": auditFrenchDateString,
"Entré(e) en vigueur le": auditFrenchDateString,
"Ce traité n'est plus en vigueur.": auditOptions([true]),
"Date de fin de vigueur": auditFrenchDateString,
"Ce traité n'est plus en vigueur": auditOptions([true]),
"Signé(e) par la France, le": auditFrenchDateString,
"Signataire(s) français": [auditTrimString, auditEmptyToNull],
"Signé par l', le, la, les": [auditTrimString, auditEmptyToNull],
"Lieu d'adoption ou de signature": [auditTrimString, auditEmptyToNull],
"Ratification par la France": [
auditArray(auditTrimString, auditEmptyToNull),
auditFunction((values) =>
values.filter((value: string) => value !== null),
),
auditEmptyToNull,
],
"Ratification par la France": [auditTrimString, auditEmptyToNull],
"Entré(e) en vigueur en France": auditFrenchDateString,
Dépositaire: [auditTrimString, auditEmptyToNull],
// Often but not always an URL:
"Accéder au site du dépositaire": [auditTrimString, auditEmptyToNull],
......@@ -381,25 +415,41 @@ async function downloadTreaties({
"Texte et annexe(s)": [auditTrimString, auditEmptyToNull],
"Conditions d'entrée en vigueur": [auditTrimString, auditEmptyToNull],
"Conditions de durée": [auditTrimString, auditEmptyToNull],
"Dénonciation par la France": auditFrenchDateString,
"Publication au JORF": [
auditTrimString,
auditEmptyToNull,
auditFunction((value) =>
value
.replace("Décret n° 20156448", "Décret n° 2015-448")
.replace("Décret n° 201661651", "Décret n° 2016-1651")
.replace("Décret n° 2016- 1776", "Décret n° 2016-1776")
.replace("Décret n° 201961334", "Décret n° 2019-1334")
.replace("Décret n° 20206842", "Décret n° 2020-842")
.replace("Décret n° 70--1334", "Décret n° 70-1334")
.replace("Décret n° 74-360||74_360", "Décret n° 74-360")
.replace("Décret n° 861277", "Décret n° 86-1277")
.replace("Décret n° 90-639,19900717", "Décret n° 90-639")
.replace("Décret n° 99,305", "Décret n° 99-305")
.replace(
"Décret n° a du 12/10/2020",
"Décret n° 2020-1248 du 12/10/2020",
)
.replace("Décret n° Ne pas publier", "")
.replace("Décret n° pas de publication requise", "")
.replace("Décret n° n° ", "Décret n° "),
),
auditEmptyToNull,
auditTest(
(value) => value.match(/^Décret n° \d+-\d+ /) !== null,
(value) =>
value.match(/^Décret n° \d+-\d+(\|\|\d+-\d+)?( |$)/) !== null,
"Invalid decree reference",
),
],
// Often an URL, but not always
"Publication autre que JORF": [auditTrimString, auditEmptyToNull],
Rectificatif: [auditTrimString, auditEmptyToNull],
"Certificat ONU": [auditTrimString, auditEmptyToNull],
Enregistrement: [auditTrimString, auditEmptyToNull],
Pièces: auditKeyValueDictionary(
auditTest(
(id) => id.match(pieceNumberRegExp) !== null,
......@@ -418,8 +468,6 @@ async function downloadTreaties({
BILATERAL: auditObject(
{
"Date de fin de vigueur": auditFrenchDateString,
"Certificat ONU": [auditTrimString, auditEmptyToNull],
Enregistrement: [auditTrimString, auditEmptyToNull],
},
{ ignore: treatyBaseKeys },
),
......@@ -428,8 +476,6 @@ async function downloadTreaties({
{
"Date de fin de vigueur": auditFrenchDateString,
"Etat des ratifications": [auditTrimString, auditEmptyToNull],
"Certificat ONU": [auditTrimString, auditEmptyToNull],
Enregistrement: [auditTrimString, auditEmptyToNull],
},
{ ignore: treatyBaseKeys },
),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment