Skip to content

Commit

Permalink
fix: typologie algo improve (#108)
Browse files Browse the repository at this point in the history
* fix: check deeper for process typologie algo

* fix: add some rules on matcher file

* fix: prettier and linter

* fix: refactor

* fix: linter

* fix: email multiple at
  • Loading branch information
abelkhay authored Jul 28, 2023
1 parent 953adeb commit 457e7ed
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 14 deletions.
9 changes: 8 additions & 1 deletion src/transformer/fields/contact/clean-operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,12 @@ const removeDashEmail = (field: string): CleanOperation => ({
field
});

const removeMultipleAtEmail = (field: string): CleanOperation => ({
name: 'multiple at',
selector: /@.+@/u,
field
});

const cleanOperationIfAny = (
cleanOperator: (colonne: string, codePostal?: string) => CleanOperation,
colonne?: string,
Expand Down Expand Up @@ -365,5 +371,6 @@ export const cleanOperations = (
...cleanOperationIfAny(fixUnexpectedEmailList, matching.courriel?.colonne),
...cleanOperationIfAny(fixObfuscatedAtInEmail, matching.courriel?.colonne),
...cleanOperationIfAny(fixMissingEmailExtension, matching.courriel?.colonne),
...cleanOperationIfAny(removeMissingAtInEmail, matching.courriel?.colonne)
...cleanOperationIfAny(removeMissingAtInEmail, matching.courriel?.colonne),
...cleanOperationIfAny(removeMultipleAtEmail, matching.courriel?.colonne)
];
11 changes: 11 additions & 0 deletions src/transformer/fields/contact/contact.field.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1019,4 +1019,15 @@ describe('contact field', (): void => {
})
);
});

