# Path: kraken/lib/exceptions.py
# class KrakenEncodeException(Exception):
# 
#     def __init__(self, message=None):
#         Exception.__init__(self, message)
# 
# class KrakenCodecException(Exception):
# 
#     def __init__(self, message=None):
#         Exception.__init__(self, message)


import logging
import numpy as np
from collections import Counter
from typing import List, Tuple, Set, Union, Dict, Sequence
from torch import IntTensor
from kraken.lib.exceptions import KrakenEncodeException, KrakenCodecException
    string in the list will be assigned a label, and in the final case each
    key string will be mapped to the value sequence of integers. In the
    first two cases labels will be assigned automatically. When a mapping
    is manually provided the label codes need to be a prefix-free code.

    As 0 is the blank label in a CTC output layer, output labels and input
    dictionaries are/should be 1-indexed.

    Args:
        charset: Input character set.
        strict: Flag indicating if encoding/decoding errors should be ignored
                or cause an exception.

    Raises:
        KrakenCodecException: If the character set contains duplicate
                              entries or the mapping is non-singular or
                              non-prefix-free.
    """
    def __init__(self, charset: Union[Dict[str, Sequence[int]], Sequence[str], str], strict=False):
        if isinstance(charset, dict):
            self.c2l = charset
        else:
            cc = Counter(charset)
            if len(cc) < len(charset):
                raise KrakenCodecException(f'Duplicate entry in codec definition string: {cc}')
            self.c2l = {k: [v] for v, k in enumerate(sorted(charset), start=1)}
        self.c_sorted = sorted(self.c2l.keys(), key=len, reverse=True)
        self.l2c = {tuple(v): k for k, v in self.c2l.items()}  # type: Dict[Tuple[int], str]
        self.strict = strict
        if not self.is_valid:

# Path: kraken/lib/exceptions.py
# class KrakenEncodeException(Exception):
# 
#     def __init__(self, message=None):
#         Exception.__init__(self, message)
# 
# class KrakenCodecException(Exception):
# 
#     def __init__(self, message=None):
#         Exception.__init__(self, message)


# Path: kraken/lib/codec.py
import logging
import numpy as np
from collections import Counter
from typing import List, Tuple, Set, Union, Dict, Sequence
from torch import IntTensor
from kraken.lib.exceptions import KrakenEncodeException, KrakenCodecException

    string in the list will be assigned a label, and in the final case each
    key string will be mapped to the value sequence of integers. In the
    first two cases labels will be assigned automatically. When a mapping
    is manually provided the label codes need to be a prefix-free code.

    As 0 is the blank label in a CTC output layer, output labels and input
    dictionaries are/should be 1-indexed.

    Args:
        charset: Input character set.
        strict: Flag indicating if encoding/decoding errors should be ignored
                or cause an exception.

    Raises:
        KrakenCodecException: If the character set contains duplicate
                              entries or the mapping is non-singular or
                              non-prefix-free.
    """
    def __init__(self, charset: Union[Dict[str, Sequence[int]], Sequence[str], str], strict=False):
        if isinstance(charset, dict):
            self.c2l = charset
        else:
            cc = Counter(charset)
            if len(cc) < len(charset):
                raise KrakenCodecException(f'Duplicate entry in codec definition string: {cc}')
            self.c2l = {k: [v] for v, k in enumerate(sorted(charset), start=1)}
        self.c_sorted = sorted(self.c2l.keys(), key=len, reverse=True)
        self.l2c = {tuple(v): k for k, v in self.c2l.items()}  # type: Dict[Tuple[int], str]
        self.strict = strict
        if not self.is_valid:

            raise KrakenCodecException('Codec is not valid (non-singular/non-prefix free).')