import type { LineKind } from "./transcript.ts"; export const ASKING = /(? plans(sentence, index === sentences.length - 1 ? next : "said"), ); } function plans(sentence: string, next: LineKind | undefined): boolean { if (PLAN_START.test(sentence) || PLAN_AFTER.test(sentence) || sentence.endsWith("?")) return true; // "Now the router:" leads into a call; a report that ends in a colon leads into its list. return sentence.endsWith(":") && (next === undefined || next === "call"); } /** Two words with the same first letters are one: "publiquei" names "Publicar". */ const STEM = 5; const COMMON_PT = "agora aqui esse essa isso esta está para pode feito fazer tudo"; const COMMON_EN = "with that this done already just have"; const COMMON = new Set(`${COMMON_PT} ${COMMON_EN}`.split(" ")); function stems(words: string): Set { return new Set( normalized(words) .split(/[^\p{L}\p{N}]+/u) .filter((word) => word.length >= 4 && !COMMON.has(word)) .map((word) => word.slice(0, STEM)), ); } export function sharesWord(left: string, right: string): boolean { const named = stems(right); return [...stems(left)].some((stem) => named.has(stem)); } export function sameWords(left: string, right: string): boolean { const a = stems(left); const b = stems(right); const shared = sharedCount(a, b); return shared > 0 && shared / Math.max(a.size, b.size) >= 0.75; } export function echoes(part: string, whole: string): boolean { const words = stems(part); return words.size > 0 && sharedCount(words, stems(whole)) / words.size >= 0.75; } function sharedCount(left: ReadonlySet, right: ReadonlySet): number { return [...left].filter((stem) => right.has(stem)).length; } export function normalized(value: string): string { return value .toLowerCase() .replace(/[*_`"'“”‘’]/g, "") .replace(/\s+/g, " ") .trim(); }