From 0778e2e49797ec52615980a087d3320e0f480fd7 Mon Sep 17 00:00:00 2001 From: Aarne Ranta Date: Wed, 27 Mar 2024 08:45:44 +0100 Subject: [PATCH] Python example of inflection --- python/other_examples/inflection.py | 53 ++++++++++++++++++++++++++++ python/other_examples/inflection.py~ | 2 ++ 2 files changed, 55 insertions(+) create mode 100644 python/other_examples/inflection.py create mode 100644 python/other_examples/inflection.py~ diff --git a/python/other_examples/inflection.py b/python/other_examples/inflection.py new file mode 100644 index 0000000..1bf5b72 --- /dev/null +++ b/python/other_examples/inflection.py @@ -0,0 +1,53 @@ +# examples of morphology + +# Latin noun inflection + +# features + +Number = ['Sg', 'Pl'] +Case = ['Nom', 'Acc', 'Gen', 'Dat', 'Abl'] +Gender = ['Masc', 'Fem'] + + +# a paradigm: the first declension + +def decl1(rosa, n, c): + ros = rosa[:-1] + match (n, c): + case ('Sg', ('Nom'|'Abl')): + return ros + 'a' + case ('Sg', 'Acc'): + return ros + 'am' + case ('Sg', ('Gen'|'Dat')) | ('Pl', 'Nom'): + return ros + 'ae' + case ('Pl', 'Gen'): + return ros + 'arum' + case ('Pl', ('Dat'|'Abl')): + return ros + 'is' + + +# inflection table as a dictionary + +def noun_dict(decl, noun): + return {n: {c: decl(noun, n, c) for c in Case} for n in Number} + + +# lexical entry: inflection table together with inherent features + +rosa_N = {'infl': noun_dict(decl1, 'rosa'), 'gender': 'Fem'} + +mensa_N = {'infl': noun_dict(decl1, 'mensa'), 'gender': 'Fem'} + + +if __name__ == '__main__': + print(rosa_N) + print(mensa_N) + + + + + + + + + diff --git a/python/other_examples/inflection.py~ b/python/other_examples/inflection.py~ new file mode 100644 index 0000000..5cefb03 --- /dev/null +++ b/python/other_examples/inflection.py~ @@ -0,0 +1,2 @@ +-- Latin noun inflection +