Skip to content

Commit

Permalink
Generate regex for courts/subcourts
Browse files Browse the repository at this point in the history
  • Loading branch information
dragon-dxw committed Dec 20, 2023
1 parent df1fab1 commit 38d4cad
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions src/ds_caselaw_utils/generate_regex.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,22 @@ def url_order_numbers(self) -> list[int]:
return [2, 1, 3]


courtlist = courts.get_all()
url_patterns = sorted(list(set(court.ncn for court in courtlist if court.ncn)))

court_strings = set()
subcourt_strings = set()
for url_pattern in url_patterns:
pattern = ParsedURLPattern(url_pattern)
print(pattern.regex, pattern.url_order_numbers, pattern.url_order)
court_strings.add(pattern.court)
if pattern.subcourt:
subcourt_strings.add(pattern.subcourt)

print(court_strings, subcourt_strings)
def all_patterns() -> list[ParsedURLPattern]:
url_patterns = [court.ncn for court in courts.get_all() if court.ncn]
for url_pattern in url_patterns:
pattern = ParsedURLPattern(url_pattern)
print(pattern.regex, pattern.url_order_numbers, pattern.url_order)
yield pattern


def all_court_regex():
return "|".join({pattern.court for pattern in all_patterns()})


def all_subcourt_regex():
return "|".join(
{pattern.subcourt for pattern in all_patterns() if pattern.subcourt}
)


print(all_court_regex(), all_subcourt_regex())

0 comments on commit 38d4cad

Please sign in to comment.