Skip to content

Commit 19c49b1

Browse files
committed
don't print edge only connected patterns header if none present
1 parent 84aa0e8 commit 19c49b1

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

serialization.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
from graph_pattern import GraphPattern
2828
from gtp_scores import GTPScores
2929
from utils import decurify
30+
from utils import run_once
3031

3132
logger = logging.getLogger(__name__)
3233

@@ -235,15 +236,19 @@ def print_results(
235236
print_graph_pattern(gp)
236237

237238
if edge_only_connected_patterns:
238-
print(
239-
'\n\n\nThe following edge only connected or mixed node and edge '
240-
'vars patterns made it into raw result patterns:\n'
241-
)
239+
@run_once
240+
def lazy_print_header():
241+
print(
242+
'\n\n\nThe following edge only connected or mixed node and edge'
243+
' vars patterns made it into raw result patterns:\n'
244+
)
242245
for gp, run in result_patterns:
243246
if gp.is_edge_connected_only():
247+
lazy_print_header()
244248
print('edge connected only pattern:')
245249
print_graph_pattern(gp, 0)
246250
if gp.mixed_node_edge_vars():
251+
lazy_print_header()
247252
print('mixed node and edge vars in pattern:')
248253
print_graph_pattern(gp, 0)
249254

utils.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,17 @@ def get_path(nested, key_path, default=None):
243243
return nested
244244

245245

246+
def run_once(func):
247+
"""Decorator that causes a function to be executed only once."""
248+
@wraps(func)
249+
def wrapper(*args, **kwds):
250+
if not wrapper.ran:
251+
wrapper.ran = True
252+
return func(*args, **kwds)
253+
wrapper.ran = False
254+
return wrapper
255+
256+
246257
def sample_from_list(l, probs, max_n=None):
247258
"""Sample list according to probs.
248259

0 commit comments

Comments
 (0)