from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.pipeline import FeatureUnion


def build_vectorizer():
    word_vectorizer = TfidfVectorizer(
        ngram_range=(1, 2),
        analyzer="word",
        lowercase=True,
        min_df=2,
        max_df=0.95
    )

    char_vectorizer = TfidfVectorizer(
        ngram_range=(3, 5),
        analyzer="char",
        lowercase=True,
        min_df=2,
        max_df=0.95
    )

    return FeatureUnion([
        ("word", word_vectorizer),
        ("char", char_vectorizer)
    ])
