def translate_ocean(s): if s in script("M:.-'M:.-'n.-T:.A:.-',"): return _rotate_sc(s) elif s in script("s.-S:.U:.-'l.-S:.O:.-'n.-T:.A:.-',"): subst, attr, mode = s return m(subst, mode, attr) elif isinstance(s, AdditiveScript): return AdditiveScript(children=[translate_ocean(c) for c in s])
def p_script_lvl_0(self, p): """ script_lvl_0 : PRIMITIVE LAYER0_MARK | REMARKABLE_ADDITION LAYER0_MARK""" if p[1] == 'E': p[0] = NullScript(layer=0) elif p[1] in REMARKABLE_ADDITION: p[0] = AdditiveScript(character=p[1]) else: p[0] = MultiplicativeScript(character=p[1])
def test_rank2_2d(self): term = sc("O:M:.M:M:.-+M:M:.O:M:.-") root_table = self.dic.tables.root(term) h = self.dic.tables[root_table] first_t = self.dic.tables[h.tables[1]] term = sc(AdditiveScript([first_t.columns[4],first_t.columns[5],first_t.columns[3]]), factorize=True) self.assertEqual(self.dic.tables[term].rank, 2)
def _rotate_sc_additive(s): """ s.-S:.U:.-'l.-S:.O:.-'n.-S:.U:.-',+M:.-'M:.-'n.-S:.U:.-', => n.-S:.U:.-'s.-S:.U:.-'l.-S:.O:.-',+n.-S:.U:.-‘M:.-‘M:.-‘,""" if isinstance(s, AdditiveScript): return AdditiveScript([_rotate_sc(_s) for _s in s]) else: return _rotate_sc(s)
def translate_formes_visuelles(s): """s.u.-'O:M:.-'O:.-',+s.u.-'M:O:.-O:.-'M:.-', => b.-S:.U:.-'O:M:.-'O:.-', + b.-S:.U:.-'M:O:.-O:.-'M:.-',""" def set_bSU_subst(s): subst, attr, mode = s return m(script("b.-S:.U:.-'"), attr, mode) if isinstance(s, AdditiveScript): return AdditiveScript([set_bSU_subst(i) for i in s.children]) else: return set_bSU_subst(s)
def translate_mouvements_et_milieux(s): """i.f.B:.-+u.f.M:.-O:.-' -> i.B:.-+u.M:.-O:.-'""" subst, attr, mode = s assert isinstance(mode, NullScript) if isinstance(subst, AdditiveScript): subst = AdditiveScript([_remove_attr_f(_s) for _s in subst]) else: subst = _remove_attr_f(subst) return m(subst, attr)
def _insert_f_additive(s): """i.B:.-+u.M:.-O:.-' => i.f.B:.-+u.f.M:.-O:.-'""" subst, attr, mode = s assert isinstance(mode, NullScript) if isinstance(subst, AdditiveScript): subst = AdditiveScript([_insert_attr_f(_s) for _s in subst]) else: subst = _insert_attr_f(subst) return m(subst, attr)
def _script(self, p): if len(p) == 3: p[0] = MultiplicativeScript(substance=AdditiveScript(p[1])) elif len(p) == 4: p[0] = MultiplicativeScript(substance=AdditiveScript(p[1]), attribute=AdditiveScript(p[2])) else: p[0] = MultiplicativeScript(substance=AdditiveScript(p[1]), attribute=AdditiveScript(p[2]), mode=AdditiveScript(p[3]))
def pack_factorisation(facto_list): """ :param facto_list: list of script or tuple of factorisation :return: """ _sum = [] for f in facto_list: if isinstance(f, Script): _sum.append(f) else: # tuple of factorisation _sum.append( MultiplicativeScript(children=(pack_factorisation(l_f) for l_f in f))) if len(_sum) == 1: return _sum[0] else: return AdditiveScript(children=_sum)
def test_duplicate_addition(self): script = AdditiveScript(children=[ AdditiveScript(children=[ MultiplicativeScript(character='wa'), MultiplicativeScript(character='wo') ]), AdditiveScript(children=[ MultiplicativeScript(character='j'), AdditiveScript(children=[ MultiplicativeScript(character='i'), MultiplicativeScript(attribute=AdditiveScript( character='M'), substance=AdditiveScript( character='O'), mode=MultiplicativeScript( character='U')) ]) ]) ]) self.assertTrue( all(isinstance(s, MultiplicativeScript) for s in script.children))
def test_reduction_single_add(self): script = self.parser.parse("M:.-',M:.-',S:.-'B:.-'n.-S:.U:.-',_") self.assertIsInstance(script, MultiplicativeScript) script = MultiplicativeScript(substance=AdditiveScript( children=[script])) self.assertIsInstance(script.children[0], MultiplicativeScript)
def add(scripts: List[Script]): layer = max(s.layer for s in scripts) _scripts = [promote(s, layer=layer) for s in scripts] return AdditiveScript(children=_scripts)
def test_str(self): self.assertIsNotNone(MultiplicativeScript(character='A')._str) self.assertIsNotNone(AdditiveScript(character='O')._str)
def p_additive_script_lvl_0(self, p): """ additive_script_lvl_0 : sum_lvl_0""" p[0] = AdditiveScript(children=p[1])
def _additive(self, p): p[0] = AdditiveScript(children=p[1])
def migrate_merge(s0, s1): """migrate just the root s.M:O:.O:O:.- O:O:.M:O:.s.- => O:O:.M:O:.s.- + s.M:O:.O:O:.-""" return AdditiveScript(children=[s0, s1])