# Path: wordseg/utils.py
# def str2type(t):
# def type2str(t):
# def strip(string):
# def null_logger():
# def get_logger(name=None, level=logging.WARNING):
#     def __init__(self, elements):
#     def __iter__(self):
#     def __next__(self):
#     def __init__(self, function):
#     def __call__(self):
#     def exit(msg):
# def get_binary(binary):
# def get_config_files(algorithm, extension=None):
#     def __init__(self, short_name=None, name=None, type=None,
#                  default=None, help=''):
#     def add_to_parser(self, parser):
#     def parsed_name(self):
# def get_parser(description=None, separator=Separator(), train_file=False):
# def prepare_main(name=None,
#                  description=None,
#                  separator=Separator(phone=None, syllable=None, word=None),
#                  add_arguments=None,
#                  train_file=False):
# class CountingIterator:
# class CatchExceptions:
# class Argument:


import codecs
import collections
import math
import os
import re
from wordseg import utils
            for bigram, freq in bigrams.items()})
    elif dependency == 'btp':
        tps = collections.defaultdict(lambda: 0, {
            bigram: float(freq) / unigrams[bigram[1]]
            for bigram, freq in bigrams.items()})
    else:  # dependency == 'mi'
        tps = collections.defaultdict(lambda: 0, {
            bigram: math.log(float(freq) / (
                unigrams[bigram[0]] * unigrams[bigram[1]]), 2)
            for bigram, freq in bigrams.items()})
    return tps


# -----------------------------------------------------------------------------
#  Segmentation
# -----------------------------------------------------------------------------

def _segment(units, tps, threshold):
    # segment the input given the transition probalities
    cwords = (_threshold_relative(units, tps) if threshold == 'relative'
              else _threshold_absolute(units, tps))
    segtext = ' '.join(''.join(c) for c in cwords)
    return [utt.strip() for utt in re.sub(' +', ' ', segtext).split('UB')]


# -----------------------------------------------------------------------------
#  Segment function
# -----------------------------------------------------------------------------

def segment(text, train_text=None, threshold='relative', dependency='ftp',

# Path: wordseg/utils.py
# def str2type(t):
# def type2str(t):
# def strip(string):
# def null_logger():
# def get_logger(name=None, level=logging.WARNING):
#     def __init__(self, elements):
#     def __iter__(self):
#     def __next__(self):
#     def __init__(self, function):
#     def __call__(self):
#     def exit(msg):
# def get_binary(binary):
# def get_config_files(algorithm, extension=None):
#     def __init__(self, short_name=None, name=None, type=None,
#                  default=None, help=''):
#     def add_to_parser(self, parser):
#     def parsed_name(self):
# def get_parser(description=None, separator=Separator(), train_file=False):
# def prepare_main(name=None,
#                  description=None,
#                  separator=Separator(phone=None, syllable=None, word=None),
#                  add_arguments=None,
#                  train_file=False):
# class CountingIterator:
# class CatchExceptions:
# class Argument:


# Path: wordseg/algos/tp.py
import codecs
import collections
import math
import os
import re
from wordseg import utils

            for bigram, freq in bigrams.items()})
    elif dependency == 'btp':
        tps = collections.defaultdict(lambda: 0, {
            bigram: float(freq) / unigrams[bigram[1]]
            for bigram, freq in bigrams.items()})
    else:  # dependency == 'mi'
        tps = collections.defaultdict(lambda: 0, {
            bigram: math.log(float(freq) / (
                unigrams[bigram[0]] * unigrams[bigram[1]]), 2)
            for bigram, freq in bigrams.items()})
    return tps


# -----------------------------------------------------------------------------
#  Segmentation
# -----------------------------------------------------------------------------

def _segment(units, tps, threshold):
    # segment the input given the transition probalities
    cwords = (_threshold_relative(units, tps) if threshold == 'relative'
              else _threshold_absolute(units, tps))
    segtext = ' '.join(''.join(c) for c in cwords)
    return [utt.strip() for utt in re.sub(' +', ' ', segtext).split('UB')]


# -----------------------------------------------------------------------------
#  Segment function
# -----------------------------------------------------------------------------

def segment(text, train_text=None, threshold='relative', dependency='ftp',

            log=utils.null_logger()):