diff --git a/package.json b/package.json index f9864e1..d0e8bb5 100644 --- a/package.json +++ b/package.json @@ -58,6 +58,7 @@ "typescript": "^5.2.2" }, "dependencies": { + "@biothings-explorer/utils": "workspace:../utils", "@commitlint/cli": "^17.8.1", "@commitlint/config-conventional": "^11.0.0", "async": "^3.2.4", diff --git a/src/transformers/trapi_transformer.ts b/src/transformers/trapi_transformer.ts index 8abdda8..0eb5dee 100644 --- a/src/transformers/trapi_transformer.ts +++ b/src/transformers/trapi_transformer.ts @@ -1,6 +1,7 @@ import BaseTransformer from "./transformer"; import { Record } from "../record"; import { JSONDoc } from "../json_transform/types"; +import { removeBioLinkPrefix } from "@biothings-explorer/utils"; export default class TRAPITransformer extends BaseTransformer { _getUniqueEdges() { @@ -19,18 +20,23 @@ export default class TRAPITransformer extends BaseTransformer { ? this.data.response.message.knowledge_graph.edges[edgeID] : undefined; const edgeHasSupportGraph = edge.attributes.some(attribute => { - if (attribute.attribute_type_id === "biolink:support_graphs" && attribute.value?.length) { + if ( + attribute.attribute_type_id === "biolink:support_graphs" && + attribute.value?.length + ) { return true; } }); if (edgeHasSupportGraph || !edgeID) return; edges[edgeID] = { subject: - (this.data.response as JSONDoc).message.knowledge_graph.edges[edgeID].subject ?? - result.node_bindings.n0[0].id, + (this.data.response as JSONDoc).message.knowledge_graph.edges[ + edgeID + ].subject ?? result.node_bindings.n0[0].id, object: - (this.data.response as JSONDoc).message.knowledge_graph.edges[edgeID].object ?? - result.node_bindings.n1[0].id, + (this.data.response as JSONDoc).message.knowledge_graph.edges[ + edgeID + ].object ?? result.node_bindings.n1[0].id, }; }); }); @@ -51,8 +57,11 @@ export default class TRAPITransformer extends BaseTransformer { } _transformIndividualEdge(edge, edgeBinding) { - let frozenRecord = { - subject: { ...this._getSubject(edgeBinding.subject), apiLabel: undefined }, + const frozenRecord = { + subject: { + ...this._getSubject(edgeBinding.subject), + apiLabel: undefined, + }, object: { original: edgeBinding.object, apiLabel: undefined, // could get from API @@ -71,8 +80,17 @@ export default class TRAPITransformer extends BaseTransformer { trapi_sources: edge.sources, }, }; - if (frozenRecord.subject.original) { - return new Record(frozenRecord, this.config, this.edge.association, this.edge.reasoner_edge); + const hasOriginal = !!frozenRecord.subject.original; + const predicateMatches = + removeBioLinkPrefix(this.edge.association.predicate) == + removeBioLinkPrefix(edge.predicate); + if (hasOriginal && predicateMatches) { + return new Record( + frozenRecord, + this.config, + this.edge.association, + this.edge.reasoner_edge, + ); } } diff --git a/tsconfig.json b/tsconfig.json index b19c056..304a67a 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,14 +1,18 @@ { - "extends": "../../tsconfig.base.json", - "compilerOptions": { - "outDir": "./built", - "rootDir": "./src" - }, - "include": [ - "./src/**/*" - ], - "exclude": [ - "node_modules", - "__tests__/" - ] + "$schema": "http://json.schemastore.org/tsconfig", + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "outDir": "./built", + "rootDir": "./src", + "paths": { + "@biothings-explorer/utils": ["../utils"] + } + }, + "include": ["./src/**/*"], + "exclude": ["node_modules", "__tests__/"], + "references": [ + { + "path": "../utils" + } + ] }