Skip to content

Commit

Permalink
fix: ensure matching predicates in trapi responses
Browse files Browse the repository at this point in the history
  • Loading branch information
tokebe committed Jan 18, 2024
1 parent b6d0197 commit b57bf45
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 21 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
36 changes: 27 additions & 9 deletions src/transformers/trapi_transformer.ts
Original file line number Diff line number Diff line change
@@ -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() {
Expand All @@ -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,
};
});
});
Expand All @@ -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
Expand All @@ -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,
);
}
}

Expand Down
28 changes: 16 additions & 12 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}

0 comments on commit b57bf45

Please sign in to comment.