/**
 * @copyright Sister Software
 * @license AGPL-3.0
 * @author Teffen Ellis, et al.
 */
const LeadingArea = {
    Admin: new Set(["locality", "region", "country"]),
    Netural: new Set(["postcode"]),
};
/**
 * This solver removes leading area classifications that are not the last non-admin classification.
 */
export class LeadingAreaDeclassifier {
    solve(context) {
        for (const solution of context.solutions) {
            // Track the last non-admin cursor position.
            let lastNonAdminCursorPosition = 0;
            for (const { classification, span } of solution.matches) {
                if (LeadingArea.Admin.has(classification))
                    continue;
                if (LeadingArea.Netural.has(classification))
                    continue;
                lastNonAdminCursorPosition = span.end;
            }
            solution.matches = solution.matches.filter(({ classification, span }) => {
                const isAdmin = LeadingArea.Admin.has(classification);
                // if (isAdmin && pair.span.end < lastNonAdminCursorPosition) return false
                return !(isAdmin && span.end < lastNonAdminCursorPosition);
            });
        }
        context.solutions.sort((a, b) => b.score - a.score);
        context.solutions.forEach((s) => s.matches.sort((a, b) => a.span.start - b.span.start));
    }
}
//# sourceMappingURL=LeadingAreaDeclassifier.js.map