Spell place slugs and names without accent stumps and capitalised small words
Gaspésie came out as gasp-sie, Lion's Head as lion-s-head and Forks of The Credit kept a capital T. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
44fbb0405b
commit
2fbce06f42
2 files changed
+15
-1
No files matched your search
@@ -178,7 +178,10 @@ class Source:
|
|||||||
|
|
||||||
|
|
||||||
def slugify(name):
|
def slugify(name):
|
||||||
|
import unicodedata
|
||||||
s = re.sub(r"\([^)]*\)", "", name.lower())
|
s = re.sub(r"\([^)]*\)", "", name.lower())
|
||||||
|
s = unicodedata.normalize("NFKD", s).encode("ascii", "ignore").decode("ascii")
|
||||||
|
s = re.sub(r"['\u2019]", "", s)
|
||||||
s = re.sub(r"[^a-z0-9]+", "-", s).strip("-")
|
s = re.sub(r"[^a-z0-9]+", "-", s).strip("-")
|
||||||
return re.sub(r"-+", "-", s)
|
return re.sub(r"-+", "-", s)
|
||||||
|
|
||||||
@@ -296,7 +299,7 @@ def _clean_cpcad_name(name):
|
|||||||
name = re.sub(r"\s+Of Canada$", "", name, flags=re.I)
|
name = re.sub(r"\s+Of Canada$", "", name, flags=re.I)
|
||||||
if name.isupper():
|
if name.isupper():
|
||||||
name = name.title()
|
name = name.title()
|
||||||
name = re.sub(r"\s(And|Of|The|Du|De)\s", lambda m: m.group(0).lower(), name)
|
name = re.sub(r"(?<=\s)(And|Of|The|Du|De)(?=\s)", lambda m: m.group(0).lower(), name)
|
||||||
return name.strip()
|
return name.strip()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -272,6 +272,17 @@ class ProposalTest(unittest.TestCase):
|
|||||||
self.assertFalse(clipped.intersects(east))
|
self.assertFalse(clipped.intersects(east))
|
||||||
self.assertTrue(clipped.contains(self.park.geometry))
|
self.assertTrue(clipped.contains(self.park.geometry))
|
||||||
|
|
||||||
|
def test_slugs_drop_accents_and_apostrophes_instead_of_leaving_hyphen_stumps(self):
|
||||||
|
self.assertEqual(P.slugify("Gaspésie National Park"), "gaspesie-national-park")
|
||||||
|
self.assertEqual(P.slugify("Lion's Head Provincial Park"), "lions-head-provincial-park")
|
||||||
|
self.assertEqual(P.slugify("Hautes-Gorges-de-la-Rivière-Malbaie National Park"),
|
||||||
|
"hautes-gorges-de-la-riviere-malbaie-national-park")
|
||||||
|
self.assertEqual(P.slugify("Sierra Nevada (USA)"), "sierra-nevada")
|
||||||
|
|
||||||
|
def test_a_small_word_in_a_cpcad_name_is_lower_case_even_after_another(self):
|
||||||
|
self.assertEqual(P._clean_cpcad_name("Forks Of The Credit Provincial Park"),
|
||||||
|
"Forks of the Credit Provincial Park")
|
||||||
|
|
||||||
def test_a_slug_collision_inside_a_kind_gets_the_state_code(self):
|
def test_a_slug_collision_inside_a_kind_gets_the_state_code(self):
|
||||||
a = outline("park", "P1", "Glacier", self.park.geometry, slug=None, hint=["MT"])
|
a = outline("park", "P1", "Glacier", self.park.geometry, slug=None, hint=["MT"])
|
||||||
b = outline("park", "P2", "Glacier", self.range.geometry, slug=None, hint=["BC"])
|
b = outline("park", "P2", "Glacier", self.range.geometry, slug=None, hint=["BC"])
|
||||||
|
|||||||
Reference in new issue
Block a user