-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanalyze_drl_patterns.py
More file actions
39 lines (30 loc) · 1.27 KB
/
analyze_drl_patterns.py
File metadata and controls
39 lines (30 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import glob
import re
def analyze_drls():
files = glob.glob("ACCESS-NYC-Rules/accessnyc/rules/S2R*.drl")
files.sort()
patterns = {}
print(f"Analyzing {len(files)} files...")
for filepath in files:
with open(filepath, 'r') as f:
content = f.read()
# Extract 'when' block
match = re.search(r'when\s+(.*?)\s+then', content, re.DOTALL)
if match:
condition_block = match.group(1).strip()
# Normalize whitespace
condition_block = re.sub(r'\s+', ' ', condition_block)
# Simple classification based on objects used
objects = set(re.findall(r'([A-Z][a-zA-Z0-9]+)\(', condition_block))
obj_key = ", ".join(sorted(list(objects)))
if obj_key not in patterns:
patterns[obj_key] = []
patterns[obj_key].append(dict(file=filepath, condition=condition_block))
print("\n--- Pattern Report ---")
for key, items in patterns.items():
print(f"\nPattern: [{key}] - {len(items)} files")
# Print first example
print(f"Example ({items[0]['file']}):")
print(f" {items[0]['condition'][:200]}...")
if __name__ == "__main__":
analyze_drls()