示例#1
0
def metathesis(left, right):
    pl = make_predicate(left)
    pr = make_predicate(right)

    def exchange(this):
        current = this.phonemes.index(this.phoneme)
        sylidx = this.syllable.phonemes.index(this.phoneme)
        try:
            next = this.phonemes[current + 1]
        except IndexError:
            return
        this.phonemes[current] = next
        this.phonemes[current + 1] = this.phoneme
        this.syllable.phonemes[sylidx] = next
        try:
            this.syllable.phonemes[sylidx + 1] = this.phoneme
        except IndexError:
            cursyl = this.syllables.index(this.syllable)
            this.syllables[cursyl + 1].phonemes[0] = this.phoneme
        this.advance()
        return next

    def defer(this):
        return exchange(this)

    return change.Change().do(defer).to(change.This.forall(Phone)(pl)).when(
        change.This.at(Phone, 1, pr))
示例#2
0
def intervocal_voicing(this):
    return change.Change().do(
        lambda this: change_functions.change_feature(
            this.phoneme, "voice", True)).to(
            change.This.forall(Phone)(make_predicate(this))).when(
                change.This.at(Phone, -1, lambda p: p.is_vowel())).when(
                    change.This.at(Phone, 1, lambda p: p.is_vowel()))
示例#3
0
def epenthesis(this, phoneme):
    p = make_predicate(this)

    if len(phoneme) == 1:
        phoneme = phoneme[0]

    def epenthesize(td, p=p, t=phoneme):
        if p(td.phoneme):
            cur_idx = td.phonemes.index(td.phoneme)
            syl_idx = td.syllable.phonemes.index(td.phoneme)
            td.phonemes.insert(cur_idx + 1, t)
            td.syllable.phonemes.insert(syl_idx + 1, t)
            td.advance()
            return td.phoneme
        return td.phoneme

    return change.Change().do(epenthesize).to(change.This.forall(Phone)(p))
示例#4
0
def lengthen(phone):
    return change.Change().do(
        lambda this: change_functions.change_feature(
            this.phoneme, "long", True)
    ).to(change.This.forall(Phone)(make_predicate(phone)))
示例#5
0
def merge(phonemes, target):
    target = target[0]
    phonemes = [p[0] for p in phonemes]
    return change.Change().do(lambda _: target).to(
        change.This.forall(Phone)(
            lambda p: any(p.is_symbol(b.symbol) for b in phonemes)))