Skip to content

Commit

Permalink
BinomialSearch allow numbers in cultivar parts
Browse files Browse the repository at this point in the history
  • Loading branch information
RoDuth committed Nov 20, 2024
1 parent b478e68 commit d9d3e37
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
6 changes: 3 additions & 3 deletions bauble/plugins/plants/species.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,8 @@ def invoke(self, search_strategy: SearchStrategy) -> list[Query]:


_BINOMIAL_RGX = re.compile(
"^[A-Z]+[a-z-]* +([a-z]+[a-z-]*$|'[A-Za-z-]*$|'[A-Za-z- ]*'$|"
"[a-z]+[a-z-]* ('[A-Za-z-]*$|'[A-Za-z- ]*'$))"
"^[A-Z]+[a-z-]* +([a-z]+[a-z-]*$|'[A-Za-z0-9-]*$|'[A-Za-z0-9- ]*'$|"
"[a-z]+[a-z-]* ('[A-Za-z0-9-]*$|'[A-Za-z0-9- ]*'$))"
)


Expand All @@ -269,7 +269,7 @@ class BinomialSearch(SearchStrategy):

genus = Word(caps, lowers).set_name("Genus epithet or partial epithet")
species = Word(lowers).set_name("species epithet or partial epithet")
cultivar = Regex("'[A-Za-z- ]*'?").set_name(
cultivar = Regex("'[A-Za-z0-9- ]*'?").set_name(
"cultivar epithet or partial epithet"
)

Expand Down
12 changes: 12 additions & 0 deletions bauble/plugins/plants/test_plants.py
Original file line number Diff line number Diff line change
Expand Up @@ -3106,6 +3106,9 @@ def test_use(self):
s = "Hibiscus rosa-sinensis"
self.assertEqual(strategy.use(s), "include")

s = "Cyn dac 'DT-1"
self.assertEqual(strategy.use(s), "include")

def test_sp_cultivar_also_matches(self):
strategy = search.strategies.get_strategy("BinomialSearch")
self.assertTrue(isinstance(strategy, BinomialSearch))
Expand Down Expand Up @@ -3195,6 +3198,15 @@ def test_hyphenated_name_search(self):
results.extend(i)
self.assertEqual(results, [self.sp5])

self.sp5.cultivar_epithet = "Test-10"
self.session.commit()

s = "Ixo ros 'Test-1"
results = []
for i in strategy.search(s, self.session):
results.extend(i)
self.assertEqual(results, [self.sp5])


class GeographyTests(BaubleClassTestCase):
@classmethod
Expand Down

0 comments on commit d9d3e37

Please sign in to comment.