Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creative-mode timer #193

Closed
wants to merge 5 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 3 additions & 32 deletions src/inferred_mode/inferred_mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ export interface CombinedResponseReport {
querySuccess: number;
queryHadResults: boolean;
mergedResults: { [resultID: string]: number };
creativeLimitHit: boolean | number;
}

// MatchedTemplate, but with IDs, etc. filled in
Expand All @@ -52,7 +51,6 @@ export default class InferredQueryHandler {
path: string;
predicatePath: string;
includeReasoner: boolean;
CREATIVE_LIMIT: number;
constructor(
parent: TRAPIQueryHandler,
queryGraph: TrapiQueryGraph,
Expand All @@ -69,7 +67,6 @@ export default class InferredQueryHandler {
this.path = path;
this.predicatePath = predicatePath;
this.includeReasoner = includeReasoner;
this.CREATIVE_LIMIT = process.env.CREATIVE_LIMIT ? parseInt(process.env.CREATIVE_LIMIT) : 500;
rjawesome marked this conversation as resolved.
Show resolved Hide resolved
}

get queryIsValid(): boolean {
Expand Down Expand Up @@ -263,7 +260,6 @@ export default class InferredQueryHandler {
querySuccess: 0,
queryHadResults: false,
mergedResults: {},
creativeLimitHit: false,
};
let mergedThisTemplate = 0;
const resultIDsFromPrevious = new Set(Object.keys(combinedResponse.message.results));
Expand Down Expand Up @@ -428,9 +424,6 @@ export default class InferredQueryHandler {
}
report.querySuccess = 1;

if (Object.keys(combinedResponse.message.results).length >= this.CREATIVE_LIMIT && !report.creativeLimitHit) {
report.creativeLimitHit = Object.keys(newResponse.message.results).length;
}
span.finish();
return report;
}
Expand Down Expand Up @@ -550,7 +543,7 @@ export default class InferredQueryHandler {
// make query and combine results/kg/logs/etc
handler.setQueryGraph(queryGraph);
await handler.query();
const { querySuccess, queryHadResults, mergedResults, creativeLimitHit } = this.combineResponse(
const { querySuccess, queryHadResults, mergedResults } = this.combineResponse(
i,
handler,
qEdgeID,
Expand All @@ -564,23 +557,6 @@ export default class InferredQueryHandler {
mergedResultsCount[result] =
result in mergedResultsCount ? mergedResultsCount[result] + countMerged : countMerged;
});
// log to user if we should stop
if (creativeLimitHit) {
stop = true;
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
} merged). `,
`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('');
debug(message);
combinedResponse.logs.push(new LogEntry(`INFO`, null, message).getLog());
}
span.finish();
} catch (error) {
handler.logs.forEach((log) => {
Expand Down Expand Up @@ -610,11 +586,7 @@ export default class InferredQueryHandler {
new LogEntry(
'INFO',
null,
[
`Final result count`,
Object.keys(combinedResponse.message.results).length > this.CREATIVE_LIMIT ? ' (before truncation):' : ':',
` ${Object.keys(combinedResponse.message.results).length}`,
].join(''),
`Final result count: ${Object.keys(combinedResponse.message.results).length}`,
rjawesome marked this conversation as resolved.
Show resolved Hide resolved
).getLog(),
);
}
Expand All @@ -623,8 +595,7 @@ export default class InferredQueryHandler {
response.message.results = Object.values(combinedResponse.message.results).sort((a, b) => {
return b.analyses[0].score - a.analyses[0].score ? b.analyses[0].score - a.analyses[0].score : 0;
});
// trim extra results and prune kg
response.message.results = response.message.results.slice(0, this.CREATIVE_LIMIT);
rjawesome marked this conversation as resolved.
Show resolved Hide resolved
// prune kg
response.description = `Query processed successfully, retrieved ${response.message.results.length} results.`;
this.pruneKnowledgeGraph(response);
// get the final summary log
Expand Down
Loading