Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…olver.js into dev
  • Loading branch information
tokebe committed Mar 8, 2024
2 parents ce85aa5 + e375b08 commit 1925e24
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
25 changes: 16 additions & 9 deletions src/attrs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,8 @@ function buildOneQuery(
const returnFields = idReturnFields + attrReturnFields;
const scopes = getInputScopes(metadata.mapping, prefix);
debug(`inputs ${inputs}`);
const userAgent = `BTE/${process.env.NODE_ENV === 'production' ? 'prod' : 'dev'} Node/${process.version} ${
process.platform
}`;
const userAgent = `BTE/${process.env.NODE_ENV === 'production' ? 'prod' : 'dev'} Node/${process.version} ${process.platform
}`;
return axios({
method: 'post',
url: metadata.url,
Expand All @@ -136,10 +135,17 @@ function buildOneQuery(
'content-type': 'application/json',
'User-Agent': userAgent,
},
}).then((response) => getDBIDs(prefix, semanticType, response.data));
})
.then((response) => getDBIDs(prefix, semanticType, response.data))
.catch(() => undefined);
}

function buildQueries(metadata: MetaDataObject, prefix: string, inputs: string[], semanticType: string) {
function buildQueries(
metadata: MetaDataObject,
prefix: string,
inputs: string[],
semanticType: string,
): Promise<IndividualResolverOutput>[] {
if (inputs.length > MAX_BIOTHINGS_INPUT_SIZE) {
return _.chunk(inputs, MAX_BIOTHINGS_INPUT_SIZE).map((batch) =>
buildOneQuery(metadata, prefix, batch, semanticType),
Expand All @@ -153,9 +159,9 @@ function getAPIMetaData(semanticType: string) {
return APIMETA[semanticType];
}

function build(semanticType: string, curies: string[]) {
function build(semanticType: string, curies: string[]): Promise<IndividualResolverOutput>[] {
const grped = groupCuriesByPrefix(curies);
return Object.keys(grped).reduce((prev, current) => {
return Object.keys(grped).reduce((prev: Promise<IndividualResolverOutput>[], current) => {
prev = [...prev, ...buildQueries(getAPIMetaData(semanticType), current, grped[current], semanticType)];
return prev;
}, []);
Expand All @@ -177,7 +183,7 @@ function getSupportedType(category: string): string {

export async function _getAttributes(idsByType: object): Promise<any> {
debug(`Adding attributes of ${JSON.stringify(idsByType)}`);
let promises = [];
let promises: Promise<IndividualResolverOutput>[] = [];
for (const type in idsByType) {
const ids = idsByType[type];
const supportedType = getSupportedType(type);
Expand All @@ -190,9 +196,10 @@ export async function _getAttributes(idsByType: object): Promise<any> {
}
}
}
let res: any = await Promise.all(promises);
let res: IndividualResolverOutput[] = await Promise.all(promises);
let merged = {};
res.forEach((res_obj) => {
if (typeof res_obj === 'undefined') return;
merged = {
...merged,
...res_obj,
Expand Down
14 changes: 9 additions & 5 deletions src/sri.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ axiosRetry(axios, {

/** convert object of arrays into array of unique IDs */
function combineInputs(userInput: ResolverInput): string[] {
const result = Object.keys(userInput).reduce(function(r, k) {
const result = Object.keys(userInput).reduce(function (r, k) {
return r.concat(userInput[k]);
}, []);
return [...new Set(result)];
Expand All @@ -32,9 +32,9 @@ function combineInputs(userInput: ResolverInput): string[] {
async function query(api_input: string[]) {
const url = {
dev: 'https://nodenormalization-sri.renci.org/get_normalized_nodes',
ci: 'https://nodenorm.ci.transltr.io/1.3/get_normalized_nodes',
test: 'https://nodenorm.test.transltr.io/1.3/get_normalized_nodes',
prod: 'https://nodenorm.transltr.io/1.3/get_normalized_nodes',
ci: 'https://nodenorm.ci.transltr.io/get_normalized_nodes',
test: 'https://nodenorm.test.transltr.io/get_normalized_nodes',
prod: 'https://nodenorm.transltr.io/get_normalized_nodes',
}[process.env.INSTANCE_ENV ?? 'prod'];

const chunked_input = _.chunk(api_input, 1000);
Expand All @@ -44,7 +44,11 @@ async function query(api_input: string[]) {
`Node/${process.version} ${process.platform}`,
].join(' ');
const axios_queries = chunked_input.map((input) => {
return axios.post(url, { curies: input }, { headers: { 'User-Agent': userAgent } });
return axios.post(
url,
{ curies: input, conflate: true, drug_chemical_conflate: true },
{ headers: { 'User-Agent': userAgent } },
);
});
//convert res array into single object with all curies
let res = await Promise.all(axios_queries);
Expand Down

0 comments on commit 1925e24

Please sign in to comment.