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/"]
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/"]
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/"
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ə/"
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/" ]
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/"]
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.']
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/"
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/"
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/"
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/"
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/"