summaryrefslogtreecommitdiff
path: root/monkey
diff options
context:
space:
mode:
authorMartin Možina <martin.mozina@fri.uni-lj.si>2017-01-31 13:35:25 +0100
committerMartin Možina <martin.mozina@fri.uni-lj.si>2017-01-31 13:35:25 +0100
commit4ef4045a05b0d6e86655f032ced6053141fbc75a (patch)
tree9d52a9d311e10c61cd705f0ffc24b76986417809 /monkey
parent77a728fa40e6df6bcc47de4c9541bae8a31ab828 (diff)
Patterns now include also singleton literals, which is needed for
some base cases.
Diffstat (limited to 'monkey')
-rw-r--r--monkey/patterns.py7
1 files 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)