def find_roots_for_partial_input(self, partial_input, whole_surface=None):
        """
        @type partial_input: unicode
        @type whole_surface: unicode
        @rtype: list of Root
        """
        assert partial_input and whole_surface
        assert len(partial_input) <= len(whole_surface)
        assert whole_surface.startswith(partial_input)
        if len(whole_surface) == len(partial_input):
            assert whole_surface == partial_input

        root = partial_input
        lemma = root
        lemma_root = lemma
        syntactic_category = SyntacticCategory.NOUN
        secondary_syntactic_category = None
        lexeme_attributes = set()

        lexeme = DynamicLexeme(lemma, lemma_root, syntactic_category, secondary_syntactic_category,
            lexeme_attributes)

        phonetic_expectations = set()
        phonetic_attributes = Phonetics.calculate_phonetic_attributes(partial_input, lexeme_attributes)

        no_orthographics_root = DynamicRoot(root, lexeme, phonetic_expectations, phonetic_attributes)

        if len(partial_input) < 2 <= len(whole_surface):
            return []

        if whole_surface == partial_input or len(partial_input) < 2:
            return [no_orthographics_root]

        last_vowel = Phonetics.get_last_vowel(partial_input)

        if not last_vowel:
            return [no_orthographics_root]

        last_char = partial_input[-1]
        first_char_after_partial_input = whole_surface[len(partial_input)]
        if last_char.isupper() or first_char_after_partial_input.isupper():
            return [no_orthographics_root]

        roots = self._get_voicing_and_doubling_roots(partial_input, last_char, first_char_after_partial_input,
            no_orthographics_root)

        first_vowel_letter_after_partial_input = self._get_first_vowel(whole_surface[len(partial_input) - 1:])
        if first_vowel_letter_after_partial_input:
            if last_vowel.frontal != first_vowel_letter_after_partial_input.frontal:
                for r in roots:
                    r.lexeme.attributes = set(r.lexeme.attributes)
                    r.lexeme.attributes.add(LexemeAttribute.InverseHarmony)

        for r in roots:
            phonetic_attributes = Phonetics.calculate_phonetic_attributes(r.str, r.lexeme.attributes)
            r.phonetic_attributes = phonetic_attributes

        return roots
예제 #2
0
    def _get_possible_passive_roots(self, last_letter,  partial_input, whole_surface, no_attr_root):
        might_have_Passive_Il = (not last_letter.vowel and any([whole_surface.startswith(partial_input+s) for s in [u'il', u'ıl', u'ul', u'ül']])) or\
                                (last_letter.vowel and whole_surface.startswith(partial_input+ u'l'))

        might_have_Passive_In = (not last_letter.vowel and any([whole_surface.startswith(partial_input+s) for s in [u'in', u'ın', u'un', u'ün']])) or\
                                (last_letter.vowel and whole_surface.startswith(partial_input+ u'n'))

        might_have_Passive_InIl = (not last_letter.vowel and any([whole_surface.startswith(partial_input+s) for s in [u'inil', u'ınıl', u'unul', u'ünül']])) or\
                                  (last_letter.vowel and any([whole_surface.startswith(partial_input+s) for s in [u'nil', u'nıl', u'nul', u'nül']]))

        might_have_passives = {(LexemeAttribute.Passive_Il, might_have_Passive_Il),
                               (LexemeAttribute.Passive_In, might_have_Passive_In),
                               (LexemeAttribute.Passive_InIl, might_have_Passive_InIl)}

        might_have_passives = filter(lambda t : t[1], might_have_passives)

        passive_roots = set()

        for passive_attr, might_have_happened in might_have_passives:
            # cannot have other passives at the same time
            # cannot have any other causative at the same time
            # cannot have progressive vowel drop at the same time
            # cannot have aorist_A or aorist_I at the same time
            generated_root = no_attr_root._clone(True)

            generated_root.lexeme.attributes = {passive_attr} if passive_attr else set()

            generated_root.lexeme.phonetic_attributes = Phonetics.calculate_phonetic_attributes(partial_input, generated_root.lexeme.attributes)

            passive_roots.add(generated_root)

        return passive_roots
예제 #3
0
 def get_phonetic_attributes(self):
     if self.has_transitions():
         suffix_so_far = self.get_surface_so_far()[len(self._root.str):]
         if not suffix_so_far or suffix_so_far.isspace() or not suffix_so_far.isalnum():
             return self._root.phonetic_attributes
         else:
             return Phonetics.calculate_phonetic_attributes(self.get_surface_so_far(), self.get_lexeme_attributes())
     else:
         return self._root.phonetic_attributes
