Skip to content

Commit

Permalink
fix: response merging special handling criteria
Browse files Browse the repository at this point in the history
  • Loading branch information
tokebe committed Aug 9, 2024
1 parent 6a8d1e5 commit 29bab45
Showing 1 changed file with 26 additions and 13 deletions.
39 changes: 26 additions & 13 deletions src/inferred_mode/inferred_mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,8 @@ export default class InferredQueryHandler {
const qualifierConstraints = (qEdge.qualifier_constraints || []).map((qualifierSetObj) => {
return Object.fromEntries(
qualifierSetObj.qualifier_set.map(({ qualifier_type_id, qualifier_value }) => [
qualifier_type_id.replace('biolink:', ''),
Array.isArray(qualifier_value)
? qualifier_value.map((string) => string.replace('biolink:', ''))
: qualifier_value.replace('biolink:', ''),
qualifier_type_id,
qualifier_value,
]),
) as CompactQualifiers;
});
Expand Down Expand Up @@ -257,7 +255,7 @@ export default class InferredQueryHandler {
qEdgeID: string,
qEdge: TrapiQEdge,
combinedResponse: CombinedResponse,
qualifers?: CompactQualifiers
qualifiers?: CompactQualifiers,
): CombinedResponseReport {
const span = Telemetry.startSpan({ description: 'creativeCombineResponse' });
const newResponse = handler.getResponse();
Expand Down Expand Up @@ -328,11 +326,17 @@ export default class InferredQueryHandler {
return (
boundEdge.qualifiers?.some((qualifier) => {
const typeMatch = queryQualifier.qualifier_type_id === qualifier.qualifier_type_id;
const valueMatch =
queryQualifier.qualifier_value === qualifier.qualifier_value ||
biolink
.getDescendantQualifiers(queryQualifier.qualifier_value as string)
.includes(qualifier.qualifier_value as string);
let valueMatch: boolean;
try {
const descendants = queryQualifier.qualifier_value.includes('biolink:')
? biolink.getDescendantPredicates(queryQualifier.qualifier_value as string)
: biolink.getDescendantQualifiers(queryQualifier.qualifier_value as string);
const valueMatch =
queryQualifier.qualifier_value === qualifier.qualifier_value ||
descendants.includes(qualifier.qualifier_value as string);
} catch (err) {
valueMatch = queryQualifier.qualifier_value === qualifier.qualifier_value;
}
return typeMatch && valueMatch;
}) ?? false
);
Expand Down Expand Up @@ -369,8 +373,17 @@ export default class InferredQueryHandler {
};
}
// Add qualifiers to edge
if (typeof qualifers == 'object' && Object.keys(qualifers).length > 0 && !combinedResponse.message.knowledge_graph.edges[inferredEdgeID].qualifiers) {
combinedResponse.message.knowledge_graph.edges[inferredEdgeID].qualifiers = Object.entries(qualifers).map(([qualifierType, qualifierValue]) => ({ qualifier_type_id: qualifierType, qualifier_value: qualifierValue }));
if (
typeof qualifiers == 'object' &&
Object.keys(qualifiers).length > 0 &&
!combinedResponse.message.knowledge_graph.edges[inferredEdgeID].qualifiers
) {
combinedResponse.message.knowledge_graph.edges[inferredEdgeID].qualifiers = Object.entries(qualifiers).map(
([qualifierType, qualifierValue]) => ({
qualifier_type_id: qualifierType,
qualifier_value: qualifierValue,
}),
);
}

let auxGraphSuffix = 0;
Expand Down Expand Up @@ -580,7 +593,7 @@ export default class InferredQueryHandler {
qEdgeID,
qEdge,
combinedResponse,
qualifiers
qualifiers,
);
// update values used in logging
successfulQueries += querySuccess;
Expand Down

0 comments on commit 29bab45

Please sign in to comment.