Skip to main content

pytrovich: a Python port of an inflector for Russian anthroponyms developed by petrovich team: https://github.com/petrovich

Project description

Pytrovich

pytrovich is a Python 3.9+ port of petrovich library which inflects Russian names to a given grammatical case. It supports first names, last names and middle names inflections. Since version 0.0.2, gender detection is also available.

petrovich-java was the main inspiration.

The alternative (earlier) port: Petrovich (@alexeyev was not aware of it at the time of porting petrovich to Python). The only meaningful difference we have found is that it does not support gender detection.

Python 3x PyPI version Downloads

Installation

Should be as simple as that

pip install pytrovich

Usage

Inflection

from pytrovich.enums import NamePart, Gender, Case
from pytrovich.maker import PetrovichDeclinationMaker

maker = PetrovichDeclinationMaker()
print(maker.make(NamePart.FIRSTNAME, Gender.MALE, Case.GENITIVE, "Иван"))  # Ивана
print(maker.make(NamePart.LASTNAME, Gender.MALE, Case.INSTRUMENTAL, "Иванов"))  # Ивановым
print(maker.make(NamePart.MIDDLENAME, Gender.FEMALE, Case.DATIVE, "Ивановна"))  # Ивановне

Gender detection

from pytrovich.detector import PetrovichGenderDetector

detector = PetrovichGenderDetector()
print(detector.detect(firstname="Иван"))  # Gender.MALE
print(detector.detect(firstname="Иван", middlename="Семёнович"))  # Gender.MALE
print(detector.detect(firstname="Арзу", middlename="Лутфияр кызы"))  # Gender.FEMALE

Custom rule file

You can replace default rules file with some custom one. Only JSON format is supported.

maker = PetrovichDeclinationMaker("/path/to/custom/rules.file.json")

E.g. if pytrovich fails on PetrovichDeclinationMaker creation, one may consider downloading rules.json directly from petrovich-rules repo as a fix (please create an issue if that actually happens).

How to cite

Not neccessary, but greatly appreciated, if you use this work.

@misc{Pytrovich,
  title     = {{petrovich/pytrovich: Python3 port of Petrovich, an inflector for Russian anthroponyms}},
  year      = {2020},
  url       = {https://github.com/petrovich/pytrovich},
  language  = {english},
}

More info

For more information on the project please refer to other petrovich repos.

TODO

  • efficiency was not a top priority, the time has come for faster algorithms, RegEx and data structures
  • evaluation based on petrovich-eval

License

This project is available under MIT license.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytrovich-0.0.7.tar.gz (32.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pytrovich-0.0.7-py3-none-any.whl (22.1 kB view details)

Uploaded Python 3

File details

Details for the file pytrovich-0.0.7.tar.gz.

File metadata

  • Download URL: pytrovich-0.0.7.tar.gz
  • Upload date:
  • Size: 32.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.18

File hashes

Hashes for pytrovich-0.0.7.tar.gz
Algorithm Hash digest
SHA256 f4149bf4a62e0da055b4387e096d12b7293f01772bb9b9e3c03ca793f85f1559
MD5 1c5135695a5114e96b9e967a286871d8
BLAKE2b-256 a14790e347e19ced20465db4aa5c0b6bf308284bc794f1699d4323abe4e22c2b

See more details on using hashes here.

File details

Details for the file pytrovich-0.0.7-py3-none-any.whl.

File metadata

  • Download URL: pytrovich-0.0.7-py3-none-any.whl
  • Upload date:
  • Size: 22.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.18

File hashes

Hashes for pytrovich-0.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 dd8e0fd99cfd251c9ddf05b8c0b0ce3d3bda3632853c14f3bc03cb29916e3366
MD5 549fbf3d1acd52bea15a59e0554897f5
BLAKE2b-256 ec6097a70dee76a8e2b3fb10d814f50522de7ccd4af5c62d49ff9e241ceb77e5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page