Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TRAPI 1.4 feature merge #82

Merged
merged 11 commits into from
May 22, 2023
12 changes: 10 additions & 2 deletions src/filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,20 @@ export const ft = (ops: SmartAPIKGOperationObject[], criteria: FilterCriteria) =
return filters[field].has(rec.association["x-translator"][field]) ? true : false;
} else if (field === "qualifiers") {
// return true;
if (rec.tags?.includes?.("bte-trapi") || criteria[field] === undefined || criteria[field].length < 1) {
if (criteria[field] === undefined || criteria[field].length < 1) {
return true;
}
return [...filters[field]].some(qualifierConstraintSet => {
return Object.entries(qualifierConstraintSet).every(([qualifierType, qualifierValue]) => {
return rec.association[field] && rec.association[field][qualifierType] === qualifierValue;
if (!rec.association[field]) return false;
const qualifierValueArray = Array.isArray(qualifierValue) ? qualifierValue : [qualifierValue];
const associationValueArray = Array.isArray(rec.association[field][qualifierType])
? rec.association[field][qualifierType]
: [rec.association[field][qualifierType]];

return qualifierValueArray.some(value => {
return associationValueArray.includes(value);
});
});
});
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,10 @@ export default class AsyncOperationsBuilderWithReasoner extends AsyncOperationsB
association: {
input_type: this.removeBioLinkPrefix(sbj),
output_type: this.removeBioLinkPrefix(obj),
predicate: this.removeBioLinkPrefix(pred),
predicate: this.removeBioLinkPrefix(typeof(pred) === "string" ? pred : pred.predicate),
api_name: metadata.title,
smartapi: metadata.smartapi,
qualifiers: (typeof(pred) === "string" || !pred.qualifiers) ? undefined : Object.fromEntries(pred.qualifiers.map((q: any) => [this.removeBioLinkPrefix(q.qualifier_type_id), q.applicable_values.map(this.removeBioLinkPrefix)])),
"x-translator": metadata["x-translator"],
},
tags: [...metadata.tags, ...["bte-trapi"]],
Expand Down
28 changes: 22 additions & 6 deletions src/operations_builder/sync_builder_factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,34 @@ export const syncBuilderFactory = (
options: BuilderOptions,
includeReasoner: boolean,
smartapi_path: string,
predicates_path: string
predicates_path: string,
): SmartAPIKGOperationObject[] => {
let builder;
if (includeReasoner === true) {
builder = new SyncOperationsBuilderWithReasoner(
options,
smartapi_path,
predicates_path
);
builder = new SyncOperationsBuilderWithReasoner(options, smartapi_path, predicates_path);
} else {
builder = new SyncOperationsBuilder(options, smartapi_path);
}
const ops = builder.build();

const primaryKnowledgeAPIs = new Set();
options.apiList?.include.forEach(api => {
if (api.primarySource) {
if (api.id) primaryKnowledgeAPIs.add(api.id);
if (api.infores) primaryKnowledgeAPIs.add(api.infores);
}
});
options.apiList?.exclude.forEach(api => {
if (api.primarySource) {
if (api.id) primaryKnowledgeAPIs.add(api.id);
if (api.infores) primaryKnowledgeAPIs.add(api.infores);
}
});
ops.map(op => {
const apiIsPrimaryKnowledgeSource =
primaryKnowledgeAPIs.has(op.association.smartapi.id) ||
primaryKnowledgeAPIs.has(op.association["x-translator"].infores);
op.association.apiIsPrimaryKnowledgeSource = apiIsPrimaryKnowledgeSource ? true : false;
});
return ops;
};
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@ export default class SyncOperationsBuilderWithReasoner extends BaseOperationsBui
input_id: metadata?.nodes?.[sbj]?.id_prefixes,
output_type: this.removeBioLinkPrefix(obj),
output_id: metadata?.nodes?.[obj]?.id_prefixes,
predicate: this.removeBioLinkPrefix(pred),
predicate: this.removeBioLinkPrefix(typeof(pred) === "string" ? pred : pred.predicate),
api_name: metadata.association.api_name,
smartapi: metadata.association.smartapi,
qualifiers: (typeof(pred) === "string" || !pred.qualifiers) ? undefined : Object.fromEntries(pred.qualifiers.map((q: any) => [this.removeBioLinkPrefix(q.qualifier_type_id), q.applicable_values.map(this.removeBioLinkPrefix)])),
"x-translator": metadata.association["x-translator"],
"x-trapi": metadata.association["x-trapi"],
},
Expand Down Expand Up @@ -78,7 +79,7 @@ export default class SyncOperationsBuilderWithReasoner extends BaseOperationsBui
const includeInfoRes = this._options.apiList.include.find(api => api.infores === op.association?.["x-translator"]?.infores && api.infores !== undefined)
const excludeSmartAPI = this._options.apiList.exclude.find(api => api.id === op.association.smartapi.id && api.id !== undefined);
const excludeInfoRes = this._options.apiList.exclude.find(api => api.infores === op.association?.["x-translator"]?.infores && api.infores !== undefined)

let willBeIncluded;
let apiValue;
if (excludeSmartAPI) {
Expand Down
7 changes: 4 additions & 3 deletions src/parser/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export interface XTranslatorObject {
component: string;
team: string[];
"infores"?: string;
infores?: string;
}

interface SmartAIPInfoObject {
Expand Down Expand Up @@ -111,7 +111,7 @@ export interface XBTEKGSOperationObject {
inputs: XBTEKGSOperationBioEntityObject[];
outputs: XBTEKGSOperationBioEntityObject[];
predicate: string;
qualifiers?: { [qualifierType: string]: string; };
qualifiers?: { [qualifierType: string]: string };
source?: string;
parameters?: XBTEParametersObject;
requestBody?: any;
Expand Down Expand Up @@ -157,11 +157,12 @@ interface KGAssociationObject {
source?: string;
api_name?: string;
component?: string;
apiIsPrimaryKnowledgeSource?: boolean;
smartapi?: SmartAPIRegistryRecordObject;
"x-translator"?: any;
"x-trapi"?: XTRAPIObject;
qualifiers?: {
[qualifierType: string]: string;
[qualifierType: string]: string | string[];
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export interface SmartAPIQueryResult {
}

export interface apiListItem {
primarySource?: boolean;
id?: string;
infores?: string;
name: string;
Expand Down Expand Up @@ -58,7 +59,7 @@ interface PredicatesNode {
}

interface ReasonerSubjectAndPredicate {
[propName: string]: string[];
[propName: string]: (string | any)[];
}

export interface ReasonerPredicatesResponse {
Expand Down