From 079842399fb2d68cb67ff345f71d0bd46ede1fee Mon Sep 17 00:00:00 2001 From: NeuralFlux <40491005+NeuralFlux@users.noreply.github.com> Date: Thu, 15 Aug 2024 17:06:15 -0400 Subject: [PATCH] fix: update test module imports, function arguments, hashes, and scores --- __test__/integration/KnowledgeGraph.test.ts | 2 +- __test__/integration/QueryEdge.test.ts | 1 - __test__/integration/graph/graph.test.ts | 66 ++++++++++----------- __test__/unittest/inferred_mode.test.ts | 5 +- src/index.ts | 1 + 5 files changed, 38 insertions(+), 37 deletions(-) diff --git a/__test__/integration/KnowledgeGraph.test.ts b/__test__/integration/KnowledgeGraph.test.ts index c993c583..18c99a90 100644 --- a/__test__/integration/KnowledgeGraph.test.ts +++ b/__test__/integration/KnowledgeGraph.test.ts @@ -1,7 +1,7 @@ import KGEdge from '../../src/graph/kg_edge'; import KGNode from '../../src/graph/kg_node'; import KnowledgeGraph from '../../src/graph/knowledge_graph'; -import { TrapiAttribute } from '../../src/types'; +import { TrapiAttribute } from '@biothings-explorer/types'; describe('Testing KnowledgeGraph Module', () => { const nodeInput = new KGNode('PUBCHEM.COMPOUND:2662-n0', { diff --git a/__test__/integration/QueryEdge.test.ts b/__test__/integration/QueryEdge.test.ts index ff2c3195..b195f01e 100644 --- a/__test__/integration/QueryEdge.test.ts +++ b/__test__/integration/QueryEdge.test.ts @@ -143,7 +143,6 @@ describe('Testing QueryEdge Module', () => { expect(res).toContain('contributes_to'); expect(res).toContain('causes'); expect(res).toContain('ameliorates'); - expect(res).toContain('treats'); }); test('Predicates not in biolink model should return itself', () => { diff --git a/__test__/integration/graph/graph.test.ts b/__test__/integration/graph/graph.test.ts index fcdb2a4c..0d650621 100644 --- a/__test__/integration/graph/graph.test.ts +++ b/__test__/integration/graph/graph.test.ts @@ -109,11 +109,11 @@ describe('Test graph class', () => { expect(g.nodes['inputPrimaryCurie'].qNodeID).toEqual('qg1'); expect(Array.from(g.nodes['inputPrimaryCurie'].targetNodes)).toEqual(['outputPrimaryCurie']); expect(Array.from(g.nodes['inputPrimaryCurie'].targetQNodeIDs)).toEqual(['qg2']); - expect(g.edges).toHaveProperty('95fe2a8089c0d79ea093b97c5991f7ba'); - expect(Array.from(g.edges['95fe2a8089c0d79ea093b97c5991f7ba'].apis)).toEqual(['API1']); - expect(g.edges['95fe2a8089c0d79ea093b97c5991f7ba'].sources).toHaveProperty('source1'); - expect(Array.from(g.edges['95fe2a8089c0d79ea093b97c5991f7ba'].publications)).toEqual(['PMID:1', 'PMID:2']); - expect(g.edges['95fe2a8089c0d79ea093b97c5991f7ba'].attributes).toHaveProperty('relation', new Set(['relation1'])); + expect(g.edges).toHaveProperty('2c826c3663b91f65a1cba70f06c7fc65'); + expect(Array.from(g.edges['2c826c3663b91f65a1cba70f06c7fc65'].apis)).toEqual(['API1']); + expect(g.edges['2c826c3663b91f65a1cba70f06c7fc65'].sources).toHaveProperty('source1'); + expect(Array.from(g.edges['2c826c3663b91f65a1cba70f06c7fc65'].publications)).toEqual(['PMID:1', 'PMID:2']); + expect(g.edges['2c826c3663b91f65a1cba70f06c7fc65'].attributes).toHaveProperty('relation', new Set(['relation1'])); }); test('Multiple query results are correctly updated for two edges having same input, predicate and output', () => { @@ -130,17 +130,17 @@ describe('Test graph class', () => { expect(Array.from(g.nodes['inputPrimaryCurie'].targetNodes)).toEqual(['outputPrimaryCurie']); expect(Array.from(g.nodes['inputPrimaryCurie'].targetQNodeIDs)).toEqual(['qg2']); - expect(g.edges).toHaveProperty('95fe2a8089c0d79ea093b97c5991f7ba'); - expect(Array.from(g.edges['95fe2a8089c0d79ea093b97c5991f7ba'].apis)).toEqual(['API1']); - expect(g.edges['95fe2a8089c0d79ea093b97c5991f7ba'].sources).toHaveProperty('source1'); - expect(Array.from(g.edges['95fe2a8089c0d79ea093b97c5991f7ba'].publications)).toEqual(['PMID:1', 'PMID:2']); - expect(g.edges['95fe2a8089c0d79ea093b97c5991f7ba'].attributes).toHaveProperty('relation', new Set(['relation1'])); + expect(g.edges).toHaveProperty('2c826c3663b91f65a1cba70f06c7fc65'); + expect(Array.from(g.edges['2c826c3663b91f65a1cba70f06c7fc65'].apis)).toEqual(['API1']); + expect(g.edges['2c826c3663b91f65a1cba70f06c7fc65'].sources).toHaveProperty('source1'); + expect(Array.from(g.edges['2c826c3663b91f65a1cba70f06c7fc65'].publications)).toEqual(['PMID:1', 'PMID:2']); + expect(g.edges['2c826c3663b91f65a1cba70f06c7fc65'].attributes).toHaveProperty('relation', new Set(['relation1'])); - expect(g.edges).toHaveProperty('9d334cb674d5671364c45cc8403184c6'); - expect(Array.from(g.edges['9d334cb674d5671364c45cc8403184c6'].apis)).toEqual(['API2']); - expect(g.edges['9d334cb674d5671364c45cc8403184c6'].sources).toHaveProperty('source2'); - expect(Array.from(g.edges['9d334cb674d5671364c45cc8403184c6'].publications)).toEqual(['PMC:1', 'PMC:2']); - expect(g.edges['9d334cb674d5671364c45cc8403184c6'].attributes).toHaveProperty('relation', new Set(['relation2'])); + expect(g.edges).toHaveProperty('827c366e2e3088b3f4a90dd88a524f15'); + expect(Array.from(g.edges['827c366e2e3088b3f4a90dd88a524f15'].apis)).toEqual(['API2']); + expect(g.edges['827c366e2e3088b3f4a90dd88a524f15'].sources).toHaveProperty('source2'); + expect(Array.from(g.edges['827c366e2e3088b3f4a90dd88a524f15'].publications)).toEqual(['PMC:1', 'PMC:2']); + expect(g.edges['827c366e2e3088b3f4a90dd88a524f15'].attributes).toHaveProperty('relation', new Set(['relation2'])); }); test('Multiple query results for different edges are correctly updated', () => { @@ -157,37 +157,37 @@ describe('Test graph class', () => { expect(Array.from(g.nodes['inputPrimaryCurie'].targetNodes)).toEqual(['outputPrimaryCurie']); expect(Array.from(g.nodes['inputPrimaryCurie'].targetQNodeIDs)).toEqual(['qg2']); - expect(g.edges).toHaveProperty('95fe2a8089c0d79ea093b97c5991f7ba'); - expect(Array.from(g.edges['95fe2a8089c0d79ea093b97c5991f7ba'].apis)).toEqual(['API1']); - expect(g.edges['95fe2a8089c0d79ea093b97c5991f7ba'].sources).toHaveProperty('source1'); - expect(Array.from(g.edges['95fe2a8089c0d79ea093b97c5991f7ba'].publications)).toEqual(['PMID:1', 'PMID:2']); - expect(g.edges['95fe2a8089c0d79ea093b97c5991f7ba'].attributes).toHaveProperty('relation', new Set(['relation1'])); + expect(g.edges).toHaveProperty('2c826c3663b91f65a1cba70f06c7fc65'); + expect(Array.from(g.edges['2c826c3663b91f65a1cba70f06c7fc65'].apis)).toEqual(['API1']); + expect(g.edges['2c826c3663b91f65a1cba70f06c7fc65'].sources).toHaveProperty('source1'); + expect(Array.from(g.edges['2c826c3663b91f65a1cba70f06c7fc65'].publications)).toEqual(['PMID:1', 'PMID:2']); + expect(g.edges['2c826c3663b91f65a1cba70f06c7fc65'].attributes).toHaveProperty('relation', new Set(['relation1'])); - expect(g.edges).toHaveProperty('9d334cb674d5671364c45cc8403184c6'); - expect(Array.from(g.edges['9d334cb674d5671364c45cc8403184c6'].apis)).toEqual(['API2']); - expect(g.edges['9d334cb674d5671364c45cc8403184c6'].sources).toHaveProperty('source2'); - expect(Array.from(g.edges['9d334cb674d5671364c45cc8403184c6'].publications)).toEqual(['PMC:1', 'PMC:2']); - expect(g.edges['9d334cb674d5671364c45cc8403184c6'].attributes).toHaveProperty('relation', new Set(['relation2'])); + expect(g.edges).toHaveProperty('827c366e2e3088b3f4a90dd88a524f15'); + expect(Array.from(g.edges['827c366e2e3088b3f4a90dd88a524f15'].apis)).toEqual(['API2']); + expect(g.edges['827c366e2e3088b3f4a90dd88a524f15'].sources).toHaveProperty('source2'); + expect(Array.from(g.edges['827c366e2e3088b3f4a90dd88a524f15'].publications)).toEqual(['PMC:1', 'PMC:2']); + expect(g.edges['827c366e2e3088b3f4a90dd88a524f15'].attributes).toHaveProperty('relation', new Set(['relation2'])); - expect(g.edges).toHaveProperty('4fe2d5d3e03e0f78f272745caf6b627d'); - expect(Array.from(g.edges['4fe2d5d3e03e0f78f272745caf6b627d'].apis)).toEqual(['API3']); - expect(g.edges['4fe2d5d3e03e0f78f272745caf6b627d'].sources).toHaveProperty('source3'); - expect(Array.from(g.edges['4fe2d5d3e03e0f78f272745caf6b627d'].publications)).toEqual(['PMC:3', 'PMC:4']); - expect(g.edges['4fe2d5d3e03e0f78f272745caf6b627d'].attributes).toHaveProperty('relation', new Set(['relation3'])); + expect(g.edges).toHaveProperty('3138ca0afca791770ed38c243dea2116'); + expect(Array.from(g.edges['3138ca0afca791770ed38c243dea2116'].apis)).toEqual(['API3']); + expect(g.edges['3138ca0afca791770ed38c243dea2116'].sources).toHaveProperty('source3'); + expect(Array.from(g.edges['3138ca0afca791770ed38c243dea2116'].publications)).toEqual(['PMC:3', 'PMC:4']); + expect(g.edges['3138ca0afca791770ed38c243dea2116'].attributes).toHaveProperty('relation', new Set(['relation3'])); }); test('Multiple attributes with the same name are merged', () => { const g = new graph(); g.update([record3, record3a]); - expect(g.edges).toHaveProperty('4fe2d5d3e03e0f78f272745caf6b627d'); - expect(Array.from(g.edges['4fe2d5d3e03e0f78f272745caf6b627d'].publications)).toEqual([ + expect(g.edges).toHaveProperty('3138ca0afca791770ed38c243dea2116'); + expect(Array.from(g.edges['3138ca0afca791770ed38c243dea2116'].publications)).toEqual([ 'PMC:3', 'PMC:4', 'PMC:6', 'PMC:7', ]); - expect(g.edges['4fe2d5d3e03e0f78f272745caf6b627d'].attributes).toHaveProperty( + expect(g.edges['3138ca0afca791770ed38c243dea2116'].attributes).toHaveProperty( 'relation', new Set(['relation3', 'relation3a', 'relation3b']), ); diff --git a/__test__/unittest/inferred_mode.test.ts b/__test__/unittest/inferred_mode.test.ts index 3aedd136..94565d1c 100644 --- a/__test__/unittest/inferred_mode.test.ts +++ b/__test__/unittest/inferred_mode.test.ts @@ -201,6 +201,7 @@ describe('Test InferredQueryHandler', () => { }, }, template: 'Chem-treats-DoP.json', + qualifiers: {} }, ]; @@ -549,7 +550,7 @@ describe('Test InferredQueryHandler', () => { expect(creativeLimitHit).toBeTruthy(); expect(Object.keys(combinedResponse.message.results)).toHaveLength(3); expect(combinedResponse.message.results['fakeCompound1-fakeDisease1'].analyses[0].score).toEqual( - 0.8421052631578949, + 0.7836531040612146, ); expect(combinedResponse.message.results['fakeCompound3-fakeDisease1'].analyses[0].score).toEqual(0.2); expect(combinedResponse.logs).toHaveLength(3); @@ -712,7 +713,7 @@ describe('Test InferredQueryHandler', () => { expect(Object.keys(mergedResults1)).toHaveLength(1); expect(creativeLimitHit1).toBeTruthy(); expect(combinedResponse.message.results['fakeCompound1-fakeDisease1'].analyses[0].score).toEqual( - 0.8421052631578949, + 0.7836531040612146, ); }); diff --git a/src/index.ts b/src/index.ts index 54d752c1..c1749190 100644 --- a/src/index.ts +++ b/src/index.ts @@ -38,6 +38,7 @@ export { default as QEdge } from './query_edge'; export { default as QNode } from './query_node'; export { default as InvalidQueryGraphError } from './exceptions/invalid_query_graph_error'; export * from './qedge2apiedge'; +export {TrapiQueryGraph, TrapiResponse, TrapiResult}; // better readability export default class TRAPIQueryHandler { logs: StampedLog[];