Skip to content

Commit

Permalink
v0.0.5 release
Browse files Browse the repository at this point in the history
  • Loading branch information
gdower committed Nov 12, 2024
1 parent 4641318 commit 88a6e2a
Show file tree
Hide file tree
Showing 7 changed files with 189 additions and 51 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
## [Unreleased]

## [0.0.5] - 2024-11-11
- Added nomenclatural code parameter
- Added result methods for cultivars
- Disabled et_al_cutoff formatting by default
- Removed preserve_in_authorship parameter from authorship() because GNparser no longer normalizes `in` to `ex`

## [0.0.4] - 2024-10-15

- Added preserve_in_authorship parameter to authorship() to optionally override normalization of `in` to `ex`
Expand Down
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,21 @@ True
['', 'Gay']
```

Parse a scientific name under a specified nomenclatural code:
```python
>>> result = gnparser('Malus domestica \'Fuji\'', code='cultivar')
>>> result.is_cultivar() # => Boolean
True
>>> result.genus() # => String
'Malus'
>>> result.species() # => String
'domestica'
>>> result.cultivar() # => String
'‘Fuji’'
>>> result.nomenclatural_code() # => String
'ICNCP'
```

---
### Parse multiple scientific names
Parse multiple scientific names by separating them with `\r\n`:
Expand Down
2 changes: 1 addition & 1 deletion pygnparser/package_metadata.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "0.0.4"
__version__ = "0.0.5"
__title__ = "pygnparser"
__author__ = "Geoff Ower"
__license__ = "MIT"
4 changes: 3 additions & 1 deletion pygnparser/pygnparser/gnparser.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from pygnparser.utils.pygnparser_utils import gnp_post, gnp_url


def gnparser(names, with_details='on', cultivars='off', diaereses='off'):
def gnparser(names, code='', with_details='on', cultivars='off', diaereses='off'):
"""
Parse scientific names
:param names: [str] Human name(s) separated by \\r\\n
:param code: [str] Specify the nomenclatural code (bacterial, botanical, cultivar, or zoological)
:param with_details: [str] Turn detailed information about the name on or off
:param cultivars: [str] Turn cultivar handling on or off
:param diaereses: [str] Turn diaereses handling on or off
Expand All @@ -18,6 +19,7 @@ def gnparser(names, with_details='on', cultivars='off', diaereses='off'):
url = gnp_url()
args = {
"names": names,
"code": code,
"with_details": with_details,
"cultivars": cultivars,
"diaereses": diaereses,
Expand Down
47 changes: 30 additions & 17 deletions pygnparser/utils/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ def parsed(self):
return self._key('parsed')


def nomenclatural_code(self):
return self._key('nomenclaturalCode')


def canonical(self):
return self._key('canonical')

Expand Down Expand Up @@ -70,6 +74,10 @@ def is_hybrid(self):
return 'hybrid' in self


def is_cultivar(self):
return 'cultivar' in self


def hybrid(self):
return self._key('hybrid')

Expand All @@ -82,8 +90,8 @@ def page(self):
page = ''
return page

def _format_authorship(self, authorship_details, et_al_cutoff=4, preserve_in_authorship=False):

def _format_authorship(self, authorship_details, et_al_cutoff=None):
authorship_list = authorship_details['authors']
match len(authorship_list):
case 0:
Expand All @@ -93,23 +101,24 @@ def _format_authorship(self, authorship_details, et_al_cutoff=4, preserve_in_aut
case 2:
authorship = f'{authorship_list[0]} & {authorship_list[1]}'
case _:
if len(authorship_list) >= et_al_cutoff:
authorship = ', '.join(authorship_list[:1]) + ' et al.'
else:
if et_al_cutoff is None or len(authorship_list) < et_al_cutoff:
authorship = ', '.join(authorship_list[:-1]) + f' & {authorship_list[-1]}'
else:
authorship = ', '.join(authorship_list[:1]) + ' et al.'

if 'year' in authorship_details:
year = self._key('year', dict=authorship_details['year'])
authorship += f', {year}'
if 'exAuthors' in authorship_details:
ex_authorship = self._format_authorship(authorship_details['exAuthors'], et_al_cutoff)
if preserve_in_authorship and ' in ' in self.authorship_verbatim():
authorship += f' in {ex_authorship}'
else:
authorship += f' ex {ex_authorship}'
authorship += f' ex {ex_authorship}'
if 'inAuthors' in authorship_details:
in_authorship = self._format_authorship(authorship_details['inAuthors'], et_al_cutoff)
authorship += f' in {in_authorship}'
return authorship


def authorship(self, et_al_cutoff=4, authorship_details=None, preserve_in_authorship=False):
def authorship(self, et_al_cutoff=None, authorship_details=None):
if authorship_details is None:
if self.hybrid() == 'HYBRID_FORMULA':
warnings.warn('Warning: authorship() returns empty for hybrid formulas. Use hybrid_formula_authorship() instead.', UserWarning)
Expand All @@ -118,9 +127,9 @@ def authorship(self, et_al_cutoff=4, authorship_details=None, preserve_in_author
authorship = ''
if authorship_details != '':
if 'originalAuth' in authorship_details:
authorship = self._format_authorship(authorship_details['originalAuth'], et_al_cutoff, preserve_in_authorship)
authorship = self._format_authorship(authorship_details['originalAuth'], et_al_cutoff)
if 'combinationAuth' in authorship_details:
combination_authorship = self._format_authorship(authorship_details['combinationAuth'], et_al_cutoff, preserve_in_authorship)
combination_authorship = self._format_authorship(authorship_details['combinationAuth'], et_al_cutoff)
authorship = f'({authorship}) {combination_authorship}'

# handles zoological authorship
Expand All @@ -129,21 +138,21 @@ def authorship(self, et_al_cutoff=4, authorship_details=None, preserve_in_author
return authorship


def original_authorship(self, et_al_cutoff=4, preserve_in_authorship=False):
def original_authorship(self, et_al_cutoff=None):
authorship_details = self.authorship_details()
authorship = ''
if authorship_details != '':
if 'originalAuth' in authorship_details:
authorship = self._format_authorship(authorship_details['originalAuth'], et_al_cutoff, preserve_in_authorship)
authorship = self._format_authorship(authorship_details['originalAuth'], et_al_cutoff)
return authorship


def combination_authorship(self, et_al_cutoff=4, preserve_in_authorship=False):
def combination_authorship(self, et_al_cutoff=None):
authorship_details = self.authorship_details()
authorship = ''
if authorship_details != '':
if 'combinationAuth' in authorship_details:
authorship = self._format_authorship(authorship_details['combinationAuth'], et_al_cutoff, preserve_in_authorship)
authorship = self._format_authorship(authorship_details['combinationAuth'], et_al_cutoff)
return authorship


Expand Down Expand Up @@ -231,13 +240,17 @@ def species(self):
return self._key('species', dict=self.details()[self._details_rank()])


def cultivar(self):
return self._key('cultivar', dict=self.details()[self._details_rank()])


def hybrid_formula_species(self):
ranks = self.hybrid_formula_ranks()
return [self.details()['hybridFormula'][0][ranks[0]]['species'],
self.details()['hybridFormula'][1][ranks[1]]['species']]


def hybrid_formula_authorship(self, et_al_cutoff=4):
def hybrid_formula_authorship(self, et_al_cutoff=None):
ranks = self.hybrid_formula_ranks()
authorship = ['', '']
for i in range(2):
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@

setup(
name="pyGNparser",
version="0.0.4",
version="0.0.5",
description="Python client for GNparser",
long_description=long_description,
long_description_content_type="text/markdown",
author="Geoff Ower",
author_email="[email protected]",
url="http://github.com/gnames/pyGNparser",
download_url="https://github.com/gnames/pyGNparser/archive/refs/tags/v0.0.4.tar.gz",
download_url="https://github.com/gnames/pyGNparser/archive/refs/tags/v0.0.5.tar.gz",
license="MIT",
packages=find_packages(exclude=["test-*"]),
install_requires=[
Expand Down
Loading

0 comments on commit 88a6e2a

Please sign in to comment.