# - Generated by tools/entrypoint_compiler.py: do not edit by hand
"""
NGram
"""

import numbers

from ..utils.entrypoints import Component
from ..utils.utils import try_set


def n_gram(
        ngram_length=1,
        skip_length=0,
        all_lengths=True,
        max_num_terms=[10000000],
        weighting='Tf',
        **params):
    """
    **Description**
        Extracts NGrams from text and convert them to vector using
        dictionary.

    :param ngram_length: Ngram length (settings).
    :param skip_length: Maximum number of tokens to skip when
        constructing an ngram (settings).
    :param all_lengths: Whether to include all ngram lengths up to
        NgramLength or only NgramLength (settings).
    :param max_num_terms: Maximum number of ngrams to store in the
        dictionary (settings).
    :param weighting: The weighting criteria (settings).
    """

    entrypoint_name = 'NGram'
    settings = {}

    if ngram_length is not None:
        settings['NgramLength'] = try_set(
            obj=ngram_length,
            none_acceptable=True,
            is_of_type=numbers.Real)
    if skip_length is not None:
        settings['SkipLength'] = try_set(
            obj=skip_length,
            none_acceptable=True,
            is_of_type=numbers.Real)
    if all_lengths is not None:
        settings['AllLengths'] = try_set(
            obj=all_lengths,
            none_acceptable=True,
            is_of_type=bool)
    if max_num_terms is not None:
        settings['MaxNumTerms'] = try_set(
            obj=max_num_terms,
            none_acceptable=True,
            is_of_type=list)
    if weighting is not None:
        settings['Weighting'] = try_set(
            obj=weighting,
            none_acceptable=True,
            is_of_type=str,
            values=[
                'Tf',
                'Idf',
                'TfIdf'])

    component = Component(
        name=entrypoint_name,
        settings=settings,
        kind='NgramExtractor')
    return component
