LucaCappelletti94/italian_csv_type_prediction

View on GitHub
italian_csv_type_prediction/simple_types/set_regex_type_predictor.py

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
from .regex_type_predictor import RegexTypePredictor
import re
from ..utils import normalize
from typing import List


class SetRegexTypePredictor(RegexTypePredictor):

    def __init__(self, words: List[str], pattern:str = r"(?:\W|\b)(?:{})(?:\W|\b)"):
        """Create new set regex based predictor.

        Parameters
        --------------------------------
        pattern: str,
            The pattern against which to test.
        """
        super().__init__(pattern.format("|".join([
            re.escape(normalize(word))
            for word in words
        ])))