diff options
author | Timotej Lazar <timotej.lazar@fri.uni-lj.si> | 2017-04-16 12:40:32 +0200 |
---|---|---|
committer | Timotej Lazar <timotej.lazar@fri.uni-lj.si> | 2017-04-16 12:40:32 +0200 |
commit | 37882ddb65ba010c060afb799b31f39684da9b1f (patch) | |
tree | 33865b298d6135b199bbef48247b8f791933c312 | |
parent | c7a948f57d1bea6c58e4451b948d3c400edf0007 (diff) |
Export rules in a JSON file for CodeQ
-rwxr-xr-x | test-rules.py | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/test-rules.py b/test-rules.py index 8762cdd..d129eef 100755 --- a/test-rules.py +++ b/test-rules.py @@ -1,6 +1,7 @@ #!/usr/bin/python3 import collections +import json import os.path import pickle import re @@ -47,6 +48,7 @@ attributes_file = os.path.join(data_dir, 'attributes.tab') rules_file = os.path.join(data_dir, 'rules.txt') users_file = os.path.join(data_dir, 'users-test.txt') programs_file = os.path.join(data_dir, 'programs.pickle') +json_file = os.path.join(data_dir, 'bugs.json') pid = int(open(pid_file, 'r').read().strip()) # read test results for known programs @@ -71,10 +73,23 @@ for line in open(rules_file, 'r').readlines(): m = tuple(match.groups()) condition = tuple(attributes[field[:-3]] for field in m[0].split(' AND ')) rules.append(Rule(m[-4], condition, (int(m[-3]), int(m[-2])), float(m[-1]))) - #print(rules[-1]) else: print('Did not understand rule:', line.strip()) +json_data = { + 'patterns': attributes_ordered, + 'rules': [{ + 'condition': r.condition, + 'class': r.klass == 'T', + 'distribution': r.distribution, + 'quality': r.quality, + } for r in rules], +} + +# export rules for tutor +with open(json_file, 'w') as f: + json.dump(json_data, f, sort_keys=True, indent=2) + def color_print(text, ranges): i = 0 for start, length, color in sorted(ranges): |