private addNameVariations()

in ts/matchers/placematcher.ts [156:186]


    private addNameVariations(place: Place, index: number, name: string, address?: string): Target<Place>[] {
        const nameTokens = EnPlaceMatcher.tokenizer.tokenize(name);
        const addressTokens = address ? EnPlaceMatcher.tokenizer.tokenize(address) : [];
        const variations: Target<Place>[] = [];

        // The idea is to have a sliding window anchored at the beginning and the end of both name and address
        // individually, and as if they were concatenated.
        nameTokens.forEach((token, i) => {
            variations.push(new Target(place, name.substring(0, token.interval.last), index));
            const split = i + 1;
            if (split < nameTokens.length) {
                const suffix = name.substring(nameTokens[split].interval.first);
                variations.push(new Target(place, suffix, index));
                if (address) {
                    variations.push(new Target(place, suffix + ` ${address}`, index));
                }
            }
        });
        addressTokens.forEach((token, i) => {
            const prefix = address!.substring(0, token.interval.last);
            variations.push(new Target(place, prefix, index));
            if (name) {
                variations.push(new Target(place, `${name} ` + prefix, index));
            }
            const split = i + 1;
            if (split < addressTokens.length) {
                variations.push(new Target(place, address!.substring(addressTokens[split].interval.first), index));
            }
        });
        return variations;
    }