def translate_update(root, f): update = {'terms': {str(s.script): str(f(s.script)) for s in term(root).relations.contains} } version = create_dictionary_version(latest_dictionary_version(), update=update) upload_to_s3(version) print(version)
def translate_script(to_translate): """ translate the root paradigms in key in argument, with the function in value :param to_translate: :return: """ version = DictionaryVersion(latest_dictionary_version()) version.load() to_remove = [] to_add = { 'terms': [], 'roots': [], 'inhibitions': {}, 'translations': {l: {} for l in LANGUAGES} } for root, func in to_translate.items(): root = script(root) terms = list(filter(lambda s: s in root, map(script, version.terms))) new_root = func(root) new_terms = [func(s) for s in terms] to_add['terms'].extend(map(str, new_terms)) to_add['roots'].append(str(new_root)) to_add['inhibitions'].update({str(new_root): version.inhibitions[root]}) for l in LANGUAGES: to_add['translations'][l].update({str(func(s)): version.translations[l][s] for s in terms}) to_remove.extend(map(str, terms)) return create_dictionary_version(version, add=to_add, remove=to_remove)
def find_and_add_script_to_current_version(to_find): t = reversed(get_available_dictionary_version()) for version in t: version.load() if to_find in version.terms: version = create_dictionary_version(merge=[version]) version.upload_to_s3() break
def find_and_add_script_to_current_version(to_find): t = reversed(get_available_dictionary_version()) for version in t: version.load() if to_find in version.terms: version = create_dictionary_version(merge=[version]) version.upload_to_s3() break
def test_text_translation(self): update = { 'terms': { "n.-S:.U:.-'T:.-'T:.-',M:.-',S:.-',_": "n.-S:.U:.-'T:.-'T:.-',S:.-',M:.-',_" } } v = create_dictionary_version(update=update) p = ieml("/[([([n.-S:.U:.-'T:.-'T:.-',M:.-',S:.-',_])]*[([wa.])]*[([we.])])]/") p.set_dictionary_version(v) self.assertEqual(str(p), "/[([([n.-S:.U:.-'T:.-'T:.-',S:.-',M:.-',_])]*[([wa.])]*[([we.])])]/")
def test_word_translation(self): update = { 'terms': { "n.-S:.U:.-'T:.-'T:.-',M:.-',S:.-',_": "n.-S:.U:.-'T:.-'T:.-',S:.-',M:.-',_" } } v = create_dictionary_version(update=update) p = ieml("[([n.-S:.U:.-'T:.-'T:.-',M:.-',S:.-',_])]") p.set_dictionary_version(v) self.assertEqual(str(p), "[([n.-S:.U:.-'T:.-'T:.-',S:.-',M:.-',_])]")
# **_up # }, # 'remove': { # *_rem # } # } # print('\n'.join("{} => {}".format(a, b) for a, b in _up.items())) # version = create_dictionary_version(latest_dictionary_version(), update=update, remove=_rem) # upload_to_s3(version) # print(version) root = "O:.M:.-M:.-'" translator = translate_ecosystem_intl_col_tern "dictionary_2018-06-08_17:07:06" print(str(translator(script(root)))) d = Dictionary("dictionary_2018-06-08_17:07:06") # translate_update("s.u.-'O:M:.-'O:.-',+s.u.-'M:O:.-O:.-'M:.-',", translate_formes_visuelles) diff = { **{ str(s.script): str(translate_competence_en_curr_data(s.script)) for s in term("M:.-O:.-'M:.-wa.e.-'t.-x.-s.y.-',", d).relations.contains }, # **{str(s.script): str(translate_ecosystem_intl_col_tern(s.script)) for s in term("O:.M:.-M:.-'", d).relations.contains}, } import json print(json.dumps(diff, indent=True)) version = create_dictionary_version(None, diff=diff) # upload_to_s3(version) print(version)
# _up, _rem = get_competence_en_curr_data_diff() # update = {'terms': { # **{str(s.script): str(translate_mouvements_et_milieux(s.script)) for s in term("i.f.B:.-+u.f.M:.-O:.-'").relations.contains}, # **_up # }, # 'remove': { # *_rem # } # } # print('\n'.join("{} => {}".format(a, b) for a, b in _up.items())) # version = create_dictionary_version(latest_dictionary_version(), update=update, remove=_rem) # upload_to_s3(version) # print(version) root = "O:.M:.-M:.-'" translator = translate_ecosystem_intl_col_tern "dictionary_2018-06-08_17:07:06" print(str(translator(script(root)))) d = Dictionary("dictionary_2018-06-08_17:07:06") # translate_update("s.u.-'O:M:.-'O:.-',+s.u.-'M:O:.-O:.-'M:.-',", translate_formes_visuelles) diff = { **{str(s.script): str(translate_competence_en_curr_data(s.script)) for s in term("M:.-O:.-'M:.-wa.e.-'t.-x.-s.y.-',", d).relations.contains}, # **{str(s.script): str(translate_ecosystem_intl_col_tern(s.script)) for s in term("O:.M:.-M:.-'", d).relations.contains}, } import json print(json.dumps(diff, indent=True)) version = create_dictionary_version(None, diff=diff) # upload_to_s3(version) print(version)
# "f.o.-f.o.-'E:.-U:.n.-l.-',E:.-U:.M:T:.-l.-'E:.-A:.M:T:.-l.-',_": "Parties du corps: le tronc", # "f.o.-f.o.-'E:.-U:.t.-l.-',E:.-U:.M:T:.-l.-'E:.-A:.M:T:.-l.-',_": "Parties du corps: la tête", # "f.o.-f.o.-',n.i.-f.i.-',M:O:.-O:.-',_": "Parties du corps: membres", # "f.o.-f.o.-'E:.-U:.S:+B:T:.-l.-',E:.-U:.M:T:.-l.-'E:.-A:.M:T:.-l.-',_": "Parties du corps: la tête et le tronc" # }, # 'en': { # "f.o.-f.o.-',n.i.-f.i.-',M:O:.-O:.-',_+f.o.-f.o.-'E:.-U:.S:+B:T:.-l.-',E:.-U:.M:T:.-l.-'E:.-A:.M:T:.-l.-',_": "body parts", # "f.o.-f.o.-'E:.-U:.n.-l.-',E:.-U:.M:T:.-l.-'E:.-A:.M:T:.-l.-',_": "Body parts: trunk", # "f.o.-f.o.-'E:.-U:.t.-l.-',E:.-U:.M:T:.-l.-'E:.-A:.M:T:.-l.-',_": "Body parts: head", # "f.o.-f.o.-',n.i.-f.i.-',M:O:.-O:.-',_": "body parts: limbs", # "f.o.-f.o.-'E:.-U:.S:+B:T:.-l.-',E:.-U:.M:T:.-l.-'E:.-A:.M:T:.-l.-',_": "Body parts: head and trunk" # # } # } # } # to_remove = ["f.o.-f.o.-'E:.-U:.n.-l.-',E:.-U:.M:T:.-l.-'E:.-A:.M:T:.-l.-',_", # "f.o.-f.o.-'E:.-U:.t.-l.-',E:.-U:.M:T:.-l.-'E:.-A:.M:T:.-l.-',_", # "f.o.-f.o.-',n.i.-f.i.-',M:O:.-O:.-',_" # ] to_remove, to_add = factorize_root( term( "b.i.-n.i.-'l.i.-n.i.-'+m.+l.i.-f.i.-'+wu.f.A:.-+a.S:.-+i.U:.-+e.O:.-+S:+T:T:.i.-'n.o.-n.o.-'+f.o.-f.o.-'+n.-B:.A:.-+S:+B:.U:.-'," )) version = create_dictionary_version(latest_dictionary_version(), add=to_add, remove=to_remove) upload_to_s3(version) print(version)