# Path: chemdataextractor/text/latex.py
# def latex_to_unicode(text, capitalize=False):
#     """Replace LaTeX entities with the equivalent unicode and optionally capitalize.
# 
#     :param text: The LaTeX string to be converted
#     :param capitalize: Can be 'sentence', 'name', 'title', 'upper', 'lower'
#     """
#     if capitalize:
#         res = []
#         brac_count = 0
#         for i, c in enumerate(text):
#             if c == '{':
#                 brac_count += 1
#             if c == '}':
#                 brac_count -= 1
#             if brac_count > 0:
#                 res.append(c)
#             elif capitalize == 'upper' or (i == 0 and not capitalize == 'lower'):
#                 res.append(c.upper())
#             elif capitalize == 'sentence' and (i > 2 and text[i - 1] == ' ' and text[i - 2] == '.'):
#                 res.append(c.upper())
#             elif (capitalize == 'name' and text[i - 1] in [' ', '-']) or (capitalize == 'title' and text[i - 1] == ' '):
#                 nextword = text[i:].split(' ', 1)[0].rstrip(string.punctuation)
#                 nextword = nextword[:1].lower() + nextword[1:] if text else ''
#                 if capitalize == 'name' and nextword in NAME_SMALL:
#                     res.append(c.lower())
#                 elif capitalize == 'title' and nextword in SMALL:
#                     res.append(c.lower())
#                 else:
#                     res.append(c.upper())
#             elif capitalize == 'name' and c == c.upper():
#                 n1 = text[i - 1] if i > 0 else None
#                 n2 = text[i - 2] if i > 1 else None
#                 n3 = text[i - 3] if i > 2 else None
#                 n4 = text[i - 4] if i > 3 else None
#                 if n2 == 'M' and n1 == 'c' and (not n3 or n3 == ' '):
#                     res.append(c)  # McCartney
#                 elif n2 == 'O' and n1 == '\'' and (not n3 or n3 == ' '):
#                     res.append(c)  # O'Boyle
#                 elif n3 == 'M' and n2 == 'a' and n1 == 'c' and (not n4 or n4 == ' '):
#                     res.append(c)  # MacGarry
#                 else:
#                     res.append(c.lower())
#             else:
#                 res.append(c.lower())
#         text = ''.join(res)
#     if any(i in text for i in ['\\', '{', '}', '$', '&', '%', '#', '_']):
#         for k, v in six.iteritems(LATEX_MAPPINGS):
#             text = text.replace(k, v)
#         for k, v in six.iteritems(LATEX_SUB_MAPPINGS):
#             text = text.replace(k, v)
#         for mod in ['mathbb', 'mathbf', 'mathbit', 'mathfrak', 'mathrm', 'mathscr', 'mathsf', 'mathsfbf', 'mathsfbfsl', 
#                     'mathsfsl', 'mathsl', 'mathslbb', 'mathtt']:
#             text = re.sub(r'\\%s\{([\\\w]+)\}' % mod, r'\1', text)
#         for k, v in six.iteritems(LATEX_SUB_SUB_MAPPINGS):
#             text = text.replace(k, v)
#         for k, v in six.iteritems(LATEX_COMBINING_CHARS):
#             text = re.sub(r'%s\{?(\w)\}?' % k, r'\1%s' % v, text)
#         text = re.sub(r'\\noopsort\{.*?\}', r'', text)
#         text = re.sub(r'\\path\|(.*?)\|', r'\1', text)
#         text = re.sub(r'(?<!\\)[{}$]', r'', text)
#         text = re.sub(r'\\([{}$&_])', r'\1', text)
#     return text
# 
# Path: chemdataextractor/text/normalize.py
# @abstractmethod
# def normalize(self, text):
#     """Normalize the text.
# 
#     :param string text: The text to normalize.
#     :returns: Normalized text.
#     :rtype: string
#     """
#     return text
# 
# Path: chemdataextractor/text/processors.py
# def extract_emails(text):
#     """Return a list of email addresses extracted from the string."""
#     text = text.replace(u'\u2024', '.')
#     emails = []
#     for m in EMAIL_RE.findall(text):
#         emails.append(m[0])
#     return emails


import logging
import unittest
from chemdataextractor.text.latex import latex_to_unicode
from chemdataextractor.text.normalize import normalize
from chemdataextractor.text.processors import extract_emails
# -*- coding: utf-8 -*-
"""
test_text
~~~~~~~~~

Test the text package.

"""

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals



logging.basicConfig(level=logging.DEBUG)
log = logging.getLogger(__name__)


class TestNormalization(unittest.TestCase):

    def test_normalize(self):
        """Test normalize function."""
        # Weird control characters
        self.assertEqual(u'The quick brown fox jumped', normalize(u'The\u0003 quick br\u0005own fo\u0008x jumped'))
        # Unusual whitespace characters

