excludes_re

This commit is contained in:
Costa Shulyupin 2020-07-21 19:29:42 +03:00
parent 82beb2d160
commit d0c1506a71
1 changed files with 8 additions and 5 deletions

View File

@ -497,20 +497,23 @@ def starts(dg): # roots of trees in a graph
return {n: dg.out_degree(n) for (n, d) in dg.in_degree if not d} return {n: dg.out_degree(n) for (n, d) in dg.in_degree if not d}
def exclude(i, excludes=[], ignores=ignores): def exclude(i, excludes_re=[]):
if i in ignores: if i in ignores:
return True return True
for e in excludes: for e in excludes_re:
if re.match(e, i): if re.match(e, i):
return True return True
def digraph_predecessors(dg, starts, levels=100, excludes=[], ignores=ignores): def digraph_predecessors(dg, starts, levels=100, excludes_re=[]):
'''
extracts referrers subgraph
'''
dg = to_dg(dg) dg = to_dg(dg)
passed = set() passed = set()
# for i in [_ for _ in dg.predecessors(start)]: # for i in [_ for _ in dg.predecessors(start)]:
p = nx.DiGraph() p = nx.DiGraph()
for e in excludes: for e in excludes_re:
log(e) log(e)
while levels: while levels:
# log(levels) # log(levels)
@ -519,7 +522,7 @@ def digraph_predecessors(dg, starts, levels=100, excludes=[], ignores=ignores):
starts = set() starts = set()
for s in s2: for s in s2:
for i in dg.predecessors(s): for i in dg.predecessors(s):
if i in passed or exclude(i, excludes, ignores): if i in passed or exclude(i, excludes_re):
continue continue
passed.add(i) passed.add(i)
starts.add(i) starts.add(i)