Python 具有边属性的networkx中的同构

Python 具有边属性的networkx中的同构,python,networkx,isomorphism,Python,Networkx,Isomorphism,我正在使用Networkx函数进行同构: GM = nx.algorithms.isomorphism.GraphMatcher(G1,G2,node_match=lambda n1,n2:n1['name']==n2['name']) 我想对名为“type”的边属性执行相同的操作,但我不知道如何执行。 我刚试过这个: GM = nx.algorithms.isomorphism.GraphMatcher(G1,G2,node_match=lambda n1,n2:n1['name'

我正在使用Networkx函数进行同构:

  GM = nx.algorithms.isomorphism.GraphMatcher(G1,G2,node_match=lambda n1,n2:n1['name']==n2['name']) 
我想对名为“type”的边属性执行相同的操作,但我不知道如何执行。 我刚试过这个:

  GM = nx.algorithms.isomorphism.GraphMatcher(G1,G2,node_match=lambda n1,n2:n1['name']==n2['name'], edge_match= lambda G[u1][v1],G2[u2][v2]: g[u1][v1]['type'] == g2[u2][v2]['type']) 
但它不起作用。 谢谢大家!

编辑: 这来自文件:

 edge_match : callable
            A function that returns True iff the edge attribute dictionary for
            the pair of nodes (u1, v1) in G1 and (u2, v2) in G2 should be
            considered equal during the isomorphism test. The function will be
            called like::

               edge_match(G1[u1][v1], G2[u2][v2])

            That is, the function will receive the edge attribute dictionaries
            of the edges under consideration. If None, then no attributes are
            considered when testing for an isomorphism.

应按如下方式更改“边匹配”函数:

GM = nx.algorithms.isomorphism.GraphMatcher(G1,G2,node_match=lambda n1,n2:n1['name']==n2['name'], edge_match= lambda e1,e2: e1['type'] == e2['type'])
说明: 文件说:

edge\u match(可调用)–在边上返回True的函数 G1和(u2,v2)中节点对(u1,v1)的属性字典 在同构测试期间,G2中的应视为相等。这个 函数的调用方式如下:

边缘匹配(G1[u1][v1],G2[u2][v2])

G[u][v]
是边(u,v)的数据字典


因此
lambda e1,e2:e1['type']==e2['type']
是一个函数,给定两条边的数据字典,如果两条边的类型相等,则返回true。

它表示KeyError'type'。但是每个边都有“type”作为属性。这对我来说很好,你能运行
print(G.edges(data=True))
来查看边吗?你使用的是什么NetworkX版本?我有2.2(您可以运行
print(nx.\uu版本)
来检查它)