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


Python Pattern.g方法代码示例

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


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

示例1: len

# 需要导入模块: from pattern import Pattern [as 别名]
# 或者: from pattern.Pattern import g [as 别名]
	print "recheck with bigQ: " , bigQ;
	while len(bigQ)!=0:
		p = bigQ.pop()
		print "p.id=",p.id,"p.x,p.y",p.x, p.y
		if len(shouldHaveAll.difference(p.covered))!=0:
			# not contain all required nodes
			print "discards p id=",p.id,"since don't covered all should cover."
			pass;

		else:
			#generate several Q'
			for e2y in p.g.out_edges():
				if node_match(p.g.node[e2y[1]],p.g.node[p.y]):
					# edges every x->y
					r = Pattern();
					r.g = p.g.copy();
					r.x = p.x;
					r.y = e2y[1];
					print r.x,"---",r.y
					print "edgesize,b4",len(r.g.edges()),r.g.degree(r.y)
					r.g.remove_edge(e2y[0],e2y[1]);
					print "edgesize,aft",len(r.g.edges()),r.g.degree(r.y)
					if r.g.degree(r.y)==0:
						print "remove y", r.y
						r.g.remove_node(r.y); 
					
					# print float(suppThreshold)/confThreshold;
					if computeSupport(baseG,r) <= float(suppThreshold)/confThreshold:
						# WARN: r will be 0;
						sigma.append(r);
			
开发者ID:yecol,项目名称:exp-armining,代码行数:32,代码来源:disc.py

示例2: union2patterns

# 需要导入模块: from pattern import Pattern [as 别名]
# 或者: from pattern.Pattern import g [as 别名]
def union2patterns(sp,op):

	# first sp then op
	# input two graph patterns and generate a list of new patterns

	dLimit = min(sp.diameter(),op.diameter());
	# print "dlimit = ", dLimit;

	newPatternList = list();
	# last node
	L = "ln";
	# diameter
	D = "di";
	# mappings
	M = "m"

	mapList = list();
	tMapList = list();

	# 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);
	
	# 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);
#.........这里部分代码省略.........
开发者ID:yecol,项目名称:exp-armining,代码行数:103,代码来源:disc.py

示例3: union2patterns

# 需要导入模块: from pattern import Pattern [as 别名]
# 或者: from pattern.Pattern import g [as 别名]
def union2patterns(sp,op):

	# first sp then op
	# input two graph patterns and generate a new pattern

	dLimit = min(sp.diameter(),op.diameter());
	# print "dlimit = ", dLimit;

	# newPatternList = list();
	# last node
	L = "ln";
	# diameter
	D = "di";
	# mappings
	M = "m"

	mapList = list();
	tMapList = list();

	# 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);

#.........这里部分代码省略.........
开发者ID:yecol,项目名称:exp-armining,代码行数:103,代码来源:discmerge2.py


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