def makeHierarchy(V,E):
    """Convert hierarchy into a network graph and creates a dictionary of ordered list to describe the hiearchy"""
    G = nx.DiGraph()
    for v in V:
        G.add_node(v)
    for e in E:
        if is_string_like(e[0]):
            s = e[0]
        else:
            s = e[0][0]
        if is_string_like(e[1]):
            t = e[1]
        else:
            t = e[1][0]
        G.add_edge(s,t)
            
    H = dict([(o,v.keys()) for (o,v) in nx.all_pairs_shortest_path(G).items()]) 
    T = nx.topological_sort(G)
    for k in H.keys():
        H[k] = [j for j in T if j in H[k]]
    
    return [G,H]
def integrate(l1,l2):
    """Combines two space objects"""
    if not l1:
        return l2
    elif not l2:
        return l1
    else:
        D = l1.copy()
        for (k,v) in l2.items():
            if is_string_like(v):
                D[k] = v
            else:
                assert is_instance(v,dict)
                D[k].update(v)
        return D
def intersect(l1,l2):
    """Intersects two space objects"""
    if l1 and l2 :
        I = dict([(k,l1[k]) for k in set(l1.keys()).intersection(l2.keys())])
        
        for (k,v) in l2.items():
            if k in I.keys() and v != I[k]:
                if is_string_like(v):
                    for j in SPACE_HIERARCHY[k]:
                        if j in I.keys():
                            I.pop(j)
                else:
                    D = intersect(I[k],v)
                    if D:
                        I[k] = D
                    else:
                        I.pop(k)
            
        return I