예제 #1
0
파일: process.py 프로젝트: arne-cl/fosay
def pre_morphen(lang, st, ind = 0):
    '''Init's the main morpho-groups before doing morphological generation'''
    st.parent = None
    if is_terminalc(st.type):
        if not st.fixed or is_empty_word(st):
            yield st
            return
        variants = [x for x in lang.words if all(y == concept["tags"] or eqx(y, x, st) for y in concept)] #musteq
        variants = score_tags(variants, st)
        new_variants = []
        if PRINT_TO_CONSOLE and len(variants) > 1: print("CAUTION: Ambiguity in 'pre_morphen' at %s" % st.descr())
        for variant in variants:
            for new_variant in new_variants:
                for f in st.fixed:
                    if variant.attr(f) != new_variant.attr(f):
                        break
                else:
                    break
            else:
                for f in st.fixed: #################################################
                    if variant.attr(f) == NONE_VALUE:
                        print("xxxxxxxxxxxpre_morphenpre_morphenpre_morphenpre_morphen")
                        break#############################################################################################################################
                else:
                    new_variants += [variant]
        variants = new_variants
        if variants == []:
            return
        for variant in variants:
            c = deepcopy(st)
            for f in c.fixed:
                c.attr(f, variant.attr(f))
            yield c
        return

    res = []
    for x in pre_morphen(lang, (st.left + st.blocks + st.right)[ind]):
        c = deepcopy(st)
        if ind < len(c.left):
            c.left[ind] = x
        elif ind < len(c.left + c.blocks):
            c.blocks[ind - len(c.left)] = x
        else:
            c.right[ind - len(c.left + c.blocks)] = x
        x.parent = c
        if not x.refresh(): continue
        res += [c]

    res = the_bests(lang, eupony_score, res)

    for c in res:
        if ind + 1 == len(c.left + c.blocks + c.right):
            yield c
        else:
            for y in pre_morphen(lang, c, ind + 1):
                yield y
예제 #2
0
파일: process.py 프로젝트: arne-cl/fosay
def morphen(lang, st, ind = 0):
    '''Morphological generation'''
    st.parent = None
    if is_terminalc(st.type):
        if is_empty_word(st):
            yield st
            return

        variants = [x for x in lang.words if all(y == concept["tags"] or eqx(y, x, st) for y in concept)] #musteq
        variants = score_tags(variants, st)

        if variants == [] or variants is None: raise Exception("Not found in the '%s' dictionary %s" % (lang.name,  st.descr()))
        if PRINT_TO_CONSOLE and len(variants) > 1:
            tmp = str([x.descr() for x in variants])
            print("CAUTION: Ambiguity in 'morphen' at %s alternatives %d (%s)" % (st.descr(), len(variants), tmp))
        for variant in variants:
            c = deepcopy(st)
            if c.type is None: raise Exception('%s hasn\'t type' % str(st))
            c.text = variant.text
            c.transcription = variant.transcription
            for p in concept: c.attr(p, variant.attr(p))
            yield c
        return
    res = []
    for x in morphen(lang, (st.left+st.blocks+st.right)[ind]):
        c = deepcopy(st)
        if ind < len(c.left):
            c.left[ind] = x
        elif ind < len(c.left + c.blocks):
            c.blocks[ind - len(c.left)] = x
        else:
            c.right[ind - len(c.left + c.blocks)] = x
        x.parent = c
        if not x.refresh():
            continue
        res += [c]

    res = the_bests(lang, eupony_score, res)
    for c in res:
        if ind + 1 == len(c.left+c.blocks+c.right):
            yield c
        else:
            for y in morphen(lang, c, ind + 1):
                yield y