Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue 104 #127

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion packages/conditor/data/RNSR.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/conditor/src/affAlign.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const existedInYears = (years) => (structure) => {
};

const addRnsrFromYearsInAffiliation = (years) => (affiliations, affiliation) => {
const isInAddress = isIn(depleteString(affiliation.address));
const isInAddress = isIn(depleteString(affiliation.address), affiliation.rnsr);
parmentf marked this conversation as resolved.
Show resolved Hide resolved
const conditorRnsr = RNSR.structures.structure
.filter(existedInYears(years))
.filter(isInAddress)
Expand Down
39 changes: 28 additions & 11 deletions packages/conditor/src/rnsr.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,9 @@ const hasNumero = (address, etabAssocs) => etabAssocs[0] && etabAssocs.some(
const followsNumeroLabel = (tokens, etabAssocs) => etabAssocs[0]
&& etabAssocs.some(
(etabAssoc) => {
const { labelAppauvri: label, numero } = etabAssoc;
if (tokens.includes(`${label}${numero}`)) return true;
const labelIndex = tokens.indexOf(label.toLowerCase());
const numeroIndex = tokens.indexOf(String(numero));
if (labelIndex === -1) return false;
if (numeroIndex === -1) return false;
if (numeroIndex < labelIndex) return false;
if (numeroIndex - labelIndex > 1) return false;
return true;
const { labelAppauvri: label, numero } = etabAssoc,
result = tokens.match(new RegExp(`(${label}( [\w]+)? ${numero})`, 'gm'));
parmentf marked this conversation as resolved.
Show resolved Hide resolved
return Array.isArray(result) && result.length > 0;
},
);
const hasPostalAddress = (address, structure) => (
Expand All @@ -97,6 +91,29 @@ const hasPostalAddress = (address, structure) => (
*/
const hasIntitule = (address, structure) => address.includes(structure.intituleAppauvri || '**');

/**
* Say if `target` items are in `arr`.
* `target` items should be sorted
parmentf marked this conversation as resolved.
Show resolved Hide resolved
*
* @param {arr} address
* @param {target} structure
* @returns {boolean}
* @private
*/
const contain = (arr, target) => {
if (arr.length < target.length) return false;
let indexes = target.map(x => arr.indexOf(x)),
sorted = true;
if (indexes.length === 1) return indexes[0] > -1;
for (let i = 0; i < indexes.length - 1; i++) {
if (arr[i] === -1 || arr[i+1] === -1 || arr[i] > arr[i+1]) {
sorted = false;
break;
}
}
return sorted;
}

/**
* Say if the `structure` is in `address` according to the presence of sigle.
*
Expand All @@ -105,7 +122,7 @@ const hasIntitule = (address, structure) => address.includes(structure.intituleA
* @returns {boolean}
* @private
*/
const hasSigle = (address, structure) => address.split(/[ -,]/).includes(structure.sigleAppauvri || '**');
const hasSigle = (address, structure) => contain(address.split(/[ \-,]/), structure.sigleAppauvri.split(' '));
parmentf marked this conversation as resolved.
Show resolved Hide resolved
parmentf marked this conversation as resolved.
Show resolved Hide resolved

/**
* Check that for at least one of the tutelles (`structure.etabAssoc.*.etab`):
Expand Down Expand Up @@ -159,7 +176,7 @@ const hasEtabAssocs = (structure) => {
export const hasLabelAndNumero = (address, structure) => {
if (!hasLabel(address, structure.etabAssoc)) return false;
if (!hasNumero(address, structure.etabAssoc)) return false;
const tokens = address.split(/[ -,]/);
const tokens = address.replace(/[ \-,]+/gm, ' ');
parmentf marked this conversation as resolved.
Show resolved Hide resolved
if (!followsNumeroLabel(tokens, structure.etabAssoc)) return false;
return true;
};
Expand Down
4 changes: 2 additions & 2 deletions packages/conditor/src/strings.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import unidecode from 'unidecode';
import { compose, replace, toLower } from 'ramda';

export const removeAccents = (str) => unidecode(str);
export const removeDash = replace(/-/g, ' ');
export const removeDash = replace(/\-/g, ' ');
parmentf marked this conversation as resolved.
Show resolved Hide resolved
export const removeQuote = replace(/'/g, ' ');
/**
* Deplete string from accents, upper case, dash and simple quotes.
* @param {string} str
* @returns {string}
* @private
*/
export const depleteString = compose(toLower, removeAccents, removeQuote, removeDash, String);
export const depleteString = compose(toLower, removeQuote, removeDash, removeAccents, String);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ça peut être dû à un encodage contenant un tiret (que removeDash supprime), donc pourquoi pas?