-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcoptic_morphology_till.py
More file actions
772 lines (660 loc) · 30.2 KB
/
Copy pathcoptic_morphology_till.py
File metadata and controls
772 lines (660 loc) · 30.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
#!/usr/bin/env python3
"""
Coptic Morphology Analyzer - Based on Walter Till's Dialectal Grammar
======================================================================
Implements Till's comprehensive dialectal patterns for Coptic morphology.
Handles segmentation of fused proclitic forms into subtokens across all
seven Coptic dialects (S, B, A, L, F, M, P).
Key function: Segment words like ⲁϥⲃⲱⲕ into:
- ⲁ (APST, past auxiliary) - Till §261
- ϥ (PPERS, subject pronoun) - Till §113-121
- ⲃⲱⲕ (V, main verb)
Source: Walter Till, "Koptische Dialektgrammatik" (French translation)
Sections §245-268 (Prefixal Conjugation)
Author: André Linden (2025)
License: CC BY-NC-SA 4.0
"""
from typing import List, Tuple, Optional, Dict
from dataclasses import dataclass
from coptic_dialect_handler import Dialect, DialectHandler, DialectalForm
@dataclass
class Segment:
"""Represents one morpheme segment"""
form: str # Surface form (e.g., "ⲁ")
lemma: str # Lemma (e.g., "ⲁ")
pos: str # Scriptorium POS tag (e.g., "APST")
feats: Dict[str, str] # Morphological features
dialect: Optional[Dialect] = None # Specific dialect variant
source_section: Optional[str] = None # Till section reference
class CopticMorphologyAnalyzerTill:
"""
Analyzes Coptic morphology based on Till's dialectal grammar.
Supports all seven Coptic dialects: S, B, A, L, F, M, P
Example:
analyzer = CopticMorphologyAnalyzerTill(dialect=Dialect.SAHIDIC)
segments = analyzer.segment_word("ⲁϥⲃⲱⲕ")
# Returns: [Segment("ⲁ", "ⲁ", "APST", {}, Dialect.SAHIDIC, "§261"),
# Segment("ϥ", "ⲛⲧⲟϥ", "PPERS", {...}, source_section="§117"),
# Segment("ⲃⲱⲕ", "ⲃⲱⲕ", "V", {...})]
"""
def __init__(self, dialect: Dialect = Dialect.SAHIDIC, prolog_engine=None):
"""
Initialize analyzer.
Args:
dialect: Default dialect for parsing
prolog_engine: Optional CopticPrologEngine for feature lookup
"""
self.dialect = dialect
self.prolog = prolog_engine
self.dialect_handler = DialectHandler(default_dialect=dialect)
self._init_patterns()
def _init_patterns(self):
"""Initialize segmentation patterns from Till's grammar"""
# §113-121: Personal pronouns (subject suffixes)
# Till provides these as suffixes attached to conjugation bases
self.pronouns = {
"ⲓ": ("ⲁⲛⲟⲕ", "PPERS", {"Person": "1", "Number": "Sing"}),
"ⲕ": ("ⲛⲧⲟⲕ", "PPERS", {"Person": "2", "Number": "Sing", "Gender": "Masc"}),
"ⲧⲉ": ("ⲛⲧⲟ", "PPERS", {"Person": "2", "Number": "Sing", "Gender": "Fem"}),
"ϥ": ("ⲛⲧⲟϥ", "PPERS", {"Person": "3", "Number": "Sing", "Gender": "Masc"}),
"ⲥ": ("ⲛⲧⲟⲥ", "PPERS", {"Person": "3", "Number": "Sing", "Gender": "Fem"}),
"ⲛ": ("ⲁⲛⲟⲛ", "PPERS", {"Person": "1", "Number": "Plur"}),
"ⲧⲛ": ("ⲛⲧⲱⲧⲛ", "PPERS", {"Person": "2", "Number": "Plur"}),
"ⲩ": ("ⲛⲧⲟⲟⲩ", "PPERS", {"Person": "3", "Number": "Plur"}),
}
# §248: Présent I (Present I - adverbial proposition, 180-182)
# Durative present with infinitive
self._register_prefix_pattern("present_i", {
Dialect.SAHIDIC: "ⲉⲣⲉ",
Dialect.LYCOPOLITAN: "ⲉⲣⲉ",
Dialect.BOHAIRIC: "ⲁⲣⲉ",
Dialect.AKHMIMIC: "ⲁⲣⲉ", # Also ⲁ(ⲣⲉ)
Dialect.FAYYUMIC: "ⲁⲗⲗⲉ",
}, "APRES", "§248")
# §249: Présent Consuétudinal I (Habitual present)
# Expresses habitual action
self._register_prefix_pattern("habitual_present", {
Dialect.SAHIDIC: "ϣⲁⲣⲉ",
Dialect.BOHAIRIC: "ϣⲁⲣⲉ",
Dialect.LYCOPOLITAN: "ϣⲁⲣⲉ",
Dialect.AKHMIMIC: "ⲥⲁⲣⲉ",
Dialect.FAYYUMIC: "ϣⲁⲗⲗⲉ",
}, "AHABPRES", "§249")
# §250: Présent cons. I négatif (Negative habitual present)
self._register_prefix_pattern("habitual_present_neg", {
Dialect.SAHIDIC: "ⲙⲉⲣⲉ", # Also SF: ⲙⲉ-
Dialect.AKHMIMIC: "ⲙⲁⲣⲉ",
Dialect.LYCOPOLITAN: "ⲙⲁⲣⲉ",
Dialect.BOHAIRIC: "ⲙⲡⲁⲣⲉ",
Dialect.FAYYUMIC: "ⲙⲉⲗⲉ",
}, "ANEGHABPRES", "§250")
# §251: Présent consuétudinal II (Habitual present II)
# Like Présent cons. I with prefixes §248
self._register_prefix_pattern("habitual_present_ii", {
Dialect.SAHIDIC: "ⲉ",
Dialect.BOHAIRIC: "ⲉ",
Dialect.LYCOPOLITAN: "ⲉ",
Dialect.AKHMIMIC: "ⲁ",
Dialect.FAYYUMIC: "ⲛ",
}, "AHABPRES2", "§251")
# §252: Futur I (Future I - adverbial proposition)
# Present II (§248) with future prefix ⲛⲁ
self._register_prefix_pattern("future_i", {
Dialect.SAHIDIC: "ⲉⲣⲉⲛⲁ", # ⲉⲣⲉ-ⲛⲁ
Dialect.LYCOPOLITAN: "ⲁⲣⲉⲛⲁ", # Usually ⲁ instead of ⲛⲁ
Dialect.BOHAIRIC: "ⲁⲣⲉⲛⲁ",
Dialect.AKHMIMIC: "ⲁⲣⲉⲛⲁ",
Dialect.FAYYUMIC: "ⲁⲗⲗⲉⲛⲉ", # F: ⲛⲉ instead of ⲛⲁ
}, "AFUT", "§252")
# §253: Futur III (Future III - prediction, desire, order)
self._register_prefix_pattern("future_iii", {
Dialect.SAHIDIC: "ⲉⲣⲉ",
Dialect.BOHAIRIC: "ⲉⲣⲉ",
Dialect.AKHMIMIC: "ⲁⲁ", # A: ⲁ-ⲁ-
Dialect.LYCOPOLITAN: "ⲉⲣⲉⲁ",
Dialect.FAYYUMIC: "ⲉⲗⲉ",
}, "AFUT3", "§253")
# §254: Futur III négatif
self._register_prefix_pattern("future_iii_neg", {
Dialect.SAHIDIC: "ⲛⲛⲉ",
Dialect.BOHAIRIC: "ⲛⲛⲉ",
Dialect.FAYYUMIC: "ⲛⲛⲉ",
Dialect.AKHMIMIC: "ⲛⲉ",
Dialect.LYCOPOLITAN: "ⲛⲉ",
}, "ANEGFUT3", "§254")
# §255: Optatif (Optative - desire/wish: "faire")
self._register_prefix_pattern("optative", {
Dialect.SAHIDIC: "ⲙⲁⲣⲉ",
Dialect.BOHAIRIC: "ⲙⲁⲣⲉ",
Dialect.AKHMIMIC: "ⲙⲁⲣⲉ",
Dialect.LYCOPOLITAN: "ⲙⲁⲣⲉ",
Dialect.FAYYUMIC: "ⲙⲁⲗⲉ",
}, "AOPT", "§255")
# §258: Final (Conjunctive future - "et ... fera")
# Development of "afin que" sense
self._register_prefix_pattern("final", {
Dialect.SAHIDIC: "ⲧⲁⲣⲉ",
Dialect.AKHMIMIC: "ⲧⲁⲣⲉ",
Dialect.LYCOPOLITAN: "ⲧⲁⲣⲉ",
Dialect.BOHAIRIC: "ⲧⲁⲣⲉ", # Also in B
Dialect.FAYYUMIC: "ⲧⲁⲗⲉ",
}, "AFINAL", "§258")
# §260: Jusqu'à (Until - "fait, respect. faisait")
self._register_prefix_pattern("until", {
Dialect.SAHIDIC: "ϣⲁⲛⲧⲉ",
Dialect.LYCOPOLITAN: "ϣⲁⲛⲧⲉ",
Dialect.FAYYUMIC: "ϣⲁⲛⲧⲉ",
Dialect.BOHAIRIC: "ϣⲁⲧⲉ",
Dialect.AKHMIMIC: "ϣⲁⲧⲉ", # BA form
}, "AUNTIL", "§260")
# §261: Parfait I (Perfect I - Preterit, past tense)
# Preterit ⲁ-; forms ⲁⲣⲉ (SB), ⲁⲣ- (A), ⲁⲗ (F)
self._register_prefix_pattern("perfect_i", {
Dialect.SAHIDIC: "ⲁⲣⲉ",
Dialect.BOHAIRIC: "ⲁⲣⲉ",
Dialect.AKHMIMIC: "ⲁⲣ",
Dialect.FAYYUMIC: "ⲁⲗ",
}, "APERF", "§261")
# Simple preterit ⲁ (common to most dialects)
self._register_prefix_pattern("perfect_i_simple", {
Dialect.SAHIDIC: "ⲁ",
Dialect.BOHAIRIC: "ⲁ",
Dialect.AKHMIMIC: "ⲁ",
Dialect.LYCOPOLITAN: "ⲁ",
Dialect.FAYYUMIC: "ⲁ",
}, "APST", "§261")
# §263: Parfait I négatif (Negative perfect)
self._register_prefix_pattern("perfect_i_neg", {
Dialect.SAHIDIC: "ⲙⲡⲉ",
Dialect.BOHAIRIC: "ⲙⲡⲉ",
Dialect.AKHMIMIC: "ⲙⲡⲉ",
Dialect.LYCOPOLITAN: "ⲙⲡⲉ",
Dialect.FAYYUMIC: "ⲙⲡⲉ",
}, "ANEGPST", "§263")
# §264: Parfait II (Perfect II - temporal sense)
# More frequent in BF
self._register_prefix_pattern("perfect_ii", {
Dialect.SAHIDIC: "ⲛⲧⲁ",
Dialect.LYCOPOLITAN: "ⲛⲧⲁ",
Dialect.FAYYUMIC: "ⲉⲧⲉⲁ", # Also ⲁⲁ-, ⲉⲧⲁ-
Dialect.BOHAIRIC: "ⲉⲧⲁ",
Dialect.AKHMIMIC: "ⲛⲁ",
}, "APERF2", "§264")
# §265: Temporel (Temporal - "comme" or "après que")
# Negative §315
self._register_prefix_pattern("temporal", {
Dialect.SAHIDIC: "ⲛⲧⲉⲣⲉ",
Dialect.AKHMIMIC: "ⲛⲧⲁⲣⲉ", # Also (ⲛ)ⲧⲁ,ⲣⲉ-
Dialect.LYCOPOLITAN: "ⲛⲧⲁⲣⲉ",
Dialect.FAYYUMIC: "ⲛⲧⲉⲗⲉ",
}, "APREC", "§265")
# §266: N'avai(en)t pas encore (Not yet)
self._register_prefix_pattern("not_yet", {
Dialect.SAHIDIC: "ⲙⲡⲁⲧⲉ",
Dialect.LYCOPOLITAN: "ⲙⲡⲁⲧⲉ",
Dialect.BOHAIRIC: "ⲙⲡⲁⲧⲉ",
}, "ANEGNOTYET", "§266")
# §267: Conjonctif (Conjunctive)
# Often replaces subjunctive; follows conjunctions
self._register_prefix_pattern("conjunctive", {
Dialect.SAHIDIC: "ⲛⲧⲉ",
Dialect.BOHAIRIC: "ⲛⲧⲉ",
Dialect.LYCOPOLITAN: "ⲛⲧⲉ",
Dialect.FAYYUMIC: "ⲛⲧⲉ",
Dialect.AKHMIMIC: "ⲧⲉ",
}, "ACONJ", "§267")
# With suffix forms (§267: ⲛⲧⲁ, B: ⲛⲧⲁ, A: ⲧⲁ)
self._register_prefix_pattern("conjunctive_suffix", {
Dialect.SAHIDIC: "ⲛⲧⲁ",
Dialect.LYCOPOLITAN: "ⲛⲧⲁ",
Dialect.FAYYUMIC: "ⲛⲧⲁ",
Dialect.BOHAIRIC: "ⲛⲧⲁ",
Dialect.AKHMIMIC: "ⲧⲁ",
}, "ACONJSUF", "§267")
# §269-270: LE PASSÉ (Passive/Imperfect)
# Particle ⲛⲉ conjugated (replaces adverbial past)
self._register_prefix_pattern("imperfect", {
Dialect.SAHIDIC: "ⲛⲉⲣⲉ",
Dialect.LYCOPOLITAN: "ⲛⲉⲣⲉ",
Dialect.BOHAIRIC: "ⲛⲁⲣⲉ",
Dialect.AKHMIMIC: "ⲛⲁⲣⲉ",
Dialect.FAYYUMIC: "ⲛⲛⲁⲗⲗⲉ", # Also (ⲛ)ⲛⲁⲗⲗⲉ
}, "AIMP", "§270")
# §272-277: La proposition circonstancielle (Circumstantial)
# §272: Basic circumstantial converter ⲉ- (temporal/modal)
# Replaces subordinate conjunctions (comme, tandis que, si, etc.)
self._register_prefix_pattern("circumstantial", {
Dialect.SAHIDIC: "ⲉ",
Dialect.BOHAIRIC: "ⲉ",
Dialect.LYCOPOLITAN: "ⲉ",
Dialect.AKHMIMIC: "ⲉ",
Dialect.FAYYUMIC: "ⲉ",
}, "CCIRC", "§272")
# §274: Conjugated circumstantial (durée/simultanéité)
# Replaces PC of PA affirmative. Very frequent in texts!
self._register_prefix_pattern("circumstantial_durative", {
Dialect.SAHIDIC: "ⲉⲣⲉ",
Dialect.BOHAIRIC: "ⲉⲣⲉ",
Dialect.LYCOPOLITAN: "ⲉⲣⲉ",
Dialect.AKHMIMIC: "ⲉⲣⲉ", # Also ⲉ- in AL
Dialect.FAYYUMIC: "ⲉⲗⲉ", # Also ⲉ-
}, "ACIRCPRES", "§274")
# §275: Circumstantial future (postériorité)
# Note: Combines ⲉ- (circumstantial) + pronoun + ⲛⲁ/ⲛⲉ (future)
# Examples: ⲉⲩⲛⲁⲥⲃⲧⲉ, ⲉⲕⲛⲁⲧⲱⲃϩ - segments as ⲉ + pronoun + ⲛⲁ + verb
# §276-277: Periphrastic (ⲱⲱⲡⲉ) and inchoative (ⲉⲓ) are syntactic patterns
# Object pronoun patterns (prepositional objects)
self.object_pronouns = {
"ⲙⲙⲟ": ("ⲛ", "PREP"), # Accusative
"ⲉⲣⲟ": ("ⲉ", "PREP"), # To/toward
"ⲛⲁ": ("ⲛⲁ", "PREP"), # To/for
"ϩⲁⲣⲟ": ("ϩⲁ", "PREP"), # Under
}
# §219-230: SUFFIXAL CONJUGATION (Quality/Stative verbs)
# These verbs conjugate with subject suffix directly (no infinitive)
self.quality_verbs = {
# §220: Various meanings
"ⲙⲉⲩⲉ": ("ⲙⲉⲩⲉ", "VSTAT", {"Meaning": "ne sais pas"}), # S
"ⲙⲉϩⲁ": ("ⲙⲉϩⲁ", "VSTAT", {"Meaning": "peut-être"}), # A
# §221: Quality verbs (big, good, beautiful, etc.)
"ⲛⲁⲁ": ("ⲛⲁⲁ", "VSTAT", {"Meaning": "grand"}), # SB
"ⲛⲉⲉ": ("ⲛⲁⲁ", "VSTAT", {"Meaning": "grand"}), # L
"ⲛⲁⲛⲟⲩ": ("ⲛⲁⲛⲟⲩ", "VSTAT", {"Meaning": "bon"}), # SAL F
"ⲛⲁⲛⲉ": ("ⲛⲁⲛⲟⲩ", "VSTAT", {"Meaning": "bon"}), # B
"ⲛⲉⲥⲱ": ("ⲛⲉⲥⲱ", "VSTAT", {"Meaning": "beau"}), # S
"ⲛⲉⲥⲃⲱⲱ": ("ⲛⲉⲥⲱ", "VSTAT", {"Meaning": "beau"}), # S
"ⲛⲁϣⲉ": ("ⲛⲁϣⲉ", "VSTAT", {"Meaning": "nombreux"}), # B also
"ⲛⲉⲃⲱ": ("ⲛⲉⲃⲱ", "VSTAT", {"Meaning": "laid"}), # S
"ⲛⲁⲛⲟⲩⲥ": ("ⲛⲁⲛⲟⲩⲥ", "VSTAT", {"Meaning": "bon"}), # A
# §222: "say" (past quality)
"ⲡⲉⲭⲉ": ("ⲡⲉⲭⲉ", "VSTAT", {"Meaning": "a dit"}), # SBF
"ⲡⲉⲭⲁ": ("ⲡⲉⲭⲉ", "VSTAT", {"Meaning": "a dit"}), # F
"ⲡⲁⲭⲉ": ("ⲡⲉⲭⲉ", "VSTAT", {"Meaning": "a dit"}), # AL
# §223: "different"
"ⲟⲩⲱⲧ": ("ⲟⲩⲱⲧ", "VSTAT", {"Meaning": "différent"}), # SAL
"ⲟⲩⲉⲧ": ("ⲟⲩⲱⲧ", "VSTAT", {"Meaning": "différent"}), # SB
"ⲟⲩⲟⲧ": ("ⲟⲩⲱⲧ", "VSTAT", {"Meaning": "différent"}), # B
"ⲟⲩⲁⲧ": ("ⲟⲩⲱⲧ", "VSTAT", {"Meaning": "différent"}), # F
# §224: "want"
"ⲍⲛⲉ": ("ⲍⲛⲉ", "VSTAT", {"Meaning": "veut"}), # SB
"ⲍⲛⲁ": ("ⲍⲛⲉ", "VSTAT", {"Meaning": "veut"}), # AL
"ⲍⲛⲏ": ("ⲍⲛⲉ", "VSTAT", {"Meaning": "veut"}), # F
# §225: "exists" (il est, il y a) - IMPORTANT!
"ⲟⲩⲛ": ("ⲟⲩⲛ", "VSTAT", {"Meaning": "il y a"}), # SAL
"ⲟⲩⲟⲛ": ("ⲟⲩⲛ", "VSTAT", {"Meaning": "il y a"}), # B
"ⲟⲩⲁⲛ": ("ⲟⲩⲛ", "VSTAT", {"Meaning": "il y a"}), # F
}
# §231-244: IMPERATIVE FORMS
# Special imperative forms (not simple infinitives)
self.imperative_forms = {
# §232: "renounce"
"ⲁⲗⲟⲕ": ("ⲁⲗⲟⲕ", "VIMP", "§232"), # S, L (m.sg.)
"ⲉⲗⲁⲕ": ("ⲁⲗⲟⲕ", "VIMP", "§232"), # L (m.sg.)
"ⲁⲗⲟ": ("ⲁⲗⲟⲕ", "VIMP", "§232"), # S (f.sg.)
"ⲁⲗⲱⲧⲛ": ("ⲁⲗⲟⲕ", "VIMP", "§232"), # SL (pl.)
# §233: "come"
"ⲁⲙⲟⲩ": ("ⲁⲙⲟⲩ", "VIMP", "§233"), # (m.sg.)
"ⲁⲙⲏ": ("ⲁⲙⲟⲩ", "VIMP", "§233"), # A (m.sg.)
"ⲁⲙⲓ": ("ⲁⲙⲟⲩ", "VIMP", "§233"), # (f.sg.)
"ⲁⲙⲏⲉⲓⲧⲁⲛ": ("ⲁⲙⲟⲩ", "VIMP", "§233"), # S
"ⲁⲙⲱⲓⲛⲓ": ("ⲁⲙⲟⲩ", "VIMP", "§233"), # A
"ⲁⲙⲏⲉⲓⲛⲉ": ("ⲁⲙⲟⲩ", "VIMP", "§233"), # A, L
# §234: "bring"
"ⲁⲛⲉⲓⲛⲉ": ("ⲁⲛⲓ", "VIMP", "§234"), # S, B
"ⲁⲛⲓⲟⲩⲓ": ("ⲁⲛⲓ", "VIMP", "§234"), # B
"ⲁⲛⲓ": ("ⲁⲛⲓ", "VIMP", "§234"), # SB LF
"ⲁⲛⲓⲧ": ("ⲁⲛⲓ", "VIMP", "§234"), # BF
# §235: "see"
"ⲁⲛⲁⲩ": ("ⲁⲛⲁⲩ", "VIMP", "§235"), # SB
"ⲁⲛⲉⲩ": ("ⲁⲛⲁⲩ", "VIMP", "§235"), # LF
# §236: "do" / "make"
"ⲁⲣⲓⲣⲉ": ("ⲁⲣⲓ", "VIMP", "§236"), # S, B
"ⲁⲣⲓⲟⲩⲓ": ("ⲁⲣⲓ", "VIMP", "§236"), # B
"ⲁⲣⲓ": ("ⲁⲣⲓ", "VIMP", "§236"), # SBAL
"ⲉⲣⲓ": ("ⲁⲣⲓ", "VIMP", "§236"), # AL, F
"ⲁⲁⲓ": ("ⲁⲣⲓ", "VIMP", "§236"), # F, SAL
"ⲁⲣⲓⲧ": ("ⲁⲣⲓ", "VIMP", "§236"), # B
"ⲁⲗⲓⲧ": ("ⲁⲣⲓ", "VIMP", "§236"), # F
# §237: "give" / "come"
"ⲁⲩⲉⲓⲥ": ("ⲁⲩⲉⲓⲥ", "VIMP", "§237"), # SLF
"ⲁⲩⲓⲥ": ("ⲁⲩⲉⲓⲥ", "VIMP", "§237"), # B
"ⲁⲩⲉⲓ": ("ⲁⲩⲉⲓⲥ", "VIMP", "§237"), # SAL
"ⲁⲩ": ("ⲁⲩⲉⲓⲥ", "VIMP", "§237"), # S
# §238: "open"
"ⲁⲟⲩⲱⲛ": ("ⲁⲟⲩⲱⲛ", "VIMP", "§238"), # SBF
"ⲁⲩⲉⲛ": ("ⲁⲟⲩⲱⲛ", "VIMP", "§238"), # L
"ⲉⲟⲩⲉⲛ": ("ⲁⲟⲩⲱⲛ", "VIMP", "§238"), # A
# §239: "say"
"ⲁⲭⲓ": ("ⲁⲭⲓ", "VIMP", "§239"), # S, BF
"ⲁⲭⲉ": ("ⲁⲭⲓ", "VIMP", "§239"), # BF, SAL F
"ⲉⲭⲓ": ("ⲁⲭⲓ", "VIMP", "§239"), # AL
"ⲁⲭⲟ": ("ⲁⲭⲓ", "VIMP", "§239"), # B
# §240: "give"
"ⲙⲁ": ("ⲙⲁ", "VIMP", "§240"), # SAL, B
"ⲙⲟⲓ": ("ⲙⲁ", "VIMP", "§240"), # B
"ⲙⲁⲓ": ("ⲙⲁ", "VIMP", "§240"), # F
"ⲙⲏⲓ": ("ⲙⲁ", "VIMP", "§240"), # B, F
}
# Store all registered patterns for lookup
self.conjugation_bases: Dict[str, Tuple[str, str]] = {}
self._build_conjugation_index()
def _register_prefix_pattern(
self,
pattern_id: str,
dialect_forms: Dict[Dialect, str],
pos_tag: str,
source_section: str
):
"""Register a prefixal conjugation pattern with dialectal variations"""
# Use Sahidic as base form (standard)
base_form = dialect_forms.get(Dialect.SAHIDIC, list(dialect_forms.values())[0])
self.dialect_handler.register_form(
base_form=base_form,
dialect_forms=dialect_forms,
pos=pos_tag,
features={},
source_section=source_section
)
def _build_conjugation_index(self):
"""Build quick lookup index for conjugation bases"""
# Get all forms from dialect handler
for base_form, df_list in self.dialect_handler.forms.items():
for df in df_list:
# Index all variant forms
for form in df.get_all_forms():
if form not in self.conjugation_bases:
self.conjugation_bases[form] = (df.pos, df.base_form)
def segment_word(
self,
word: str,
pos_hint: Optional[str] = None,
dialect: Optional[Dialect] = None
) -> List[Segment]:
"""
Segment a Coptic word into morphemes using Till's patterns.
Args:
word: Surface form (e.g., "ⲁϥⲃⲱⲕ")
pos_hint: Optional POS tag hint
dialect: Optional dialect override
Returns:
List of Segment objects
Example:
>>> analyzer.segment_word("ⲁϥⲃⲱⲕ", dialect=Dialect.SAHIDIC)
[Segment("ⲁ", "ⲁ", "APST", {}, Dialect.SAHIDIC, "§261"),
Segment("ϥ", "ⲛⲧⲟϥ", "PPERS", {...}, source_section="§117"),
Segment("ⲃⲱⲕ", "ⲃⲱⲕ", "V", {})]
"""
target_dialect = dialect or self.dialect
# NEW: Try imperative forms (§231-244)
result = self._try_imperative(word, target_dialect)
if result:
return result
# NEW: Try quality/stative verbs (§219-230)
result = self._try_quality_verb(word, target_dialect)
if result:
return result
# Try verbal pattern (conjugation base + pronoun + verb)
result = self._try_verbal_pattern(word, target_dialect)
if result:
return result
# Try object pronoun pattern (e.g., ⲙⲙⲟϥ)
result = self._try_object_pronoun(word, target_dialect)
if result:
return result
# No segmentation found - return as single token
return [Segment(
form=word,
lemma=word,
pos=pos_hint or "UNKNOWN",
feats={},
dialect=target_dialect
)]
def _try_verbal_pattern(
self,
word: str,
dialect: Dialect
) -> Optional[List[Segment]]:
"""
Try to segment: CONJUGATION_BASE + PRONOUN + VERB
Examples (Sahidic):
ⲁϥⲃⲱⲕ → ⲁ + ϥ + ⲃⲱⲕ (he went, §261)
ⲉϥⲥⲱⲧⲙ → ⲉ + ϥ + ⲥⲱⲧⲙ (when he hears, §272)
ⲛⲧⲉⲣⲉϥⲃⲱⲕ → ⲛⲧⲉⲣⲉ + ϥ + ⲃⲱⲕ (after he went, §265)
"""
# Try conjugation bases (longest first to match greedy)
for base_form in sorted(self.conjugation_bases.keys(), key=len, reverse=True):
if not word.startswith(base_form):
continue
remainder = word[len(base_form):]
if not remainder:
continue
base_pos, base_lemma = self.conjugation_bases[base_form]
# Get dialectal form info
df = self.dialect_handler.get_morpheme(base_form, dialect)
source_section = df.source_section if df else None
# Try to find pronoun at start of remainder
for pron_form in sorted(self.pronouns.keys(), key=len, reverse=True):
if not remainder.startswith(pron_form):
continue
verb = remainder[len(pron_form):]
if not verb or len(verb) < 2: # Verb must be at least 2 chars
continue
# Success! We found: base + pronoun + verb
pron_lemma, pron_pos, pron_feats = self.pronouns[pron_form]
return [
Segment(
form=base_form,
lemma=base_lemma,
pos=base_pos,
feats={},
dialect=dialect,
source_section=source_section
),
Segment(
form=pron_form,
lemma=pron_lemma,
pos=pron_pos,
feats=pron_feats.copy(),
dialect=dialect,
source_section="§117"
),
Segment(
form=verb,
lemma=verb,
pos="V",
feats={"VerbForm": "Fin"},
dialect=dialect
)
]
return None
def _try_imperative(
self,
word: str,
dialect: Dialect
) -> Optional[List[Segment]]:
"""
Try to match imperative forms (§231-244).
Examples (Till):
ⲁⲙⲟⲩ → "come!" (imperative)
ⲁⲣⲓ → "do!" (imperative)
ⲙⲁ → "give!" (imperative)
"""
# Check if word is in imperative forms dictionary
if word in self.imperative_forms:
lemma, pos, source = self.imperative_forms[word]
return [Segment(
form=word,
lemma=lemma,
pos=pos,
feats={"VerbForm": "Imp"},
dialect=dialect,
source_section=source
)]
return None
def _try_quality_verb(
self,
word: str,
dialect: Dialect
) -> Optional[List[Segment]]:
"""
Try to match quality/stative verbs (§219-230).
These verbs conjugate with subject suffixes directly (no infinitive).
Examples (Till):
ⲟⲩⲛ → "il y a" (existential)
ⲛⲁⲁ → "grand" (quality: big)
ⲡⲉⲭⲉ → "a dit" (quality: said)
With suffixes:
ⲟⲩⲛⲧⲁϥ → ⲟⲩⲛ + ⲧⲁ + ϥ (il a)
ⲡⲉⲭⲁϥ → ⲡⲉⲭⲁ + ϥ (he said)
"""
# Try to match quality verb stems
for verb_form in sorted(self.quality_verbs.keys(), key=len, reverse=True):
if not word.startswith(verb_form):
continue
remainder = word[len(verb_form):]
lemma, pos, feats = self.quality_verbs[verb_form]
# If no remainder, return the verb alone
if not remainder:
return [Segment(
form=word,
lemma=lemma,
pos=pos,
feats=feats.copy(),
dialect=dialect,
source_section="§219-230"
)]
# Check for suffix patterns (§226-227)
# Pattern: VERB + ⲧⲁ/ⲧⲉ + PRONOUN (with nominal/pronominal subject)
# Example: ⲟⲩⲛⲧⲁϥ → ⲟⲩⲛ + ⲧⲁ + ϥ
if remainder.startswith("ⲧⲁ") or remainder.startswith("ⲧⲉ"):
suffix = remainder[:2] # ⲧⲁ or ⲧⲉ
pron = remainder[2:]
if pron in self.pronouns:
pron_lemma, pron_pos, pron_feats = self.pronouns[pron]
return [
Segment(
form=verb_form,
lemma=lemma,
pos=pos,
feats=feats.copy(),
dialect=dialect,
source_section="§226"
),
Segment(
form=suffix,
lemma=suffix,
pos="PART", # Particle linking verb to subject
feats={},
dialect=dialect
),
Segment(
form=pron,
lemma=pron_lemma,
pos=pron_pos,
feats=pron_feats.copy(),
dialect=dialect
)
]
# Check for direct pronoun suffix (§220-225)
# Some quality verbs can take direct suffixes
# Example: ⲡⲉⲭⲁϥ → ⲡⲉⲭⲁ + ϥ
if remainder in self.pronouns:
pron_lemma, pron_pos, pron_feats = self.pronouns[remainder]
return [
Segment(
form=verb_form,
lemma=lemma,
pos=pos,
feats=feats.copy(),
dialect=dialect,
source_section="§220-225"
),
Segment(
form=remainder,
lemma=pron_lemma,
pos=pron_pos,
feats=pron_feats.copy(),
dialect=dialect
)
]
return None
def _try_object_pronoun(
self,
word: str,
dialect: Dialect
) -> Optional[List[Segment]]:
"""
Try to segment: PREP + PRONOUN (object pronouns)
Examples:
ⲙⲙⲟϥ → ⲙⲙⲟ + ϥ (him, accusative)
ⲉⲣⲟⲕ → ⲉⲣⲟ + ⲕ (to you)
"""
# Try object pronoun prefixes
for prep_form in sorted(self.object_pronouns.keys(), key=len, reverse=True):
if not word.startswith(prep_form):
continue
remainder = word[len(prep_form):]
if not remainder:
continue
prep_lemma, prep_pos = self.object_pronouns[prep_form]
# Check if remainder is a pronoun suffix
if remainder in self.pronouns:
pron_lemma, pron_pos, pron_feats = self.pronouns[remainder]
return [
Segment(
form=prep_form,
lemma=prep_lemma,
pos=prep_pos,
feats={},
dialect=dialect
),
Segment(
form=remainder,
lemma=pron_lemma,
pos="PPERO",
feats=pron_feats.copy(),
dialect=dialect
)
]
return None
def is_fused(self, word: str, dialect: Optional[Dialect] = None) -> bool:
"""
Check if word is likely a fused form that needs segmentation.
Args:
word: Word to check
dialect: Optional dialect
Returns:
True if word appears to be fused
"""
target_dialect = dialect or self.dialect
# Quick heuristic checks
for base in self.conjugation_bases.keys():
if word.startswith(base) and len(word) > len(base) + 1:
return True
for prep in self.object_pronouns.keys():
if word.startswith(prep) and len(word) > len(prep):
return True
return False
def get_multitoken_range(self, segments: List[Segment], start_id: int) -> Tuple[int, int]:
"""
Calculate ID range for multi-token word.
Args:
segments: List of segments
start_id: Starting token ID
Returns:
Tuple of (start_id, end_id) for CoNLL-U range notation
"""
return (start_id, start_id + len(segments) - 1)
def create_morphology_analyzer_till(
dialect: Dialect = Dialect.SAHIDIC,
prolog_engine=None
) -> CopticMorphologyAnalyzerTill:
"""
Factory function to create Till-based morphology analyzer.
Args:
dialect: Default dialect for parsing
prolog_engine: Optional Prolog engine for enhanced feature lookup
Returns:
CopticMorphologyAnalyzerTill instance
"""
return CopticMorphologyAnalyzerTill(dialect, prolog_engine)