本文整理汇总了Python中pattern.Pattern.y方法的典型用法代码示例。如果您正苦于以下问题:Python Pattern.y方法的具体用法?Python Pattern.y怎么用?Python Pattern.y使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pattern.Pattern
的用法示例。
在下文中一共展示了Pattern.y方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: loadPatternsFromFile
# 需要导入模块: from pattern import Pattern [as 别名]
# 或者: from pattern.Pattern import y [as 别名]
def loadPatternsFromFile(f):
# load patterns from file f
# return: a list of patterns
patterns = list();
xy = False;
p = 0;
ifile = open(f);
for line in ifile:
if(line.startswith("===")):
if p!=0:
patterns.append(p)
p = Pattern();
xy = True;
continue;
elements = line.strip().split("\t");
if xy == True:
xy = False;
p.x = elements[0];
p.y = elements[1];
v1 = p.g.add_node(elements[0],l=int(elements[1]));
for i in range(2,len(elements)):
p.g.add_edge(elements[0],elements[i]);
# g.elements[0]
p.covered.add(p.id);
if(p!=0):
patterns.append(p);
if(debug):
for p in patterns:
# printG(g,1,0);
print p.id;
print p.g.nodes(data=True)
print p.g.edges();
return patterns;
示例2: union2patterns
# 需要导入模块: from pattern import Pattern [as 别名]
# 或者: from pattern.Pattern import y [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);
#.........这里部分代码省略.........
示例3: len
# 需要导入模块: from pattern import Pattern [as 别名]
# 或者: from pattern.Pattern import y [as 别名]
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'
# test if the new pattern is duplicates.
for ynode in p.y:
# edges every x->y
r = Pattern();
r.g = p.g.copy();
r.x = p.x;
r.y = p.y.copy();
r.y.remove(ynode);
print r.x,"---",r.y
print "edgesize,b4 edgessize =",len(r.g.edges()),"degree of y =",ynode,r.g.degree(ynode)
r.g.remove_edge(p.x,ynode);
print "edgesize,aft edgesize =",len(r.g.edges()),"degree of y =",ynode,r.g.degree(ynode)
if r.g.degree(ynode)==0:
print "remove y", ynode
r.g.remove_node(ynode);
# print float(suppThreshold)/confThreshold;
if computeSupport(baseG,r) <= float(suppThreshold)/confThreshold:
# WARN: r will be 0;
sigma.append(r);
else:
print "discards r, p.id=",r.id,"since don't enough support";
示例4: len
# 需要导入模块: from pattern import Pattern [as 别名]
# 或者: from pattern.Pattern import y [as 别名]
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);
# output sigma
print "======================================================"
示例5: union2patterns
# 需要导入模块: from pattern import Pattern [as 别名]
# 或者: from pattern.Pattern import y [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);
#.........这里部分代码省略.........