def _getSmartIndenter(indenterName, qpart, indenter):
    """Get indenter by name.
    Available indenters are none, normal, cstyle, haskell, lilypond, lisp, python, ruby, xml
    Indenter name is not case sensitive
    Raise KeyError if not found
    indentText is indentation, which shall be used. i.e. '\t' for tabs, '    ' for 4 space symbols
    """
    indenterName = indenterName.lower()

    if indenterName in ('haskell', 'lilypond'):  # not supported yet
        logger.warning('Smart indentation for %s not supported yet. But you could be a hero who implemented it' % indenterName)
        from qutepart.indenter.base import IndentAlgNormal as indenterClass
    elif 'none' == indenterName:
        from qutepart.indenter.base import IndentAlgBase as indenterClass
    elif 'normal' == indenterName:
        from qutepart.indenter.base import IndentAlgNormal as indenterClass
    elif 'cstyle' == indenterName:
        from qutepart.indenter.cstyle import IndentAlgCStyle as indenterClass
    elif 'python' == indenterName:
        from qutepart.indenter.python import IndentAlgPython as indenterClass
    elif 'ruby' == indenterName:
        from qutepart.indenter.ruby import IndentAlgRuby as indenterClass
    elif 'xml' == indenterName:
        from qutepart.indenter.xmlindent import IndentAlgXml as indenterClass
    elif 'haskell' == indenterName:
        from qutepart.indenter.haskell import IndenterHaskell as indenterClass
    elif 'lilypond' == indenterName:
        from qutepart.indenter.lilypond import IndenterLilypond as indenterClass
    elif 'lisp' == indenterName:
        from qutepart.indenter.lisp import IndentAlgLisp as indenterClass
    elif 'scheme' == indenterName:
        from qutepart.indenter.scheme import IndentAlgScheme as indenterClass
    else:
        raise KeyError("Indenter %s not found" % indenterName)

    return indenterClass(qpart, indenter)
def _filter_examples_by_class(target_values, downsampling_dict,
                              test_mode=False):
    """Filters examples by target value.

    E = number of examples

    :param target_values: length-E numpy array of target values (integer class
        labels).
    :param downsampling_dict: Dictionary, where each key is the integer
        ID for a target class (-2 for "dead storm") and the corresponding value
        is the number of examples desired from said class.  If
        `downsampling_dict is None`, `example_dict` will be returned
        without modification.
    :param test_mode: Never mind.  Just leave this alone.
    :return: indices_to_keep: 1-D numpy array with indices of examples to keep.
        These are all integers in [0, E - 1].
    """

    num_examples = len(target_values)

    if downsampling_dict is None:
        return numpy.linspace(0, num_examples - 1, num=num_examples, dtype=int)

    indices_to_keep = numpy.array([], dtype=int)
    class_keys = list(downsampling_dict.keys())

    for this_class in class_keys:
        this_num_storm_objects = downsampling_dict[this_class]
        these_indices = numpy.where(target_values == this_class)[0]

        this_num_storm_objects = min(
            [this_num_storm_objects, len(these_indices)]
        )
        if this_num_storm_objects == 0:
            continue

        if test_mode:
            these_indices = these_indices[:this_num_storm_objects]
        else:
            these_indices = numpy.random.choice(
                these_indices, size=this_num_storm_objects, replace=False)

        indices_to_keep = numpy.concatenate((indices_to_keep, these_indices))

    return indices_to_keep