当前位置: 首页>>代码示例>>Python>>正文


Python Pattern.covered方法代码示例

本文整理汇总了Python中pattern.Pattern.covered方法的典型用法代码示例。如果您正苦于以下问题:Python Pattern.covered方法的具体用法?Python Pattern.covered怎么用?Python Pattern.covered使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pattern.Pattern的用法示例。


在下文中一共展示了Pattern.covered方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: union2patterns

# 需要导入模块: from pattern import Pattern [as 别名]
# 或者: from pattern.Pattern import covered [as 别名]

#.........这里部分代码省略.........
		if cmap[D]>= dLimit:
			print "terminate due to the diameter limit."
			continue;

		for snb in sp.g.neighbors(cmap[L]):
			snb_label = sp.g.node[snb]["l"];
			# print "snbLabel in snb", snb_label;

			# print op.g.nodes(data=True);
			for onb in op.g.neighbors(cmap[M][cmap[L]]):
				onb_label = op.g.node[onb]["l"]
				if onb_label == snb_label:
					# print snb ,"->", onb;
					# print "potential cmap[M]:",cmap[M];
					# find a new map;
					if snb not in cmap and onb not in cmap[M].values():
						# print "confirmed as new.";
						mapd = dict();
						mapd[M] = cmap[M].copy();
						# depth +=1
						mapd[D]=cmap[D]+1;
						mapd[M][snb] = onb;
						mapd[L] = snb;
						# print mapd;
						tMapList.append(mapd);
	
	# print "merged result:",len(mapList)
	for mapping in mapList:
		# print "last=",mapping[L],"d=",mapping[D],mapping[M];
		# print "mappingD = ",mapping[M]

		# generate new patterns
		np = Pattern();
		np.x = sp.x;
		np.y = sp.y;
		np.g = nx.union(sp.g,op.g,"SO");
		# print "after norename new graph nodes = ", np.g.nodes(data=True)
		# print "after norename new graph edges = ", np.g.edges()

		# print "mapping" ,mapping[M];
		# mapping

		for k in mapping[M]:
			# virtual node, to be merged and removed.
			vnode = "O"+mapping[M][k];
			target = "S"+k;
			# print "vnode=",vnode,"target=",target;
			for eo in np.g.out_edges(vnode):
				if np.g.has_edge(target, eo[1]) == False:
					np.g.add_edge(target,eo[1]);
				np.g.remove_edge(eo[0],eo[1]);
			for ei in np.g.in_edges(vnode):
				if np.g.has_edge(ei[0], target) == False:
					np.g.add_edge(ei[0],target);
				np.g.remove_edge(ei[0],ei[1]);
			np.g.remove_node(vnode);

		# print "after norename new graph edges -2 = ", np.g.edges()
		
		# rename
		rename = dict();
		index = 1;
		for node in np.g.nodes():
			rename[node] = str(index);
			index = index +1;
		np.x = rename["S"+np.x];
		np.y = rename["S"+np.y];
		np.g = nx.relabel_nodes(np.g,rename, copy=False)

		# add merged originals
		np.covered = sp.covered.union(op.covered);

		# WARN:np is always be supergraph of sp and op,
		# but networkx will not allways get subgraph_isomorphism
		# since networkx only support node-induced graph isomorphism

		# GM1 = isomorphism.DiGraphMatcher(np.g,sp.g,node_match);
		# print "subgraph_isomorphism with source graph=",GM1.subgraph_is_isomorphic();
		# GM2 = isomorphism.DiGraphMatcher(np.g,op.g,node_match);
		# print "subgraph_isomorphism with others graph=",GM2.subgraph_is_isomorphic();

		# if(GM1.subgraph_is_isomorphic()==False):
		# 	print "s nodes = ", sp.g.nodes(data=True)
		# 	print "s graph = ",sp.g.edges();
		# 	print "====================="
		# 	print "new graph nodes = ", np.g.nodes(data=True)
		# 	print "new graph = ",np.g.edges();

		# if(GM2.subgraph_is_isomorphic()==False):
		# 	print "o nodes = ", op.g.nodes(data=True)
		# 	print "o graph = ",op.g.edges();
		# 	print "x=",op.x, "y=",op.y;
		# 	print "====================="
		# 	print "new graph nodes = ", np.g.nodes(data=True)
		# 	print "new graph = ",np.g.edges();
		# 	print "x=",np.x, "y=",np.y;

		newPatternList.append(np);

	return newPatternList;
