Example #1
0
 def apply_diacritic_type(self, diacritic_dict):
     ''' Simple way to sprinkle in some diacritics into the vowels '''
     for letter, phoneme_ids in diacritic_dict.iteritems():
         for phoneme_id in phoneme_ids:
             if chance(1, top=len(phoneme_ids)):
                 self.mapping[phoneme_id] = Glyph(phoneme_id=phoneme_id, normal=letter)
                 continue
Example #2
0
    def __init__(self, parent_language, parent_orthography=None):

        self.parent_language = parent_language
        # The parent orthography this one is descended from, if any
        self.parent_orthography = parent_orthography
        # A list of languages which can be written in this orthography
        self.languages = []

        self.syllable_division = None

        ## ------------------ Consonants -------------------- ##

        glyph_bank = {'q', 'c', 'x', c_s, 'ph', 'dh', 'cn', 'kn', 'gn'}
        used_apostrophe = 0

        # Allow specification of any symbols that are predefined
        self.mapping = {phoneme: PHONEMES_WRITTEN[phoneme] for phoneme in PHONEMES_WRITTEN}

        # aspirated_plosives = self.parent_language.get_matching_consonants(method='plosive', special='aspirated')
        # unaspirated_plosives = self.parent_language.get_matching_consonants(method='plosive', special=None)

        # if chance(15):
        #     self.syllable_division = '-'

        # Potentially replace aspirated plosives with an apostrophe after it's name
        if chance(15) and not self.syllable_division:
            # used_apostrophe = 1
            self.mapping[251] = Glyph(251, 'p\'', before_consonant='p', at_end='p')  # ph
            self.mapping[252] = Glyph(252, 'b\'', before_consonant='b', at_end='b')  # bh
            self.mapping[253] = Glyph(253, 't\'', before_consonant='t', at_end='t')  # th
            self.mapping[254] = Glyph(254, 'd\'', before_consonant='d', at_end='d')  # dh
            self.mapping[255] = Glyph(255, 'k\'', before_consonant='k', at_end='k')  # kh
            self.mapping[256] = Glyph(256, 'g\'', before_consonant='g', at_end='g')  # gh

        if 'c' in glyph_bank and chance(40):
            glyph_bank.remove('c')
            self.mapping[205] = Glyph(205, 'c')

        # -------- /ny/ phoneme ------- #
        if chance(25):
            self.mapping[230] = Glyph(230, 'kn', after_consonant='n', at_end='n') # cn
            self.mapping[231] = Glyph(231, 'gn', after_consonant='n', at_end='n') #
        
        elif chance(5):
            self.mapping[230] = Glyph(230, 'nh', after_consonant='n', at_end='n') 
            self.mapping[231] = Glyph(231, 'nh', after_consonant='n', at_end='n') 
        # ------------------------------ #

        if chance(35):
            self.mapping[232] = Glyph(232, 'cy', before_consonant='c')
            self.mapping[233] = Glyph(233, 'gy', before_consonant='g')

        if chance(45):
            self.mapping[236] = Glyph(236, 'x', after_consonant='h') # ch, x c_s  xh
        elif chance(35):
            self.mapping[236] = Glyph(236, 'ch', after_consonant='h')
            # self.mapping[237] =  # c_s  gh

        if chance(25):
            self.mapping[215] = Glyph(215, 'x', before_consonant='sh')
            self.mapping[216] = Glyph(216, 'x', before_consonant='sh')


        if chance(25):
            self.mapping[212] = Glyph(212, 'dh') # th

        # Chance of language putting placeholders where missing onsets / codas go
        # if chance(10) and not self.syllable_division:
        #     # (300 and 301 are special - used at syllable onsets which don't start with
        #     # a consonant and syllable codas which don't end with a consonant, respectively
        #     self.mapping[300] = Glyph(300, '-', before_consonant='', at_beginning='', at_end='')
        #     self.mapping[301] = Glyph(301, '-', before_consonant='', at_beginning='', at_end='')

        # Chance to give some variation to the "r" letter
        if chance(35):
            self.mapping[221].at_beginning = 'rh'
        if chance(25) and not self.syllable_division:
            self.mapping[221].normal = 'rr'

        # Chance to give some variation to the "l" letter
        if chance(5):
            self.mapping[224].at_beginning = 'lh'
        if chance(5):
            self.mapping[224].at_end = 'll'
        if chance(15 and not self.syllable_division):
            self.mapping[224].normal = 'll'

        # Some variation for the "m" and "n" letters
        if chance(15) and not self.syllable_division:
            self.mapping[218].normal = 'mm'
        if chance(15) and not self.syllable_division:
            self.mapping[219].normal = 'nn'
        

        ## ------------------ Vowels -------------------- ##


        if chance(85):
            diacritic_types = ['left_accent', 'right_accent', 'carrot', 'umlaut']
            chosen_types = []

            number_of_diacritics = random.choice((1, 2, 2, 2, 3))

            for _ in xrange(number_of_diacritics):
                diacritic = diacritic_types.pop(random.randrange(len(diacritic_types)))
                chosen_types.append(diacritic)

            if 'left_accent'  in chosen_types:  self.apply_diacritic_type(diacritic_dict=LEFT_ACCENTS)
            if 'right_accent' in chosen_types:  self.apply_diacritic_type(diacritic_dict=RIGHT_ACCENTS)
            if 'carrot'       in chosen_types:  self.apply_diacritic_type(diacritic_dict=CARROTS)
            if 'umlaut'       in chosen_types:  self.apply_diacritic_type(diacritic_dict=UMLAUTS)

        if chance(10):
            self.mapping[105] = Glyph(105, ae)