pytrovich: a Python port of an inflector for Russian anthroponyms developed by petrovich team: https://github.com/petrovich
Project description
pytrovich is a Python 3.6+ 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.
Installation
Should be as simple as that
pip install pytrovich
Usage
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, "Ивановна")) # Ивановне
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for pytrovich-0.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c60b6636477273bc4c4694e76d5465ce5bc8766d0decff007210962453110527 |
|
MD5 | e1176b18f719f44ffbd5ad6a3996a07b |
|
BLAKE2b-256 | e7a6a144ec5c6e3219fe609ea40f631994dd4ad3933a0a742a386fc631f78647 |