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 {types} from '../data/mock.js';
import {useAsync} from '../util.js';

View File

@ -13,6 +13,19 @@ const keys = Object.assign(Object.create(null), {
'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.
*
@ -20,10 +33,19 @@ const keys = Object.assign(Object.create(null), {
* @param term Terme à vérifier.
* @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())
.startsWith(diacritics.remove(prefix.toLowerCase()));
const haystack = [name].concat(alias)
.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 = {
disease: 'Maladie',
symptom: 'Symptôme',
sign: 'Signe'
sign: 'Signe',
};
/**
@ -15,112 +15,175 @@ export const terms = {
Q2840: {
id: 'Q2840',
name: 'Grippe',
alias: [],
types: [types.disease],
weight: 0.000035
weight: 0.000035,
},
Q154882: {
id: 'Q154882',
name: 'Légionellose',
alias: [
'Légionnellose',
'Légionnelose',
'Légionelose',
'Maladie des légionnaires',
],
types: [types.disease],
weight: 0.000015
weight: 0.000015,
},
Q155098: {
id: 'Q155098',
name: 'Leptospirose',
alias: [],
types: [types.disease],
weight: 0.00001
weight: 0.00001,
},
Q326663: {
id: 'Q326663',
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],
weight: 0.000001
weight: 0.000001,
},
Q133780: {
id: 'Q133780',
name: 'Peste',
alias: [],
types: [types.disease],
weight: 0.000032
weight: 0.000032,
},
Q38933: {
id: 'Q38933',
name: 'Fièvre',
types: [types.symptom]
alias: [
'Pyrexie',
],
types: [types.symptom],
},
Q474959: {
id: 'Q474959',
name: 'Myalgie',
types: [types.symptom]
alias: [
'Douleur musculaire',
],
types: [types.symptom],
},
Q86: {
id: 'Q86',
name: 'Céphalée',
types: [types.sign]
alias: [
'Mal de tête',
],
types: [types.sign],
},
Q1115038: {
id: 'Q1115038',
name: 'Rhinorrhée',
types: [types.symptom]
alias: [
'Nez qui coule',
'Écoulement nasal',
],
types: [types.symptom],
},
Q9690: {
id: 'Q9690',
name: 'Fatigue',
types: [types.symptom]
alias: [],
types: [types.symptom],
},
Q127076: {
id: 'Q127076',
name: 'Vomissement',
types: [types.symptom, types.sign]
alias: [
'Vomissements',
'Vomi',
'Vomissage',
'Vomir',
],
types: [types.symptom, types.sign],
},
Q178061: {
id: 'Q178061',
name: 'Choc circulatoire',
alias: [
'Insuffisance circulatoire aiguë',
],
types: [types.disease],
weight: 0.000038
weight: 0.000038,
},
Q35805: {
id: 'Q35805',
name: 'Toux',
types: [types.symptom, types.sign]
alias: [
'Tousse',
'Toussote',
],
types: [types.symptom, types.sign],
},
Q647099: {
id: 'Q647099',
name: 'Hémoptysie',
types: [types.symptom]
alias: [
'Expectoration sanglante',
],
types: [types.symptom],
},
Q653197: {
id: 'Q653197',
name: 'Rash',
types: [types.symptom, types.sign]
alias: [],
types: [types.symptom, types.sign],
},
Q160796: {
id: 'Q160796',
name: 'Syndrome confusionnel',
alias: [
'Confusion mentale',
],
types: [types.disease],
weight: 0.000004
weight: 0.000004,
},
Q186235: {
id: 'Q186235',
name: 'Myocardite',
alias: [],
types: [types.disease],
weight: 0.0000075
weight: 0.0000075,
},
Q476921: {
id: 'Q476921',
name: 'Insuffisance rénale',
alias: [],
types: [types.disease],
weight: 0.0000046
weight: 0.0000046,
},
Q281289: {
id: 'Q281289',
name: 'Photophobie',
types: [types.sign]
alias: [],
types: [types.sign],
},
Q159557: {
id: 'Q159557',
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', 'Q647099'],
['Q133780', 'Q653197'],
['Q133780', 'Q160796']
['Q133780', 'Q160796'],
];
/**