mlinflect 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.
- mlinflect-0.0.1/.gitignore +11 -0
- mlinflect-0.0.1/LICENSE +201 -0
- mlinflect-0.0.1/LIMITATIONS.md +66 -0
- mlinflect-0.0.1/NOTICE +9 -0
- mlinflect-0.0.1/PKG-INFO +86 -0
- mlinflect-0.0.1/README.md +63 -0
- mlinflect-0.0.1/REFERENCES.md +40 -0
- mlinflect-0.0.1/pyproject.toml +36 -0
- mlinflect-0.0.1/src/mlinflect/__init__.py +26 -0
- mlinflect-0.0.1/src/mlinflect/nouns.py +176 -0
- mlinflect-0.0.1/src/mlinflect/py.typed +0 -0
- mlinflect-0.0.1/src/mlinflect/rules.py +199 -0
- mlinflect-0.0.1/src/mlinflect/types.py +79 -0
- mlinflect-0.0.1/tests/test_nouns.py +195 -0
mlinflect-0.0.1/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# Limitations
|
|
2
|
+
|
|
3
|
+
mlsynth never emits a wrong form. When it cannot produce a form it has not verified,
|
|
4
|
+
it raises instead. Two exception types:
|
|
5
|
+
|
|
6
|
+
- **`UnsupportedRoot`**: the root's shape is not in a supported noun class.
|
|
7
|
+
- **`NotImplementedError`**: a supported class, but that case/number is not encoded.
|
|
8
|
+
|
|
9
|
+
This document is generated from the current rules.
|
|
10
|
+
|
|
11
|
+
## Supported noun classes
|
|
12
|
+
|
|
13
|
+
| Class | Shape | Example | Coverage |
|
|
14
|
+
|-------|-------|---------|----------|
|
|
15
|
+
| `am_neuter` | consonant + anuswara | `മരം` | complete (11 cases, sg + pl) |
|
|
16
|
+
| `i_vowel` | `-ി` vowel-final | `കുട്ടി` | complete (11 cases, sg + pl) |
|
|
17
|
+
| `u_vowel` | `-ഉ` / `-ഊ` vowel-final | `പശു` | complete singular; plural extrapolated |
|
|
18
|
+
| `vowel_anuswara` | vowel + anuswara | `കലാം`, `ടീം` | singular minus instrumental; no plural |
|
|
19
|
+
| `ṭ_geminate` | `-ട്` final (geminating) | `വീട്` | singular minus instrumental; no plural |
|
|
20
|
+
|
|
21
|
+
## A. Root shapes that raise `UnsupportedRoot`
|
|
22
|
+
|
|
23
|
+
These classes are not encoded yet:
|
|
24
|
+
|
|
25
|
+
| Root shape | Examples | Planned class |
|
|
26
|
+
|------------|----------|---------------|
|
|
27
|
+
| `-അ` / `-എ` vowel stems | `അമ്മ`, `പുഴ` | a/e-stem (`യ` glide) |
|
|
28
|
+
| chillu final | `അവൻ`, `നായർ`, `പാൽ`, `മകൾ` | chillu classes (per-chillu) |
|
|
29
|
+
| long `-ീ` vowel stems | `സ്ത്രീ` | a/e/ī-stem (`യ` glide) |
|
|
30
|
+
| no Malayalam base letter, or empty | `ABC`, `123`, bare signs, `""` | rejected by design |
|
|
31
|
+
|
|
32
|
+
The a/e-stem class needs predicate-based matching (those roots end in a bare consonant,
|
|
33
|
+
not a fixed suffix); the chillu classes need per-chillu handling. Both are specced and
|
|
34
|
+
deferred to the next release.
|
|
35
|
+
|
|
36
|
+
## B. Case/number combinations that raise `NotImplementedError`
|
|
37
|
+
|
|
38
|
+
- **`vowel_anuswara`** (`കലാം`): instrumental and the whole plural are not encoded.
|
|
39
|
+
- **`ṭ_geminate`** (`വീട്`): instrumental and the whole plural are not encoded.
|
|
40
|
+
|
|
41
|
+
`am_neuter`, `i_vowel`, and `u_vowel` (singular) have no such gaps.
|
|
42
|
+
|
|
43
|
+
## C. Produced but not native-ratified (`verified=False`)
|
|
44
|
+
|
|
45
|
+
- **`u_vowel` plural**: the `-ക്കൾ` marker is native-given (`പശുക്കൾ`), but the plural
|
|
46
|
+
oblique paradigm (`പശുക്കളുടെ`, ...) is extrapolated. Gate on `result.verified` for
|
|
47
|
+
ratified output only.
|
|
48
|
+
|
|
49
|
+
## D. Known matching caveat
|
|
50
|
+
|
|
51
|
+
`u_vowel` matches any root ending in `-ു` / `-ൂ`. A non-standard input that writes a
|
|
52
|
+
final samvruthokaram (half-u) as a bare `-ു` instead of `-്` could be mis-routed here.
|
|
53
|
+
Standard orthography writes samvruthokaram with the virama, so genuine `-ഉ`-final nouns
|
|
54
|
+
(`പശു`, `ഗുരു`) inflect correctly; the risk is limited to non-standard/transliterated input.
|
|
55
|
+
|
|
56
|
+
## E. Out of scope in this release
|
|
57
|
+
|
|
58
|
+
- **Verbs**: noun synthesis only; verb synthesis is the next major addition.
|
|
59
|
+
- **Pronouns**: irregular; deferred.
|
|
60
|
+
- **Derivation, compounding, and external sandhi** (word + word) are out of scope.
|
|
61
|
+
|
|
62
|
+
## Roadmap
|
|
63
|
+
|
|
64
|
+
Next: the a/e-stem and chillu classes (section A), the instrumental + plural of the
|
|
65
|
+
two partial classes (section B), and native ratification of the `u_vowel` plural.
|
|
66
|
+
Verbs follow as 0.1.0.
|
mlinflect-0.0.1/NOTICE
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
mlsynth
|
|
2
|
+
Copyright 2026 Jayashankar R
|
|
3
|
+
|
|
4
|
+
This product includes software developed for permissive, rule-based Malayalam
|
|
5
|
+
morphological synthesis.
|
|
6
|
+
|
|
7
|
+
Linguistic rules implemented here are restated facts drawn from published
|
|
8
|
+
scholarship (see REFERENCES.md). No third-party text, tables, code, or datasets
|
|
9
|
+
are included or redistributed.
|
mlinflect-0.0.1/PKG-INFO
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: mlinflect
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Permissive, rule-based Malayalam morphological synthesizer (noun inflection generation).
|
|
5
|
+
Project-URL: Homepage, https://github.com/jayashankarvr/mlinflect
|
|
6
|
+
Project-URL: Source, https://github.com/jayashankarvr/mlinflect
|
|
7
|
+
Project-URL: Issues, https://github.com/jayashankarvr/mlinflect/issues
|
|
8
|
+
Author-email: Jayashankar R <56070307+jayashankarvr@users.noreply.github.com>
|
|
9
|
+
License-Expression: Apache-2.0
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
License-File: NOTICE
|
|
12
|
+
Keywords: agglutinative,dravidian,inflection,malayalam,morphology,nlp,synthesis
|
|
13
|
+
Classifier: Development Status :: 3 - Alpha
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Intended Audience :: Science/Research
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Topic :: Text Processing :: Linguistic
|
|
18
|
+
Classifier: Typing :: Typed
|
|
19
|
+
Requires-Python: >=3.9
|
|
20
|
+
Provides-Extra: dev
|
|
21
|
+
Requires-Dist: pytest>=7; extra == 'dev'
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
|
|
24
|
+
# mlinflect
|
|
25
|
+
|
|
26
|
+
A permissive, rule-based Malayalam morphological synthesizer. It does forward
|
|
27
|
+
morphological generation: given a root and grammatical features, it produces the
|
|
28
|
+
inflected surface form (the counterpart to morphological analysis/segmentation).
|
|
29
|
+
|
|
30
|
+
```python
|
|
31
|
+
from mlinflect import synthesize_noun, Case, Number
|
|
32
|
+
|
|
33
|
+
synthesize_noun("മരം", Case.LOCATIVE).surface # 'മരത്തിൽ'
|
|
34
|
+
synthesize_noun("മരം", Case.GENITIVE).surface # 'മരത്തിന്റെ'
|
|
35
|
+
synthesize_noun("കുട്ടി", Case.GENITIVE).surface # 'കുട്ടിയുടെ'
|
|
36
|
+
synthesize_noun("മരം", Case.NOMINATIVE, number=Number.PLURAL).surface # 'മരങ്ങൾ'
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Why this exists
|
|
40
|
+
|
|
41
|
+
Existing Malayalam morphology tools are either copyleft (Apertium, libindic =
|
|
42
|
+
GPL/AGPL) or, in the case of the one permissive *generator* (`mlmorph`, MIT), built
|
|
43
|
+
on a GPL FST runtime. There is no permissive, dependency-clean, rule-based Malayalam
|
|
44
|
+
**synthesizer**. `mlinflect` aims to fill that gap with a small pure-Python rule engine
|
|
45
|
+
and no copyleft dependencies.
|
|
46
|
+
|
|
47
|
+
## Design
|
|
48
|
+
|
|
49
|
+
- **Declarative, provenance-tagged rules** (`mlinflect/rules.py`): each rule cites the
|
|
50
|
+
source it was drawn from and carries a `verified` flag that is `True` only when the
|
|
51
|
+
form has been ratified by a native reviewer. Adding or correcting a paradigm is a
|
|
52
|
+
data edit, not a code change.
|
|
53
|
+
- **Inspectable results**: every `synthesize_noun(...)` returns a `SynthResult` with the
|
|
54
|
+
`surface` form, the `morphemes` that compose it, the `stem_class`, the `provenance`
|
|
55
|
+
key, and `verified`. Feature combinations that are not yet encoded raise rather than
|
|
56
|
+
return a silently wrong form.
|
|
57
|
+
- **Akshara-correct joins**: suffixes are represented matra-initial so concatenation
|
|
58
|
+
produces correct conjuncts/vowel signs; the genitive uses the canonical *nta* form
|
|
59
|
+
(NA + virama + RRA).
|
|
60
|
+
|
|
61
|
+
## Status
|
|
62
|
+
|
|
63
|
+
Alpha. Five ending-conditioned noun classes: `am_neuter` (മരം) and `i_vowel` (കുട്ടി)
|
|
64
|
+
are complete across 11 cases (singular and plural); `vowel_anuswara` (കലാം), `u_vowel`
|
|
65
|
+
(പശു), and `ṭ_geminate` (വീട്) are partial. Includes differential object marking and a
|
|
66
|
+
synthetic/colloquial register for the instrumental. Most forms are native-ratified
|
|
67
|
+
(`verified=True`); a few are SMC-sourced pending sign-off (`verified=False`). See
|
|
68
|
+
[`LIMITATIONS.md`](LIMITATIONS.md) for exactly what is unsupported. Remaining noun
|
|
69
|
+
classes (a/e-stems, chillu), verbs, and pronouns are future work.
|
|
70
|
+
|
|
71
|
+
## Install
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
pip install mlinflect # once published
|
|
75
|
+
# from source:
|
|
76
|
+
pip install -e ".[dev]"
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## License
|
|
80
|
+
|
|
81
|
+
Apache-2.0. See `LICENSE` and `NOTICE`. Contributions are accepted under Apache-2.0
|
|
82
|
+
§5 (inbound = outbound); no separate CLA is required.
|
|
83
|
+
|
|
84
|
+
The implemented linguistic rules are **facts** restated in our own code; no source's
|
|
85
|
+
text, tables, code, or data is reproduced. Sources are credited in `REFERENCES.md` as
|
|
86
|
+
scholarship; that implies no endorsement and creates no license obligation.
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# mlinflect
|
|
2
|
+
|
|
3
|
+
A permissive, rule-based Malayalam morphological synthesizer. It does forward
|
|
4
|
+
morphological generation: given a root and grammatical features, it produces the
|
|
5
|
+
inflected surface form (the counterpart to morphological analysis/segmentation).
|
|
6
|
+
|
|
7
|
+
```python
|
|
8
|
+
from mlinflect import synthesize_noun, Case, Number
|
|
9
|
+
|
|
10
|
+
synthesize_noun("മരം", Case.LOCATIVE).surface # 'മരത്തിൽ'
|
|
11
|
+
synthesize_noun("മരം", Case.GENITIVE).surface # 'മരത്തിന്റെ'
|
|
12
|
+
synthesize_noun("കുട്ടി", Case.GENITIVE).surface # 'കുട്ടിയുടെ'
|
|
13
|
+
synthesize_noun("മരം", Case.NOMINATIVE, number=Number.PLURAL).surface # 'മരങ്ങൾ'
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Why this exists
|
|
17
|
+
|
|
18
|
+
Existing Malayalam morphology tools are either copyleft (Apertium, libindic =
|
|
19
|
+
GPL/AGPL) or, in the case of the one permissive *generator* (`mlmorph`, MIT), built
|
|
20
|
+
on a GPL FST runtime. There is no permissive, dependency-clean, rule-based Malayalam
|
|
21
|
+
**synthesizer**. `mlinflect` aims to fill that gap with a small pure-Python rule engine
|
|
22
|
+
and no copyleft dependencies.
|
|
23
|
+
|
|
24
|
+
## Design
|
|
25
|
+
|
|
26
|
+
- **Declarative, provenance-tagged rules** (`mlinflect/rules.py`): each rule cites the
|
|
27
|
+
source it was drawn from and carries a `verified` flag that is `True` only when the
|
|
28
|
+
form has been ratified by a native reviewer. Adding or correcting a paradigm is a
|
|
29
|
+
data edit, not a code change.
|
|
30
|
+
- **Inspectable results**: every `synthesize_noun(...)` returns a `SynthResult` with the
|
|
31
|
+
`surface` form, the `morphemes` that compose it, the `stem_class`, the `provenance`
|
|
32
|
+
key, and `verified`. Feature combinations that are not yet encoded raise rather than
|
|
33
|
+
return a silently wrong form.
|
|
34
|
+
- **Akshara-correct joins**: suffixes are represented matra-initial so concatenation
|
|
35
|
+
produces correct conjuncts/vowel signs; the genitive uses the canonical *nta* form
|
|
36
|
+
(NA + virama + RRA).
|
|
37
|
+
|
|
38
|
+
## Status
|
|
39
|
+
|
|
40
|
+
Alpha. Five ending-conditioned noun classes: `am_neuter` (മരം) and `i_vowel` (കുട്ടി)
|
|
41
|
+
are complete across 11 cases (singular and plural); `vowel_anuswara` (കലാം), `u_vowel`
|
|
42
|
+
(പശു), and `ṭ_geminate` (വീട്) are partial. Includes differential object marking and a
|
|
43
|
+
synthetic/colloquial register for the instrumental. Most forms are native-ratified
|
|
44
|
+
(`verified=True`); a few are SMC-sourced pending sign-off (`verified=False`). See
|
|
45
|
+
[`LIMITATIONS.md`](LIMITATIONS.md) for exactly what is unsupported. Remaining noun
|
|
46
|
+
classes (a/e-stems, chillu), verbs, and pronouns are future work.
|
|
47
|
+
|
|
48
|
+
## Install
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
pip install mlinflect # once published
|
|
52
|
+
# from source:
|
|
53
|
+
pip install -e ".[dev]"
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## License
|
|
57
|
+
|
|
58
|
+
Apache-2.0. See `LICENSE` and `NOTICE`. Contributions are accepted under Apache-2.0
|
|
59
|
+
§5 (inbound = outbound); no separate CLA is required.
|
|
60
|
+
|
|
61
|
+
The implemented linguistic rules are **facts** restated in our own code; no source's
|
|
62
|
+
text, tables, code, or data is reproduced. Sources are credited in `REFERENCES.md` as
|
|
63
|
+
scholarship; that implies no endorsement and creates no license obligation.
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# References
|
|
2
|
+
|
|
3
|
+
`mlsynth` implements Malayalam morphological **facts** (case-marker allomorphy,
|
|
4
|
+
oblique-stem augments, glide insertion) restated in our own rule engine. **No text,
|
|
5
|
+
tables, code, or datasets from any source below are reproduced or redistributed.**
|
|
6
|
+
These citations are scholarly credit; they imply no endorsement and create no license
|
|
7
|
+
obligation.
|
|
8
|
+
|
|
9
|
+
Each rule in `mlsynth/rules.py` carries a `provenance` key from this list. Forms are
|
|
10
|
+
ratified through a native-reviewer workflow; a rule's `verified` flag is `True` only
|
|
11
|
+
after native sign-off.
|
|
12
|
+
|
|
13
|
+
## Provenance keys
|
|
14
|
+
|
|
15
|
+
- **`vinod-2012`**: Vinod P. M., Jayan V., Bhadran V. K. *Implementation of Malayalam
|
|
16
|
+
Morphological Analyzer Based on Hybrid Approach.* Proc. ROCLING 2012 (ACL Anthology
|
|
17
|
+
O12-1028). Source of the `am_neuter` (-ം, oblique -ത്ത-) singular paradigm.
|
|
18
|
+
- **`krishnan-2021`**: Krishnan G. G., Raghunathan A., Sarma V. M. *Acquisition of
|
|
19
|
+
Malayalam inflections: Complexity of morphosyntactic rules and its impact on
|
|
20
|
+
developing grammars.* First Language. Case inventory and allomorphy for the
|
|
21
|
+
`i_vowel` class.
|
|
22
|
+
- **`native-14`**: Native-reviewer ratification (project correctness log, item #14):
|
|
23
|
+
the modern genitive form കുട്ടിയുടെ (over the archaic FST form).
|
|
24
|
+
- **`native-2026`**: Native-reviewer worksheet ratification of the മരം and കുട്ടി
|
|
25
|
+
singular/plural paradigms, the differential-object-marking rule (inanimate accusative
|
|
26
|
+
defaults bare), and the synthetic/analytic instrumental register.
|
|
27
|
+
- **`smc-morph`**: SMC's Malayalam morphology documentation, covering nominal inflection rules
|
|
28
|
+
(https://morph.smc.org.in/ninfl/cases.html) and the mlmorph tagset
|
|
29
|
+
(https://gitlab.com/smc/mlmorph). Used for cases pending native sign-off
|
|
30
|
+
(ablative, allative, perlative, vocative). Rules restated as facts, no data copied.
|
|
31
|
+
|
|
32
|
+
## Additional background consulted (facts only)
|
|
33
|
+
|
|
34
|
+
- Gayathri G. Krishnan. *Malayalam Morphosyntax: Inflectional Features and their
|
|
35
|
+
Acquisition.* PhD thesis, IIT Bombay, 2019.
|
|
36
|
+
- Premjith B., Soman K. P. *Deep Learning Approach for the Morphological Synthesis in
|
|
37
|
+
Malayalam and Tamil at the Character Level.* ACM TALLIP 20(6), 2021. (Framing of
|
|
38
|
+
synthesis as morpheme-boundary transformation.)
|
|
39
|
+
- Kunjamma S. *Lexical and Grammatical Meaning in Malayalam.* Language in India, 2019.
|
|
40
|
+
(Case-role semantics; positive/negative verb opposition.)
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "mlinflect"
|
|
7
|
+
version = "0.0.1"
|
|
8
|
+
description = "Permissive, rule-based Malayalam morphological synthesizer (noun inflection generation)."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.9"
|
|
11
|
+
license = "Apache-2.0"
|
|
12
|
+
license-files = ["LICENSE", "NOTICE"]
|
|
13
|
+
authors = [{ name = "Jayashankar R", email = "56070307+jayashankarvr@users.noreply.github.com" }]
|
|
14
|
+
keywords = ["malayalam", "morphology", "nlp", "inflection", "dravidian", "agglutinative", "synthesis"]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Development Status :: 3 - Alpha",
|
|
17
|
+
"Intended Audience :: Developers",
|
|
18
|
+
"Intended Audience :: Science/Research",
|
|
19
|
+
"Programming Language :: Python :: 3",
|
|
20
|
+
"Topic :: Text Processing :: Linguistic",
|
|
21
|
+
"Typing :: Typed",
|
|
22
|
+
]
|
|
23
|
+
|
|
24
|
+
[project.urls]
|
|
25
|
+
Homepage = "https://github.com/jayashankarvr/mlinflect"
|
|
26
|
+
Source = "https://github.com/jayashankarvr/mlinflect"
|
|
27
|
+
Issues = "https://github.com/jayashankarvr/mlinflect/issues"
|
|
28
|
+
|
|
29
|
+
[project.optional-dependencies]
|
|
30
|
+
dev = ["pytest>=7"]
|
|
31
|
+
|
|
32
|
+
[tool.hatch.build.targets.wheel]
|
|
33
|
+
packages = ["src/mlinflect"]
|
|
34
|
+
|
|
35
|
+
[tool.pytest.ini_options]
|
|
36
|
+
testpaths = ["tests"]
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
# Copyright 2026 Jayashankar R
|
|
3
|
+
"""A permissive, rule-based Malayalam morphological synthesizer.
|
|
4
|
+
|
|
5
|
+
Forward morphological generation (root + features -> inflected surface form),
|
|
6
|
+
starting with noun inflection. Rules are declarative and provenance-tagged; see
|
|
7
|
+
REFERENCES.md for the linguistic sources and the project's native-ratification
|
|
8
|
+
workflow.
|
|
9
|
+
"""
|
|
10
|
+
from .nouns import UnsupportedRoot, list_supported_classes, synthesize_noun
|
|
11
|
+
from .types import Animacy, Case, Gender, NounFeatures, Number, Register, SynthResult
|
|
12
|
+
|
|
13
|
+
__version__ = "0.0.1"
|
|
14
|
+
__all__ = [
|
|
15
|
+
"Animacy",
|
|
16
|
+
"Case",
|
|
17
|
+
"Gender",
|
|
18
|
+
"Number",
|
|
19
|
+
"NounFeatures",
|
|
20
|
+
"Register",
|
|
21
|
+
"SynthResult",
|
|
22
|
+
"synthesize_noun",
|
|
23
|
+
"list_supported_classes",
|
|
24
|
+
"UnsupportedRoot",
|
|
25
|
+
"__version__",
|
|
26
|
+
]
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
# Copyright 2026 Jayashankar R
|
|
3
|
+
"""Rule-based Malayalam noun synthesis: (root + features) -> inflected surface form.
|
|
4
|
+
|
|
5
|
+
The forward (generation) counterpart to morphological analysis, applying the
|
|
6
|
+
ending-conditioned rules in :mod:`mlsynth.rules`. Every result carries the rule's
|
|
7
|
+
provenance and a ``verified`` flag (true only for native-ratified forms).
|
|
8
|
+
|
|
9
|
+
Two cross-cutting rules from the native review / SMC docs:
|
|
10
|
+
* Differential object marking (DOM): an inanimate noun's accusative defaults to the
|
|
11
|
+
bare form (മരം), the overt form (മരത്തെ) only on request; an animate noun's
|
|
12
|
+
accusative is always overt.
|
|
13
|
+
* Register: the instrumental is synthetic by default (മരത്താൽ) but analytic in the
|
|
14
|
+
colloquial register (മരം കൊണ്ട്).
|
|
15
|
+
"""
|
|
16
|
+
from __future__ import annotations
|
|
17
|
+
|
|
18
|
+
from typing import List, Optional
|
|
19
|
+
|
|
20
|
+
from .rules import CLASSES, NounClass
|
|
21
|
+
from .types import Animacy, Case, Gender, NounFeatures, Number, Register, SynthResult
|
|
22
|
+
|
|
23
|
+
# Chillu -> base consonant (a chillu reverts before a following vowel sign).
|
|
24
|
+
_CHILLU_BASE = {
|
|
25
|
+
"ൺ": "ണ", "ൻ": "ന", "ർ": "ര", "ൽ": "ല", "ൾ": "ള", "ൿ": "ക",
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def _is_vowel_sign(ch: str) -> bool:
|
|
30
|
+
o = ord(ch)
|
|
31
|
+
return 0x0D3E <= o <= 0x0D4C or o in (0x0D57, 0x0D62, 0x0D63)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def _is_independent_vowel(ch: str) -> bool:
|
|
35
|
+
o = ord(ch)
|
|
36
|
+
return 0x0D05 <= o <= 0x0D14 or o in (0x0D60, 0x0D61)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def _attach(stem: str, suffix: str) -> str:
|
|
40
|
+
"""Join a matra-initial suffix to a stem, reverting a trailing chillu to its base."""
|
|
41
|
+
if not suffix:
|
|
42
|
+
return stem
|
|
43
|
+
if stem and _is_vowel_sign(suffix[0]) and stem[-1] in _CHILLU_BASE:
|
|
44
|
+
stem = stem[:-1] + _CHILLU_BASE[stem[-1]]
|
|
45
|
+
return stem + suffix
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
class UnsupportedRoot(ValueError):
|
|
49
|
+
"""No noun class matches the root and none was given explicitly."""
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def list_supported_classes() -> List[str]:
|
|
53
|
+
return sorted(CLASSES)
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def _has_base_letter(s: str) -> bool:
|
|
57
|
+
# Reject input made only of signs/virama/anusvara or non-Malayalam text.
|
|
58
|
+
return any("അ" <= ch <= "ഺ" for ch in s)
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def _class_matches(cls: NounClass, root: str) -> bool:
|
|
62
|
+
for e in cls.endings:
|
|
63
|
+
if root.endswith(e):
|
|
64
|
+
if cls.pre:
|
|
65
|
+
pre = root[: -len(e)]
|
|
66
|
+
if not pre:
|
|
67
|
+
return False
|
|
68
|
+
is_vowel = _is_vowel_sign(pre[-1]) or _is_independent_vowel(pre[-1])
|
|
69
|
+
# consonant+anuswara (മരം) vs vowel+anuswara (കലാം, ഓം): same ending,
|
|
70
|
+
# disambiguated by what precedes it.
|
|
71
|
+
if cls.pre == "consonant" and is_vowel:
|
|
72
|
+
return False
|
|
73
|
+
if cls.pre == "vowel" and not is_vowel:
|
|
74
|
+
return False
|
|
75
|
+
return True
|
|
76
|
+
return False
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def _resolve_class(root: str, stem_class: Optional[str]) -> NounClass:
|
|
80
|
+
if stem_class is not None:
|
|
81
|
+
try:
|
|
82
|
+
cls = CLASSES[stem_class]
|
|
83
|
+
except KeyError:
|
|
84
|
+
raise UnsupportedRoot(
|
|
85
|
+
f"unknown stem_class {stem_class!r}; supported: {list_supported_classes()}"
|
|
86
|
+
) from None
|
|
87
|
+
if not _class_matches(cls, root):
|
|
88
|
+
raise UnsupportedRoot(
|
|
89
|
+
f"root {root!r} does not fit class {cls.name!r} (endings {cls.endings}"
|
|
90
|
+
+ (f", {cls.pre}-stem only)" if cls.pre else ")")
|
|
91
|
+
)
|
|
92
|
+
return cls
|
|
93
|
+
for cls in sorted(
|
|
94
|
+
CLASSES.values(), key=lambda c: max(len(e) for e in c.endings), reverse=True
|
|
95
|
+
):
|
|
96
|
+
if _class_matches(cls, root):
|
|
97
|
+
return cls
|
|
98
|
+
raise UnsupportedRoot(
|
|
99
|
+
f"cannot infer a noun class for root {root!r}; pass stem_class= explicitly "
|
|
100
|
+
f"(supported: {list_supported_classes()})"
|
|
101
|
+
)
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def synthesize_noun(
|
|
105
|
+
root: str,
|
|
106
|
+
case: Case,
|
|
107
|
+
number: Number = Number.SINGULAR,
|
|
108
|
+
*,
|
|
109
|
+
animacy: Optional[Animacy] = None,
|
|
110
|
+
register: Register = Register.FORMAL,
|
|
111
|
+
gender: Optional[Gender] = None,
|
|
112
|
+
stem_class: Optional[str] = None,
|
|
113
|
+
marked: bool = False,
|
|
114
|
+
) -> SynthResult:
|
|
115
|
+
"""Generate the inflected surface form of ``root`` for the given features.
|
|
116
|
+
|
|
117
|
+
``animacy`` drives DOM (accusative) and is recorded on the result; with it unknown,
|
|
118
|
+
the accusative defaults to the overt form. ``marked=True`` forces the overt
|
|
119
|
+
accusative for an inanimate noun. ``gender`` is recorded but unused by current
|
|
120
|
+
classes. Unencoded feature combinations raise :class:`NotImplementedError`;
|
|
121
|
+
unresolvable/ill-formed roots raise :class:`UnsupportedRoot`. Never a silently
|
|
122
|
+
wrong form.
|
|
123
|
+
"""
|
|
124
|
+
if not root:
|
|
125
|
+
raise UnsupportedRoot("root must be a non-empty string")
|
|
126
|
+
if not _has_base_letter(root):
|
|
127
|
+
raise UnsupportedRoot(f"root {root!r} contains no Malayalam base letter")
|
|
128
|
+
cls = _resolve_class(root, stem_class)
|
|
129
|
+
features = NounFeatures(
|
|
130
|
+
case=case, number=number, animacy=animacy, register=register, gender=gender
|
|
131
|
+
)
|
|
132
|
+
|
|
133
|
+
def _result(surface, morphemes, provenance, verified, analytic=False):
|
|
134
|
+
return SynthResult(
|
|
135
|
+
surface=surface, root=root, features=features, morphemes=morphemes,
|
|
136
|
+
stem_class=cls.name, provenance=provenance, verified=verified, analytic=analytic,
|
|
137
|
+
)
|
|
138
|
+
|
|
139
|
+
table = cls.plural_cases if number is Number.PLURAL else cls.cases
|
|
140
|
+
try:
|
|
141
|
+
rule = table[case]
|
|
142
|
+
except KeyError:
|
|
143
|
+
raise NotImplementedError(
|
|
144
|
+
f"case {case.value!r} ({number.value}) not yet encoded for class {cls.name!r}"
|
|
145
|
+
) from None
|
|
146
|
+
|
|
147
|
+
# The nominative form of the requested number (used by DOM and the analytic register).
|
|
148
|
+
nom_rule = table[Case.NOMINATIVE]
|
|
149
|
+
nom_stem = (cls.plural_marker.apply(root) if number is Number.PLURAL else root)
|
|
150
|
+
nominative = _attach(nom_stem, nom_rule.suffix) if nom_rule.use_oblique else nom_stem
|
|
151
|
+
|
|
152
|
+
# Colloquial instrumental is analytic (nominative + കൊണ്ട്); verified/provenance
|
|
153
|
+
# track the nominative, so non-ratified inputs aren't over-claimed (worksheet Q2).
|
|
154
|
+
if case is Case.INSTRUMENTAL and register is Register.COLLOQUIAL:
|
|
155
|
+
return _result(nominative + " കൊണ്ട്", [nominative, "കൊണ്ട്"],
|
|
156
|
+
nom_rule.provenance, nom_rule.verified, analytic=True)
|
|
157
|
+
|
|
158
|
+
# DOM: inanimate accusative is the bare nominative (worksheet Q1); inherits its flags.
|
|
159
|
+
if case is Case.ACCUSATIVE and animacy is Animacy.INANIMATE and not marked:
|
|
160
|
+
return _result(nominative, [nominative], nom_rule.provenance, nom_rule.verified)
|
|
161
|
+
|
|
162
|
+
if number is Number.PLURAL:
|
|
163
|
+
stem = cls.plural_marker.apply(root)
|
|
164
|
+
surface = _attach(stem, rule.suffix)
|
|
165
|
+
morphemes = [stem, rule.suffix] if rule.suffix else [stem]
|
|
166
|
+
return _result(surface, morphemes, rule.provenance, rule.verified)
|
|
167
|
+
|
|
168
|
+
if rule.oblique is not None:
|
|
169
|
+
stem = rule.oblique.apply(root) # per-case stem (e.g. ട് gemination)
|
|
170
|
+
elif rule.use_oblique:
|
|
171
|
+
stem = cls.oblique.apply(root)
|
|
172
|
+
else:
|
|
173
|
+
stem = root
|
|
174
|
+
surface = _attach(stem, rule.suffix)
|
|
175
|
+
morphemes = [stem, rule.suffix] if rule.suffix else [stem]
|
|
176
|
+
return _result(surface, morphemes, rule.provenance, rule.verified)
|
|
File without changes
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
# Copyright 2026 Jayashankar R
|
|
3
|
+
"""Declarative, provenance-tagged noun-inflection rules, conditioned on stem ending.
|
|
4
|
+
|
|
5
|
+
A noun class is selected by the root's ending (anuswara `ം`, vowel sign `ി`/`ു`, the
|
|
6
|
+
`ട്` cluster, ...) plus an optional `pre` constraint (whether a consonant or a vowel
|
|
7
|
+
precedes the ending). Each class supplies an oblique-stem transform and a matra-initial
|
|
8
|
+
suffix per case; a case may override the stem (e.g. `ട്` geminates only for the spatial
|
|
9
|
+
cases). Suffixes attach via ``nouns._attach``, which reverts a trailing chillu to its
|
|
10
|
+
base consonant before a vowel sign (so plural മരങ്ങൾ + `ുടെ` → മരങ്ങളുടെ).
|
|
11
|
+
|
|
12
|
+
Provenance keys (see REFERENCES.md): ``native-2026`` (native-ratified), ``smc-morph``
|
|
13
|
+
(SMC docs, pending native sign-off), ``native-14`` (genitive #14). Editing a paradigm
|
|
14
|
+
is a data edit here; flip ``verified`` after native sign-off.
|
|
15
|
+
"""
|
|
16
|
+
from __future__ import annotations
|
|
17
|
+
|
|
18
|
+
from dataclasses import dataclass
|
|
19
|
+
from typing import Dict, Optional, Tuple
|
|
20
|
+
|
|
21
|
+
from .types import Case
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
@dataclass(frozen=True)
|
|
25
|
+
class StemTransform:
|
|
26
|
+
strip: str
|
|
27
|
+
append: str
|
|
28
|
+
|
|
29
|
+
def apply(self, root: str) -> str:
|
|
30
|
+
if self.strip and root.endswith(self.strip):
|
|
31
|
+
root = root[: -len(self.strip)]
|
|
32
|
+
return root + self.append
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
@dataclass(frozen=True)
|
|
36
|
+
class CaseRule:
|
|
37
|
+
suffix: str # matra-initial; "" for the bare nominative
|
|
38
|
+
use_oblique: bool # attach to the class oblique stem (True) or the bare root (False)
|
|
39
|
+
provenance: str
|
|
40
|
+
verified: bool = False
|
|
41
|
+
oblique: Optional[StemTransform] = None # per-case stem override (e.g. ട് gemination)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
@dataclass(frozen=True)
|
|
45
|
+
class NounClass:
|
|
46
|
+
name: str
|
|
47
|
+
description: str
|
|
48
|
+
endings: Tuple[str, ...]
|
|
49
|
+
oblique: StemTransform
|
|
50
|
+
cases: Dict[Case, CaseRule]
|
|
51
|
+
plural_marker: StemTransform
|
|
52
|
+
plural_cases: Dict[Case, CaseRule]
|
|
53
|
+
# "" = match on ending alone; "consonant"/"vowel" = also require that kind of
|
|
54
|
+
# character before the ending (disambiguates മരം consonant+anuswara from കലാം
|
|
55
|
+
# vowel+anuswara, both ending in ം).
|
|
56
|
+
pre: str = ""
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
# ട് gemination, shared by the spatial cases of the ṭ_geminate class.
|
|
60
|
+
_GEMINATE_T = StemTransform("ട്", "ട്ട")
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
# Plural case markers attach to the plural stem (its trailing chillu ൾ reverts to ള
|
|
64
|
+
# before a vowel sign). Includes vocative -ഏ (worksheet Part B). Provenance/verified
|
|
65
|
+
# are per-class.
|
|
66
|
+
def _plural_cases(provenance: str, verified: bool) -> Dict[Case, CaseRule]:
|
|
67
|
+
v = verified
|
|
68
|
+
return {
|
|
69
|
+
Case.NOMINATIVE: CaseRule("", False, provenance, v),
|
|
70
|
+
Case.ACCUSATIVE: CaseRule("െ", True, provenance, v),
|
|
71
|
+
Case.DATIVE: CaseRule("ക്ക്", True, provenance, v),
|
|
72
|
+
Case.GENITIVE: CaseRule("ുടെ", True, provenance, v),
|
|
73
|
+
Case.SOCIATIVE: CaseRule("ോട്", True, provenance, v),
|
|
74
|
+
Case.LOCATIVE: CaseRule("ിൽ", True, provenance, v),
|
|
75
|
+
Case.INSTRUMENTAL: CaseRule("ാൽ", True, provenance, v),
|
|
76
|
+
Case.VOCATIVE: CaseRule("േ", True, provenance, v),
|
|
77
|
+
Case.ABLATIVE: CaseRule("ിൽനിന്ന്", True, provenance, v),
|
|
78
|
+
Case.ALLATIVE: CaseRule("ിലേക്ക്", True, provenance, v),
|
|
79
|
+
Case.PERLATIVE: CaseRule("ിലൂടെ", True, provenance, v),
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
CLASSES: Dict[str, NounClass] = {
|
|
84
|
+
# Consonant + anuswara (e.g. മരം); oblique augment -ത്ത-. Vocative uses a -മ- stem
|
|
85
|
+
# (മരം -> മരമേ). Core cases native-ratified; abl/all/perl ratified in worksheet C.
|
|
86
|
+
"am_neuter": NounClass(
|
|
87
|
+
name="am_neuter",
|
|
88
|
+
description="Consonant + anuswara nouns (e.g. മരം 'tree'); oblique augment -ത്ത-.",
|
|
89
|
+
endings=("ം",),
|
|
90
|
+
pre="consonant",
|
|
91
|
+
oblique=StemTransform("ം", "ത്ത"),
|
|
92
|
+
cases={
|
|
93
|
+
Case.NOMINATIVE: CaseRule("", False, "native-2026", True),
|
|
94
|
+
Case.ACCUSATIVE: CaseRule("െ", True, "native-2026", True),
|
|
95
|
+
Case.DATIVE: CaseRule("ിന്", True, "native-2026", True),
|
|
96
|
+
Case.GENITIVE: CaseRule("ിന്റെ", True, "native-2026", True),
|
|
97
|
+
Case.SOCIATIVE: CaseRule("ോട്", True, "native-2026", True),
|
|
98
|
+
Case.LOCATIVE: CaseRule("ിൽ", True, "native-2026", True),
|
|
99
|
+
Case.INSTRUMENTAL: CaseRule("ാൽ", True, "native-2026", True),
|
|
100
|
+
Case.VOCATIVE: CaseRule("േ", False, "native-2026", True, oblique=StemTransform("ം", "മ")),
|
|
101
|
+
Case.ABLATIVE: CaseRule("ിൽനിന്ന്", True, "native-2026", True),
|
|
102
|
+
Case.ALLATIVE: CaseRule("ിലേക്ക്", True, "native-2026", True),
|
|
103
|
+
Case.PERLATIVE: CaseRule("ിലൂടെ", True, "native-2026", True),
|
|
104
|
+
},
|
|
105
|
+
plural_marker=StemTransform("ം", "ങ്ങൾ"),
|
|
106
|
+
plural_cases=_plural_cases("native-2026", True),
|
|
107
|
+
),
|
|
108
|
+
# Vowel + anuswara (e.g. കലാം, ടീം); anuswara behaves as -മ- and suffixes take the
|
|
109
|
+
# -ഇന- linker. acc/gen native-ratified (worksheet A); dative extrapolated.
|
|
110
|
+
"vowel_anuswara": NounClass(
|
|
111
|
+
name="vowel_anuswara",
|
|
112
|
+
description="Vowel + anuswara nouns (e.g. കലാം, ടീം); -മ- stem with -ഇന- linker.",
|
|
113
|
+
endings=("ം",),
|
|
114
|
+
pre="vowel",
|
|
115
|
+
oblique=StemTransform("ം", "മ"),
|
|
116
|
+
cases={
|
|
117
|
+
Case.NOMINATIVE: CaseRule("", False, "native-2026", True),
|
|
118
|
+
Case.ACCUSATIVE: CaseRule("ിനെ", True, "native-2026", True),
|
|
119
|
+
Case.GENITIVE: CaseRule("ിന്റെ", True, "native-2026", True),
|
|
120
|
+
Case.DATIVE: CaseRule("ിന്", True, "native-2026", True),
|
|
121
|
+
Case.SOCIATIVE: CaseRule("ിനോട്", True, "native-2026", True),
|
|
122
|
+
Case.LOCATIVE: CaseRule("ിൽ", True, "native-2026", True),
|
|
123
|
+
Case.VOCATIVE: CaseRule("േ", True, "native-2026", True),
|
|
124
|
+
Case.ABLATIVE: CaseRule("ിൽനിന്ന്", True, "native-2026", True),
|
|
125
|
+
Case.ALLATIVE: CaseRule("ിലേക്ക്", True, "native-2026", True),
|
|
126
|
+
Case.PERLATIVE: CaseRule("ിലൂടെ", True, "native-2026", True),
|
|
127
|
+
},
|
|
128
|
+
plural_marker=StemTransform("", ""),
|
|
129
|
+
plural_cases={},
|
|
130
|
+
),
|
|
131
|
+
# Vowel-final -ി nouns (e.g. കുട്ടി); glide -യ-, dative on root. Singular core +
|
|
132
|
+
# abl/all/perl native-ratified (worksheet); genitive #14.
|
|
133
|
+
"i_vowel": NounClass(
|
|
134
|
+
name="i_vowel",
|
|
135
|
+
description="Vowel-final nouns ending in -ി (e.g. കുട്ടി 'child'); glide -യ-.",
|
|
136
|
+
endings=("ി",),
|
|
137
|
+
oblique=StemTransform("", "യ"),
|
|
138
|
+
cases={
|
|
139
|
+
Case.NOMINATIVE: CaseRule("", False, "native-2026", True),
|
|
140
|
+
Case.ACCUSATIVE: CaseRule("െ", True, "native-2026", True),
|
|
141
|
+
Case.DATIVE: CaseRule("ക്ക്", False, "native-2026", True),
|
|
142
|
+
Case.GENITIVE: CaseRule("ുടെ", True, "native-14", True),
|
|
143
|
+
Case.SOCIATIVE: CaseRule("ോട്", True, "native-2026", True),
|
|
144
|
+
Case.LOCATIVE: CaseRule("ിൽ", True, "native-2026", True),
|
|
145
|
+
Case.INSTRUMENTAL: CaseRule("ാൽ", True, "native-2026", True),
|
|
146
|
+
Case.VOCATIVE: CaseRule("േ", True, "native-2026", True),
|
|
147
|
+
Case.ABLATIVE: CaseRule("ിൽനിന്ന്", True, "native-2026", True),
|
|
148
|
+
Case.ALLATIVE: CaseRule("ിലേക്ക്", True, "native-2026", True),
|
|
149
|
+
Case.PERLATIVE: CaseRule("ിലൂടെ", True, "native-2026", True),
|
|
150
|
+
},
|
|
151
|
+
plural_marker=StemTransform("", "കൾ"),
|
|
152
|
+
plural_cases=_plural_cases("native-2026", True),
|
|
153
|
+
),
|
|
154
|
+
# Vowel-final -ഉ/-ഊ nouns (e.g. പശു, മുത്തു); glide -വ-. gen/vocative native-
|
|
155
|
+
# ratified (worksheet A); acc/dat/loc extrapolated from the -ഇന- linker pattern.
|
|
156
|
+
"u_vowel": NounClass(
|
|
157
|
+
name="u_vowel",
|
|
158
|
+
description="Vowel-final nouns ending in -ഉ/-ഊ (e.g. പശു 'cow'); glide -വ-.",
|
|
159
|
+
endings=("ു", "ൂ"),
|
|
160
|
+
oblique=StemTransform("", "വ"),
|
|
161
|
+
cases={
|
|
162
|
+
Case.NOMINATIVE: CaseRule("", False, "native-2026", True),
|
|
163
|
+
Case.ACCUSATIVE: CaseRule("ിനെ", True, "native-2026", True),
|
|
164
|
+
Case.DATIVE: CaseRule("ിന്", True, "native-2026", True),
|
|
165
|
+
Case.GENITIVE: CaseRule("ിന്റെ", True, "native-2026", True),
|
|
166
|
+
Case.SOCIATIVE: CaseRule("ിനോട്", True, "native-2026", True),
|
|
167
|
+
Case.LOCATIVE: CaseRule("ിൽ", True, "native-2026", True),
|
|
168
|
+
Case.INSTRUMENTAL: CaseRule("ിനാൽ", True, "native-2026", True),
|
|
169
|
+
Case.VOCATIVE: CaseRule("േ", True, "native-2026", True),
|
|
170
|
+
Case.ABLATIVE: CaseRule("ിൽനിന്ന്", True, "native-2026", True),
|
|
171
|
+
Case.ALLATIVE: CaseRule("ിലേക്ക്", True, "native-2026", True),
|
|
172
|
+
Case.PERLATIVE: CaseRule("ിലൂടെ", True, "native-2026", True),
|
|
173
|
+
},
|
|
174
|
+
plural_marker=StemTransform("", "ക്കൾ"), # പശു -> പശുക്കൾ (marker native-given)
|
|
175
|
+
plural_cases=_plural_cases("smc-morph", False),
|
|
176
|
+
),
|
|
177
|
+
# -ട് final nouns (e.g. വീട്, കാട്); geminate ട്->ട്ട for the spatial cases, plain
|
|
178
|
+
# stem (-ഇന- linker) for gen/dat. Worksheet A native-ratified; perlative extrapolated.
|
|
179
|
+
"ṭ_geminate": NounClass(
|
|
180
|
+
name="ṭ_geminate",
|
|
181
|
+
description="-ട് final nouns (e.g. വീട് 'house'); geminate ട്->ട്ട for spatial cases.",
|
|
182
|
+
endings=("ട്",),
|
|
183
|
+
oblique=StemTransform("്", ""), # plain oblique for gen/dat/acc/soc/voc: വീട്->വീട
|
|
184
|
+
cases={
|
|
185
|
+
Case.NOMINATIVE: CaseRule("", False, "native-2026", True),
|
|
186
|
+
Case.ACCUSATIVE: CaseRule("ിനെ", True, "native-2026", True),
|
|
187
|
+
Case.DATIVE: CaseRule("ിന്", True, "native-2026", True),
|
|
188
|
+
Case.GENITIVE: CaseRule("ിന്റെ", True, "native-2026", True),
|
|
189
|
+
Case.SOCIATIVE: CaseRule("ിനോട്", True, "native-2026", True),
|
|
190
|
+
Case.VOCATIVE: CaseRule("േ", True, "native-2026", True),
|
|
191
|
+
Case.LOCATIVE: CaseRule("ിൽ", True, "native-2026", True, oblique=_GEMINATE_T),
|
|
192
|
+
Case.ALLATIVE: CaseRule("ിലേക്ക്", True, "native-2026", True, oblique=_GEMINATE_T),
|
|
193
|
+
Case.ABLATIVE: CaseRule("ിൽനിന്ന്", True, "native-2026", True, oblique=_GEMINATE_T),
|
|
194
|
+
Case.PERLATIVE: CaseRule("ിലൂടെ", True, "native-2026", True, oblique=_GEMINATE_T),
|
|
195
|
+
},
|
|
196
|
+
plural_marker=StemTransform("", ""),
|
|
197
|
+
plural_cases={},
|
|
198
|
+
),
|
|
199
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
# Copyright 2026 Jayashankar R
|
|
3
|
+
"""Typed feature inventory and result types for Malayalam noun synthesis.
|
|
4
|
+
|
|
5
|
+
Feature values match the mlmorph tagset (gitlab.com/smc/mlmorph) for interop, with
|
|
6
|
+
two features mlmorph leaves lexical: ``Animacy`` (drives differential object marking
|
|
7
|
+
and plural choice) and ``Register`` (synthetic vs analytic forms).
|
|
8
|
+
"""
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
from dataclasses import dataclass
|
|
12
|
+
from enum import Enum
|
|
13
|
+
from typing import List, Optional
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class Case(str, Enum):
|
|
17
|
+
NOMINATIVE = "nominative"
|
|
18
|
+
ACCUSATIVE = "accusative"
|
|
19
|
+
DATIVE = "dative"
|
|
20
|
+
GENITIVE = "genitive"
|
|
21
|
+
SOCIATIVE = "sociative"
|
|
22
|
+
LOCATIVE = "locative"
|
|
23
|
+
INSTRUMENTAL = "instrumental"
|
|
24
|
+
VOCATIVE = "vocative"
|
|
25
|
+
ABLATIVE = "ablative"
|
|
26
|
+
ALLATIVE = "allative"
|
|
27
|
+
PERLATIVE = "perlative"
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class Number(str, Enum):
|
|
31
|
+
SINGULAR = "singular"
|
|
32
|
+
PLURAL = "plural"
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class Gender(str, Enum):
|
|
36
|
+
MASCULINE = "masculine"
|
|
37
|
+
FEMININE = "feminine"
|
|
38
|
+
NEUTRAL = "neutral"
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
class Animacy(str, Enum):
|
|
42
|
+
"""Lexical animacy/humanness. Governs accusative marking (DOM) and plural choice."""
|
|
43
|
+
|
|
44
|
+
HUMAN = "human"
|
|
45
|
+
ANIMATE = "animate" # animate, non-human (e.g. കിളി 'bird')
|
|
46
|
+
INANIMATE = "inanimate"
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
class Register(str, Enum):
|
|
50
|
+
FORMAL = "formal" # synthetic forms (e.g. instrumental മരത്താൽ)
|
|
51
|
+
COLLOQUIAL = "colloquial" # analytic forms (e.g. മരം കൊണ്ട്)
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
@dataclass(frozen=True)
|
|
55
|
+
class NounFeatures:
|
|
56
|
+
case: Case
|
|
57
|
+
number: Number = Number.SINGULAR
|
|
58
|
+
animacy: Optional[Animacy] = None
|
|
59
|
+
register: Register = Register.FORMAL
|
|
60
|
+
gender: Optional[Gender] = None
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
@dataclass(frozen=True)
|
|
64
|
+
class SynthResult:
|
|
65
|
+
"""One synthesized inflected form.
|
|
66
|
+
|
|
67
|
+
``provenance`` is the citation key of the rule that produced it (see REFERENCES.md);
|
|
68
|
+
``verified`` is true only for native-ratified forms; ``analytic`` is true for
|
|
69
|
+
multi-word forms (e.g. the colloquial instrumental മരം കൊണ്ട്).
|
|
70
|
+
"""
|
|
71
|
+
|
|
72
|
+
surface: str
|
|
73
|
+
root: str
|
|
74
|
+
features: NounFeatures
|
|
75
|
+
morphemes: List[str]
|
|
76
|
+
stem_class: str
|
|
77
|
+
provenance: str
|
|
78
|
+
verified: bool
|
|
79
|
+
analytic: bool = False
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
# Copyright 2026 Jayashankar R
|
|
3
|
+
"""Tests for mlsynth noun synthesis.
|
|
4
|
+
|
|
5
|
+
Expected surface forms are typed as independent literals (the forms attested in the
|
|
6
|
+
sources / native worksheet), and the engine constructs them from root + rules, so a
|
|
7
|
+
passing test confirms the rule encoding reproduces the attested paradigm rather than
|
|
8
|
+
being a tautology.
|
|
9
|
+
"""
|
|
10
|
+
import pytest
|
|
11
|
+
|
|
12
|
+
from mlsynth import (
|
|
13
|
+
Animacy,
|
|
14
|
+
Case,
|
|
15
|
+
Number,
|
|
16
|
+
Register,
|
|
17
|
+
UnsupportedRoot,
|
|
18
|
+
list_supported_classes,
|
|
19
|
+
synthesize_noun,
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
# മരം 'tree', consonant + anuswara class.
|
|
23
|
+
AM = "മരം"
|
|
24
|
+
AM_SG = {
|
|
25
|
+
Case.NOMINATIVE: "മരം", Case.ACCUSATIVE: "മരത്തെ", Case.DATIVE: "മരത്തിന്",
|
|
26
|
+
Case.GENITIVE: "മരത്തിന്റെ", Case.SOCIATIVE: "മരത്തോട്", Case.LOCATIVE: "മരത്തിൽ",
|
|
27
|
+
Case.INSTRUMENTAL: "മരത്താൽ", Case.VOCATIVE: "മരമേ", Case.ABLATIVE: "മരത്തിൽനിന്ന്",
|
|
28
|
+
Case.ALLATIVE: "മരത്തിലേക്ക്", Case.PERLATIVE: "മരത്തിലൂടെ",
|
|
29
|
+
}
|
|
30
|
+
AM_PL = {
|
|
31
|
+
Case.NOMINATIVE: "മരങ്ങൾ", Case.ACCUSATIVE: "മരങ്ങളെ", Case.DATIVE: "മരങ്ങൾക്ക്",
|
|
32
|
+
Case.GENITIVE: "മരങ്ങളുടെ", Case.SOCIATIVE: "മരങ്ങളോട്", Case.LOCATIVE: "മരങ്ങളിൽ",
|
|
33
|
+
Case.INSTRUMENTAL: "മരങ്ങളാൽ", Case.VOCATIVE: "മരങ്ങളേ",
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
# കുട്ടി 'child', vowel-final -ി class.
|
|
37
|
+
KUTTI = "കുട്ടി"
|
|
38
|
+
KUTTI_SG = {
|
|
39
|
+
Case.NOMINATIVE: "കുട്ടി", Case.ACCUSATIVE: "കുട്ടിയെ", Case.DATIVE: "കുട്ടിക്ക്",
|
|
40
|
+
Case.GENITIVE: "കുട്ടിയുടെ", Case.SOCIATIVE: "കുട്ടിയോട്", Case.LOCATIVE: "കുട്ടിയിൽ",
|
|
41
|
+
Case.INSTRUMENTAL: "കുട്ടിയാൽ", Case.VOCATIVE: "കുട്ടിയേ",
|
|
42
|
+
}
|
|
43
|
+
KUTTI_PL = {
|
|
44
|
+
Case.NOMINATIVE: "കുട്ടികൾ", Case.ACCUSATIVE: "കുട്ടികളെ", Case.DATIVE: "കുട്ടികൾക്ക്",
|
|
45
|
+
Case.GENITIVE: "കുട്ടികളുടെ", Case.VOCATIVE: "കുട്ടികളേ",
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
@pytest.mark.parametrize("case,expected", list(AM_SG.items()))
|
|
50
|
+
def test_am_singular(case, expected):
|
|
51
|
+
assert synthesize_noun(AM, case).surface == expected
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
@pytest.mark.parametrize("case,expected", list(AM_PL.items()))
|
|
55
|
+
def test_am_plural(case, expected):
|
|
56
|
+
assert synthesize_noun(AM, case, number=Number.PLURAL).surface == expected
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
@pytest.mark.parametrize("case,expected", list(KUTTI_SG.items()))
|
|
60
|
+
def test_i_vowel_singular(case, expected):
|
|
61
|
+
assert synthesize_noun(KUTTI, case).surface == expected
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
@pytest.mark.parametrize("case,expected", list(KUTTI_PL.items()))
|
|
65
|
+
def test_i_vowel_plural(case, expected):
|
|
66
|
+
assert synthesize_noun(KUTTI, case, number=Number.PLURAL).surface == expected
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
# --- new classes ---
|
|
70
|
+
|
|
71
|
+
@pytest.mark.parametrize("root,case,expected", [
|
|
72
|
+
("കലാം", Case.ACCUSATIVE, "കലാമിനെ"),
|
|
73
|
+
("കലാം", Case.GENITIVE, "കലാമിന്റെ"),
|
|
74
|
+
("ടീം", Case.GENITIVE, "ടീമിന്റെ"),
|
|
75
|
+
("ഓം", Case.ACCUSATIVE, "ഓമിനെ"), # independent vowel + anuswara
|
|
76
|
+
("ക്രീം", Case.ACCUSATIVE, "ക്രീമിനെ"),
|
|
77
|
+
("കലാം", Case.SOCIATIVE, "കലാമിനോട്"),
|
|
78
|
+
("കലാം", Case.VOCATIVE, "കലാമേ"),
|
|
79
|
+
("കലാം", Case.ABLATIVE, "കലാമിൽനിന്ന്"),
|
|
80
|
+
])
|
|
81
|
+
def test_vowel_anuswara(root, case, expected):
|
|
82
|
+
assert synthesize_noun(root, case).surface == expected
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
@pytest.mark.parametrize("root,case,expected", [
|
|
86
|
+
("പശു", Case.GENITIVE, "പശുവിന്റെ"),
|
|
87
|
+
("പശു", Case.VOCATIVE, "പശുവേ"),
|
|
88
|
+
("മുത്തു", Case.VOCATIVE, "മുത്തുവേ"),
|
|
89
|
+
("പശു", Case.DATIVE, "പശുവിന്"),
|
|
90
|
+
("പശു", Case.ACCUSATIVE, "പശുവിനെ"),
|
|
91
|
+
("പശു", Case.SOCIATIVE, "പശുവിനോട്"),
|
|
92
|
+
("പശു", Case.INSTRUMENTAL, "പശുവിനാൽ"),
|
|
93
|
+
])
|
|
94
|
+
def test_u_vowel(root, case, expected):
|
|
95
|
+
assert synthesize_noun(root, case).surface == expected
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def test_u_vowel_plural_marker():
|
|
99
|
+
assert synthesize_noun("പശു", Case.NOMINATIVE, number=Number.PLURAL).surface == "പശുക്കൾ"
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
@pytest.mark.parametrize("root,case,expected", [
|
|
103
|
+
("വീട്", Case.GENITIVE, "വീടിന്റെ"), # plain stem
|
|
104
|
+
("വീട്", Case.DATIVE, "വീടിന്"),
|
|
105
|
+
("വീട്", Case.ACCUSATIVE, "വീടിനെ"),
|
|
106
|
+
("വീട്", Case.VOCATIVE, "വീടേ"),
|
|
107
|
+
("വീട്", Case.LOCATIVE, "വീട്ടിൽ"), # geminated stem
|
|
108
|
+
("വീട്", Case.ALLATIVE, "വീട്ടിലേക്ക്"),
|
|
109
|
+
("വീട്", Case.ABLATIVE, "വീട്ടിൽനിന്ന്"),
|
|
110
|
+
("വീട്", Case.PERLATIVE, "വീട്ടിലൂടെ"),
|
|
111
|
+
("കാട്", Case.GENITIVE, "കാടിന്റെ"),
|
|
112
|
+
("കാട്", Case.LOCATIVE, "കാട്ടിൽ"),
|
|
113
|
+
])
|
|
114
|
+
def test_t_geminate(root, case, expected):
|
|
115
|
+
assert synthesize_noun(root, case).surface == expected
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def test_vocative():
|
|
119
|
+
assert synthesize_noun("മരം", Case.VOCATIVE).surface == "മരമേ"
|
|
120
|
+
assert synthesize_noun("മരം", Case.VOCATIVE, number=Number.PLURAL).surface == "മരങ്ങളേ"
|
|
121
|
+
assert synthesize_noun("കുട്ടി", Case.VOCATIVE, number=Number.PLURAL).surface == "കുട്ടികളേ"
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
# --- differential object marking + register ---
|
|
125
|
+
|
|
126
|
+
def test_inanimate_accusative_defaults_bare():
|
|
127
|
+
assert synthesize_noun(AM, Case.ACCUSATIVE, animacy=Animacy.INANIMATE).surface == "മരം"
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
def test_inanimate_accusative_marked_on_request():
|
|
131
|
+
assert synthesize_noun(AM, Case.ACCUSATIVE, animacy=Animacy.INANIMATE, marked=True).surface == "മരത്തെ"
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
def test_animate_accusative_is_overt():
|
|
135
|
+
assert synthesize_noun(KUTTI, Case.ACCUSATIVE, animacy=Animacy.HUMAN).surface == "കുട്ടിയെ"
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
def test_colloquial_instrumental_is_analytic():
|
|
139
|
+
r = synthesize_noun(AM, Case.INSTRUMENTAL, register=Register.COLLOQUIAL)
|
|
140
|
+
assert r.surface == "മരം കൊണ്ട്" and r.analytic is True
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
def test_dom_and_register_inherit_nominative_flags():
|
|
144
|
+
# The DOM/register forms inherit verified/provenance from the nominative they are
|
|
145
|
+
# built on, so they never over-claim relative to it.
|
|
146
|
+
nom = synthesize_noun(KUTTI, Case.NOMINATIVE)
|
|
147
|
+
bare = synthesize_noun(KUTTI, Case.ACCUSATIVE, animacy=Animacy.INANIMATE)
|
|
148
|
+
assert (bare.surface, bare.verified, bare.provenance) == (nom.surface, nom.verified, nom.provenance)
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
# --- verified / provenance discipline ---
|
|
152
|
+
|
|
153
|
+
def test_native_ratified_forms_are_verified():
|
|
154
|
+
assert synthesize_noun(AM, Case.ABLATIVE).verified is True # worksheet C
|
|
155
|
+
assert synthesize_noun(KUTTI, Case.GENITIVE).provenance == "native-14"
|
|
156
|
+
assert synthesize_noun("വീട്", Case.LOCATIVE).verified is True
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
def test_extrapolated_forms_are_unverified():
|
|
160
|
+
# u_vowel plural: only the -ക്കൾ marker is native-given; the oblique paradigm is extrapolated.
|
|
161
|
+
r = synthesize_noun("പശു", Case.GENITIVE, number=Number.PLURAL)
|
|
162
|
+
assert r.surface == "പശുക്കളുടെ" and r.verified is False
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
def test_morphemes_join_to_surface():
|
|
166
|
+
r = synthesize_noun(AM, Case.LOCATIVE)
|
|
167
|
+
assert "".join(r.morphemes) == r.surface
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
# --- soundness: raise, never silently wrong ---
|
|
171
|
+
|
|
172
|
+
@pytest.mark.parametrize("root", ["അമ്മ", "പുഴ", "അവൻ", "നായർ", "സ്ത്രീ", "ABC", "123", "ി", ""])
|
|
173
|
+
def test_unsupported_roots_raise(root):
|
|
174
|
+
with pytest.raises(UnsupportedRoot):
|
|
175
|
+
synthesize_noun(root, Case.GENITIVE)
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
def test_explicit_mismatched_class_raises():
|
|
179
|
+
with pytest.raises(UnsupportedRoot):
|
|
180
|
+
synthesize_noun(AM, Case.ACCUSATIVE, stem_class="i_vowel")
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
def test_unencoded_case_raises():
|
|
184
|
+
with pytest.raises(NotImplementedError):
|
|
185
|
+
synthesize_noun("കലാം", Case.INSTRUMENTAL) # vowel_anuswara has no instrumental yet
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
def test_unencoded_plural_raises():
|
|
189
|
+
with pytest.raises(NotImplementedError):
|
|
190
|
+
synthesize_noun("കലാം", Case.GENITIVE, number=Number.PLURAL) # no plural encoded
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
def test_supported_classes_listed():
|
|
194
|
+
cls = list_supported_classes()
|
|
195
|
+
assert {"am_neuter", "i_vowel", "vowel_anuswara", "u_vowel", "ṭ_geminate"} <= set(cls)
|