Beispiel #1
0
def eliminate_ilr_s0(m,n):
    arr_non_term = elel.init_range(1,m+1,1)
    arr_non_term = elel.mapiv(arr_non_term,lambda i,v:"Aa"+str(i))
    arr_term = elel.init_range(1,n+1,1)
    arr_term = elel.mapiv(arr_term,lambda i,v:"B"+str(i))
    arr = arr_non_term + arr_term 
    s = elel.join(arr,"|")
    s = "A -> " + s
    return(s)
Beispiel #2
0
def get_children(jobj):
    if(isinstance(jobj,list)):
        children = elel.mapiv(jobj,lambda i,r:(i,r))
    elif(isinstance(jobj,dict)):
        children = eded.d2kvlist(jobj)
    elif(isinstance(jobj,tuple)):
        children = elel.mapiv(jobj,lambda i,r:(i,r))
    else:
        children = [(null,jobj)]
    return(children)
Beispiel #3
0
def get_children(jobj):
    ele = jobj.__ele
    if(isinstance(ele,list)):
        children = elel.mapiv(ele,lambda i,chele:_lele2chjobj(i,chele,ele))
    elif(isinstance(ele,dict)):
        items = list(ele.items())
        children = elel.mapiv(items,lambda i,item:_dele2chjobj(i,item,ele))
    elif(isinstance(ele,tuple)):
        children = elel.mapiv(ele,lambda i,chele:_lele2chjobj(i,chele,ele))
    else:
        children =[]
    return(children)
Beispiel #4
0
def eliminate_ilr(arr_alpha,arr_beta,non_term="A"):
    arr_alpha_tmp = elel.mapiv(arr_alpha,lambda i,v:non_term+v)
    arr = arr_alpha_tmp + arr_beta
    s = elel.join(arr,"|")
    s = non_term + " -> " + s
    print(s)
    arr_beta = elel.mapiv(arr_beta,lambda i,v:v+non_term+"'")
    s = elel.join(arr_beta,"|")
    s = non_term + " -> " + s
    print(s)
    arr_alpha = elel.mapiv(arr_alpha,lambda i,v:v+non_term+"'" )
    s = elel.join(arr_alpha,"|")
    s = non_term + "'"  + " -> " + s +"|" + "epsilon"
    print(s)    
Beispiel #5
0
def get_children(plnd):
    '''
        这一步会填充ele.pbreadth,因为get_children之后,父节点就脱离了,完全依赖pbreadth
        这一步会填充ele.ftag,因为当前层的key(dict) seq(list,tuple)  dummy_seq(set)会在这一层决定
        这一步会填充ele.sibseq, 在兄弟中是第几个
        这一步会填充ele.depth, 在兄弟中是第几个
        这一步会填充ele.fpl, 在兄弟中是第几个
        这一步会填充ele['type'] 这个spec info
    '''
    fpl = plnd.ele.fpl  #current fpl  will be used as children pfpl
    jobj = plnd.jobj  #current jobj
    if (isinstance(jobj, dict)):
        ftagl, _ = eded.d2kvlist(jobj)  #get keys-list (ftagl)
    elif (isinstance(jobj, list) or isinstance(jobj, tuple)
          or isinstance(jobj, set)):
        ftagl = elel.init_range(0, len(jobj), 1)
    else:
        ftagl = []  #others all leaf-plnds
    #####
    pfpl = fpl
    chfpls = elel.mapv(ftagl, plfunc.ppl2pl,
                       [pfpl])  #get children-full-pathlist
    #######
    pjobj = jobj
    pele = plnd.ele
    children = elel.mapiv(
        chfpls, init_plnd, [pele, pjobj]
    )  #get all-children,init_plnd-will-fill-pbreadth=ftag=sibseq,fill-parent-ele-children
    return (children)
Beispiel #6
0
def nds2rsh(nds):
    '''
        rsh = nds2rsh(nds)
    '''
    sdfsnds = nds2sdfsnds(nds)
    depths = elel.mapv(sdfsnds,lambda nd:ndgetdepth(nd,nds))
    lns = elel.mapiv(depths,lambda i,depth:"    "*depth+"v"+str(sdfsnds[i].val))
    rsh = elel.join(lns,"\n")
    return(rsh)
Beispiel #7
0
def fpl2fapl(fpl,typel):
    '''
        >>> wfsm[3][0].typel
        ['dict', 'list', 'dict', 'str']
        >>>
        >>> wfsm[3][0].fpl
        ['body', 0, 'type']
        >>>
        >>> plfuncs.fpl2fapl(['body', 0, 'type'],['dict', 'list', 'dict', 'str'])
        ['body', 'l0_', 'type']
    '''
    fapl = elel.mapiv(fpl,lambda i,k,o:kastr.ftag2fatag(k,o[i]),[typel])
    return(fapl)
Beispiel #8
0
def add_col(dtb,colname,colarg):
    '''
        >>> colname
        'five'
        >>> col
        [100, 200, 300, 400, 500]
        >>> parr(add_col(dtb,colname,col))
        {'one': 3, 'two': 1, 'three': 2, 'four': 4, 'five': 100}
        {'one': 8, 'two': 6, 'three': 7, 'four': 9, 'five': 200}
        {'one': 13, 'two': 11, 'three': 12, 'four': 14, 'five': 300}
        {'one': 18, 'two': 16, 'three': 17, 'four': 19, 'five': 400}
        {'one': 23, 'two': 21, 'three': 22, 'four': 24, 'five': 500}
        >>>
    '''
    def map_func(i,v,o1,o2):
        v[o1] = o2[i]
        return(v)
    cvl = colarg2cvl(colarg)
    dtb = elel.mapiv(dtb,map_func,[colname,cvl])
    return(dtb)
Beispiel #9
0
def rslctri(dtb,cond_func,*oargs):
    '''
        #ri  row-index
        #cond_func(ri,row,*oargs)
        >>> ndtb = rslctri(dtb,lambda i,row:(row['two']%2==1)and(i>2))
        >>>
        >>> parr(dtb)
        {'one': 3, 'two': 1, 'three': 2, 'four': 4}
        {'one': 8, 'two': 6, 'three': 7, 'four': 9}
        {'one': 13, 'two': 11, 'three': 12, 'four': 14}
        {'one': 18, 'two': 16, 'three': 17, 'four': 19}
        {'one': 23, 'two': 21, 'three': 22, 'four': 24}
        >>>
        >>> ndtb = rslctri(dtb,lambda i,row:(row['two']%2==1)and(i>2))
        >>>
        >>> parr(ndtb)
        {'one': 23, 'two': 21, 'three': 22, 'four': 24}
        >>>
        
    '''
    conds = elel.mapiv(dtb,cond_func,oargs)
    nseqs = elel.indexes_all(conds,True)
    ndtb = elel.select_seqs(dtb,nseqs)
    return(ndtb)
Beispiel #10
0
def eliminate_ilr_s2(n):
    arr = elel.init_range(1,n+1,1)
    arr = elel.mapiv(arr,lambda i,v:"a"+str(i)+"A'")
    s = elel.join(arr,"|")
    s = "A' -> " + s + "|" + "epsilon"
    return(s)
Beispiel #11
0
def eliminate_ilr_s1(n):
    arr = elel.init_range(1,n+1,1)
    arr = elel.mapiv(arr,lambda i,v:"b"+str(i)+"A'")
    s = elel.join(arr,"|")
    s = "A -> " + s
    return(s)