diff --git a/src/graph/kg_edge.ts b/src/graph/kg_edge.ts index b4a54281..d6422ab4 100644 --- a/src/graph/kg_edge.ts +++ b/src/graph/kg_edge.ts @@ -25,7 +25,7 @@ export default class KGEdge { }; publications: Set; qualifiers: { - [qualifier_type_id: string]: string; + [qualifier_type_id: string]: string | string[]; }; attributes: { [attribute_type_id: string]: Set | TrapiAttribute[]; @@ -105,7 +105,7 @@ export default class KGEdge { }); } - addQualifier(name: string, value: string): void { + addQualifier(name: string, value: string | string[]): void { this.qualifiers[name] = value; } diff --git a/src/inferred_mode/inferred_mode.ts b/src/inferred_mode/inferred_mode.ts index fde4f8a0..727f8c52 100644 --- a/src/inferred_mode/inferred_mode.ts +++ b/src/inferred_mode/inferred_mode.ts @@ -168,7 +168,9 @@ export default class InferredQueryHandler { return Object.fromEntries( qualifierSetObj.qualifier_set.map(({ qualifier_type_id, qualifier_value }) => [ qualifier_type_id.replace('biolink:', ''), - qualifier_value.replace('biolink:', ''), + Array.isArray(qualifier_value) + ? qualifier_value.map((string) => string.replace('biolink:', '')) + : qualifier_value.replace('biolink:', ''), ]), ) as CompactQualifiers; }); diff --git a/src/query_edge.ts b/src/query_edge.ts index 476fa527..e380b51c 100644 --- a/src/query_edge.ts +++ b/src/query_edge.ts @@ -151,14 +151,25 @@ export default class QEdge { return { qualifier_set: qualifierSetObj.qualifier_set.map(({ qualifier_type_id, qualifier_value }) => { const new_qualifier_values = qualifier_type_id.includes('predicate') - ? Array.from( - new Set( - biolink - .getDescendantPredicates(utils.removeBioLinkPrefix(qualifier_value)) - .map((item) => `biolink:${utils.removeBioLinkPrefix(item)}`), - ), - ) - : Array.from(new Set(biolink.getDescendantQualifiers(utils.removeBioLinkPrefix(qualifier_value)))); + ? Array.isArray(qualifier_value) + ? Array.from( + qualifier_value.reduce((set: Set, predicate: string) => { + biolink + .getDescendantPredicates(utils.removeBioLinkPrefix(predicate)) + .forEach((item) => set.add(`biolink:${utils.removeBioLinkPrefix(item)}`)); + return set; + }, new Set()), + ) + : Array.from( + new Set( + biolink + .getDescendantPredicates(utils.removeBioLinkPrefix(qualifier_value)) + .map((item) => `biolink:${utils.removeBioLinkPrefix(item)}`), + ), + ) + : Array.from( + new Set(biolink.getDescendantQualifiers(utils.removeBioLinkPrefix(qualifier_value as string))), + ); return { qualifier_type_id, @@ -180,7 +191,11 @@ export default class QEdge { let newQualifierType = qualifier_type_id; let newQualifierValue = qualifier_value; if (qualifier_type_id.includes('predicate')) { - newQualifierValue = `biolink:${this.getReversedPredicate(qualifier_value.replace('biolink:', ''))}`; + if (Array.isArray(qualifier_value)) { + newQualifierValue = qualifier_value.map((str) => `biolink:${str.replace('biolink', '')}`); + } else { + newQualifierValue = `biolink:${qualifier_value.replace('biolink:', '')}`; + } } if (qualifier_type_id.includes('subject')) { newQualifierType = qualifier_type_id.replace('subject', 'object'); @@ -204,7 +219,9 @@ export default class QEdge { return Object.fromEntries( qualifierSetObj.qualifier_set.map(({ qualifier_type_id, qualifier_value }) => [ qualifier_type_id.replace('biolink:', ''), - qualifier_value.replace('biolink:', ''), + Array.isArray(qualifier_value) + ? qualifier_value.map((string) => string.replace('biolink:', '')) + : qualifier_value.replace('biolink:', ''), ]), ); }); diff --git a/src/types.ts b/src/types.ts index 367271c9..5e02e4ad 100644 --- a/src/types.ts +++ b/src/types.ts @@ -93,7 +93,7 @@ export interface TrapiAttribute { export interface TrapiQualifier { qualifier_type_id: string; - qualifier_value: string; + qualifier_value: string | string[]; } export interface TrapiQualifierConstraint { diff --git a/src/utils.ts b/src/utils.ts index bd41f14d..1d999058 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -9,11 +9,12 @@ export function getUnique(input: Type[]): Type[] { return Array.from(new Set(input)); } -export function removeBioLinkPrefix(input: string): string { - if (input && input.startsWith('biolink:')) { - return input.slice(8); +export function removeBioLinkPrefix(input: T): T { + if (Array.isArray(input)) { + return input.map((str: string) => str.replace('biolink:', '')) as T; + } else { + return input.replace('biolink:', '') as T; } - return input; } // This gets the intersection of two sets.