it('should remove email if multiple At', (): void => {
const contact: Contact = processContact(Report().entry(0))(
{
[EMAIL_FIELD]: 'msap@marchaux1@orange.fr'
} as DataSource,
matching
);

expect(contact).toStrictEqual<Contact>(Contact({}));
});
});
26 changes: 13 additions & 13 deletions src/transformer/fields/typologies/name-to-typologie.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import { TypologieMatcher } from './typologies.field';
export const TYPOLOGIE_MATCHERS: TypologieMatcher[] = [
{
typologie: Typologie.MUNI,
matchers: [/mairie/iu, /commune/iu, /^ville d[eu]/iu, /hôtel de ville/iu]
matchers: [/mairie/iu, /commune/iu, /^ville d[eu]/iu, /h[oô]tel de ville/iu]
},
{
typologie: Typologie.PE,
matchers: [/p[ôo]le emploi/iu]
},
{
typologie: Typologie.BIB,
matchers: [/m[ée]diath[èe]que/iu, /biblioth[èe]que/iu]
matchers: [/m[ée]diath[èeé]que/iu, /biblioth[èeé]que/iu]
},
{
typologie: Typologie.TIERS_LIEUX,
Expand All @@ -32,14 +32,14 @@ export const TYPOLOGIE_MATCHERS: TypologieMatcher[] = [
typologie: Typologie.MDS,
matchers: [
/maison du d[ée]partement/iu,
/(?:maison|espace) départementale? des solidarités/iu,
/(?:maison|espace) départementale? de la solidarité/iu,
/(?:maison|espace) de la solidarité départementale/iu
/(?:maison|espace) d[eé]partementale? des solidarit[eé]s/iu,
/(?:maison|espace) d[eé]partementale? de la solidarit[ée]/iu,
/(?:maison|espace) de la solidarit[eé] d[eé]partementale/iu
]
},
{
typologie: Typologie.CHRS,
matchers: [/centre d'hébergement et de réinsertion sociale/iu]
matchers: [/centre d'h[eé]bergement et de r[eé]insertion sociale/iu]
},
{
typologie: Typologie.CHU,
Expand All @@ -63,7 +63,7 @@ export const TYPOLOGIE_MATCHERS: TypologieMatcher[] = [
/(?:^|\W)ASS(?:\W|$)/iu,
/(?:^|\W)ASSOC(?:\W|$)/iu,
/association/iu,
/emmaüs/iu,
/emma[üu]s/iu,
/secours populaire/iu,
/croix[\s-]Rouge/iu,
/secours catholique/iu,
Expand All @@ -78,11 +78,11 @@ export const TYPOLOGIE_MATCHERS: TypologieMatcher[] = [
},
{
typologie: Typologie.PREF,
matchers: [/sous[-\s]prefecture/iu]
matchers: [/sous[-\s]pr[ée]fecture/iu]
},
{
typologie: Typologie.CD,
matchers: [/conseil départemental/iu]
matchers: [/conseil d[eé]partemental/iu]
},
{
typologie: Typologie.CC,
Expand Down Expand Up @@ -116,7 +116,7 @@ export const TYPOLOGIE_MATCHERS: TypologieMatcher[] = [
typologie: Typologie.CCONS,
matchers: [
/chambre[\w\s']+agriculture/iu,
/chambre[\w\s']+metiers[\w\s']+artisanat/iu,
/chambre[\w\s']+m[ée]tiers[\w\s']+artisanat/iu,
/chambre[\w\s']+commerce[\w\s']+industrie/iu,
/(?:^|\W)CCI(?:\W|$)/iu
]
Expand All @@ -134,9 +134,9 @@ export const TYPOLOGIE_MATCHERS: TypologieMatcher[] = [
matchers: [
/(?:^|\W)EFS(?:\W|$)/iu,
/frances?[\s-]services?/iu,
/Fixe Bruay-sur-l'Escaut\s{2}\( Département du Nord\)/iu,
/Folschviller - Antenne de L'Hôpital/iu,
/Communauté de communes Vaison Ventoux/iu
/Fixe Bruay-sur-l'Escaut\s{2}\( D[ée]partement du Nord\)/iu,
/Folschviller - Antenne de L'H[ôo]pital/iu,
/Communaut[eé] de communes Vaison Ventoux/iu
]
},
{
Expand Down
11 changes: 11 additions & 0 deletions src/transformer/fields/typologies/typologies.field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,18 @@ const inferTypologies = (source: DataSource, matching: LieuxMediationNumeriqueMa
? Typologies([Typologie.RFS])
: TYPOLOGIE_MATCHERS.reduce(toTypologieMatchingName(source, matching), Typologies([]));

const checkingTypologieSourceValues = (source: DataSource, matching: LieuxMediationNumeriqueMatching): boolean[] | undefined =>
matching.typologie?.map(
(typo: Choice<Typologie>): boolean =>
typo.colonnes != null && source[typo.colonnes[0] ?? ''] != null && source[typo.colonnes[0] ?? ''] !== ''
);

const typologiesArePreset = (matching: LieuxMediationNumeriqueMatching): boolean =>
matching.typologie?.[0]?.cible != null && matching.typologie[0].colonnes == null && matching.typologie[0].termes == null;

export const processTypologies = (source: DataSource, matching: LieuxMediationNumeriqueMatching): Typologies =>
((checkingTypologieSourceValues(source, matching) ?? []).some((check: boolean): boolean => !check) &&
!typologiesArePreset(matching)) ||
matching.typologie?.at(0)?.cible == null
? inferTypologies(source, matching)
: Typologies(Array.from(new Set(matching.typologie.reduce(appendTypologies(source), []))));
31 changes: 31 additions & 0 deletions src/transformer/fields/typologies/typologies.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,35 @@ describe('typologies field', (): void => {

expect(typologies).toStrictEqual([Typologie.BIB]);
});

it('should process algo research in name even if there is matching', (): void => {
const matching: LieuxMediationNumeriqueMatching = {
nom: { colonne: 'name' },
typologie: [{ colonnes: ['checkboxListeTypelieu'], termes: ['5'], cible: Typologie.BIB }]
} as LieuxMediationNumeriqueMatching;

const typologies: Typologies = processTypologies({ name: 'médiathèque' }, matching);

expect(typologies).toStrictEqual([Typologie.BIB]);
});

it('should get Bib even if the typo of mediathèque is not good', (): void => {
const matching: LieuxMediationNumeriqueMatching = {
nom: { colonne: 'name' }
} as LieuxMediationNumeriqueMatching;

const typologies: Typologies = processTypologies({ name: 'médiathéque' }, matching);

expect(typologies).toStrictEqual([Typologie.BIB]);
});

it('should get Bib even if the typo of bibliothèque is not good', (): void => {
const matching: LieuxMediationNumeriqueMatching = {
nom: { colonne: 'name' }
} as LieuxMediationNumeriqueMatching;

const typologies: Typologies = processTypologies({ name: 'bibliothéque' }, matching);

expect(typologies).toStrictEqual([Typologie.BIB]);
});
});

0 comments on commit 457e7ed

Please sign in to comment.