Beispiel #1
0
    def allomorph(self,
                  word,
                  morph,
                  tolerance_style=DEFAULT_TOLERANCE_STYLE,
                  guess_coda=DEFAULT_GUESS_CODA):
        """Determines one of allomorphic morphs based on a word.

        .. see also:: :meth:`allomorph`.

        """
        suffix = self.match(morph)
        if suffix is None:
            return None
        coda = guess_coda(word)
        if coda is not None:
            # Coda guessed successfully.
            morph = self.rule(coda)
        elif isinstance(tolerance_style, text_type):
            # User specified the style themselves
            morph = tolerance_style
        elif not suffix or not is_consonant(suffix[0]):
            # Choose the tolerant morph.
            morph = self.tolerance(tolerance_style)
        else:
            # Suffix starts with a consonant.  Generate a new tolerant morph
            # by combined morphs.
            morph1 = (combine_words(self.morph1, suffix)
                      if self.morph1 else suffix[1:])
            morph2 = (combine_words(self.morph2, suffix)
                      if self.morph2 else suffix[1:])
            tolerances = generate_tolerances(morph1, morph2)
            return get_tolerance_from_iterator(tolerances, tolerance_style)
        return combine_words(morph, suffix)
Beispiel #2
0
def test_particle_tolerances():
    t = lambda _1, _2: set(generate_tolerances(_1, _2))
    s = lambda x: set(x.split())
    assert t(u'이', u'가') == s(u'이(가) (이)가 가(이) (가)이')
    assert t(u'이', u'') == s(u'(이)')
    assert t(u'으로', u'로') == s(u'(으)로')
    assert t(u'이여', u'여') == s(u'(이)여')
    assert t(u'이시여', u'시여') == s(u'(이)시여')
    assert t(u'아', u'야') == s(u'아(야) (아)야 야(아) (야)아')
    assert \
        t(u'가나다', u'나나다') == \
        s(u'가(나)나다 (가)나나다 나(가)나다 (나)가나다')
    assert \
        t(u'가나다', u'마바사') == \
        s(u'가나다(마바사) (가나다)마바사 마바사(가나다) (마바사)가나다')
Beispiel #3
0
def test_particle_tolerances():
    t = lambda _1, _2: set(generate_tolerances(_1, _2))
    s = lambda x: set(x.split())
    assert t(u'이', u'가') == s(u'이(가) (이)가 가(이) (가)이')
    assert t(u'이', u'') == s(u'(이)')
    assert t(u'으로', u'로') == s(u'(으)로')
    assert t(u'이여', u'여') == s(u'(이)여')
    assert t(u'이시여', u'시여') == s(u'(이)시여')
    assert t(u'아', u'야') == s(u'아(야) (아)야 야(아) (야)아')
    assert \
        t(u'가나다', u'나나다') == \
        s(u'가(나)나다 (가)나나다 나(가)나다 (나)가나다')
    assert \
        t(u'가나다', u'마바사') == \
        s(u'가나다(마바사) (가나다)마바사 마바사(가나다) (마바사)가나다')
Beispiel #4
0
 def tolerances(self):
     """The tuple containing all the possible tolerant morphs."""
     return tuple(generate_tolerances(self.morph1, self.morph2))