def test_tar(self): words = sce.apply_ruleset(['a'], 'a>') changed_word = str(words[0]) self.assertEqual(changed_word, '')
def test_final_addition_change(self): words = sce.apply_ruleset(['ac'], '+b/_#') changed_word = str(words[0]) self.assertEqual(changed_word, 'acb')
def test_final_subtraction_change(self): words = sce.apply_ruleset(['bacb'], '-b/_#') changed_word = str(words[0]) self.assertEqual(changed_word, 'bac')
def test_simple_multrep_in_tar_and_rep(self): words = sce.apply_ruleset(['cacbc'], 'a,b>d,e') changed_word = str(words[0]) self.assertEqual(changed_word, 'cdcec')
def test_complex_multrep_in_tar_and_rep(self): words = sce.apply_ruleset(['cacabc'], 'a@-1,b>d,e') changed_word = str(words[0]) self.assertEqual(changed_word, 'cacdec')
def test_category_metathesis(self): ruleset = ['x=a,b', 'y=c,d', '[x][y]><'] words = sce.apply_ruleset(['acbccbdca'], ruleset) changed_word = str(words[0]) self.assertEqual(changed_word, 'cacbcdbca')
def test_at_symbol_with_negative_index(self): words = sce.apply_ruleset(['aaaa'], 'a@-1>b') changed_word = str(words[0]) self.assertEqual(changed_word, 'aaab')
def test_subtract_unnamed_cat(self): words = sce.apply_ruleset(['abcd'], '-[b,c]') changed_word = str(words[0]) self.assertEqual(changed_word, 'ad')
def test_multiple_rules_with_single_ignore_flag(self): ruleset = ['a>b', 'b>c ignore', 'c>d'] words = sce.apply_ruleset(['abcd'], ruleset) changed_word = str(words[0]) self.assertEqual(changed_word, 'bbdd')
def test_only_unnamed_cat_in_target(self): words = sce.apply_ruleset(['abc'], '[a,b]>c') changed_word = str(words[0]) self.assertEqual(changed_word, 'ccc')
def test_unnamed_cat_and_non_cat_in_target(self): words = sce.apply_ruleset(['abacbccc'], '[a,b]c>d') changed_word = str(words[0]) self.assertEqual(changed_word, 'abddcc')
def test_subtract_cat(self): ruleset = ['x=b,c', '-[x]'] words = sce.apply_ruleset(['abcd'], ruleset) changed_word = str(words[0]) self.assertEqual(changed_word, 'ad')
def test_cat_and_non_cat_in_target(self): ruleset = ['x=a,b', 'd[x]>c'] words = sce.apply_ruleset(['abcdadbdc'], ruleset) changed_word = str(words[0]) self.assertEqual(changed_word, 'abcccdc')
def test_only_cat_in_target(self): ruleset = ['x=a,b', '[x]>c'] words = sce.apply_ruleset(['abc'], ruleset) changed_word = str(words[0]) self.assertEqual(changed_word, 'ccc')
def test_single_rule_with_ignore_flag(self): words = sce.apply_ruleset(['a'], 'a>b ignore') changed_word = str(words[0]) self.assertEqual(changed_word, 'a')
def test_unconditional_stop_flag(self): ruleset = ['a>b stop', 'b>c'] words = sce.apply_ruleset(['abc'], ruleset) changed_word = str(words[0]) self.assertEqual(changed_word, 'bbc')
import copy from context import conlanger from conlanger import core, sce words = [] with open('input.txt', 'r') as f: for line in f: words.append(core.Word(lexeme=line[:-1])) with open('rules.txt', 'r') as f: parsed_words = sce.apply_ruleset(copy.deepcopy(words), f.read(), debug=True) for word_in, word_out in zip(words, parsed_words): print(f"{word_in} → {word_out}")
def test_non_matching_conditional_stop_flag(self): ruleset = ['a>b/_# stop', 'b>c'] words = sce.apply_ruleset(['abc'], ruleset) changed_word = str(words[0]) self.assertEqual(changed_word, 'acc')
def test_nonce_category_metathesis(self): words = sce.apply_ruleset(['acbccbdca'], '[a,b][c,d]><') changed_word = str(words[0]) self.assertEqual(changed_word, 'cacbcdbca')
def test_non_matching_ditto_flag(self): ruleset = ['a>b/_#', '+d ditto'] words = sce.apply_ruleset(['abc'], ruleset) changed_word = str(words[0]) self.assertEqual(changed_word, 'abc')
def test_at_symbol_with_pipe(self): words = sce.apply_ruleset(['aaaa'], 'a@0|2>b') changed_word = str(words[0]) self.assertEqual(changed_word, 'baba')
def test_null_value_repeat_flag(self): words = sce.apply_ruleset(['baaa'], 'a>b/b_ repeat') changed_word = str(words[0]) self.assertEqual(changed_word, 'bbbb')
def test_basic_metathesis(self): words = sce.apply_ruleset(['abba'], 'ab><') changed_word = str(words[0]) self.assertEqual(changed_word, 'baba')
def test_overflowing_repeat_flag(self): words = sce.apply_ruleset(['baaa'], 'a>b/c_ repeat') changed_word = str(words[0]) self.assertEqual(changed_word, 'baaa')
def test_medial_addition_change(self): words = sce.apply_ruleset(['ac'], '+b/a_c') changed_word = str(words[0]) self.assertEqual(changed_word, 'abc')
def test_given_value_age_flag(self): ruleset = ['a>b age:2', 'b>a'] words = sce.apply_ruleset(['aaa'], ruleset) changed_word = str(words[0]) self.assertEqual(changed_word, 'bbb')
def test_initial_subtraction_change(self): words = sce.apply_ruleset(['babc'], '-b/#_') changed_word = str(words[0]) self.assertEqual(changed_word, 'abc')
def test_null_value_age_flag(self): ruleset = ['a>b age', '+a/_b', '+a/_b', '+a/_b'] words = sce.apply_ruleset(['a'], ruleset) changed_word = str(words[0]) self.assertEqual(changed_word, 'bbbbbbbb')
def test_standard_change(self): words = sce.apply_ruleset(['a'], 'a>b') changed_word = str(words[0]) self.assertEqual(changed_word, 'b')
def test_tar_rep_env_exc_else(self): words = sce.apply_ruleset(['baba'], 'a>d/b_!_#>c') changed_word = str(words[0]) self.assertEqual(changed_word, 'bdbc')