From 4ef4045a05b0d6e86655f032ced6053141fbc75a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Mo=C5=BEina?= Date: Tue, 31 Jan 2017 13:35:25 +0100 Subject: Patterns now include also singleton literals, which is needed for some base cases. --- monkey/patterns.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/monkey/patterns.py b/monkey/patterns.py index e22c39b..051544d 100644 --- a/monkey/patterns.py +++ b/monkey/patterns.py @@ -132,6 +132,7 @@ def get_patterns(tree): yield pat, selected # yield patterns for variable-literal / literal-literal pairs + # yield patterns for singleton literals # (only within a topmost compound / binop / unop) def patterns_with_literals(node): if not isinstance(node, Tree): @@ -139,7 +140,9 @@ def get_patterns(tree): if node.label() in {'compound', 'binop', 'unop'}: vars = [n for n in node.subtrees() if n.label() == 'variable'] lits = [n for n in node.subtrees() if n.label() == 'literal'] - for selected in chain(combinations(lits, 2), product(lits, vars)): + for selected in chain(combinations(lits, 1), + combinations(lits, 2), + product(lits, vars)): pat = pattern(clause, selected) if pat: yield pat, selected @@ -203,7 +206,7 @@ if __name__ == '__main__': attrs = [] with open('data/attributes-{:03}.tab'.format(pid), 'w') as pattern_file: for i, (pat, count) in enumerate(patterns.most_common()): - if count < 1: + if count < 5: break attrs.append(pat) print('a{}\t{}'.format(i, pat), file=pattern_file) -- cgit v1.2.1