示例#1
0
def _make_digraph(x, check_varprops):
    dg = nx.DiGraph()
    for ep in x.eps():
        nid, pred, args = ep[0], ep[1], ep[3]
        if CONSTARG_ROLE in args:
            s = '{}({})'.format(pred.string, args[CONSTARG_ROLE])
        else:
            s = pred.string
        dg.add_node(nid, sig=s)
        dg.add_edges_from((nid, var_id(val)) for role, val in args.items()
                          if role != CONSTARG_ROLE)
    for var, vd in x._vars.items():
        aspects = []
        if check_varprops:
            aspects.extend('%s=%s' % (p,v) for p,v in vd['props'])
        aspects.extend('%s:%s' % (dg.node[tgt]['sig'], ref)
                       for ref, tgts in vd['refs'].items()
                       for tgt in tgts if tgt in x._eps)
        s = '{}|{}'.format(var_sort(var), '|'.join(sorted(aspects)))
        dg.add_node(var_id(var), sig=s)
    dg.add_edges_from((var_id(hi), var_id(lo), {'sig':reln})
                      for hi, reln, lo in x.hcons())
    return dg
示例#2
0
def _make_digraph(x, check_varprops):
    dg = nx.DiGraph()
    for ep in x.eps():
        nid, pred, args = ep[0], ep[1], ep[3]
        if CONSTARG_ROLE in args:
            s = '{}({})'.format(pred.string, args[CONSTARG_ROLE])
        else:
            s = pred.string
        dg.add_node(nid, sig=s)
        dg.add_edges_from((nid, var_id(val)) for role, val in args.items()
                          if role != CONSTARG_ROLE)
    for var, vd in x._vars.items():
        aspects = []
        if check_varprops:
            aspects.extend('%s=%s' % (p,v) for p,v in vd['props'])
        aspects.extend('%s:%s' % (dg.node[tgt]['sig'], ref)
                       for ref, tgts in vd['refs'].items()
                       for tgt in tgts if tgt in x._eps)
        s = '{}|{}'.format(var_sort(var), '|'.join(sorted(aspects)))
        dg.add_node(var_id(var), sig=s)
    dg.add_edges_from((var_id(hi), var_id(lo), {'sig':reln})
                      for hi, reln, lo in x.hcons())
    return dg
示例#3
0
def test_var_id():
    assert var_id('x1') == 1
    assert var_id('event10') == 10
    with pytest.raises(ValueError): var_id('1')