示例#1
0
def test_compound_expression_with_word_break_in_relexp(wf):
    sc = parser.compile("CHANGE BEGIN /o/ -> /we/ | #[+consonantal]_ END")[0]
    words = [
        wf.make_word(w) for w in ["ok.to", "a.po.lo", "te.o.lo", "kon.dre.lo"]
    ]
    new_words = [repr(sc.apply(w)) for w in words]
    assert new_words == ["/ok.to/", "/a.po.lo/", "/te.o.lo/", "/kwen.dre.lo/"]
示例#2
0
def test_word_break_final_in_relexp(wf):
    sc = parser.compile("CHANGE BEGIN /o/ -> /u/ | _# END")[0]
    words = [
        wf.make_word(w) for w in ["ok.to", "a.po.lo", "te.o.lo", "kon.dre.lo"]
    ]
    new_words = [repr(sc.apply(w)) for w in words]
    assert new_words == ["/ok.tu/", "/a.po.lu/", "/te.o.lu/", "/kon.dre.lu/"]
示例#3
0
def test_simple_conditional_with_relexp(wf):
    sc = parser.compile("""
    CHANGE BEGIN
      /a/ => /e/ | _[+front]
          => /o/
    END
    """)[0]
    w = wf.make_word("ko'raj.ka")
    nw = sc.apply(w)
    assert repr(nw) == "/ko.'rej.ko/"
示例#4
0
def test_multiple_conditional_with_relexp(wf):
    sc = parser.compile("""
    CHANGE BEGIN
      {/a/, /aː/} => {/e/, /eː/} | _[+front]
                  => {/ə/, /oː/}
    END
    """)[0]

    word1 = wf.make_word("ka.laj'kaː")
    word2 = wf.make_word("paː'jet.na")
    nw1 = sc.apply(word1)
    nw2 = sc.apply(word2)

    assert repr(nw1) == "/kə.lej.'koː/"
    assert repr(nw2) == "/peː.'jet.nə/"
示例#5
0
def test_replace_by_feature_conditional_with_relexp(wf):
    sc = parser.compile("""
    CHANGE BEGIN
      [+sibilant] => /0/ | [-consonantal]_[-consonantal]
                  => /h/
    END
    """)[0]

    words = [
        wf.make_word(w)
        for w in ["sa.lo.ka", "ke.se.nam", "pas.ko.ne", "lak.si.nam", "a.tas"]
    ]
    new_words = [repr(sc.apply(w)) for w in words]
    assert new_words == [
        "/ha.lo.ka/", "/ke.e.nam/", "/pah.ko.ne/", "/lak.hi.nam/", "/a.tah/"
    ]
示例#6
0
def test_change_feature_conditional_with_relexp(wf):
    sc = parser.compile("""
    CHANGE BEGIN
      [+sibilant] => [+voice]    | [-consonantal]_[-consonantal]
                  => [+front]    | _[-consonantal +front]
                  => [+sibilant]
    END
    """)[0]

    w1 = wf.make_word("mak'si.ra")
    w2 = wf.make_word("ma'sa.la")
    w3 = wf.make_word("pe'si.ka")
    w4 = wf.make_word("sa'mo.ŋe")

    nws = [repr(sc.apply(w)) for w in [w1, w2, w3, w4]]
    assert nws == ["/mak.'ɕi.ra/", "/ma.'za.la/", "/pe.'ʑi.ka/", "/sa.'mo.ŋe/"]
示例#7
0
文件: main.py 项目: defseg/PyLaut
def simulate(parent: str, language: str, date=None, project_path='.'):
    "Simulate the sound changes defined for a certain language."
    pp = pathlib.Path(project_path).resolve()
    project_name = pp.name
    if not pp.exists():
        return [
            "Could not find project: {}.".format(project_name),
            " Did you forget to specify a project path?"
        ]
    parent_path = pp / '{}.json'.format(parent)
    language_path = pp / '{}.json'.format(language)
    with parent_path.open() as pjs:
        parent_tree = lt.LanguageTree.from_json(pjs.read())
    with language_path.open() as ljs:
        language_tree = lt.LanguageTree.from_json(ljs.read())

    scp = pathlib.Path(
        language_tree.meta.data_path) / language_tree.meta.change_file_name
    lexp = pathlib.Path(
        parent_tree.meta.data_path) / parent_tree.meta.lexicon_file_name
    new_lexp = pathlib.Path(
        language_tree.meta.data_path) / language_tree.meta.lexicon_file_name
    with lexp.open() as lexf:
        lex = lexf.read()
    with scp.open() as scf:
        sc = scf.read()
    changes = parser.compile(sc)
    words = []
    new_words = []
    for line in lex:
        if line.startswith('#'):
            continue
        else:
            word = line.split()
            words.append(word)
    for word in words:
        for ch in changes:
            word[0] = ch.apply(word[0])
        new_words.append(word)
    with new_lexp.open() as nlf:
        strw = [str(word) for word in new_words]
        nlf.write("\n".join(strw))

    return ['Simulation successful.']
示例#8
0
def test_basic_conditional_sound_change_with_relexp(wf):
    sc = parser.compile("CHANGE BEGIN /a/ -> /e/ | _[+front] END")[0]
    w = wf.make_word("ko'raj.ka")
    nw = sc.apply(w)
    assert repr(nw) == "/ko.'rej.ka/"
示例#9
0
def test_replace_by_feature(wf):
    sc = parser.compile("CHANGE BEGIN [+sibilant] -> /h/ END")[0]
    w = wf.make_word("ma'sa.la")
    nw = sc.apply(w)
    assert repr(nw) == "/ma.'ha.la/"
示例#10
0
def test_change_feature(wf):
    sc = parser.compile("CHANGE BEGIN [+sibilant] -> [+voice] END")[0]
    w = wf.make_word("ma'sa.la")
    nw = sc.apply(w)
    assert repr(nw) == "/ma.'za.la/"
示例#11
0
def test_multiple_unconditional(wf):
    sc = parser.compile("CHANGE BEGIN {/b/,/d/,/ɡ/} -> {/β/,/ð/,/ɣ/} END")[0]
    w = wf.make_word("ba'ɡo.dam")
    nw = sc.apply(w)
    assert repr(nw) == "/βa.'ɣo.ðam/"
示例#12
0
def test_simple_unconditional(wf):
    sc = parser.compile("CHANGE BEGIN /a/ -> /e/ END")[0]
    w = wf.make_word("'at.na")
    nw = sc.apply(w)
    assert repr(nw) == "/'et.ne/"