Skip to content

Commit

Permalink
fix: more specific direct edge criteria
Browse files Browse the repository at this point in the history
  • Loading branch information
tokebe committed Aug 5, 2024
1 parent 1da1bde commit 37f7680
Showing 1 changed file with 32 additions and 15 deletions.
47 changes: 32 additions & 15 deletions src/inferred_mode/inferred_mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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' },
],
};
}
Expand All @@ -357,7 +377,7 @@ export default class InferredQueryHandler {
},
[] as string[],
),
attributes: []
attributes: [],
};
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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('');
Expand All @@ -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());
}
Expand Down

0 comments on commit 37f7680

Please sign in to comment.