-
Notifications
You must be signed in to change notification settings - Fork 0
/
getSynonyms.js
58 lines (53 loc) · 1.85 KB
/
getSynonyms.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
const config = require("./config");
const logger = require("./common/logger");
const fs = require("fs");
const path = require("path");
const {
fetch,
readNCItDiseaseTerms,
readNCItTumorSiteTerms,
} = require('./common/utils');
const getDiseaseSynonyms = async function(){
let output_file_path = path.join(__dirname, 'data_files', 'ncit_disease_synonyms.json');
const diseaseTerms = readNCItDiseaseTerms();
let synonyms = {};
const keys = Object.keys(diseaseTerms);
for(let k = 0 ; k < keys.length; k++){
const t = keys[k];
logger.info("Getting disease synonyms for term: " + t + " - "+ diseaseTerms[t]);
let d = await fetch(config.ncitAPI + diseaseTerms[t]);
const syns = [];
d.synonyms.map((syn) => {
if (syns.indexOf(syn.name) === -1 && syn.source && syn.source === "NCI") {
syns.push(syn.name);
}
});
synonyms[t.trim().toLowerCase()] = syns;
}
fs.writeFileSync(output_file_path, JSON.stringify(synonyms), err => {
if (err) return logger.error(err);
});
};
const getTumorSiteSynonyms = async function(){
let output_file_path = path.join(__dirname, 'data_files', 'ncit_tumor_site_synonyms.json');
const tumorSiteTerms = readNCItTumorSiteTerms();
let synonyms = {};
const keys = Object.keys(tumorSiteTerms);
for(let k = 0 ; k < keys.length; k++){
const t = keys[k];
logger.info("Getting tumor site synonyms for term: " + t + " - "+ tumorSiteTerms[t]);
let d = await fetch(config.ncitAPI + tumorSiteTerms[t]);
const syns = [];
d.synonyms.map((syn) => {
if (syns.indexOf(syn.name) === -1 && syn.source && syn.source === "NCI") {
syns.push(syn.name);
}
});
synonyms[t.trim().toLowerCase()] = syns;
}
fs.writeFileSync(output_file_path, JSON.stringify(synonyms), err => {
if (err) return logger.error(err);
});
};
getDiseaseSynonyms();
getTumorSiteSynonyms();