-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainFile.py
1402 lines (1230 loc) · 52.7 KB
/
MainFile.py
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
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Copyright (C) 2013 Bimba Andrew Thomas, 2016 Linas Valiukas
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details <http://www.gnu.org/licenses/>.
from dict_lookup import ROOT_WORDS
# noinspection SpellCheckingInspection
class HausaStemmer1:
def __init__(self):
self.b = "" # buffer for word to be stemmed
self.k = 0
self.k0 = 0
self.j = 0 # j is a general offset into the string
self.h = 0 # h is a hyphen offset into the string
@staticmethod
def __check_dict(word):
if word in ROOT_WORDS:
return word
else:
return ''
def __cons(self, i):
"""Returns True <=> b[i] is a consonant."""
if self.b[i] == 'a' or self.b[i] == 'e' or self.b[i] == 'i' or self.b[i] == 'o' or self.b[i] == 'u':
return 0
else:
return 1
# if self.b[i] == 'y':
# if i == self.k0:
# return 1
# else:
# return (not self.cons(i - 1))
# return 1
def __hyphen(self, i):
"""Returns True <=> b[i] is a hyphen."""
if self.b[i] == '-':
self.h = i
return 1
else:
return 0
def __m(self):
"""Measures the number of consonant sequences between k0 and j. If c is a consonant sequence and v a vowel
sequence, and <..> indicates arbitrary presence,
<c><v> gives 0
<c>vc<v> gives 1
<c>vcvc<v> gives 2
<c>vcvcvc<v> gives 3
...
"""
n = 0
i = self.k0
while 1:
if i > self.j:
return n
if not self.__cons(i):
break
i += 1
i += 1
while 1:
while 1:
if i > self.j:
return n
if self.__cons(i):
break
i += 1
i += 1
n += 1
while 1:
if i > self.j:
return n
if not self.__cons(i):
break
i += 1
i += 1
def __has_single_hyphen(self):
"""Returns True <=> k0,...j contains single hyphen."""
for i in range(self.k0, self.j + 1):
if self.__hyphen(i):
return 1
return 0
def __has_double_hyphen(self):
"""Returns True <=> k0,...j contains double hyphens."""
count = 0
for i in range(self.k0, self.j + 1):
if self.__hyphen(i):
count += 1
if count == 2:
return 1
return 0
def __is_duplicate(self):
"""Returns True <=> k0,...j contains duplicate words."""
# if self.__has_single_hyphen:
# for i in range(self.k0, self.j + 1):
if self.h >= self.k0 + 4:
if self.b[self.k0] == self.b[self.h + 1] and self.b[self.k0 + 1] == self.b[self.h + 2] and self.b[
self.k0 + 2] == self.b[self.h + 3] and self.b[self.k0 + 3] == self.b[self.h + 4]:
return 1
else:
return 0
else:
return 0
#this can be upgrade/enhance
def __ends_with(self, s):
"""Returns True <=> k0,...k ends with the string s."""
length = len(s)
if s[length - 1] != self.b[self.k]: # tiny speed-up
return 0
if length > (self.k - self.k0 + 1):
return 0
if self.b[self.k - length + 1:self.k + 1] != s:
return 0
self.j = self.k - length
return 1
#this can be upgrade/enhance
def __starts_with(self, s):
"""Returns True <=> k0,...k starts with the string s."""
length = len(s)
if s[0] != self.b[self.k0]: # tiny speed-up
return 0
if length > (self.k - self.k0 + 1):
return 0
if self.b[self.k0:self.k0 + length] != s:
return 0
self.j = length - 1
return 1
def __set_to(self, s):
"""Sets (j+1),...k to the characters in the string s, readjusting k."""
length = len(s)
self.b = self.b[:self.j + 1] + s + self.b[self.j + length + 1:]
self.k = self.j + length
def __r(self, s):
if self.__m() >= 0 and len(self.b) > 4:
self.__set_to(s)
def __chk_center_combo_3(self):
if (len(self.b) - self.k0) > 7:
if (self.b[self.k0 + 2] + self.b[self.k0 + 3] + self.b[self.k0 + 4]) == (
self.b[self.k0 + 5] + self.b[self.k0 + 6] + self.b[self.k0 + 7]):
return 1
else:
return 0
return 0
def __chk_start_combo_3(self):
if (len(self.b) - self.k0) > 4:
if self.__cons(self.k0) and not self.__cons(self.k0 + 1) and self.b[self.k0] == self.b[self.k0 + 2] == \
self.b[
self.k0 + 3]:
return 1
elif (len(self.b) - self.k0) > 6:
if (self.b[self.k0] + self.b[self.k0 + 1] + self.b[self.k0 + 2]) == (
self.b[self.k0 + 3] + self.b[self.k0 + 4] + self.b[self.k0 + 5]):
return 1
else:
return 0
return 0
def __chk_start_combo_2(self):
if (len(self.b) - self.k0) > 6:
if (self.b[self.k0] + self.b[self.k0 + 1]) == (self.b[self.k0 + 2] + self.b[self.k0 + 3]):
return 1
else:
return 0
else:
return 0
def __chk_end_combo_2(self):
if (len(self.b) - self.k0) > 4:
if (self.b[self.k - 1] + self.b[self.k]) == (self.b[self.k - 3] + self.b[self.k - 2]):
return 1
else:
return 0
else:
return 0
def __calc(self, s):
"""Replaces prefix (k-len(s)),...k based on the string s to the appropriate characters,
by adding certain characters."""
length = len(s)
if length > (self.k - self.k0 + 1):
return
if self.__m() > 0:
# Step 1c (ii)
# m>1 for word starting with prefix "ma" and suffix "awa"
# *cvcawa->*cvcv
# ***mafadawa -> mafada (counselor)*** mafada (counselors)-> mafadi (counselor)
# ***madugawa -> madugu (chief of a caravan)***
# maguzawa -> Maguza
if s == "awa":
c = self.k - length
v = self.k - length - 1
vr = self.b[len(self.b) - length - 2]
if self.__cons(c) and not self.__cons(v):
self.__r(vr)
# Step 1e (i)
# m>1, *vwvchi -> *vwv e.g
# ***Marowachi (greediness) -> rowa (to be greedy)*** Marowaci (greediness) -> rowa (to be greedy)
elif s == "chi":
v = self.k - length
c = self.k - length - 1
cr = self.b[len(self.b) - length - 2]
vr = self.b[len(self.b) - length - 3]
if cr == "w" and not self.__cons(v):
self.__r("")
self.k0 += 2
# Step 1e (ii)
# m>0, *cvuchi -> *cvuta e.g
# ***Mafauchi (butcher) -> fauta (slaughter)*** Mahauta (butchers) -> mahauci (butcher)
# ***marubuchi -> rubuta (write)*** marubuci -> rubutu (writing)
#
elif self.b[v] == "u":
self.__r("ta")
self.k0 = 2
# m>0, *vcvchi -> *vcv e.g
# ***Marokachi (begging and beggar) -> roko (to beg)*** Maroki (begging and beggar) -> roko (to beg)
# ***Matsorachi (cowardice) -> tsoro (fear)*** Matsoraci (cowardice/coward) -> tsoro (fear)
#
# elif s=="chi":
# c=self.k-length
# v=self.k-length-1
# vr=self.b[len(self.b)-length-2]
if self.__cons(c) and not self.__cons(v):
self.__ends_with(self.b[v] + "chi")
self.__r(vr)
self.k0 += 2
# m>0, *nchi -> *nta e.g
# ***Makaranchi (scholar) -> karanta (to read)*** Makaranci (scholar) -> karanta (to read)
elif self.__cons(c + 1) and self.b[c + 1] == "n":
self.__r("ta")
self.k0 += 2
# m>1 remove "suwa" with a preceding vowel and replace preceding
# vowel with "a" i.e *cvsuwa -> *ca e.g
# ***Tayesuwa (helping) -> taya (to help)*** Tayawa (helping) -> taya (to help)
# ***Fitasuwa (coming out) -> fita (to come out)*** Fitowa (coming out) -> fita (to come out)
elif s == "suwa":
v = self.k - length
if not self.__cons(v):
self.__ends_with(self.b[v] + "suwa")
self.__r("a")
# m>1 remove "suwa" with a preceding consonant and add "e" i.e *csuwa -> *ce e.g
# Rantsuwa (swearing, oath) -> rantse (to swear)
else:
self.__ends_with("uwa")
self.__r("e")
# m>1 remove "ta" and add the next preceding vowel
#
# ***makafta (blindness) -> makafa (blind man)*** makanta (blindness) -> makaho (blind man)
# ***Gajerta (shortness) -> gajere (short)*** Gajarta (shortness) -> gajere (short)
# ***Kasamta (uncleanness) -> kasama (unclean, dirty person)*** Kazanta (uncleanness) -> kazami (unclean, dirty person)
# Kuturta (leprosy) -> Kuturu (to be leprous, leper)
elif s == "ta":
c = self.k - length
v = self.k - length - 1
vr = self.b[len(self.b) - length - 2]
if not self.__cons(v) and self.__cons(c):
self.__r(vr)
# m>1 remove "ta"
# ***kariata (lying) -> karia (lie)*** karya (lying) -> karya (lie)
# ***Mugunta (evil) -> mugun*** Mugunta (evil) -> mugu
if not self.__cons(c):
self.__r("")
if vr == "u":
self.__ends_with("uta")
self.__r("wa")
# m>1 replace "oshi" with "i" if next word is a consonant else truncate "oshi" e.g
# ***garwashoshi -> garwashi (burning charcoal)*** garwashi -> garwashi (burning charcoal)
elif s == "oshi":
c = self.k - length
w = self.k0 + 1
# ofisoshi -> ofis (office)
if self.__cons(w):
self.__r("")
# kusoshi -> kusa (nail)
elif self.b[c] == "s":
self.__r("a")
# garwashoshi -> garwashi (burning charcoal)
elif self.__cons(c):
self.__r("i")
# m>1 replace suffix "ye" with "ya" if remaining letters are repeated e.g
# ***mamaye -> mamaya (Attack suddenly; capture suddenly)*** mamayewa -> mamaya (Attack suddenly; capture suddenly)
elif s == "aye":
cva = self.b[self.k0] + self.b[self.k0 + 1]
cvb = self.b[self.k0 + 2] + self.b[self.k0 + 3]
if cva == cvb:
self.__r("aya")
# kwallaye -> kwallo
elif self.b[self.k - 3] == self.b[self.k - 4]:
self.__r("o")
def __step_1a(self):
"""Stem word reduplication and concrete nouns formed from prefixed particles and other nouns that use hyphens.
Search for all hyphens and remove along with the attaching prepositions and word duplication if any.
E.g.:
* da-n-zunzua -> zunzua,
* mai-gona -> gona,
* ya-l-kano -> kano,
* ba-haushe -> haushe,
* chiye-chiye -> chiye,
* guje-guje -> guje,
* karanche-karanche -> karanche,
* masu-aiki -> aiki,
* masu-gona -> gona,
* zanga-zangar -> zanga,
* baya-bayan -> baya,
* koke-kokensu -> koke,
* tsince-tsincen -> tsince,
* Na-Bakin-Kogi -> kogi,
* Abi-n-chi (food) -> chi (to eat),
* Abin-mamaki -> mamaki,
* Abin-tsoro (a thing to fear) -> tsoro (to fear),
* Wuri-n-rubutu (writing place) -> rubutu (to write),
* da-n-makaranta -> makaranta
Exception: Guje-guje (running) -> gudu (to run).
"""
########################################################################################
if self.__ends_with("sace-sace"):
self.__r("sata")
elif self.__ends_with("mabukaci") or self.__ends_with("mabukaciya") or self.__ends_with("mabukacin") or self.__ends_with("bukatu") or self.__ends_with("mabukaciyar") or self.__ends_with("bukatar"):
self.__r("bukata")
elif self.__ends_with("sabuwar"):
self.__r("sabo ")
elif self.__ends_with("mummunan"):
self.__r(" muni ")
elif self.__ends_with("matsoraci"):
self.__r("tsoro")
elif self.__ends_with("makaranci"):
self.__r("karatu")
elif self.__starts_with("mahauka"):
self.__r("ka")
elif self.__ends_with("marowaci"):
self.__r("rowawa")
elif self.__ends_with("mafadaci") and len(self.b) > 6:
self.__r("fada")
elif self.__ends_with("makamanci") and len(self.b) > 6:
self.__r("kama")
elif self.__ends_with("maketaci") and len(self.b) > 6:
self.__r("keta")
elif self.__ends_with("makancewa") and len(self.b) > 6:
self.__r("mamakantata")
elif self.__ends_with("malalewa") and len(self.b) > 6:
self.__r("malalala")
elif self.__ends_with("natsuwa") and len(self.b) > 6:
self.__r("natsuwawa")
elif self.__ends_with("a-ci-shiru") and len(self.b) > 6:
self.__r("a-ci-shiru ")
elif self.__ends_with("guje-guje") and len(self.b) > 6:
self.__r("gudu")
elif self.__ends_with("shaye-shaye") and len(self.b) > 6:
self.__r("sha")
elif self.__ends_with("bare-bare") and len(self.b) > 6:
self.__r("bari")
elif self.__ends_with("gwaje-gwaje") and len(self.b) > 6:
self.__r("gwaji")
elif self.__ends_with("raye-raye") and len(self.b) > 6:
self.__r("rawa ")
elif self.__ends_with("kade-kade") and len(self.b) > 6:
self.__r("kida")
elif self.__ends_with("buge-buge") and len(self.b) > 6:
self.__r("bugu ")
elif self.__ends_with("gane-gane") and len(self.b) > 6:
self.__r("gani")
elif self.__ends_with("gine-gine") and len(self.b) > 6:
self.__r("gini")
elif self.__ends_with("dare-da-rana") and len(self.b) > 6:
self.__r("dare-da-rana ")
elif self.__ends_with("yau-da-gobe") and len(self.b) > 6:
self.__r("yau-da-gobe")
elif self.__ends_with("yau-da-kullum") and len(self.b) > 6:
self.__r("yau-da-kullum")
elif self.__ends_with("karance-karance") and len(self.b) > 6:
self.__r("karatu")
elif self.__ends_with("sinasir") and len(self.b) > 6:
self.__r("sinasir ")
elif self.__ends_with("zigidir") and len(self.b) > 6:
self.__r("zigidir ")
elif self.__ends_with("sintiri") and len(self.b) > 6:
self.__r("sintiri ")
elif self.__ends_with("sananne") and len(self.b) > 6:
self.__r("sani ")
elif self.__ends_with("maimaitawa") and len(self.b) > 6:
self.__r(" maimaici ")
elif self.__ends_with("maimaita") and len(self.b) > 6:
self.__r(" maimaici ")
elif self.__ends_with("maimaici") and len(self.b) > 6:
self.__r(" maimaici ")
elif self.__ends_with("mayanka") and len(self.b) > 6:
self.__r("yanka")
elif self.__ends_with("makwabtaka") and len(self.b) > 6:
self.__r("makwabci ")
elif self.__ends_with("masussuka") and len(self.b) > 6:
self.__r("mashi ")
elif self.__ends_with("matsaya") and len(self.b) > 6:
self.__r("matsaya ")
elif self.__ends_with("mashaya") and len(self.b) > 6:
self.__r("mashaya ")
elif self.__ends_with("dandano") and len(self.b) > 6:
self.__r(" dandano ")
elif self.__ends_with("yartsana") and len(self.b) > 6:
self.__r(" yartsana ")
elif self.__ends_with("yantsaki") and len(self.b) > 6:
self.__r(" yantsaki ")
elif self.__ends_with("dillanci") and len(self.b) > 6:
self.__r(" dillali ")
elif self.__ends_with("shashanci") and len(self.b) > 6:
self.__r(" shashashasha ")
elif self.__ends_with("banbanci") and len(self.b) > 6:
self.__r(" banbanci ")
elif self.__ends_with("turanci") and len(self.b) > 6:
self.__r(" turanci ")
elif self.__ends_with("bakunci") and len(self.b) > 6:
self.__r(" bako ")
elif self.__ends_with("ragwantaka") and len(self.b) > 6:
self.__r(" rago ")
elif self.__ends_with("bakunta") and len(self.b) > 6:
self.__r(" bako ")
elif self.__ends_with("yarintaka") and len(self.b) > 6:
self.__r(" yaro ")
elif self.__ends_with("zumuntaka") and len(self.b) > 6:
self.__r(" zumunci ")
elif self.__ends_with("zumunci") and len(self.b) > 6:
self.__r(" zumunci ")
elif self.__ends_with("furanni") and len(self.b) > 6:
self.__r(" fure ")
elif self.__ends_with("dodanni") and len(self.b) > 6:
self.__r(" dodo ")
elif self.__ends_with("raunuka") and len(self.b) > 6:
self.__r("rauni ")
elif self.__ends_with("tsaunuka") and len(self.b) > 6:
self.__r("tsauni ")
elif self.__ends_with("kofuka") and len(self.b) > 6:
self.__r(" kofi ")
elif self.__ends_with("kazanta") and len(self.b) > 6:
self.__r("kazanta ")
elif self.__ends_with("tuluna"):
self.__r("tulu ")
elif self.__ends_with("anguna"):
self.__r("ango")
elif self.__ends_with("raguna"):
self.__r("rago")
elif self.__ends_with("jakuna"):
self.__r("jaki")
elif self.__ends_with("maguna"):
self.__r("mage")
elif self.__ends_with("alluna"):
self.__r("allo")
elif self.__ends_with("barazana"):
self.__r("barazana ")
elif self.__ends_with("kanana"):
self.__r("karami")
elif self.__ends_with("masana"):
self.__r("sani ")
elif self.__ends_with("bangaye"):
self.__r("bango")
elif self.__ends_with("bebaye"):
self.__r("bebe ")
elif self.__ends_with("kifaye"):
self.__r("kifi")
elif self.__ends_with("buzaye"):
self.__r("buzu")
elif self.__ends_with("jajaye"):
self.__r(" jajaye ")
elif self.__ends_with("koraye"):
self.__r("kore")
elif self.__ends_with("shanye"):
self.__r("sha")
elif self.__ends_with("kiranye"):
self.__r("kira")
elif self.__ends_with("saye-saye"):
self.__r("saye ")
elif self.__ends_with("filaye"):
self.__r("fili")
elif self.__ends_with("guntaye"):
self.__r("guntu")
elif self.__ends_with("jirwaye"):
self.__r("jirwaye ")
elif self.__ends_with("kwaye"):
self.__r("kwayewa")
elif self.__ends_with("tagwaye"):
self.__r("tagwaye ")
elif self.__ends_with("zagaye"):
self.__r("zagaye ")
elif self.__ends_with("dardar"):
self.__r("dardardar ")
elif self.__ends_with("farfar"):
self.__r("farfarfar ")
elif self.__ends_with("gargar"):
self.__r("gargargar ")
elif self.__ends_with("dakyar"):
self.__r("dakyar ")
elif self.__ends_with("madaki"):
self.__r("madaki ")
elif self.__ends_with("lantarki"):
self.__r("lantarki ")
elif self.__ends_with("kabaki"):
self.__r("kabaki ")
elif self.__ends_with("wadanda"):
self.__r("wadanda ")
elif self.__ends_with("baitoci"):
self.__r("baiti ")
elif self.__ends_with("nassoshi"):
self.__r("nassi ")
elif self.__ends_with("koshi"):
self.__r("koshi ")
elif self.__ends_with("toshi"):
self.__r("toshi ")
elif self.__ends_with("maguzawa"):
self.__r("maguzawa ")
elif self.__ends_with("mahauci"):
self.__r("mahauci ")
elif self.__ends_with("marubuci"):
self.__r("rubutu ")
elif self.__ends_with("albishirin"):
self.__r("albishir ")
elif self.__ends_with("batirin"):
self.__r("batiri ")
elif self.__ends_with("alamarin"):
self.__r("alamari ")
elif self.__ends_with("alkawarin"):
self.__r("alkawari ")
elif self.__ends_with("sigarin"):
self.__r("sigari ")
elif self.__ends_with("sikarin"):
self.__r("sikari ")
elif self.__ends_with("kowanne"):
self.__r("kowa ")
elif self.__ends_with("kowadanne"):
self.__r("kowa ")
elif self.__ends_with("wadatacce"):
self.__r("wadata ")
elif self.__ends_with("farkakke"):
self.__r("farkewa ")
elif self.__ends_with("wankakke"):
self.__r("wanki ")
elif self.__ends_with("madinka"):
self.__r("dinki ")
elif self.__ends_with("matata"):
self.__r("matata ")
elif self.__ends_with("maraya"):
self.__r("maraya ")
elif self.__ends_with("danruwa"):
self.__r("danruwa ")
elif self.__ends_with("wawanci"):
self.__r("wawawa ")
elif self.__ends_with("wawantaka"):
self.__r("wawawa ")
elif self.__ends_with("kakanni"):
self.__r("kakaka ")
elif self.__ends_with("karyarka"):
self.__r("karya ")
elif self.__ends_with("karyarku"):
self.__r("karya ")
elif self.__ends_with("jarumtaka"):
self.__r("jarumta ")
elif self.__ends_with("hakimci"):
self.__r("hakimi ")
elif self.__ends_with("haramci"):
self.__r("haramci ")
elif self.__ends_with("karamci"):
self.__r("karamci ")
elif self.__ends_with("gabobi"):
self.__r("gaba ")
elif self.__ends_with("butoci"):
self.__r("buta ")
elif self.__ends_with("motoci"):
self.__r("mota ")
elif self.__ends_with("kofofi"):
self.__r("kofa ")
elif self.__ends_with("kafofi"):
self.__r("kafa ")
elif self.__ends_with("karofi"):
self.__r("karofi ")
elif self.__ends_with("rugoji"):
self.__r("ruga ")
elif self.__ends_with("sojoji"):
self.__r("soja ")
elif self.__ends_with("rigogi"):
self.__r("riga ")
elif self.__ends_with("tagogi"):
self.__r("taga ")
elif self.__ends_with("gololi"):
self.__r("gola ")
elif self.__ends_with("alamomi"):
self.__r("alama ")
elif self.__ends_with("kalmomi"):
self.__r("kalma ")
elif self.__ends_with("surori"):
self.__r("sura ")
elif self.__ends_with("garori"):
self.__r("gara ")
elif self.__ends_with("wayoyi"):
self.__r("waya ")
elif self.__ends_with("doyoyi"):
self.__r("doya ")
elif self.__ends_with("lunguna"):
self.__r("lungu")
elif self.__ends_with("shaguna"):
self.__r("shago")
elif self.__ends_with("wanduna"):
self.__r("wando")
elif self.__ends_with("zakuna"):
self.__r("zaki")
elif self.__ends_with("kekuna"):
self.__r("keke ")
elif self.__ends_with("fursunoni"):
self.__r("fursuna ")
elif self.__ends_with("ruwana"):
self.__r("ruwa ")
elif self.__ends_with("kekena"):
self.__r("keke ")
elif self.__ends_with("takalmana"):
self.__r("takalmi")
elif self.__ends_with("babana"):
self.__r("baba ")
elif self.__ends_with("kakana"):
self.__r("kaka ")
elif self.__ends_with("ena"):
self.__r("e")
elif self.__ends_with("matar"):
self.__r("mata ")
elif self.__ends_with("matatar"):
self.__r("matata ")
elif self.__ends_with("lokacinda"):
self.__r("lokaci ")
elif self.__ends_with("rmu"):
self.__r("")
elif self.__ends_with("likitoci"):
self.__r("likita ")
elif self.__ends_with("oci"):
self.__r("a")
elif self.__ends_with("sarewa"):
self.__r("sarewa ")
elif self.__ends_with("maita"):
self.__r(" maita ")
elif self.__ends_with("mayya"):
self.__r(" maita ")
elif self.__ends_with("ramuka"):
self.__r("rami")
elif self.__ends_with("basuka"):
self.__r("bashi")
elif self.__ends_with("kofuka"):
self.__r("kofi")
elif self.__ends_with("aiyuka"):
self.__r("aiki")
elif self.__ends_with("aibobi"):
self.__r("aibi")
elif self.__ends_with("kaloli"):
self.__r("kala")
elif self.__ends_with("makoki"):
self.__r("makoki ")
elif self.__ends_with("madoki"):
self.__r("madoki ")
########################################################################################
if self.__has_double_hyphen():
self.k0 = self.h + 1
elif self.__has_single_hyphen() and self.__is_duplicate():
self.k = self.h - 1
elif self.__has_single_hyphen():
self.k0 = self.h + 1
# m>1 rin->r
# teburin -> tebur (table)
#
elif self.__ends_with("rin") and len(self.b) > 6:
self.__r("r")
# and #m>1, replace repeated prefix e.g
# ***gagarumar-> garuma (a ring, a circular support)*** gagarumar-> gagaruma (a ring, a circular support)
if self.__chk_start_combo_2():
self.k0 = 2
# m>1, replace prefix with consonant and vowel combination of form cvccv with cv where the all the c's are
# same alphabet and the v's are same
#
# e.g:
# ***kakkausar -> kausar -> kausa (roughness)*** kakkausa -> kakkausar -> kaushi (roughness)
# ***tattaunawar -> taunawar -> tauna (chew, deal with principals)*** tattaunawar -> taunawar -> tauna (chew, deal with principals)
# ***rarrabuwar -> rabuwar -> rabu (separate)*** rarrabuwar -> rabuwar -> rabuwa (separate)
#
# and #m>1, replace repeated prefix e.g
# ***murmure-> mure (Become convalescent; recover from illness or bad times)*** murmurewa -> murmure (Become convalescent; recover from illness or bad times)
if self.__chk_start_combo_3():
self.k0 = 3
# m>1 fen->
# kafafen -> kafa (leg)
if self.__ends_with("fen") and len(self.b) > 6:
self.__r("")
# m>1 ir->i
# ***kungurmir -> kungurmi (The crown of the head)*** kungurmin -> kungurmi (The crown of the head)
elif self.__ends_with("ir") and len(self.b) > 5:
self.__r("i")
# m>1 ar->a
# ranar -> rana
# kungiyar -> kungiya
# mutuwar->mutuwa
elif self.__ends_with("ar") and len(self.b) > 4:
self.__r("a")
# m>1 Remove "n" at the end of the word e.g
# Watan (month of) -> wata (month)
# Mugun (from "mugunta" evil) -> mugu (bad, bad person)
# Manyan -> manya (big)
# Matsalolin-> Matsaloli (problem)
if self.__ends_with("n") and len(self.b) > 4:
self.__r("")
# m>1 cce->
# kowacce -> kowa (table)
if self.__ends_with("cce"):
self.__r("")
def __step_1b(self):
"""Stem concrete nouns formed from verb and prefixed with personal particles without hyphens:
m>0 Remove "Mai" e.g
Maihalbi (marksman, hunter) -> halbi (to shoot)
Maikoiyo (learner) -> koiyo (to learn)
"""
if self.__starts_with("mai") and len(self.b) > 5:
self.k0 = 3
def __step_1c(self):
"""Stem Plural of compound nouns formed with prefix "ma" and suffix "ai"
M>1 ai->a e.g
madaffai -> madaffa (kitchen) -> daffa (to cook)
mahaukatai -> mahuakata (place of mad people)-> huakata (to be mad)
mafautai -> mafauta (slaughter-place)-> fauta (to slaughter)
makarantai -> makaranta (school)-> karanta (to read)
mafutai -> mafuta (resting place)-> futa (t)
* exceptions: madumkai -> madumki (tailor), mafarai -> mafari (beginning)
"""
if self.__ends_with("ai") and len(self.b) > 4:
self.__r("a")
self.k0 = 2
# M>1 for word starting with prefix "ma" and suffix "ra" replace suffix with "ri" and remove "ma"
# e.g
# mafara->mafari->fari (begin)
#
elif self.__ends_with("ra") and len(self.b) > 4:
self.__r("ri")
self.k0 = 2
# M>1 for word starting with prefix "ma" and suffix "ka" replace suffix with "ki" and remove "ma"
# e.g
# ***madunka ->madunki (tailor) ->dunki (saw)*** madinka ->madinki (tailor) ->dinki (saw)
#
elif self.__ends_with("ka") and len(self.b) > 4:
self.__r("ki")
self.k0 = 2
# M>1 for word starting with prefix "ma" and suffix "ta" or "fa" remove prefix "ma"
# e.g
# ***madaffa (kitchen) -> daffa (to cook)*** madafa (kitchen) -> dafa (to cook)
# ***mahuakata (place of mad people) ->huakata (to be mad)*** mahaukata (place of mad people) ->hauka (to be mad)
# ***mafauta (slaughter-place) -> fauta (to slaughter)*** mahauta (slaughter-place) -> fawa (to slaughter)
# makaranta (school) i->karanta (to read)
# ***mafuta (resting place) ->futa (to rest)*** mahuta (resting place) ->hutu (to rest)
elif self.__ends_with("ta") or self.__ends_with("fa") and len(self.b) > 4:
self.k0 = 2
# m>1, for word starting with prefix "ma" and suffix "awa"
# *cvcawa->*cvcv
# mafadawa -> mafada (counselor)
# madugawa -> madugu (chief of a caravan)
elif self.__ends_with("awa"):
self.__calc("awa")
# Stem Plural of compound nouns formed with prefix "ma" and has the suffix "ta"
# m>1, ta->chi e.g
# ***mafauta->mafauchi (butcher)*** mahauta->mahauci (butcher)
# ***mahaukata->mahaukachi (madman)*** mahaukata->mahaukaci (madman)
# ***marubuta ->marubuchi (writer)*** marubuta ->marubuci (writer)
# ***makaranta->makaranchi (school)*** makaranta->makaranci (school)
# ***mafuta->mafuchi (resting place)*** mahuta->mahuci (resting place)
elif self.__ends_with("ta"):
self.__r("chi")
# Stem Abstract nouns formed from a verb or adjective with suffix "chi" and prefix "ma".
# Search for words with suffix "chi" and prefix "ma" remove "ma" and perform the action indicated
# m>1, Remove "ma", e.g
# ***Marowachi (greediness) -> rowa (to be greedy)*** Marowaci (greediness) -> rowa (to be greedy)
# ***mahaukachi->hauka (madman)*** mahaukaci->hauka (madman)
#
elif self.__ends_with("chi"):
self.__calc("chi")
# Stem concrete nouns formed from verb with "Ma" prefixed and "Ya" suffixed
# m>1, Remove "ma" and "ya", e.g
# Mashaya (dinking place) -> sha
elif self.__ends_with("ya"):
self.__r("")
self.k0 += 2
def __step_2(self):
# m>1 step 2 (i) change che -> tu "plural duplication"
# ***Rubuche-rubuche (writing) -> rubutu (write)*** Rubuce-rubuce (writings) -> rubutu (writing)
# ***Karanche-karanche (reading) ->karatu (read)*** Karance-karance (reading) ->karatu (read)
if self.__ends_with("che"):
self.__r("tu")
# m>1 step 2 (ii)remove "suwa" with a preceding vowel and replace preceding vowel with "a" i.e *cvsuwa -> *ca
# E.g.:
# ***Tayesuwa (helping) -> taya (to help)*** Tayawa (helping) -> taya (to help)
# ***Fitasuwa (coming out) -> fita (to come out)*** Fitarwa (coming out) -> fita (to come out)
elif self.__ends_with("suwa"):
self.__calc("suwa")
# Stem words with prefix "yan"
#
# If word >=8, remove "yan", e.g
# Yankaba (children of destruction) -> kaba (name applied to pain)
elif self.__starts_with("yan") and len(self.b) > 6:
self.k0 += 3
# m>1, remove "owa" with preceding vowel "o" and replace "o" with "a", e.g
# ***Tadowa (raising) -> tada (to rise)*** Tasowa (raising) -> tashi (to rise)
elif self.__ends_with("owa"):
self.__r("a")
# m>1, remove "nchi" and "ntaka", e.g
# ***baranchi, barantaka (service) -> bara (servant)*** baranci, barantaka (service) -> bara (servant)
# ***daianchi, daiantaka (singleness) -> daia (one)*** dayanci, dayantaka (singleness) -> daya (one)
# ***gadonchi, gadontaka (inheritance) -> gado (inheritance)*** gadonci, gadontaka (inheritance) -> gado (inheritance)
#
# Exceptions:
# ***turanchi (what belongs to the white man) -> ture (white man's country),
# ***bakunchi*** Bakunta
# bakuntaka (strangeness) -> bako (stranger),
# raganchi*** ragantaka
# ragantaka (laziness) -> rago (idler, lazy person),
# sarkanchi
# sarkantaka(kingship) -> sariki (king), ***Sarauta
# yaranchi*** yyaranci
# yarantaka (youthfulness) -> yaro (boy)
elif self.__ends_with("nchi") or self.__ends_with("ntaka"):
self.__r("")
# m>1, remove "nci", e.g
# fuskanci(to face) -> fuska (face)
elif self.__ends_with("nci") and len(self.b) > 6:
self.__r("")
# m>1, remove "manzanni", e.g
# manzanni(angels) -> manzo (angel)
elif self.__ends_with("manzanni") and len(self.b) > 4:
self.__r("manzo")
# m>1, remove "nni", e.g
# wasanni(games) -> wasa (game)
elif self.__ends_with("anni") and len(self.b) > 6:
self.__r("a")
# m>1, remove "barmu", e.g
# tabarmu(mates) -> tabarma (mate)
elif self.__ends_with("barmu") and len(self.b) > 4:
self.__r("barma")
# m>1, remove "nsa" or "nsu", e.g
# wasansa(his play) -> wasa (play)
# kurensu (their limit)->kure(limit)
# motocinsu (their car) -> motoci (cars)
elif self.__ends_with("nsa") or self.__ends_with("nsu"):
self.__r("")
# m>1, remove "nshi","nka", or "nku" e.g
# wasanshi (his play) -> wasa (play)
# karyanka (you are lied)->karya(lie)
# karyanku -> karya(lie)
elif self.__ends_with("nshi") or self.__ends_with("nka") or self.__ends_with("nku"):
self.__r("")
# m>1, replace suffix "uka" with "e" e.g
# kauyuka->kauye
# karnuka ->kare
elif len(self.b) > 5 and self.__ends_with("uka"):
if self.__cons(self.k - 3) and self.__cons(self.k - 4):
# self.b= self.b[self.k0:self.k-3]
self.__ends_with(self.b[self.k - 3] + "uka")
self.__r("e")
else:
self.__r("e")
# m>1, replace suffix "nta" e.g
# jagoranta -> jagora (blind person's guide)
# mugunta -> mugu (wicked)
elif self.__ends_with("nta") and len(self.b) > 5:
self.__r("")
# m>1, remove "chi" and "taka" for words with preceding consonant "m" and replace with "i", e.g
# ***zarumchi, zarumtaka (bravery) -> zarumi (brave man)*** jarumi, jaruma, jarumai, jarumtaka (bravery) -> jarumta (brave man)
#
elif self.__ends_with("mchi") or self.__ends_with("mtaka"):
self.__r("i")
# m>1 remove "ta" and replace preceding "u" with "wa" if preceding consonant is not w. If "w" replace with "o"
# e.g
# ***Chiwuta (sickness) -> chiwo (sick)*** Cuta (sickness) -> ciwo (sick)
# wauta (folly) -> wawa (fool)
# ***fauta (slaughter) ->fawa (to slaughter)*** fawa (butchering) ->fawa (to slaughter)
# bauta (slavery) -> bawa (slave)
# * exception sarauta (kingdom) -> sarki (king) not sarawa
if self.__ends_with("ta"):
self.__calc("ta")
# m>1 nna->n:
# tukunna -> tukun (already)
elif self.__ends_with("nna"):
self.__r("n")
def __step_3(self):
# m>1 replace "obi" with "a", e.g:
# ***gabobi->gaba (front, breast)*** gabobi->gaba (joint)
# ***gambobi -> gamba (grass, a kind of hoe)*** gambar -> gamba (grass, a kind of hoe)
# ***goribobi -> goriba (a palm fruit)***goriba -> goriba (a palm fruit)
# ***habobi-> haba (chin)*** habar-> haba (chin)
if self.__ends_with("obi"):
self.__r("a")
# m>1 replace "ochi" with "a", e.g:
# ***batochi -> bata (small box made of skin)*** batoci -> bata (small box made of skin)
# ***hanchochi->hanchi (nose)*** hanci->hanci (nose)
elif self.__ends_with("ochi"):
self.__r("a")
# m>1 replace "odi" with "a", e.g:
# ***Adodi -> ado (splendor)***Ado -> ado (splendor)
# ***kafadodi->kafada (shoulder) *** kafadu->kafada (shoulder)
#* fadodi->fada (chief's court)
#* gadodi->gado (inheritence)
elif self.__ends_with("odi"):
self.__r("a")
# m>1 replace "ofi" with "a", e.g:
# kofofi->kofa (door)