# Path: talon/utils.py
# def to_unicode(str_or_unicode, precise=False):
#     """
#     Safely returns a unicode version of a given string
#     >>> utils.to_unicode('привет')
#         u'привет'
#     >>> utils.to_unicode(u'привет')
#         u'привет'
#     If `precise` flag is True, tries to guess the correct encoding first.
#     """
#     if not isinstance(str_or_unicode, six.text_type):
#         encoding = quick_detect_encoding(str_or_unicode) if precise else 'utf-8'
#         return six.text_type(str_or_unicode, encoding, 'replace')
#     return str_or_unicode


import unicodedata
import regex as re
from talon.utils import to_unicode
from talon.signature.constants import SIGNATURE_MAX_LINES
    >>> categories_percent("q,w.", ["Po"])
    50.0
    >>> categories_percent("qqq ggg hhh", ["Nd"])
    0.0
    >>> categories_percent("q5", ["Nd"])
    50.0
    >>> categories_percent("s.s,5s", ["Po", "Nd"])
    50.0
    '''
    count = 0
    s = to_unicode(s, precise=True)
    for c in s:
        if unicodedata.category(c) in categories:
            count += 1
    return 100 * float(count) / len(s) if len(s) else 0


def punctuation_percent(s):
    '''Returns punctuation percent.

    >>> punctuation_percent("qqq ggg hhh")
    0.0
    >>> punctuation_percent("q,w.")
    50.0
    '''
    return categories_percent(s, ['Po'])


def capitalized_words_percent(s):
    '''Returns capitalized words percent.'''

# Path: talon/utils.py
# def to_unicode(str_or_unicode, precise=False):
#     """
#     Safely returns a unicode version of a given string
#     >>> utils.to_unicode('привет')
#         u'привет'
#     >>> utils.to_unicode(u'привет')
#         u'привет'
#     If `precise` flag is True, tries to guess the correct encoding first.
#     """
#     if not isinstance(str_or_unicode, six.text_type):
#         encoding = quick_detect_encoding(str_or_unicode) if precise else 'utf-8'
#         return six.text_type(str_or_unicode, encoding, 'replace')
#     return str_or_unicode


# Path: talon/signature/learning/helpers.py
import unicodedata
import regex as re
from talon.utils import to_unicode
from talon.signature.constants import SIGNATURE_MAX_LINES

    >>> categories_percent("q,w.", ["Po"])
    50.0
    >>> categories_percent("qqq ggg hhh", ["Nd"])
    0.0
    >>> categories_percent("q5", ["Nd"])
    50.0
    >>> categories_percent("s.s,5s", ["Po", "Nd"])
    50.0
    '''
    count = 0
    s = to_unicode(s, precise=True)
    for c in s:
        if unicodedata.category(c) in categories:
            count += 1
    return 100 * float(count) / len(s) if len(s) else 0


def punctuation_percent(s):
    '''Returns punctuation percent.

    >>> punctuation_percent("qqq ggg hhh")
    0.0
    >>> punctuation_percent("q,w.")
    50.0
    '''
    return categories_percent(s, ['Po'])


def capitalized_words_percent(s):
    '''Returns capitalized words percent.'''

    s = to_unicode(s, precise=True)