示例#1
0
def _name2ilocs(rowname,colname,**kwargs):
    if('index_map' in kwargs):
        index_map = kwargs['index_map']
    else:
        df = kwargs['DF']
        index_map = _index_map(df)
    if('columns_map' in kwargs):
        columns_map = kwargs['columns_map']
    else:
        df = kwargs['DF']
        columns_map = _columns_map(df)
    kl,vl =   eded.d2kvlist(index_map)
    rlocs = elel.indexes_all(vl,rowname)
    kl,vl =   eded.d2kvlist(columns_map)
    clocs = elel.indexes_all(vl,colname)
    return((rlocs,clocs))
示例#2
0
def _insert_cols(df,pos,*args,**kwargs):
    df = copy.deepcopy(df)
    if(isinstance(pos,int)):
        pass
    else:
        clocs = _cn2clocs(pos,**kwargs)
        if('which' in kwargs):
            which = kwargs['which']
        else:
            which = 0
        pos = clocs[which] + 1
    args = list(args)
    if(isinstance(args[0],dict)):
        kl,vl = eded.d2kvlist(args[0])
    else:
        if(isinstance(args[1],list)):
            kl =  elel.select_evens(args)
            vl =  elel.select_odds(args)
        else:
            kl,vl = elel.brkl2kvlist(args,df.index.__len__()+1)
    for i in range(kl.__len__()):
        colname = kl[i]
        values = vl[i]
        df.insert(pos+i,colname,values,kwargs['allow_duplicates'])
    return(df)
示例#3
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)
示例#4
0
文件: dtable.py 项目: ihgazni2/dtable
def get_cnl(dtb):
    '''
        get_cnl(dtb)
        ['one', 'two', 'three', 'four']
    '''
    row = dtb[0]
    kl,vl = eded.d2kvlist(row)
    return(kl)
示例#5
0
def _cn2clocs(colname,**kwargs):
    if('columns_map' in kwargs):
        columns_map = kwargs['columns_map']
    else:
        df = kwargs['DF']
        columns_map = _columns_map(df)
    kl,vl =   eded.d2kvlist(columns_map)
    clocs = elel.indexes_all(vl,colname)
    clocs.sort()
    return(clocs)
示例#6
0
def _rn2rlocs(rowname,**kwargs):
    if('index_map' in kwargs):
        index_map = kwargs['index_map']
    else:
        df = kwargs['DF']
        index_map = _index_map(df)
    kl,vl =   eded.d2kvlist(index_map)
    rlocs = elel.indexes_all(vl,rowname)
    rlocs.sort()
    return(rlocs)
示例#7
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)
示例#8
0
def _repl_cols(df,poses,*args,**kwargs):
    df = copy.deepcopy(df)
    args = list(args)
    if(isinstance(args[0],dict)):
        kl,vl = eded.d2kvlist(args[0])
    else:
        if(isinstance(args[1],list)):
            kl =  elel.select_evens(args)
            vl =  elel.select_odds(args)
        else:
            kl,vl = elel.brkl2kvlist(args,df.index.__len__()+1)
    if(isinstance(poses[0],int)):
        pass
    else:
        colnames = poses 
        clocs_array = []
        for i in range(colnames.__len__()):
            clocs = _cn2clocs(colnames[i],**kwargs)
            clocs_array.append((clocs,i))
        if("whiches" in kwargs):
            whiches = kwargs['whiches']
            clocs_array = elel.mapv(clocs_array,lambda ele:ele[0])
            clocs = elel.batexec(lambda clocs,which:clocs[which],clocs_array,whiches)
            poses = clocs
        else:
            #by default replace all
            nkl = []
            nvl = []
            nclocs = []
            for i in range(clocs_array.__len__()):
                clocs = clocs_array[i][0]
                index = clocs_array[i][1]
                tmpkl = elel.init(clocs.__len__(),kl[i])
                tmpvl = elel.init(clocs.__len__(),vl[i])
                nkl = elel.concat(nkl,tmpkl)
                nvl = elel.concat(nvl,tmpvl)
                nclocs = elel.concat(nclocs,clocs)
            #batsort
            poses = nclocs
            kl,vl = elel.batsorted(nclocs,nkl,nvl)
    poses = elel.mapv(poses,lambda pos:pos+1)
    poses.sort()
    for i in range(0,poses.__len__()):
        pos = poses[i]
        df.insert(pos,kl[i],vl[i],kwargs['allow_duplicates'])
        pos = pos -1
        all_clocs = elel.init_range(0,df.columns.__len__(),1)
        all_clocs.remove(pos)
        df = df.iloc[:,all_clocs]
    return(df)
示例#9
0
 def __init__(self,**kwargs):
     self.dmat = []
     if("shared" in kwargs):
         self.shared = kwargs["shared"]
     else:
         if("shared_kl" in kwargs):
             shared_kl = kwargs["shared_kl"]
         else:
             shared_kl = None
         if("shared_vl" in kwargs):
             shared_vl = kwargs["shared_vl"]
         else:
             shared_vl = None
         self.shared = _init_shared(shared_kl,shared_vl)
     if("root" in kwargs):
         self.root = kwargs["root"]
         self.ele_kl,self.root_vl  = d2kvlist(self.root)
     else:
         ele_kl = kwargs["ele_kl"]
         root_vl = kwargs["root_vl"]
         self.root = kvlist2d(self.ele_kl,self.root_vl)
     self.unhandled,self.dmat= _init_unhandled(self.root,self.dmat)
     self.get_children = kwargs['get_children']
     self.gen = _gen(self.unhandled,self.shared,self.get_children,self.dmat)
示例#10
0
from efdir import fs
import elist.elist as elel
import edict.edict as eded
full_verbs = fs.rjson("verbs-es.json")
kl, vl = eded.d2kvlist(full_verbs)
verbs = kl
roots = elel.mapv(vl, lambda ele: ele['root'])
tems = elel.mapv(vl, lambda ele: ele['template'])

fs.touch("verbs.cat")
fs.touch("verbs.root.cat")
fs.touch("verbs.tem.cat")

for i in range(verbs.__len__()):
    fs.afile("verbs.cat", verbs[i] + "\n")
    fs.afile("verbs.root.cat", roots[i] + "\n")
    fs.afile("verbs.tem.cat", tems[i] + "\n")
示例#11
0
def wfsel2m(l):
    d = elel.groupby_attr_lngth(l,"fpl")
    kl,vl = eded.d2kvlist(d)
    rslt = elel.sorted_refer_to(vl,kl)
    m = rslt['list']
    return(m)
示例#12
0
from dlist.dlist import dlist2dict
from edict.edict import d2kvlist

# MANIFEST.in 设置完毕后
# 记住在setup.py 设置
#      include_package_data=True,
#      package_data = {
#          'resources':["estring/emoji/resources/*"]
#      },


dtbfn = pkg_resources.resource_filename("estring","emoji/resources/emoji.dtb.json")
dtb = fs.rjson(dtbfn)
_dl = mapv(dtb,lambda row:{row['desc']:row['ord']})
d = dlist2dict(_dl)
_kl,_vl = d2kvlist(d)

class _Null():
    def __init__(self,*args):
        self.Θ = "null" if(len(args) ==0) else args[0]
    def __repr__(self):
        return(self.Θ)

def _get_emojies():
    obj = _Null("emoji")
    for k in d:
        obj.__setattr__(k,d[k])
    return(obj)


emoji = _get_emojies()