开发者ID:yecol,项目名称:exp-armining,代码行数:104,代码来源:disc.py

示例2: union2patterns

# 需要导入模块: from pattern import Pattern [as 别名]
# 或者: from pattern.Pattern import covered [as 别名]

#.........这里部分代码省略.........
	# init
	d = dict();
	d[D] = 0;
	d[M] = dict();

	d[M][sp.x] = op.x;
	d[L] = sp.x;

	tMapList.append(d);

	# pop out from templist and find new mappings, start from last node
	while len(tMapList)!=0:
		# first add it to final maplist;
		cmap = tMapList.pop();
		# print cmap;
		mapList.append(cmap);

		if cmap[D]>= dLimit:
			print "terminate due to the diameter limit."
			continue;

		for snb in sp.g.neighbors(cmap[L]):
			snb_label = sp.g.node[snb]["l"];
			# print "snbLabel in snb", snb_label;

			# print op.g.nodes(data=True);
			for onb in op.g.neighbors(cmap[M][cmap[L]]):
				onb_label = op.g.node[onb]["l"]
				if onb_label == snb_label:
					# print snb ,"->", onb;
					# print "potential cmap[M]:",cmap[M];
					# find a new map;
					if snb not in cmap and onb not in cmap[M].values():
						# print "confirmed as new.";
						mapd = dict();
						mapd[M] = cmap[M].copy();
						# depth +=1
						mapd[D]=cmap[D]+1;
						mapd[M][snb] = onb;
						mapd[L] = snb;
						# print mapd;
						tMapList.append(mapd);
	
	# pop the last one
	mapping = mapList.pop();

	if len(mapping[M].keys())==2:
		# only x matches x
		return None;
	# for mapping in mapList:
	# print "last=",mapping[L],"d=",mapping[D],mapping[M];
	print "mappingD = ",mapping[M]

	# generate new patterns
	np = Pattern();
	np.x = sp.x;
	np.y = sp.y;

	np.g = nx.union(sp.g,op.g,"SO");
	# print "after norename new graph nodes = ", np.g.nodes(data=True)
	# print "after norename new graph edges = ", np.g.edges()

	# print "mapping" ,mapping[M];
	# mapping


	for k in mapping[M]:
		# virtual node, to be merged and removed.
		vnode = "O"+mapping[M][k];
		target = "S"+k;
		# print "vnode=",vnode,"target=",target;
		for eo in np.g.out_edges(vnode):
			if np.g.has_edge(target, eo[1]) == False:
				np.g.add_edge(target,eo[1]);
			np.g.remove_edge(eo[0],eo[1]);
		for ei in np.g.in_edges(vnode):
			if np.g.has_edge(ei[0], target) == False:
				np.g.add_edge(ei[0],target);
			np.g.remove_edge(ei[0],ei[1]);
		np.g.remove_node(vnode);

		# if mapping[M][k] in op.y:
		# 	tempSY.add(k);
		# 	tempOY.remove(mapping[M][k]);
		# print "after norename new graph edges -2 = ", np.g.edges()
		
	# rename
	rename = dict();
	index = 1;
	for node in np.g.nodes():
		rename[node] = str(index);
		index = index +1;
	np.x = rename["S"+np.x];
	np.y = rename["S"+np.y];
	np.g = nx.relabel_nodes(np.g,rename, copy=False)

	# add merged originals
	np.covered = sp.covered.union(op.covered);

	return np;
开发者ID:yecol,项目名称:exp-armining,代码行数:104,代码来源:discmerge2.py


注:本文中的pattern.Pattern.covered方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。