Package: dclua
Declensor libraryUsingdclua.pylibrary you can train declension models and decline words. This will just replace suffix of the word to correspond new morphological properties you want the word to have. Here's some topics that will help you understand how it works.Morphological vectorMorphological vector is a vector which determines morphology properties for the lexeme. Number on each coordinate determine some property. You can use your vectors for your language, but here's the structure, which is suggested to use for Ukrainian.Noun vectorsNoun vectors has 2 coordinates:[number][case]. Here's the table, what means each value.CoordinateNumberCase0Nominative1SingularGenitive2PluralDative3Accusative4Instrumental5Locative6VocativeInfinitive suffix placed at[0][0].Verbs vectorsNoun vectors has 4 coordinates:[tense][person][number][gender].CoordinateTensePersonNumberGender0FirstSingularMasculine1PresentSecondPluralFeminine2FutureThirdNeutral3PastInfinitive suffix placed at[0][0][0][0].Adjective vectorsNoun vectors has 3 coordinates:[gender][number][person].CoordinateGenderNumberPerson0SingularFirst1MasculinePluralSecond2FeminineThird3NeutralInfinitive suffix placed at[0][0][0].Declension ruleDeclension rule is a multidimensional array which contains declensed suffixes, which is indexed usingmorphology vectors. You can create such model for your word in this way:rule=dclua.DeclenseTrainer.analyze({(0,0):'усмішка',(1,0):'усмішка',(1,1):'усмішки',(1,2):'усмішці',#...(2,6):'усмішки'});Now the rule will look like this:rule[0][0]=='ка'rule[1][0]=='ка'rule[1][1]=='ки'rule[1][2]=='ці'#...rule[2][6]=='ки'Every word has its suffix, so you need to create rule for each of them in order to use in the future.analyzemethod also acceptminsizeargument, which determine size of the minimal producing suffix.Word declensionOnce you have model (bundle of rules) for different suffixes, you can use them to decline words. The syntax is following:Declensor.declense(str word, tuple newmporph, tuple morphology=None)Suppose, you havemodelvariable, which contains models for all suffixes we want. Then you can decline words in the following way:>>>dcl=dclua.Declensor(model)>>>dcl.declense('сонцю',(1,1))<<<'сонця'The morphology vector of given word will be recognized automatically, so it may take some time to found appropriate declension model inmodels. If you already know the morphology of the word you want to declense, assign it to themorphologyargument:>>>dcl=dclua.Declensor(model)>>>dcl.declense('сонцю',(1,1),morphology=(1,2))<<<'сонця'Train your modelIn order to train your model you can use template fromtemplate.pyin this directory.Generalizing modelSometimes suffix in a model can appear in slight variations. For example,aab,aac: only the last letter is different. You can set up groups of letters, which can differ in such cases, and generalize your model according to this groups. Example of using:>>>dclua.DeclenseTrainer.generalizeModel(...model=[...[["она"],["они"],["онів"]],...[["ова"],["ови"],["овів"]],...],...groups=[...["н","в","п","м"]...],...threshold=.3...)...<<<[...[...[['она'],['они'],['онів']],...[['ова'],['ови'],['овів']],...[['опа'],['опи'],['опів']],...[['ома'],['оми'],['омів']]...]...]Threshold parameter is a ratio between amount of rules, which can be generalized to some group and size of that group. It's equal to.3by default, so if there are less then.3 * size_of_grouprules, they won't be generalized.