Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | 597x 1138x 924x 924x 12x | import type { CurriculumTopic } from "./curriculum-schema";
import { matchesFactRequirement, type SketchFacts } from "./sketch-facts";
export interface TopicMatch {
readonly topic: CurriculumTopic;
readonly score: number;
}
export interface TopicMatcher {
match(topics: readonly CurriculumTopic[], facts: SketchFacts): readonly TopicMatch[];
}
export class DefaultTopicMatcher implements TopicMatcher {
match(topics: readonly CurriculumTopic[], facts: SketchFacts): readonly TopicMatch[] {
return topics
.map((topic) => {
const matched = topic.activation.any.filter((requirement) => matchesFactRequirement(facts, requirement)).length;
return { topic, score: matched };
})
.filter(({ score }) => score > 0)
.sort((left, right) => right.score - left.score || left.topic.id.localeCompare(right.topic.id));
}
}
|