# Path: latin/latin_syllable.py
# def separate_syllaba(word_uc):
#     def type(ch):
#         return VOWEL if is_vowel(ch) else CONSONANT
# 
#     last_type = None
#     chunks = []
#     for ch in word_uc:
#         curr_type = type(ch)
#         if last_type != curr_type:
#             chunks.append([curr_type])
#             last_type = curr_type
#         chunks[-1].append(ch)
#     # caesar: [1 c] [0 a e] [1 s] [0 a] [1 r]
#     # novembris: [1 n] [0 o] [1 v] [0 e] [1 m b r] [0 i] [1 s]
#     # deus: [1 d] [0 e u] [1 s]
# 
#     chunks = map(joint, chunks)
#     # caesar: [1 c] [0 ae] [1 s] [0 a] [1 r]
#     # novembris: [1 n] [0 o] [1 v] [0 e] [1 m br] [0 i] [1 s]
#     # deus: [1 d] [0 e u] [1 s]
# 
#     pre = []
#     vowel = []
# 
#     res = []
# 
#     for i, chunk in enumerate(chunks):
#         if chunk[0] == VOWEL:
#             vowel = chunk[1:]
#         else: # consonant
#             if len(chunk[1:]) == 1:
#                 # 排出
#                 if vowel != []:
#                     if len(vowel) == 2 and i == len(chunks)-1:
#                         res.append(pre + vowel[:1] + [])
#                         res.append(vowel[1:] + chunk[1:])
#                         pre = []
#                         vowel = []
#                     else:
#                         res.append(pre + vowel + [])
#                         pre = chunk[1:]
#                         vowel = []
#                 else:
#                     pre = chunk[1:]
#             else:
#                 res.append(pre + vowel + [chunk[1]])
#                 pre = chunk[2:]
#                 vowel = []
# 
#     if vowel != []:
#         res.append(pre + vowel)
#     elif pre != []:
#         if res:
#             res[-1] += pre
#         else:
#             res = pre
#     # caesar: [c ae] [s a r]
#     # novembris: [n o] [v e m] [br i s]
#     # deus: [d e] [u s]
# 
#     syl = [u''.join(r) for r in res]
#     # caesar: [cae sar]
#     # novembris: [no vem bris]
#     # deus: [de us]
# 
#     return syl
# 
# def locate_accent(syllables):
#     def is_long(syl):
#         if is_vowel(syl[-1]):
#             return syl[-1] in [u'ā', u'ē', u'ī', u'ō', u'ū', u'ȳ']
#         else:
#             return True
#     len_syl = len(syllables)
#     if len_syl == 1:
#         return None
#     elif len_syl == 2:
#         return 0
#     elif len_syl >= 3:
#         paenultima = len_syl-2
#         if is_long(syllables[paenultima]):
#             return paenultima
#         else:
#             return paenultima-1


from latin.latin_syllable import separate_syllaba, locate_accent
import unittest
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# A=ā E=ē I=ī O=ō U=ū Y=ȳ


class SyllabaTestCase(unittest.TestCase):
    def assertSep(self, word_utf8, expected_separation_utf8):
        syllables = separate_syllaba(word_utf8.decode('utf-8'))
        actual_separation_utf8 = (u'-'.join(syllables)).encode('utf-8')
        self.assertEqual(actual_separation_utf8, expected_separation_utf8)

    def assertAccent(self, word_utf8, expected_accent_utf8):

# Path: latin/latin_syllable.py
# def separate_syllaba(word_uc):
#     def type(ch):
#         return VOWEL if is_vowel(ch) else CONSONANT
# 
#     last_type = None
#     chunks = []
#     for ch in word_uc:
#         curr_type = type(ch)
#         if last_type != curr_type:
#             chunks.append([curr_type])
#             last_type = curr_type
#         chunks[-1].append(ch)
#     # caesar: [1 c] [0 a e] [1 s] [0 a] [1 r]
#     # novembris: [1 n] [0 o] [1 v] [0 e] [1 m b r] [0 i] [1 s]
#     # deus: [1 d] [0 e u] [1 s]
# 
#     chunks = map(joint, chunks)
#     # caesar: [1 c] [0 ae] [1 s] [0 a] [1 r]
#     # novembris: [1 n] [0 o] [1 v] [0 e] [1 m br] [0 i] [1 s]
#     # deus: [1 d] [0 e u] [1 s]
# 
#     pre = []
#     vowel = []
# 
#     res = []
# 
#     for i, chunk in enumerate(chunks):
#         if chunk[0] == VOWEL:
#             vowel = chunk[1:]
#         else: # consonant
#             if len(chunk[1:]) == 1:
#                 # 排出
#                 if vowel != []:
#                     if len(vowel) == 2 and i == len(chunks)-1:
#                         res.append(pre + vowel[:1] + [])
#                         res.append(vowel[1:] + chunk[1:])
#                         pre = []
#                         vowel = []
#                     else:
#                         res.append(pre + vowel + [])
#                         pre = chunk[1:]
#                         vowel = []
#                 else:
#                     pre = chunk[1:]
#             else:
#                 res.append(pre + vowel + [chunk[1]])
#                 pre = chunk[2:]
#                 vowel = []
# 
#     if vowel != []:
#         res.append(pre + vowel)
#     elif pre != []:
#         if res:
#             res[-1] += pre
#         else:
#             res = pre
#     # caesar: [c ae] [s a r]
#     # novembris: [n o] [v e m] [br i s]
#     # deus: [d e] [u s]
# 
#     syl = [u''.join(r) for r in res]
#     # caesar: [cae sar]
#     # novembris: [no vem bris]
#     # deus: [de us]
# 
#     return syl
# 
# def locate_accent(syllables):
#     def is_long(syl):
#         if is_vowel(syl[-1]):
#             return syl[-1] in [u'ā', u'ē', u'ī', u'ō', u'ū', u'ȳ']
#         else:
#             return True
#     len_syl = len(syllables)
#     if len_syl == 1:
#         return None
#     elif len_syl == 2:
#         return 0
#     elif len_syl >= 3:
#         paenultima = len_syl-2
#         if is_long(syllables[paenultima]):
#             return paenultima
#         else:
#             return paenultima-1


# Path: test/latin_syllable_test.py
from latin.latin_syllable import separate_syllaba, locate_accent
import unittest

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# A=ā E=ē I=ī O=ō U=ū Y=ȳ


class SyllabaTestCase(unittest.TestCase):
    def assertSep(self, word_utf8, expected_separation_utf8):
        syllables = separate_syllaba(word_utf8.decode('utf-8'))
        actual_separation_utf8 = (u'-'.join(syllables)).encode('utf-8')
        self.assertEqual(actual_separation_utf8, expected_separation_utf8)

    def assertAccent(self, word_utf8, expected_accent_utf8):

        syllables = separate_syllaba(word_utf8.decode('utf-8'))