Esempio n. 1
0
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)
Esempio n. 2
0
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)
Esempio n. 3
0
        count = [
            set(w0.root).intersection(w1.root),
            set(w0.flexing).intersection(w1.flexing),
            set(w0.root).intersection(w1.flexing)
            | set(w1.root).intersection(w0.flexing)
        ]

        if any(count):
            return max((1, 2, 3), key=lambda i: len(count[i - 1]))
        else:
            return 0

    return f


relations = get_matrix('relation', latest_dictionary_version())


def count_relations(w0):
    """
    0 -> no terms idd
    1 -> most term idd are shared in root morphem
    2 -> most term idd are shared in flexing morphem
    3 -> most term idd are shared root <-> flexing (crossed)
    :param w0:
    :param w1:
    :return:
    """

    root_w0_relations = set(
        chain.from_iterable(relations[t.index, :].indices for t in w0.root))
Esempio n. 4
0
    #             "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)