app: Recherche dans les alias de termes

This commit is contained in:
Mattéo Delabre 2019-12-04 13:39:57 -05:00
parent 4681c440fd
commit 1cbc093f56
Signed by: matteo
GPG Key ID: AE3FBD02DC583ABB
3 changed files with 112 additions and 27 deletions

View File

@ -1,4 +1,4 @@
import React, {useEffect} from 'react'; import React from 'react';
import Graph from './Graph.js'; import Graph from './Graph.js';
import {types} from '../data/mock.js'; import {types} from '../data/mock.js';
import {useAsync} from '../util.js'; import {useAsync} from '../util.js';

View File

@ -13,6 +13,19 @@ const keys = Object.assign(Object.create(null), {
'down': 40, 'down': 40,
}); });
/**
* Met le nom dun terme sous forme normalisée pour la recherche approximative.
*
* Dans la forme normalisée, tous les accents sont ôtés et la casse est réduite
* en minuscules.
*
* @param name Nom à normaliser.
* @return Liste des mots du nom de terme normalisé.
*/
const normalizeName = name =>
diacritics.remove(name.toLowerCase())
.split(/\s+/g);
/** /**
* Vérifie si un terme est similaire à un préfixe saisi. * Vérifie si un terme est similaire à un préfixe saisi.
* *
@ -20,10 +33,19 @@ const keys = Object.assign(Object.create(null), {
* @param term Terme à vérifier. * @param term Terme à vérifier.
* @return Vrai si le terme est considéré comme similaire au préfixe. * @return Vrai si le terme est considéré comme similaire au préfixe.
*/ */
const termMatchesPrefix = (prefix, {name}) => const termMatchesPrefix = (prefix, {name, alias}) =>
{ {
return diacritics.remove(name.toLowerCase()) const haystack = [name].concat(alias)
.startsWith(diacritics.remove(prefix.toLowerCase())); .map(normalizeName)
.reduce((prev, next) => prev.concat(next), []);
const needle = normalizeName(prefix);
return needle.every(item =>
haystack.some(word =>
word.startsWith(item)
)
);
}; };
/** /**

View File

@ -4,7 +4,7 @@
export const types = { export const types = {
disease: 'Maladie', disease: 'Maladie',
symptom: 'Symptôme', symptom: 'Symptôme',
sign: 'Signe' sign: 'Signe',
}; };
/** /**
@ -15,112 +15,175 @@ export const terms = {
Q2840: { Q2840: {
id: 'Q2840', id: 'Q2840',
name: 'Grippe', name: 'Grippe',
alias: [],
types: [types.disease], types: [types.disease],
weight: 0.000035 weight: 0.000035,
}, },
Q154882: { Q154882: {
id: 'Q154882', id: 'Q154882',
name: 'Légionellose', name: 'Légionellose',
alias: [
'Légionnellose',
'Légionnelose',
'Légionelose',
'Maladie des légionnaires',
],
types: [types.disease], types: [types.disease],
weight: 0.000015 weight: 0.000015,
}, },
Q155098: { Q155098: {
id: 'Q155098', id: 'Q155098',
name: 'Leptospirose', name: 'Leptospirose',
alias: [],
types: [types.disease], types: [types.disease],
weight: 0.00001 weight: 0.00001,
}, },
Q326663: { Q326663: {
id: 'Q326663', id: 'Q326663',
name: 'Encéphalite à tiques', name: 'Encéphalite à tiques',
alias: [
'Encéphalite à tique',
'Encéphalites à tiques',
'Encéphalite d\'Europe centrale',
'Encéphalite verno-estivale russe',
'Méningoencéphalite à tique',
'Méningoencéphalite diphasique',
'Méningoencéphalite biondulante',
'Fièvre de lait diphasique',
'Maladie de Schneider',
'Maladie de Kumlinge',
],
types: [types.disease], types: [types.disease],
weight: 0.000001 weight: 0.000001,
}, },
Q133780: { Q133780: {
id: 'Q133780', id: 'Q133780',
name: 'Peste', name: 'Peste',
alias: [],
types: [types.disease], types: [types.disease],
weight: 0.000032 weight: 0.000032,
}, },
Q38933: { Q38933: {
id: 'Q38933', id: 'Q38933',
name: 'Fièvre', name: 'Fièvre',
types: [types.symptom] alias: [
'Pyrexie',
],
types: [types.symptom],
}, },
Q474959: { Q474959: {
id: 'Q474959', id: 'Q474959',
name: 'Myalgie', name: 'Myalgie',
types: [types.symptom] alias: [
'Douleur musculaire',
],
types: [types.symptom],
}, },
Q86: { Q86: {
id: 'Q86', id: 'Q86',
name: 'Céphalée', name: 'Céphalée',
types: [types.sign] alias: [
'Mal de tête',
],
types: [types.sign],
}, },
Q1115038: { Q1115038: {
id: 'Q1115038', id: 'Q1115038',
name: 'Rhinorrhée', name: 'Rhinorrhée',
types: [types.symptom] alias: [
'Nez qui coule',
'Écoulement nasal',
],
types: [types.symptom],
}, },
Q9690: { Q9690: {
id: 'Q9690', id: 'Q9690',
name: 'Fatigue', name: 'Fatigue',
types: [types.symptom] alias: [],
types: [types.symptom],
}, },
Q127076: { Q127076: {
id: 'Q127076', id: 'Q127076',
name: 'Vomissement', name: 'Vomissement',
types: [types.symptom, types.sign] alias: [
'Vomissements',
'Vomi',
'Vomissage',
'Vomir',
],
types: [types.symptom, types.sign],
}, },
Q178061: { Q178061: {
id: 'Q178061', id: 'Q178061',
name: 'Choc circulatoire', name: 'Choc circulatoire',
alias: [
'Insuffisance circulatoire aiguë',
],
types: [types.disease], types: [types.disease],
weight: 0.000038 weight: 0.000038,
}, },
Q35805: { Q35805: {
id: 'Q35805', id: 'Q35805',
name: 'Toux', name: 'Toux',
types: [types.symptom, types.sign] alias: [
'Tousse',
'Toussote',
],
types: [types.symptom, types.sign],
}, },
Q647099: { Q647099: {
id: 'Q647099', id: 'Q647099',
name: 'Hémoptysie', name: 'Hémoptysie',
types: [types.symptom] alias: [
'Expectoration sanglante',
],
types: [types.symptom],
}, },
Q653197: { Q653197: {
id: 'Q653197', id: 'Q653197',
name: 'Rash', name: 'Rash',
types: [types.symptom, types.sign] alias: [],
types: [types.symptom, types.sign],
}, },
Q160796: { Q160796: {
id: 'Q160796', id: 'Q160796',
name: 'Syndrome confusionnel', name: 'Syndrome confusionnel',
alias: [
'Confusion mentale',
],
types: [types.disease], types: [types.disease],
weight: 0.000004 weight: 0.000004,
}, },
Q186235: { Q186235: {
id: 'Q186235', id: 'Q186235',
name: 'Myocardite', name: 'Myocardite',
alias: [],
types: [types.disease], types: [types.disease],
weight: 0.0000075 weight: 0.0000075,
}, },
Q476921: { Q476921: {
id: 'Q476921', id: 'Q476921',
name: 'Insuffisance rénale', name: 'Insuffisance rénale',
alias: [],
types: [types.disease], types: [types.disease],
weight: 0.0000046 weight: 0.0000046,
}, },
Q281289: { Q281289: {
id: 'Q281289', id: 'Q281289',
name: 'Photophobie', name: 'Photophobie',
types: [types.sign] alias: [],
types: [types.sign],
}, },
Q159557: { Q159557: {
id: 'Q159557', id: 'Q159557',
name: 'Coma', name: 'Coma',
types: [types.sign] alias: [
} 'Perdre connaissance',
'Coma végétatif',
'Perte de connaissance',
],
types: [types.sign],
},
}; };
/** /**
@ -161,7 +224,7 @@ export const hasSymptom = [
['Q133780', 'Q35805'], ['Q133780', 'Q35805'],
['Q133780', 'Q647099'], ['Q133780', 'Q647099'],
['Q133780', 'Q653197'], ['Q133780', 'Q653197'],
['Q133780', 'Q160796'] ['Q133780', 'Q160796'],
]; ];
/** /**