From 37f768005feafbd63d36cf8c30e72d4887ef6c58 Mon Sep 17 00:00:00 2001 From: tokebe <43009413+tokebe@users.noreply.github.com> Date: Mon, 5 Aug 2024 15:05:08 -0400 Subject: [PATCH 1/2] fix: more specific direct edge criteria --- src/inferred_mode/inferred_mode.ts | 47 ++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 15 deletions(-) diff --git a/src/inferred_mode/inferred_mode.ts b/src/inferred_mode/inferred_mode.ts index bc6f3dd7..0061edbb 100644 --- a/src/inferred_mode/inferred_mode.ts +++ b/src/inferred_mode/inferred_mode.ts @@ -309,8 +309,28 @@ export default class InferredQueryHandler { const resultID = `${resultCreativeSubjectID}-${resultCreativeObjectID}`; // Direct edge answers stand on their own, not as an inferred edge. - if (Object.keys(result.node_bindings).length == 2) { - const boundEdgeID = Object.values(result.analyses[0].edge_bindings)[0][0].id; + const boundEdgeID = Object.values(result.analyses[0].edge_bindings)[0][0].id; + const boundEdge = combinedResponse.message.knowledge_graph.edges[boundEdgeID]; + const specialHandling = [ + Object.keys(result.node_bindings).length === 2, // Direct edge + // Predicate matches or is descendant + qEdge.predicates.some( + (predicate) => + predicate === boundEdge.predicate || + biolink.getDescendantPredicates(predicate).includes(boundEdge.predicate), + ), + // All query qualifiers (if any) are accounted for (more is fine) + qEdge.qualifier_constraints.every(({ qualifier_set }) => { + return qualifier_set.every((queryQualifier) => + boundEdge.qualifiers.some( + (qualifier) => + queryQualifier.qualifier_type_id === qualifier.qualifier_type_id && + queryQualifier.qualifier_value === qualifier.qualifier_value, + ), + ); + }), + ].every((test) => test); + if (specialHandling) { translatedResult.analyses[0].edge_bindings = { [qEdgeID]: [{ id: boundEdgeID, attributes: [] }] }; } else { // Create an aux graph using the result and associate it with an inferred Edge @@ -334,8 +354,8 @@ export default class InferredQueryHandler { ], attributes: [ { attribute_type_id: 'biolink:support_graphs', value: [] }, - { attribute_type_id: 'biolink:knowledge_level', value: "prediction" }, - { attribute_type_id: 'biolink:agent_type', value: "computational_model" }, + { attribute_type_id: 'biolink:knowledge_level', value: 'prediction' }, + { attribute_type_id: 'biolink:agent_type', value: 'computational_model' }, ], }; } @@ -357,7 +377,7 @@ export default class InferredQueryHandler { }, [] as string[], ), - attributes: [] + attributes: [], }; } @@ -390,9 +410,9 @@ export default class InferredQueryHandler { if (typeof combinedResponse.message.results[resultID].analyses[0].score !== 'undefined') { combinedResponse.message.results[resultID].analyses[0].score = resScore ? scaled_sigmoid( - inverse_scaled_sigmoid(combinedResponse.message.results[resultID].analyses[0].score) + - inverse_scaled_sigmoid(resScore), - ) + inverse_scaled_sigmoid(combinedResponse.message.results[resultID].analyses[0].score) + + inverse_scaled_sigmoid(resScore), + ) : combinedResponse.message.results[resultID].analyses[0].score; } else { combinedResponse.message.results[resultID].analyses[0].score = resScore; @@ -560,11 +580,9 @@ export default class InferredQueryHandler { const message = [ `Addition of ${creativeLimitHit} results from Template ${i + 1}`, Object.keys(combinedResponse.message.results).length === this.CREATIVE_LIMIT ? ' meets ' : ' exceeds ', - `creative result maximum of ${this.CREATIVE_LIMIT} (reaching ${ - Object.keys(combinedResponse.message.results).length + `creative result maximum of ${this.CREATIVE_LIMIT} (reaching ${Object.keys(combinedResponse.message.results).length } merged). `, - `Response will be truncated to top-scoring ${this.CREATIVE_LIMIT} results. Skipping remaining ${ - subQueries.length - (i + 1) + `Response will be truncated to top-scoring ${this.CREATIVE_LIMIT} results. Skipping remaining ${subQueries.length - (i + 1) } `, subQueries.length - (i + 1) === 1 ? `template.` : `templates.`, ].join(''); @@ -589,9 +607,8 @@ export default class InferredQueryHandler { const total = Object.values(mergedResultsCount).reduce((sum, count) => sum + count, 0) + Object.keys(mergedResultsCount).length; - const message = `Merging Summary: (${total}) inferred-template results were merged into (${ - Object.keys(mergedResultsCount).length - }) final results, reducing result count by (${total - Object.keys(mergedResultsCount).length})`; + const message = `Merging Summary: (${total}) inferred-template results were merged into (${Object.keys(mergedResultsCount).length + }) final results, reducing result count by (${total - Object.keys(mergedResultsCount).length})`; debug(message); combinedResponse.logs.push(new LogEntry('INFO', null, message).getLog()); } From f4e63f7e46aeede6f17ee1d6acf51d6ca2fa4eb8 Mon Sep 17 00:00:00 2001 From: tokebe <43009413+tokebe@users.noreply.github.com> Date: Mon, 5 Aug 2024 15:09:56 -0400 Subject: [PATCH 2/2] fix: satisfy 1+ qualifier set, not all necessarily --- src/inferred_mode/inferred_mode.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/inferred_mode/inferred_mode.ts b/src/inferred_mode/inferred_mode.ts index 0061edbb..1c973fc6 100644 --- a/src/inferred_mode/inferred_mode.ts +++ b/src/inferred_mode/inferred_mode.ts @@ -320,7 +320,7 @@ export default class InferredQueryHandler { biolink.getDescendantPredicates(predicate).includes(boundEdge.predicate), ), // All query qualifiers (if any) are accounted for (more is fine) - qEdge.qualifier_constraints.every(({ qualifier_set }) => { + qEdge.qualifier_constraints.some(({ qualifier_set }) => { return qualifier_set.every((queryQualifier) => boundEdge.qualifiers.some( (qualifier) =>