/**
 * @copyright Sister Software
 * @license AGPL-3.0
 * @author Teffen Ellis, et al.
 */
/**
 * Comparator for sorting solution matches by their start index.
 */
export function compareMatchesByStart(a, b) {
    return a.span.start - b.span.start;
}
export class SolutionMatch {
    /**
     * The span of text that was matched.
     */
    span;
    /**
     * Matched classifications and their respective metadata.
     */
    #match;
    /**
     * The classification of the match.
     */
    get classification() {
        return this.#match.classification;
    }
    /**
     * The confidence of the match, from 0 to 1.
     *
     * This indicates how certain the classifier is that the match is correct.
     */
    get confidence() {
        return this.#match.confidence;
    }
    /**
     * The body of the matched span.
     */
    get value() {
        return this.span.body;
    }
    /**
     * The start index of the span.
     */
    get start() {
        return this.span.start;
    }
    /**
     * The end index of the span.
     */
    get end() {
        return this.span.end;
    }
    /**
     * The languages that the match was classified as.
     */
    get languages() {
        return this.#match.languages;
    }
    /**
     * The range of the span, i.e. the number of characters covered.
     */
    get coverage() {
        return this.span.coverage;
    }
    constructor(span, classification) {
        this.span = span;
        this.#match =
            typeof classification === "string"
                ? {
                    classification,
                    confidence: 1,
                }
                : classification;
    }
    toJSON() {
        return {
            ...this.#match,
            value: this.span.body,
            start: this.span.start,
            end: this.span.end,
        };
    }
}
export function calculateRangeScore(match) {
    let range;
    if (match.span.children.size) {
        range = Iterator
            // ---
            .from(match.span.children)
            .reduce((sum, child) => sum + (child.end - child.start), 0);
    }
    else {
        range = match.end - match.start;
    }
    return {
        range,
        confidence: match.confidence * range,
    };
}
//# sourceMappingURL=SolutionMatch.js.map