diff options
Diffstat (limited to 'scripts/Violations_processor.py')
| -rw-r--r-- | scripts/Violations_processor.py | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/scripts/Violations_processor.py b/scripts/Violations_processor.py index 62c1ade..2178d87 100644 --- a/scripts/Violations_processor.py +++ b/scripts/Violations_processor.py | |||
| @@ -17,7 +17,7 @@ class Cleaner: | |||
| 17 | self._used_words = 0 | 17 | self._used_words = 0 |
| 18 | self._cache = {} | 18 | self._cache = {} |
| 19 | 19 | ||
| 20 | def clean(self, violation, prefix): | 20 | def clean(self, violation, prefix, query_predicate=None): |
| 21 | j = 0 | 21 | j = 0 |
| 22 | atoms = [] | 22 | atoms = [] |
| 23 | for i in range(3): | 23 | for i in range(3): |
| @@ -25,8 +25,11 @@ class Cleaner: | |||
| 25 | j = violation.find('>', i) | 25 | j = violation.find('>', i) |
| 26 | atom = violation[i:j] | 26 | atom = violation[i:j] |
| 27 | if atom not in self._cache: | 27 | if atom not in self._cache: |
| 28 | self._cache[atom] = str(prefix) + self._words[self._used_words] | 28 | if atom == query_predicate: |
| 29 | self._used_words += 1 | 29 | self._cache[atom] = 'Q' |
| 30 | else: | ||
| 31 | self._cache[atom] = str(prefix) + self._words[self._used_words] | ||
| 32 | self._used_words += 1 | ||
| 30 | atoms.append(self._cache[atom]) | 33 | atoms.append(self._cache[atom]) |
| 31 | return '%10s(X) -> %10s(X,Y), %10s(Y)' % (atoms[2], atoms[0], atoms[1]) | 34 | return '%10s(X) -> %10s(X,Y), %10s(Y)' % (atoms[2], atoms[0], atoms[1]) |
| 32 | 35 | ||
| @@ -34,6 +37,7 @@ class Cleaner: | |||
| 34 | if __name__ == '__main__': | 37 | if __name__ == '__main__': |
| 35 | parser = argparse.ArgumentParser(description='Transform violations (as output by PAGOdA) into a very readable form.') | 38 | parser = argparse.ArgumentParser(description='Transform violations (as output by PAGOdA) into a very readable form.') |
| 36 | parser.add_argument('input', help='json file containing violations') | 39 | parser.add_argument('input', help='json file containing violations') |
| 40 | parser.add_argument('-q', help='query predicate') | ||
| 37 | args = parser.parse_args() | 41 | args = parser.parse_args() |
| 38 | 42 | ||
| 39 | cleaner = Cleaner() | 43 | cleaner = Cleaner() |
| @@ -42,7 +46,7 @@ if __name__ == '__main__': | |||
| 42 | clean_rules_list_list = [] | 46 | clean_rules_list_list = [] |
| 43 | i = 0 | 47 | i = 0 |
| 44 | for violations_list in violations_list_list: | 48 | for violations_list in violations_list_list: |
| 45 | clean_rules_list_list.append(sorted(map(lambda x: cleaner.clean(x, i), violations_list))) | 49 | clean_rules_list_list.append(sorted(map(lambda x: cleaner.clean(x, i, args.q), violations_list))) |
| 46 | i += 1 | 50 | i += 1 |
| 47 | print json.dumps(clean_rules_list_list, indent=2) | 51 | print json.dumps(clean_rules_list_list, indent=2) |
| 48 | 52 | ||
