# Path: talon/signature/learning/helpers.py
# RE_EMAIL = rc('\S@\S')
# RE_RELAX_PHONE = rc('(\(? ?[\d]{2,3} ?\)?.{,3}?){2,}')
# RE_URL = rc(r'''https?://|www\.[\S]+\.[\S]''')
# RE_SEPARATOR = rc('^[\s]*---*[\s]*$')
# RE_SPECIAL_CHARS = rc(('^[\s]*([\*]|#|[\+]|[\^]|-|[\~]|[\&]|[\$]|_|[\!]|'
#                        '[\/]|[\%]|[\:]|[\=]){10,}[\s]*$'))
# RE_SIGNATURE_WORDS = rc(('(T|t)hank.*,|(B|b)est|(R|r)egards|'
#                          '^sent[ ]{1}from[ ]{1}my[\s,!\w]*$|BR|(S|s)incerely|'
#                          '(C|c)orporation|Group'))
# RE_NAME = rc('[A-Z][a-z]+\s\s?[A-Z][\.]?\s\s?[A-Z][a-z]+')
# INVALID_WORD_START = rc('\(|\+|[\d]')
# BAD_SENDER_NAMES = [
#     # known mail domains
#     'hotmail', 'gmail', 'yandex', 'mail', 'yahoo', 'mailgun', 'mailgunhq',
#     'example',
#     # first level domains
#     'com', 'org', 'net', 'ru',
#     # bad words
#     'mailto'
#     ]
# def binary_regex_search(prog):
# def binary_regex_match(prog):
# def flatten_list(list_to_flatten):
# def contains_sender_names(sender):
# def extract_names(sender):
# def categories_percent(s, categories):
# def punctuation_percent(s):
# def capitalized_words_percent(s):
# def many_capitalized_words(s):
# def has_signature(body, sender):


from ... import *
from talon.signature.learning import helpers as h
from talon.signature.learning.helpers import *
from six.moves import range
import regex as re

    for sender, expected_names in senders_names.items():
        extracted_names = h.extract_names(sender)
        # check that extracted names could be compiled
        try:
            re.compile("|".join(extracted_names))
        except Exception as e:
            ok_(False, ("Failed to compile extracted names {}"
                        "\n\nReason: {}").format(extracted_names, e))
        if expected_names:
            for name in expected_names:
                assert_in(name, extracted_names)
        else:
            eq_(expected_names, extracted_names)

    # words like `ru`, `gmail`, `com`, `org`, etc. are not considered
    # sender's names
    for word in h.BAD_SENDER_NAMES:
        eq_(h.extract_names(word), [])

    # duplicates are not allowed
    eq_(h.extract_names("sergey <sergey@example.com"), ["sergey"])


def test_categories_percent():
    eq_(0.0, h.categories_percent("qqq ggg hhh", ["Po"]))
    eq_(50.0, h.categories_percent("q,w.", ["Po"]))
    eq_(0.0, h.categories_percent("qqq ggg hhh", ["Nd"]))
    eq_(50.0, h.categories_percent("q5", ["Nd"]))
    eq_(50.0, h.categories_percent("s.s,5s", ["Po", "Nd"]))

# Path: talon/signature/learning/helpers.py
# RE_EMAIL = rc('\S@\S')
# RE_RELAX_PHONE = rc('(\(? ?[\d]{2,3} ?\)?.{,3}?){2,}')
# RE_URL = rc(r'''https?://|www\.[\S]+\.[\S]''')
# RE_SEPARATOR = rc('^[\s]*---*[\s]*$')
# RE_SPECIAL_CHARS = rc(('^[\s]*([\*]|#|[\+]|[\^]|-|[\~]|[\&]|[\$]|_|[\!]|'
#                        '[\/]|[\%]|[\:]|[\=]){10,}[\s]*$'))
# RE_SIGNATURE_WORDS = rc(('(T|t)hank.*,|(B|b)est|(R|r)egards|'
#                          '^sent[ ]{1}from[ ]{1}my[\s,!\w]*$|BR|(S|s)incerely|'
#                          '(C|c)orporation|Group'))
# RE_NAME = rc('[A-Z][a-z]+\s\s?[A-Z][\.]?\s\s?[A-Z][a-z]+')
# INVALID_WORD_START = rc('\(|\+|[\d]')
# BAD_SENDER_NAMES = [
#     # known mail domains
#     'hotmail', 'gmail', 'yandex', 'mail', 'yahoo', 'mailgun', 'mailgunhq',
#     'example',
#     # first level domains
#     'com', 'org', 'net', 'ru',
#     # bad words
#     'mailto'
#     ]
# def binary_regex_search(prog):
# def binary_regex_match(prog):
# def flatten_list(list_to_flatten):
# def contains_sender_names(sender):
# def extract_names(sender):
# def categories_percent(s, categories):
# def punctuation_percent(s):
# def capitalized_words_percent(s):
# def many_capitalized_words(s):
# def has_signature(body, sender):


# Path: tests/signature/learning/helpers_test.py
from ... import *
from talon.signature.learning import helpers as h
from talon.signature.learning.helpers import *
from six.moves import range
import regex as re


    for sender, expected_names in senders_names.items():
        extracted_names = h.extract_names(sender)
        # check that extracted names could be compiled
        try:
            re.compile("|".join(extracted_names))
        except Exception as e:
            ok_(False, ("Failed to compile extracted names {}"
                        "\n\nReason: {}").format(extracted_names, e))
        if expected_names:
            for name in expected_names:
                assert_in(name, extracted_names)
        else:
            eq_(expected_names, extracted_names)

    # words like `ru`, `gmail`, `com`, `org`, etc. are not considered
    # sender's names
    for word in h.BAD_SENDER_NAMES:
        eq_(h.extract_names(word), [])

    # duplicates are not allowed
    eq_(h.extract_names("sergey <sergey@example.com"), ["sergey"])


def test_categories_percent():
    eq_(0.0, h.categories_percent("qqq ggg hhh", ["Po"]))
    eq_(50.0, h.categories_percent("q,w.", ["Po"]))
    eq_(0.0, h.categories_percent("qqq ggg hhh", ["Nd"]))
    eq_(50.0, h.categories_percent("q5", ["Nd"]))
    eq_(50.0, h.categories_percent("s.s,5s", ["Po", "Nd"]))

    eq_(0.0, h.categories_percent("", ["Po", "Nd"]))