Use

Installation

Install in the normal way:

$ pip install nominally

Working on a project within a virtual environment is highly recommended:

$ python3 -m venv .venv
$ source ./.venv/bin/activate
(.venv) $ pip install nominally
Collecting nominally
  Downloading [...]/nominally-1.0.3-py3-none-any.whl
Collecting unidecode>=1.0 (from nominally)
  Downloading [...]/Unidecode-1.1.1-py2.py3-none-any.whl
Installing collected packages: unidecode, nominally
Successfully installed nominally-1.0.3 unidecode-1.1.1

Nominally requires Python 3.6 or higher and has one external dependency (unidecode).

parse_name() function

The nominally.api.parse_name() function returns the five core fields:

>>> from pprint import pprint
>>> import nominally
>>> parsed = nominally.parse_name('Samuel "Young Sam" Vimes II')
>>> pprint(parsed)
{'first': 'samuel',
 'last': 'vimes',
 'middle': '',
 'nickname': 'young sam',
 'suffix': 'ii',
 'title': ''}

Name() class

Additional features are exposed via the nominally.parser.Name class:

>>> from pprint import pprint
>>> from nominally import Name
>>> n = Name('Delphine Angua von Uberwald')
>>> pprint(n.report())
{'cleaned': {'delphine angua von uberwald'},
 'first': 'delphine',
 'last': 'von uberwald',
 'list': ['', 'delphine', 'angua', 'von uberwald', '', ''],
 'middle': 'angua',
 'nickname': '',
 'parsed': 'von uberwald, delphine angua',
 'raw': 'Delphine Angua von Uberwald',
 'suffix': '',
 'title': ''}
>>> n.raw
'Delphine Angua von Uberwald'
>>> n.cleaned
{'delphine angua von uberwald'}
>>> n.first
'delphine'
>>> n['first']
'delphine'
>>> n.get('first')
'delphine'
>>> pprint(dict(n))
{'first': 'delphine',
 'last': 'von uberwald',
 'middle': 'angua',
 'nickname': '',
 'suffix': '',
 'title': ''}

From the Console

For convenience, single names can be run at the command line.

$ nominally "St John Nobbs, Cecil (Nobby) Wormsborough"
       raw: St John Nobbs, Cecil (Nobby) Wormsborough
   cleaned: {'nobby', 'st john nobbs, cecil wormsborough'}
    parsed: st john nobbs, cecil (nobby) wormsborough
      list: ['', 'cecil', 'wormsborough', 'st john nobbs', '', 'nobby']
     title: 
     first: cecil
    middle: wormsborough
      last: st john nobbs
    suffix: 
  nickname: nobby

Extended Examples

See https://github.com/vaneseltine/nominally-examples/ for detailed examples of nominally usage.