lesya 0.0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
lesya-0.0.1/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2018 The Python Packaging Authority
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ SOFTWARE.
lesya-0.0.1/PKG-INFO ADDED
@@ -0,0 +1,109 @@
1
+ Metadata-Version: 2.1
2
+ Name: lesya
3
+ Version: 0.0.1
4
+ Summary: Python package to form Ukrainian names cases : 'Леся Українка' -- 'Лесі Українки' , 'Лесі Українці', 'Лесею Українкою' ... etc.
5
+ Author: Dmytro Ustynov
6
+ Author-email: Dmytro Ustynov <ustynov.dev@gmail.com>
7
+ License: Copyright (c) 2018 The Python Packaging Authority
8
+
9
+ Permission is hereby granted, free of charge, to any person obtaining a copy
10
+ of this software and associated documentation files (the "Software"), to deal
11
+ in the Software without restriction, including without limitation the rights
12
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
+ copies of the Software, and to permit persons to whom the Software is
14
+ furnished to do so, subject to the following conditions:
15
+
16
+ The above copyright notice and this permission notice shall be included in all
17
+ copies or substantial portions of the Software.
18
+
19
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25
+ SOFTWARE.
26
+ Project-URL: Homepage, https://github.com/ustynov-py-dev/lesya.git
27
+ Project-URL: Issues, https://github.com/ustynov-py-dev/lesya/issues
28
+ Classifier: Programming Language :: Python :: 3
29
+ Classifier: License :: OSI Approved :: MIT License
30
+ Classifier: Operating System :: OS Independent
31
+ Requires-Python: >=3.8
32
+ Description-Content-Type: text/markdown
33
+ License-File: LICENSE
34
+
35
+ # Lesya
36
+
37
+ Lesya is a simple Python package for declining Ukrainian personal names into Ukrainian grammatical cases (_відмінки_): NOMINATIVE, GENITIVE, DATIVE, ACCUSATIVE, INSTRUMENTAL, PREPOSITIONAL, and VOCATIVE (_називний, родовий, давальний, знахідний, орудний, місцевий, кличний_).
38
+
39
+ ## Usage example
40
+
41
+ The most common usage is to convert a name into all cases:
42
+
43
+ ```python
44
+ from lesya import Lesya
45
+
46
+ person = Lesya('Леся Українка')
47
+ print(person.nominative) # Леся Українка
48
+ print(person.genitive) # Лесі Українки
49
+ print(person.dative) # Лесі Українці
50
+ print(person.accusative) # Лесю Українку
51
+ print(person.instrumental) # Лесею Українкою
52
+ print(person.prepositional) # Лесі Українці
53
+ print(person.vocative) # Лесе Українко
54
+ ```
55
+
56
+ You can also get a name in a specific case:
57
+
58
+ ```python
59
+ from lesya import Lesya
60
+ from lesya import CaseUA
61
+
62
+ person = Lesya('Тарас Григорович Шевченко')
63
+ print(person[CaseUA.DATIVE]) # Тарасу Григоровичу Шевченку
64
+ print(person[CaseUA.PREPOSITIONAL]) # Тарасові Григоровичу Шевченкові
65
+ print(person['орудний']) # Тарасом Григоровичем Шевченком
66
+ ```
67
+
68
+ ## Double names support
69
+
70
+ Lesya works well with double last names:
71
+
72
+ ```python
73
+ from lesya import Lesya
74
+
75
+ person = Lesya('Іван Семенович Нечуй-Левицький')
76
+ print(person.forms)
77
+ # Output:
78
+ {
79
+ 'називний': 'Іван Семенович Нечуй-Левицький',
80
+ 'родовий': 'Івана Семеновича Нечуя-Левицького',
81
+ 'давальний': 'Івану Семеновичу Нечуєві-Левицькому',
82
+ 'знахідний': 'Івана Семеновича Нечуя-Левицького',
83
+ 'орудний': 'Іваном Семеновичем Нечуєм-Левицьким',
84
+ 'місцевий': 'Іванові Семеновичу Нечуєві-Левицькому',
85
+ 'кличний': 'Іване Семеновичу Нечую-Левицький'
86
+ }
87
+ ```
88
+
89
+ ## `forms` attribute
90
+
91
+ You can get all cases at once using the forms attribute. It returns a dictionary where the keys are case names (in lowercase Ukrainian), and the values are the corresponding declined names.
92
+
93
+ ## Foreign names support
94
+
95
+ Lesya supports foreign names. However, since it does not use an ML model to automatically detect a person's gender, it works better if you explicitly provide the gender:
96
+
97
+ ```python
98
+ from lesya import Lesya
99
+ from lesya import CaseUA
100
+ from lesya import Gender
101
+
102
+ person = Lesya('Джозеф Байден', gender='male')
103
+ print(person[CaseUA.DATIVE]) # Джозефу Байдену
104
+ print(person[CaseUA.PREPOSITIONAL]) # Джозефові Байденові
105
+
106
+ person = Lesya('Камала Гаріс', gender=Gender.FEMALE)
107
+ print(person[CaseUA.DATIVE]) # Камалі Гаріс
108
+ print(person[CaseUA.PREPOSITIONAL]) # Камалі Гаріс
109
+ ```
lesya-0.0.1/README.md ADDED
@@ -0,0 +1,75 @@
1
+ # Lesya
2
+
3
+ Lesya is a simple Python package for declining Ukrainian personal names into Ukrainian grammatical cases (_відмінки_): NOMINATIVE, GENITIVE, DATIVE, ACCUSATIVE, INSTRUMENTAL, PREPOSITIONAL, and VOCATIVE (_називний, родовий, давальний, знахідний, орудний, місцевий, кличний_).
4
+
5
+ ## Usage example
6
+
7
+ The most common usage is to convert a name into all cases:
8
+
9
+ ```python
10
+ from lesya import Lesya
11
+
12
+ person = Lesya('Леся Українка')
13
+ print(person.nominative) # Леся Українка
14
+ print(person.genitive) # Лесі Українки
15
+ print(person.dative) # Лесі Українці
16
+ print(person.accusative) # Лесю Українку
17
+ print(person.instrumental) # Лесею Українкою
18
+ print(person.prepositional) # Лесі Українці
19
+ print(person.vocative) # Лесе Українко
20
+ ```
21
+
22
+ You can also get a name in a specific case:
23
+
24
+ ```python
25
+ from lesya import Lesya
26
+ from lesya import CaseUA
27
+
28
+ person = Lesya('Тарас Григорович Шевченко')
29
+ print(person[CaseUA.DATIVE]) # Тарасу Григоровичу Шевченку
30
+ print(person[CaseUA.PREPOSITIONAL]) # Тарасові Григоровичу Шевченкові
31
+ print(person['орудний']) # Тарасом Григоровичем Шевченком
32
+ ```
33
+
34
+ ## Double names support
35
+
36
+ Lesya works well with double last names:
37
+
38
+ ```python
39
+ from lesya import Lesya
40
+
41
+ person = Lesya('Іван Семенович Нечуй-Левицький')
42
+ print(person.forms)
43
+ # Output:
44
+ {
45
+ 'називний': 'Іван Семенович Нечуй-Левицький',
46
+ 'родовий': 'Івана Семеновича Нечуя-Левицького',
47
+ 'давальний': 'Івану Семеновичу Нечуєві-Левицькому',
48
+ 'знахідний': 'Івана Семеновича Нечуя-Левицького',
49
+ 'орудний': 'Іваном Семеновичем Нечуєм-Левицьким',
50
+ 'місцевий': 'Іванові Семеновичу Нечуєві-Левицькому',
51
+ 'кличний': 'Іване Семеновичу Нечую-Левицький'
52
+ }
53
+ ```
54
+
55
+ ## `forms` attribute
56
+
57
+ You can get all cases at once using the forms attribute. It returns a dictionary where the keys are case names (in lowercase Ukrainian), and the values are the corresponding declined names.
58
+
59
+ ## Foreign names support
60
+
61
+ Lesya supports foreign names. However, since it does not use an ML model to automatically detect a person's gender, it works better if you explicitly provide the gender:
62
+
63
+ ```python
64
+ from lesya import Lesya
65
+ from lesya import CaseUA
66
+ from lesya import Gender
67
+
68
+ person = Lesya('Джозеф Байден', gender='male')
69
+ print(person[CaseUA.DATIVE]) # Джозефу Байдену
70
+ print(person[CaseUA.PREPOSITIONAL]) # Джозефові Байденові
71
+
72
+ person = Lesya('Камала Гаріс', gender=Gender.FEMALE)
73
+ print(person[CaseUA.DATIVE]) # Камалі Гаріс
74
+ print(person[CaseUA.PREPOSITIONAL]) # Камалі Гаріс
75
+ ```
@@ -0,0 +1,3 @@
1
+ from .language.case_helpers import CaseUA
2
+ from .language.case_helpers import Gender
3
+ from .language.name_case import Lesya
File without changes
@@ -0,0 +1,138 @@
1
+ class Gender:
2
+ """
3
+ A class containing constants for gender determination
4
+ """
5
+ MALE = 'male'
6
+ FEMALE = 'female'
7
+ MAN = 'male'
8
+ WOMAN = 'female'
9
+
10
+
11
+ class CaseUA:
12
+ """
13
+ A class containing constants for grammatical cases in Ukrainian
14
+ """
15
+ NOMINATIVE = "nominative" # "Називний відмінок (Nominative)" # Nominative case
16
+ GENITIVE = "genitive" # "Родовий відмінок (Genitive)" # Genitive case
17
+ DATIVE = "dative" # "Давальний відмінок (Dative)" # Dative case
18
+ ACCUSATIVE = "accusative" # "Знахідний відмінок (Accusative)" # Accusative case
19
+ INSTRUMENTAL = "instrumental" # "Орудний відмінок (Instrumental)" # Instrumental case
20
+ PREPOSITIONAL = "prepositional" # "Місцевий відмінок (Prepositional)" # Prepositional case
21
+ VOCATIVE = "vocative" # "Кличний відмінок (Vocative)" # Vocative case
22
+
23
+ @classmethod
24
+ def __getitem__(cls, number: int):
25
+ if number in range(7):
26
+ return {0: cls.NOMINATIVE,
27
+ 1: cls.GENITIVE,
28
+ 2: cls.DATIVE,
29
+ 3: cls.ACCUSATIVE,
30
+ 4: cls.INSTRUMENTAL,
31
+ 5: cls.PREPOSITIONAL,
32
+ 6: cls.VOCATIVE}.get(number)
33
+ raise TypeError("The number must be in the range from 0 to 6")
34
+
35
+ def all(self, lang='en'):
36
+ if lang == 'en':
37
+ return [self.NOMINATIVE, self.GENITIVE, self.DATIVE, self.ACCUSATIVE, self.INSTRUMENTAL, self.PREPOSITIONAL,
38
+ self.VOCATIVE]
39
+ elif lang == 'ua':
40
+ return ['називний', 'родовий', 'давальний', 'знахідний', 'орудний', 'місцевий', 'кличний']
41
+
42
+ @staticmethod
43
+ def count():
44
+ return 7
45
+
46
+ @classmethod
47
+ def __len__(cls):
48
+ return cls.count()
49
+
50
+
51
+ class NamePart:
52
+ FIRSTNAME = 'firstname'
53
+ LASTNAME = 'lastname'
54
+ PATRONYMIC = 'patronymic'
55
+
56
+
57
+ class NCLNameCaseWord:
58
+ """
59
+ A class representing a word with additional properties and methods for handling name cases and gender determination.
60
+ """
61
+ def __init__(self, word):
62
+ self.word = word.lower()
63
+ self.word_orig = word
64
+ self.name_part = None
65
+ self.gender_man = 0
66
+ self.gender_woman = 0
67
+ self.gender_solved = None
68
+ # mask to define origin capital and string letters: X, or x
69
+ self.letter_mask = ''
70
+ # array of cases for the word
71
+ self.name_cases = []
72
+ # self.rule = 0
73
+ self.create_mask(word)
74
+
75
+ def create_mask(self, word):
76
+ """
77
+ Generating mask for the word
78
+ """
79
+ for letter in word:
80
+ if letter.isupper():
81
+ self.letter_mask += 'X'
82
+ else:
83
+ self.letter_mask += 'x'
84
+
85
+ def return_mask(self):
86
+ """ Convert the word to the capital / small letter format according to its mask
87
+ """
88
+ mask_length = len(self.letter_mask)
89
+ for i, case in enumerate(self.name_cases):
90
+ case_length = len(case)
91
+ max_len = min(case_length, mask_length)
92
+ new_case = ''
93
+ for j in range(max_len):
94
+ letter = case[j]
95
+ if self.letter_mask[j] == 'X':
96
+ letter = letter.upper()
97
+ new_case += letter
98
+ new_case += case[max_len:case_length]
99
+ self.name_cases[i] = new_case
100
+
101
+ def set_name_cases(self, name_cases, is_return_mask=True):
102
+ self.name_cases = name_cases
103
+ if is_return_mask:
104
+ self.return_mask()
105
+
106
+ def get_name_cases(self):
107
+ return self.name_cases
108
+
109
+ def gender(self):
110
+ if not self.gender_solved:
111
+ if self.gender_man >= self.gender_woman:
112
+ self.gender_solved = Gender.MALE
113
+ else:
114
+ self.gender_solved = Gender.FEMALE
115
+ return self.gender_solved
116
+
117
+ def set_gender(self, man, woman):
118
+ self.gender_man = man
119
+ self.gender_woman = woman
120
+
121
+ def set_true_gender(self, gender):
122
+ self.gender_solved = gender
123
+
124
+ def get_gender(self):
125
+ return {Gender.MALE: self.gender_man, Gender.FEMALE: self.gender_woman}
126
+
127
+ def is_gender_solved(self):
128
+ return bool(self.gender_solved)
129
+
130
+ def __repr__(self):
131
+ return f'{self.word_orig} - {self.name_cases}'
132
+
133
+ def __eq__(self, other):
134
+ if isinstance(other, str):
135
+ return self.word_orig == other
136
+ elif isinstance(other, NCLNameCaseWord):
137
+ return self.word_orig == other.word_orig
138
+ return False