# Path: chemdataextractor/text/latex.py
# def latex_to_unicode(text, capitalize=False):
#     """Replace LaTeX entities with the equivalent unicode and optionally capitalize.
# 
#     :param text: The LaTeX string to be converted
#     :param capitalize: Can be 'sentence', 'name', 'title', 'upper', 'lower'
#     """
#     if capitalize:
#         res = []
#         brac_count = 0
#         for i, c in enumerate(text):
#             if c == '{':
#                 brac_count += 1
#             if c == '}':
#                 brac_count -= 1
#             if brac_count > 0:
#                 res.append(c)
#             elif capitalize == 'upper' or (i == 0 and not capitalize == 'lower'):
#                 res.append(c.upper())
#             elif capitalize == 'sentence' and (i > 2 and text[i - 1] == ' ' and text[i - 2] == '.'):
#                 res.append(c.upper())
#             elif (capitalize == 'name' and text[i - 1] in [' ', '-']) or (capitalize == 'title' and text[i - 1] == ' '):
#                 nextword = text[i:].split(' ', 1)[0].rstrip(string.punctuation)
#                 nextword = nextword[:1].lower() + nextword[1:] if text else ''
#                 if capitalize == 'name' and nextword in NAME_SMALL:
#                     res.append(c.lower())
#                 elif capitalize == 'title' and nextword in SMALL:
#                     res.append(c.lower())
#                 else:
#                     res.append(c.upper())
#             elif capitalize == 'name' and c == c.upper():
#                 n1 = text[i - 1] if i > 0 else None
#                 n2 = text[i - 2] if i > 1 else None
#                 n3 = text[i - 3] if i > 2 else None
#                 n4 = text[i - 4] if i > 3 else None
#                 if n2 == 'M' and n1 == 'c' and (not n3 or n3 == ' '):
#                     res.append(c)  # McCartney
#                 elif n2 == 'O' and n1 == '\'' and (not n3 or n3 == ' '):
#                     res.append(c)  # O'Boyle
#                 elif n3 == 'M' and n2 == 'a' and n1 == 'c' and (not n4 or n4 == ' '):
#                     res.append(c)  # MacGarry
#                 else:
#                     res.append(c.lower())
#             else:
#                 res.append(c.lower())
#         text = ''.join(res)
#     if any(i in text for i in ['\\', '{', '}', '$', '&', '%', '#', '_']):
#         for k, v in six.iteritems(LATEX_MAPPINGS):
#             text = text.replace(k, v)
#         for k, v in six.iteritems(LATEX_SUB_MAPPINGS):
#             text = text.replace(k, v)
#         for mod in ['mathbb', 'mathbf', 'mathbit', 'mathfrak', 'mathrm', 'mathscr', 'mathsf', 'mathsfbf', 'mathsfbfsl', 
#                     'mathsfsl', 'mathsl', 'mathslbb', 'mathtt']:
#             text = re.sub(r'\\%s\{([\\\w]+)\}' % mod, r'\1', text)
#         for k, v in six.iteritems(LATEX_SUB_SUB_MAPPINGS):
#             text = text.replace(k, v)
#         for k, v in six.iteritems(LATEX_COMBINING_CHARS):
#             text = re.sub(r'%s\{?(\w)\}?' % k, r'\1%s' % v, text)
#         text = re.sub(r'\\noopsort\{.*?\}', r'', text)
#         text = re.sub(r'\\path\|(.*?)\|', r'\1', text)
#         text = re.sub(r'(?<!\\)[{}$]', r'', text)
#         text = re.sub(r'\\([{}$&_])', r'\1', text)
#     return text
# 
# Path: chemdataextractor/text/normalize.py
# @abstractmethod
# def normalize(self, text):
#     """Normalize the text.
# 
#     :param string text: The text to normalize.
#     :returns: Normalized text.
#     :rtype: string
#     """
#     return text
# 
# Path: chemdataextractor/text/processors.py
# def extract_emails(text):
#     """Return a list of email addresses extracted from the string."""
#     text = text.replace(u'\u2024', '.')
#     emails = []
#     for m in EMAIL_RE.findall(text):
#         emails.append(m[0])
#     return emails


# Path: tests/test_text.py
import logging
import unittest
from chemdataextractor.text.latex import latex_to_unicode
from chemdataextractor.text.normalize import normalize
from chemdataextractor.text.processors import extract_emails

# -*- coding: utf-8 -*-
"""
test_text
~~~~~~~~~

Test the text package.

"""

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals



logging.basicConfig(level=logging.DEBUG)
log = logging.getLogger(__name__)


class TestNormalization(unittest.TestCase):

    def test_normalize(self):
        """Test normalize function."""
        # Weird control characters
        self.assertEqual(u'The quick brown fox jumped', normalize(u'The\u0003 quick br\u0005own fo\u0008x jumped'))
        # Unusual whitespace characters

        self.assertEqual(u'The quick brown fox jumped', normalize(u'The\u00A0quick\u2000brown\u2008fox\u000Bjumped'))