How to use the cltk.phonology.orthophonology.AbstractPhoneme function in cltk

To help you get started, we’ve selected a few cltk examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cltk / cltk / cltk / phonology / orthophonology.py View on Github external
def merge(self, other):
        if isinstance(other, Consonant):
            return other
        else:
            return AbstractPhoneme.merge(self, other)
github cltk / cltk / cltk / phonology / orthophonology.py View on Github external
specifying whether the phoneme occurs at a word or syllable boundary,
    or its position in an environment.
    """

    pos_phoneme = deepcopy(phoneme)
    pos_phoneme.word_initial = word_initial
    pos_phoneme.word_final = word_final
    pos_phoneme.syllable_initial = syllable_initial
    pos_phoneme.syllable_final = syllable_final
    pos_phoneme.env_start = env_start
    pos_phoneme.env_end = env_end

    return pos_phoneme


class AlwaysMatchingPseudoPhoneme(AbstractPhoneme):
    """
    A pseudo-phoneme that matches all other phonemes.
    """

    def __init__(self):
        AbstractPhoneme.__init__(self, ipa='*')

    def matches(self, other):
        return True


class WordBoundaryPseudoPhoneme(AbstractPhoneme):
    """
    A pseudo-phoneme that only matches at the start or end of a word.
    """
github cltk / cltk / cltk / phonology / orthophonology.py View on Github external
def __init__(self, *phonemes):
        super().__init__(self)
        if any([not isinstance(p, AbstractPhoneme) and
                not isinstance(p, PhonologicalFeature) and
                not isinstance(p, list) for p in phonemes]):
            raise TypeError(phonemes)
        true_phonemes = [make_phoneme(p) if not isinstance(p, AbstractPhoneme) else p for p in phonemes]
        self.extend(true_phonemes)
github cltk / cltk / cltk / phonology / orthophonology.py View on Github external
def __init__(self, height, backness, rounded, length, ipa):
        assert height is not None
        assert backness is not None
        assert rounded is not None
        assert length is not None
        assert ipa is not None

        AbstractPhoneme.__init__(self, {
            Consonantal: Consonantal.neg,
            Height: height,
            Backness: backness,
            Roundedness: rounded,
            Length: length},
                                 ipa)
github cltk / cltk / cltk / phonology / orthophonology.py View on Github external
class WordBoundaryPseudoPhoneme(AbstractPhoneme):
    """
    A pseudo-phoneme that only matches at the start or end of a word.
    """

    def __init__(self):
        AbstractPhoneme.__init__(self, ipa='#')

    def matches(self, other):
        return other is None

    def is_equal(self, other):
        return self is other


class SyllableBoundaryPseudoPhoneme(AbstractPhoneme):
    """
    A pseudo-phoneme that matches at word boundaries
    and matches positioned phonemes that are at syllable boundaries.
    """

    def __init__(self):
        AbstractPhoneme.__init__(self, ipa='$')

    def matches(self, other):
        if other is None:
            return True
        elif getattr(self, 'env_start', False) and getattr(other, 'syllable_final', False):
            return True
        elif getattr(self, 'env_end', False) and getattr(other, 'syllable_initial', False):
            return True
        else:
github cltk / cltk / cltk / phonology / orthophonology.py View on Github external
return pos_phoneme


class AlwaysMatchingPseudoPhoneme(AbstractPhoneme):
    """
    A pseudo-phoneme that matches all other phonemes.
    """

    def __init__(self):
        AbstractPhoneme.__init__(self, ipa='*')

    def matches(self, other):
        return True


class WordBoundaryPseudoPhoneme(AbstractPhoneme):
    """
    A pseudo-phoneme that only matches at the start or end of a word.
    """

    def __init__(self):
        AbstractPhoneme.__init__(self, ipa='#')

    def matches(self, other):
        return other is None

    def is_equal(self, other):
        return self is other


class SyllableBoundaryPseudoPhoneme(AbstractPhoneme):
    """
github cltk / cltk / cltk / phonology / orthophonology.py View on Github external
return AbstractPhoneme.merge(self, other)

    def geminate(self):
        """
        Returns a new Consonant with its Geminate pos,
        and "ː" appended to its IPA symbol.
        """
        consonant = deepcopy(self)

        if consonant[Geminate] == Geminate.neg:
            consonant[Geminate] = Geminate.pos
            consonant.ipa += 'ː'
        return consonant


class Vowel(AbstractPhoneme):
    """
    The representation of a vowel by its features, as given in the IPA chart for vowels.
    See http://www.ipachart.com/
    """

    def __init__(self, height, backness, rounded, length, ipa):
        assert height is not None
        assert backness is not None
        assert rounded is not None
        assert length is not None
        assert ipa is not None

        AbstractPhoneme.__init__(self, {
            Consonantal: Consonantal.neg,
            Height: height,
            Backness: backness,
github cltk / cltk / cltk / phonology / orthophonology.py View on Github external
"""
        other = make_phoneme(other) if not (isinstance(other, AbstractPhoneme) or
                                            isinstance(other, PhonemeDisjunction)) \
            else other
        env_start = [PositionedPhoneme(phoneme, env_start=True) for phoneme in self]
        env_end = PositionedPhoneme(other, env_end=True)
        return lambda before, _, after: any([phoneme <= before for phoneme in env_start]) and env_end <= after

    def __le__(self, other):
        return False if other is None else self.matches(other)

    def __ge__(self, other):
        return False if other is None else other.matches(self)


class Consonant(AbstractPhoneme):
    """
    Based on cltk.phonology.utils by @clemsciences.
    A consonant is a phoneme that is specified for the features listed in the IPA chart for consonants:
    Place, Manner, Voicing.  These may be read directly off the IPA chart, which also gives the IPA symbol.
    The Consonantal feature is set to positive, and the aspirated is defaulted to negative.
    See http://www.ipachart.com/
    """

    def __init__(self, place, manner, voiced, ipa, geminate=Geminate.neg, aspirated=Aspirated.neg):
        assert place is not None
        assert manner is not None
        assert voiced is not None
        assert geminate is not None
        assert ipa is not None

        AbstractPhoneme.__init__(self, {
github cltk / cltk / cltk / phonology / orthophonology.py View on Github external
def make_phoneme(*feature_values):
    """
    Creates an abstract phoneme made of the feature specifications given in the vararg.
    """
    phoneme = AbstractPhoneme({})
    phoneme = phoneme << feature_values
    return phoneme