Repository: freelawproject/courts-db

Issue:
Need jurisdiction/location flag
We need to add a jurisdiction/location flag to differentiate between all the small local level courts in the Harvard dataset. 

For example, testing against all courts - we have the following results.
```
Testing Calhoun County Circuit Court ...         Mich.   ['flacirct14cal']
Testing Calhoun County Circuit Court ...         Fla.    ['flacirct14cal']
```

Calhoun County Circuit Court for Michigan hasn't been added yet - so it clearly assumed that the court str was from Calhoun County Florida.  



Comments:

Patch:
diff --git a/courts_db/__init__.py b/courts_db/__init__.py
index c4c8c76..3bf78dc 100644
--- a/courts_db/__init__.py
+++ b/courts_db/__init__.py
@@ -7,7 +7,7 @@ from __future__ import (
 
 import re
 from datetime import datetime
-from typing import List
+from typing import List, Optional
 
 import six
 
@@ -48,7 +48,9 @@ def __getattr__(name):
     return value
 
 
-def find_court_ids_by_name(court_str: str, bankruptcy: bool) -> List[str]:
+def find_court_ids_by_name(
+    court_str: str, bankruptcy: Optional[bool], location: Optional[str]
+) -> List[str]:
     """Find court IDs with our courts-db regex list
 
     :param court_str: test string
@@ -63,7 +65,10 @@ def find_court_ids_by_name(court_str: str, bankruptcy: bool) -> List[str]:
 
     court_matches = set()
     matches = []
-    for regex, court_id, court_name, court_type in regexes:
+    for regex, court_id, court_name, court_type, court_location in regexes:
+        # If location provided - check if overlapped.
+        if location and court_location != location:
+            continue
         # Filter gathered regexes by bankruptcy flag.
         if bankruptcy is True:
             if court_type != "bankruptcy":
@@ -158,7 +163,11 @@ def find_court_by_id(court_id):
 
 
 def find_court(
-    court_str, bankruptcy=None, date_found=None, strict_dates=False
+    court_str: str,
+    bankruptcy: Optional[bool] = None,
+    date_found: Optional[datetime] = None,
+    strict_dates: Optional[bool] = False,
+    location: Optional[str] = None,
 ):
     """Finds a list of court ID for a given string and parameters
 
@@ -166,11 +175,12 @@ def find_court(
     :param bankruptcy: Tells function to exclude or include bankruptcy cases
     :param date_found: Date object
     :param strict_dates: Boolean that helps tell the sytsem how to handle
+    :param location: Where the court is located.
     null dates in courts-db
     :return: List of court IDs if any
     """
     court_str = strip_punc(court_str)
-    matches = find_court_ids_by_name(court_str, bankruptcy)
+    matches = find_court_ids_by_name(court_str, bankruptcy, location)
     if bankruptcy is not None:
         matches = filter_courts_by_bankruptcy(
             matches=matches, bankruptcy=bankruptcy
diff --git a/courts_db/data/courts.json b/courts_db/data/courts.json
index c4b3392..3d7153c 100644
--- a/courts_db/data/courts.json
+++ b/courts_db/data/courts.json
@@ -9794,6 +9794,72 @@
         "location": "Michigan",
         "citation_string": "Mich."
     },
+    {
+        "regex": [],
+        "name_abbreviation": "Michigan Cir. Ct.",
+        "dates": [
+            {
+                "start": null,
+                "end": null
+            }
+        ],
+        "name": "Michigan Circuit Court",
+        "level": "gjc",
+        "case_types": [],
+        "jurisdiction": "M.I.",
+        "system": "state",
+        "examples": [],
+        "type": "trial",
+        "id": "micirct",
+        "location": "Michigan",
+        "citation_string": "Michigan Cir. Ct."
+    },
+    {
+        "regex": [],
+        "name_abbreviation": "Mich. 37th Cir.",
+        "dates": [
+            {
+                "start": null,
+                "end": null
+            }
+        ],
+        "name": "Circuit Court of the 37th Circuit of Michigan",
+        "level": "gjc",
+        "case_types": [],
+        "jurisdiction": "M.I.",
+        "system": "state",
+        "examples": [],
+        "type": "trial",
+        "id": "micirct37",
+        "group_id": "micirct",
+        "location": "Michigan",
+        "citation_string": "Mich. 37th Cir."
+    },
+  {
+        "regex": [
+            "Calhoun County Circuit Court"
+        ],
+        "name_abbreviation": "Michigan Cir. Ct., Calhoun Cty.",
+        "dates": [
+            {
+                "start": null,
+                "end": null
+            }
+        ],
+        "name": "Circuit Court of the 37th Circuit of Michigan, Calhoun County",
+        "level": "gjc",
+        "case_types": [],
+        "jurisdiction": "M.I.",
+        "system": "state",
+        "examples": [
+            "Calhoun County Circuit Court"
+        ],
+        "type": "trial",
+        "id": "micirct37cal",
+        "group_id": "micirct37",
+        "location": "Michigan",
+        "citation_string": "Mich. 37th Cir., Calhoun Cty."
+    },
     {
         "regex": [
             "${wd} ${mi}",
diff --git a/courts_db/utils.py b/courts_db/utils.py
index 31ee234..ef984f2 100644
--- a/courts_db/utils.py
+++ b/courts_db/utils.py
@@ -71,6 +71,14 @@ def gather_regexes(courts):
     for court in courts:
         for reg_str in court["regex"]:
             regex = re.compile(reg_str, (re.I | re.U))
-            regexes.append((regex, court["id"], court["name"], court["type"]))
+            regexes.append(
+                (
+                    regex,
+                    court["id"],
+                    court["name"],
+                    court["type"],
+                    court.get("location"),
+                )
+            )
 
     return regexes


Test patch:
diff --git a/tests.py b/tests.py
index 6ec3dd6..cd590e3 100644
--- a/tests.py
+++ b/tests.py
@@ -49,6 +49,34 @@ class DataTest(CourtsDBTestCase):
                 )
                 print("√")
 
+    def test_location_filter(self):
+        """Can we use location to filter properly"""
+
+        court_ids = find_court("Calhoun County Circuit Court")
+        self.assertEqual(
+            court_ids,
+            ["flacirct14cal", "micirct37cal"],
+            msg="Court filtering failed",
+        )
+
+        florida_court_ids = find_court(
+            "Calhoun County Circuit Court", location="Florida"
+        )
+        self.assertEqual(
+            ["flacirct14cal"],
+            florida_court_ids,
+            msg="Florida county court not found",
+        )
+
+        michigan_court_ids = find_court(
+            "Calhoun County Circuit Court", location="Michigan"
+        )
+        self.assertEqual(
+            ["micirct37cal"],
+            michigan_court_ids,
+            msg="Michican county court not found",
+        )
+
 
 class ExamplesTest(CourtsDBTestCase):
     def test_all_non_bankruptcy_examples(self):