예제 #4
0
 def _set_lexeme_and_phonetic_attributes(self, generated_roots):
     for r in generated_roots:
         r.phonetic_attributes = Phonetics.calculate_phonetic_attributes(r.str, r.lexeme.attributes)
         if r.str.endswith(u'd') and r.lexeme.root.endswith(u't'):
             if LexemeAttribute.NoVoicing in r.lexeme.attributes:
                 r.lexeme.attributes.remove(LexemeAttribute.NoVoicing)
             r.lexeme.attributes.add(LexemeAttribute.Voicing)
         else:
             if LexemeAttribute.Voicing in r.lexeme.attributes:
                 r.lexeme.attributes.remove(LexemeAttribute.Voicing)
             r.lexeme.attributes.add(LexemeAttribute.NoVoicing)
예제 #5
0
 def get_phonetic_attributes(self):
     if self.has_transitions():
         suffix_so_far = self.get_surface_so_far()[len(self._root.str):]
         if not suffix_so_far or suffix_so_far.isspace(
         ) or not suffix_so_far.isalnum():
             return self._root.phonetic_attributes
         else:
             return Phonetics.calculate_phonetic_attributes(
                 self.get_surface_so_far(), self.get_lexeme_attributes())
     else:
         return self._root.phonetic_attributes
예제 #6
0
 def _set_lexeme_and_phonetic_attributes(self, generated_roots):
     for r in generated_roots:
         r.phonetic_attributes = Phonetics.calculate_phonetic_attributes(
             r.str, r.lexeme.attributes)
         if r.str.endswith(u'd') and r.lexeme.root.endswith(u't'):
             if LexemeAttribute.NoVoicing in r.lexeme.attributes:
                 r.lexeme.attributes.remove(LexemeAttribute.NoVoicing)
             r.lexeme.attributes.add(LexemeAttribute.Voicing)
         else:
             if LexemeAttribute.Voicing in r.lexeme.attributes:
                 r.lexeme.attributes.remove(LexemeAttribute.Voicing)
             r.lexeme.attributes.add(LexemeAttribute.NoVoicing)
예제 #7
0
    def _get_possible_causative_roots(self, partial_input, whole_surface,
                                      no_attr_root):
        # no voicing can happen on causative_t
        might_have_Causative_t = whole_surface.startswith(partial_input + u't')

        might_have_Causative_Ir = any([
            whole_surface.startswith(partial_input + s)
            for s in [u'ir', u'ır', u'ur', u'ür']
        ])

        # no voicing can happen on causative_It
        might_have_Causative_It = any([
            whole_surface.startswith(partial_input + s)
            for s in [u'it', u'ıt', u'ut', u'üt']
        ])

        might_have_Causative_Ar = any([
            whole_surface.startswith(partial_input + s)
            for s in [u'ar', u'er']
        ])

        might_have_Causative_dIr = any([whole_surface.startswith(partial_input+s) for s in [u'dir', u'dır', u'dur', u'dür']]) or\
                                   any([whole_surface.startswith(partial_input+s) for s in [u'tir', u'tır', u'tur', u'tür']])

        might_have_causatives = {
            (LexemeAttribute.Causative_t, might_have_Causative_t),
            (LexemeAttribute.Causative_Ir, might_have_Causative_Ir),
            (LexemeAttribute.Causative_It, might_have_Causative_It),
            (LexemeAttribute.Causative_Ar, might_have_Causative_Ar),
            (LexemeAttribute.Causative_dIr, might_have_Causative_dIr)
        }

        might_have_causatives = filter(lambda t: t[1], might_have_causatives)

        causative_roots = set()

        for causative_attr, might_have_happened in might_have_causatives:
            # cannot have other causatives at the same time
            # cannot have any other passive at the same time
            # cannot have progressive vowel drop at the same time
            # cannot have aorist_A or aorist_I at the same time
            generated_root = no_attr_root._clone(True)

            generated_root.lexeme.attributes = {causative_attr
                                                } if causative_attr else set()

            generated_root.lexeme.phonetic_attributes = Phonetics.calculate_phonetic_attributes(
                partial_input, generated_root.lexeme.attributes)

            causative_roots.add(generated_root)

        return causative_roots
