Skip to main content

A Python library for declension of personal names in Serbian

Project description

deklinacija

A Python library for grammatically correct declension (Serbian: deklinacija) of personal first and last names in Serbian, with support for both Cyrillic and Latin scripts, and even creation of posessive forms, with also a few useful tools for working with the Serbian language. Check out this web demo: https://deklinacija.pythonanywhere.com/

Installation

The source code is currently hosted on GitHub: https://github.com/urelja/deklinacija

The latest binary versions are hosted on the Python Package Index (PyPI): https://pypi.org/project/deklinacija/

pip install deklinacija

Usage

Simply import the package. It is recommended to set the alias to dek.

import deklinacija as dek

To decline names, all you have to do is to call the appropriate function for the grammatical case you want to use, and specify the name and the gender parameter. The name parameter must be a string, can have either Latin or Cyrillic characters (automatically detected), and can contain uppercase or lowercase letters (the script respects the capitalisation of the name and will capitalise the added suffixes according to the last character's capitalisation, see vokativ2 below). You can also input a full name (with a first name and a last name, multiple last names are supported too, separated with a whitespace character) and the script will change the name accordingly.

The functions in this example return a string.

import deklinacija as dek

genitiv = dek.genitiv("Velja","male") #Velje
genitiv2 = dek.genitiv("Velja Petrović","male") #Velje Petrovića
dativ = dek.dativ("Jana","female") #Jani
dativ2 = dek.dativ("Jana Paunovska","female") #Jani Paunovskoj
akuzativ = dek.akuzativ("Петар","male") #Петра
akuzativ2 = dek.akuzativ("Петар Петровић","male") #Петра Петровића
vokativ = dek.vokativ("Predrag","male") #Predraže
vokativ2 = dek.vokativ("PREDRAG JANKOVIĆ","male") #PREDRAŽE JANKOVIĆU
instrumental = dek.instrumental("Uroš","male") #Urošem
instrumental2 = dek.instrumental("Uroš Konstantinović","male") #Urošem Konstantinovićem
lokativ = dek.lokativ("Lana","female") #Lani
lokativ = dek.lokativ("Lana Petrović","female") #Lani Petrović

print(f"Zdravo, {vokativ}! Dobio si zahtev za prijateljstvo od {genitiv2}.") 
#Zdravo Predraže! Dobio si zahtev za prijateljstvo od Velje Petrovića. // Translation: Hello Predrag! You have received a friend request from Velja Petrović.

You can also immediatelly decline a name through all grammatical cases by calling the declineAll() function.

The declineAll() function returns a dictionary, where the keys are the grammatical cases.

import deklinacija as dek

name = dek.declineAll("Nikola","male") 
#{'nominativ': 'Nikola', 'genitiv': 'Nikole', 'dativ': 'Nikoli', 'akuzativ': 'Nikolu', 
#'vokativ':'Nikola', 'instrumental': 'Nikolom', 'lokativ': 'Nikoli'}

print("Dali ste poklon",name['dativ']) 
#Dali ste poklon Nikoli // Translation: You have given a gift to Nikola

Posessive Forms

As of version 1.6 there is a new feature: posessive forms. Aside from the name and the gender of the person, you also have to specify the gender of the posessed object and its grammatical number. In case the gender of the posessed object is unknown, you can just pass the object itself to the object_gender parameter and the program will figure out which gender it is, provided that the grammatical_number is set correctly (default value is "singular").

The functions in this example return a string.

import deklinacija as dek

name = dek.posessive(name = "Stefan", gender = "male", object_gender = "female", grammatical_number = "singular")
name2 = dek.posessive(name = "Stefan", gender = "male", object_gender = "grupa") #passing the object "group" instead of "female", default grammatical_number value is "singular" so it's not required to specify it in this case
name3 = dek.posessive(name = "Stefan", gender = "male", object_gender = "slušalice", grammatical_number = "plural") #passing the object "headphones"

print(name,"grupa") #Stefanova grupa // Translation: Stefan's group
print(name2,"grupa") #Stefanova grupa
print(name3,"slušalice") #Stefanove slušalice // Translation: Stefan's headphones

You can also immediately transform the name through all possible posessive forms (male, female, neutral in singular and plural) by calling the posessiveAll() function. Only the name and gender parameters are required.

The posessiveAll() function returns a dictionary where the keys are in the "GENDER_NUMBER" format.

import deklinacija as dek

name = dek.posessiveAll("Stefan","male") #{'name': 'Stefan', 'male_singular': 'Stefanov', 'male_plural': 'Stefanovi', 'female_singular': 'Stefanova', 'female_plural': 'Stefanove', 'neutral_singular': 'Stefanovo', 'neutral_plural': 'Stefanova'}

print(name['male_plural'],"prijatelji") #Stefanovi prijatelji // Translation: Stefan's friends

Other tools

This library makes extensive use of a few internal utilities that one may find useful when working with the Serbian language. These include:

toLatin(word), toCyrillic(word): Converts input string from Latin into Cyrillic and vice versa. Works with Serbian Latin letter pairs (lj, nj, dž, etc.)

separateLetters(word): Separates letters from word, while making sure that certain letter pairs in Serbian Latin (lj, nj, dž etc.) stay together. Returns a list.

isLatin(word): Returns a boolean indicating whether the last character of the input string is in the Latin script. Raises an error if the character isn't in neither Latin or Cyrillic.

Todo

All promised features have been implemented. All that is left is code cleanup. Feel free to suggest new features on the GitHub page.

Attribution

Vokativi by Startit is licensed under CC BY 4.0 / Modifications: converted into Cyrillic and filtered out names longer than 6 characters

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

deklinacija-1.6.1.tar.gz (17.1 kB view details)

Uploaded Source

Built Distribution

deklinacija-1.6.1-py3-none-any.whl (12.6 kB view details)

Uploaded Python 3

File details

Details for the file deklinacija-1.6.1.tar.gz.

File metadata

  • Download URL: deklinacija-1.6.1.tar.gz
  • Upload date:
  • Size: 17.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for deklinacija-1.6.1.tar.gz
Algorithm Hash digest
SHA256 077d45edae17934455e02e72a71bf649b9673c413c0e94db22ed5544fd049530
MD5 f23a450f07e22d9991e61d68a59c559c
BLAKE2b-256 8c8c10273cf6acc770793a24c8c910a5d8afded8ec5922d4ee803a0976e55ab3

See more details on using hashes here.

File details

Details for the file deklinacija-1.6.1-py3-none-any.whl.

File metadata

  • Download URL: deklinacija-1.6.1-py3-none-any.whl
  • Upload date:
  • Size: 12.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for deklinacija-1.6.1-py3-none-any.whl
Algorithm Hash digest
SHA256 74c2d7b917bd36219553b147aa1b9809aa99d55a7274d59a674680ec11261238
MD5 f9635358e797cc1d6f0cfc7c830d08ad
BLAKE2b-256 c085438942b9e02f6bfbc0d1eda6d1e7156520b495985acf15febcdbf564604f

See more details on using hashes here.

Supported by

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