예제 #8
0
    def _get_possible_causative_roots(self, partial_input, whole_surface, no_attr_root):
        # no voicing can happen on causative_t
        might_have_Causative_t = whole_surface.startswith(partial_input + u't')

        might_have_Causative_Ir = any([whole_surface.startswith(partial_input+s) for s in [u'ir', u'ır', u'ur', u'ür']])

        # no voicing can happen on causative_It
        might_have_Causative_It = any([whole_surface.startswith(partial_input+s) for s in [u'it', u'ıt', u'ut', u'üt']])

        might_have_Causative_Ar = any([whole_surface.startswith(partial_input+s) for s in [u'ar', u'er']])

        might_have_Causative_dIr = any([whole_surface.startswith(partial_input+s) for s in [u'dir', u'dır', u'dur', u'dür']]) or\
                                   any([whole_surface.startswith(partial_input+s) for s in [u'tir', u'tır', u'tur', u'tür']])

        might_have_causatives = {(LexemeAttribute.Causative_t, might_have_Causative_t),
                                 (LexemeAttribute.Causative_Ir, might_have_Causative_Ir),
                                 (LexemeAttribute.Causative_It, might_have_Causative_It),
                                 (LexemeAttribute.Causative_Ar, might_have_Causative_Ar),
                                 (LexemeAttribute.Causative_dIr, might_have_Causative_dIr)}

        might_have_causatives = filter(lambda t : t[1], might_have_causatives)

        causative_roots = set()

        for causative_attr, might_have_happened in might_have_causatives:
            # cannot have other causatives at the same time
            # cannot have any other passive at the same time
            # cannot have progressive vowel drop at the same time
            # cannot have aorist_A or aorist_I at the same time
            generated_root = no_attr_root._clone(True)

            generated_root.lexeme.attributes = {causative_attr} if causative_attr else set()

            generated_root.lexeme.phonetic_attributes = Phonetics.calculate_phonetic_attributes(partial_input, generated_root.lexeme.attributes)

            causative_roots.add(generated_root)

        return causative_roots
예제 #9
0
    def _get_possible_passive_roots(self, last_letter, partial_input,
                                    whole_surface, no_attr_root):
        might_have_Passive_Il = (not last_letter.vowel and any([whole_surface.startswith(partial_input+s) for s in [u'il', u'ıl', u'ul', u'ül']])) or\
                                (last_letter.vowel and whole_surface.startswith(partial_input+ u'l'))

        might_have_Passive_In = (not last_letter.vowel and any([whole_surface.startswith(partial_input+s) for s in [u'in', u'ın', u'un', u'ün']])) or\
                                (last_letter.vowel and whole_surface.startswith(partial_input+ u'n'))

        might_have_Passive_InIl = (not last_letter.vowel and any([whole_surface.startswith(partial_input+s) for s in [u'inil', u'ınıl', u'unul', u'ünül']])) or\
                                  (last_letter.vowel and any([whole_surface.startswith(partial_input+s) for s in [u'nil', u'nıl', u'nul', u'nül']]))

        might_have_passives = {
            (LexemeAttribute.Passive_Il, might_have_Passive_Il),
            (LexemeAttribute.Passive_In, might_have_Passive_In),
            (LexemeAttribute.Passive_InIl, might_have_Passive_InIl)
        }

        might_have_passives = filter(lambda t: t[1], might_have_passives)

        passive_roots = set()

        for passive_attr, might_have_happened in might_have_passives:
            # cannot have other passives at the same time
            # cannot have any other causative at the same time
            # cannot have progressive vowel drop at the same time
            # cannot have aorist_A or aorist_I at the same time
            generated_root = no_attr_root._clone(True)

            generated_root.lexeme.attributes = {passive_attr
                                                } if passive_attr else set()

            generated_root.lexeme.phonetic_attributes = Phonetics.calculate_phonetic_attributes(
                partial_input, generated_root.lexeme.attributes)

            passive_roots.add(generated_root)

        return passive_roots
예제 #10
0
def ap(word, form_str, lexeme_attributes=None):
    phonetic_attributes = Phonetics.calculate_phonetic_attributes(
        word, lexeme_attributes)
    word, application = Phonetics.apply(word, phonetic_attributes, form_str,
                                        lexeme_attributes)
    return word + application
예제 #11
0
def ap(word, form_str, lexeme_attributes=None):
    phonetic_attributes = Phonetics.calculate_phonetic_attributes(word, lexeme_attributes)
    word, application = Phonetics.apply(word, phonetic_attributes, form_str, lexeme_attributes)
    return word + application