-
Notifications
You must be signed in to change notification settings - Fork 1
/
conjugat.cpp
1801 lines (1542 loc) · 55.5 KB
/
conjugat.cpp
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
/*
conjugate - verb conjugation routines in Lisp, C and C++
Coded by Antti Karttunen, http://www.iki.fi/~kartturi/
Copyright (C) (1993-2003) by Antti Karttunen.
Compile as:
#!/bin/sh
gcc -c -o wildcard.o wildcard.cpp
gcc -c -o conjtest.o conjtest.cpp
gcc -c -o conjugat.o conjugat.cpp
gcc -o conjugat.cgi conjugat.o conjtest.o wildcard.o
References:
Eugene Holman: Handbook of Finnish Verbs, published by SKS,
ISBN 951-717-362-8 (ISSN 0355-1768)
Fred Karlsson: Finnish Grammar, published by WSOY.
CHANGES:
1.1.1997 by Antti Karttunen:
Fixed inflections of the verbs "jaella" 41 ja- (NSS 28)
"maata" 50 maa- (NSS 35), "taata" 50 taa- (NSS 35) and
"koota" 56 koo- (NSS 38), by ensuring that their stem is gradated
correctly from weak to strong when the strong form is needed.
(by overwriting the method gradate_for_svs() in the respective
verb classes).
Transferred verbs "rangaista" and "vavista" (in our class 33)
from the NSS class 24 to the unused NSS class 41, which
allows us to use a different method get_abstract_noun for them than
for the verbs of our classes 34 & 36.
This "transferring" was made by editing the array verbclassflags
Added more implementations of the method
virtual void get_abstract_noun()
to various verb classes.
Note that this method is only for experimental use!
For many verbs it will produce ERRONEOUS or totally NONEXISTENT forms.
For some verb classes it will simply return invalid_combination();
which is a default action.
Note that only with a few Finnish verb classes it is possible to
produce all the "abstract nouns" productively from the
corresponding verbs. Even the whole concept of the "abstract noun"
has some laxity in it. What is actually meant with it?
The nominal inflection of these nouns has not been implemented
(the singular cases MIGHT accidentally work with some verb classes.)
2.JAN.1997
Fixed a little bit more.
Added a CGI-script functionality by editing CONJTEST.CPP
Can be now used from the Web.
19. FEB 2003
Changed '{' -> 'ä' = \344, '|' -> 'ö' = \366.
I guess this could be made much more compact with the
help of "natural categories" for Finnish consonants.
*/
typedef unsigned char Uchar;
typedef unsigned int Uint;
typedef int (*PFI)(Uchar); /* Pointer to function returning int. */
#define toUstr(X) ((Uchar*) (X))
#define toStr(X) ((char *) (X))
#include "conjugat.h"
#include "string.h"
extern "C"
{
#include "stdio.h"
#include "ctype.h"
#ifdef AZTEC
#define strchr index
#endif
/* extern Uchar *strcpy(Uchar *, Uchar const *); */
/*
extern Uchar *strncpy(Uchar *, Uchar const *, size_t);
extern Uchar *strcat(Uchar *, Uchar const *);
extern Uchar *strncat(Uchar *, Uchar const *, size_t);
extern Uchar *strchr(Uchar const *, Uchar);
*/
/* extern size_t strlen(Uchar const *); */
};
int weak2strong(Uchar *s);
int strong2weak(Uchar *s);
#define MASK_GRADATION 1
#define MASK_VHARMONY 6
#define NO_GRADATION 0
#define GRADATION 1
/* Use strong2weak or weak2strong to get another stem */
#define ALWAYS_BACK 0 /* Infinitive ends with 'a' */
#define ALWAYS_FRONT 2 /* Infinitive ends with 'ä' */
#define LAST_OF_STEM 4 /* Determine it from the last character of stem. */
#define USE_BACKHARMOP 6 /* Use back1harmop() function to determine it. */
#define get_gradmask() (verbclassflags[(Otype<<1)+1] & MASK_GRADATION)
#define get_vharmonymask() (verbclassflags[(Otype<<1)+1] & MASK_VHARMONY)
#define tunteap() (NSS_Class == 14)
/* Are we inflecting "olla"-verb? */
#define ollap() ((NSS_Class == 46))
#define nahda_or_tehdap() (NSS_Class == 33)
#define tietaa_or_taitaap() (NSS_Class == 43)
#define seistap() (Otype == 35)
#define class1verb() (!(Otype & 32))
#define class2verb() (Otype & 32) /* Verbs with infinitive stem. */
#define class2verb_or_nahda_tehdap() (Otype >= 30)
/* Should we apply gradation to stem to get another stem? */
#define gradationp get_gradmask
/* Even indexed bytes in this array contain the "traditional" verb class
number used in Nykysuomen Sanakirja (NSS class).
Odd indexed bytes contain flags which tell whether we should apply
the consonantal gradation to the stem of verb (to get another stem),
and also flags which tell how it's is determined whether to use
backharmonizing vowels (a, o and u) or front harmonizing
(ä, ö and y, that is, the same vowels with dots) with that verb.
*/
/* Note that now NSS verbclasses 3-8, 43, 12, 14, 16 and 33 are defined
with gradation on, although their strong vowel stems are not
synthetized until at run time. The alternative get_wvs() methods
for synthetizing the weak vovel stems are commented out. Instead,
the wvs is get from the synthetized svs with Strong2Weak call.
Maybe it's a little bit slower and little bit more compact this way.
(space-time tradeoff)
1.1.1997: verbs rangaista + vavista (in our class 33) were
transferred from the NSS class 24 to unused NSS class 41, which
allows us to use different method get_abstract_noun for them than
for the verbs of our classes 34 & 36.
*/
Uchar verbclassflags[]=
{
/* 0 */ 0, 0,
/* 1 */ 1, GRADATION +LAST_OF_STEM, /* ahavoitu+a, ehty+ä */
/* 2 */ 1, NO_GRADATION+LAST_OF_STEM, /* ammu+a, edisty+ä */
/* 3 */ 2, GRADATION +ALWAYS_BACK, /* aloitt+aa */
/* 4 */ 2, NO_GRADATION+ALWAYS_BACK, /* ajast+aa */
/* 5 */ 2, GRADATION +ALWAYS_FRONT, /* eitt+ää */
/* 6 */ 2, NO_GRADATION+ALWAYS_FRONT, /* el+ää */
/* 7 */ 3, GRADATION +LAST_OF_STEM, /* huu+taa, löy+tää, pyy+tää */
/* 8 */ 43, GRADATION +USE_BACKHARMOP, /* tai+taa, tie+tää */
/* 9 */ 4, GRADATION +USE_BACKHARMOP, /* hoi+taa, kii+tää */
/* 10 */ 5, GRADATION +USE_BACKHARMOP, /* ime+ltää, joke+ltaa */
/* 11 */ 6, GRADATION +USE_BACKHARMOP, /* ahe+rtaa, hyke+rtää */
/* 12 */ 7, GRADATION +LAST_OF_STEM, /* so+rtaa */
/* 13 */ 8, GRADATION +ALWAYS_BACK, /* ale+ntaa (Also NSS class 42) */
/* 14 */ 8, GRADATION +ALWAYS_FRONT, /* koele+ntää (Also NSS class 42)*/
/* 15 */ 9, GRADATION +ALWAYS_BACK, /* aht+aa, aj+aa */
/* 16 */ 10, GRADATION +ALWAYS_BACK, /* autt+aa, haast+aa */
/* 17 */ 11, GRADATION +ALWAYS_BACK, /* paist+aa, taitt+aa, virkk+aa */
/* 18 */ 12, GRADATION +ALWAYS_BACK, /* kaar+taa, saar+taa */
/* 19 */ 13, GRADATION +USE_BACKHARMOP, /* hak+ea, im+eä, pot+ea, pät+eä */
/* Also NSS class 15 (päteä) */
/* 20 */ 14, GRADATION +ALWAYS_BACK, /* tun+tea */
/* 21 */ 16, GRADATION +ALWAYS_FRONT, /* lä+hteä */
/* 22 */ 17, NO_GRADATION+USE_BACKHARMOP, /* aist+ia, ets+iä, nuuhk+ia */
/* 23 */ 17, GRADATION +USE_BACKHARMOP, /* ahneht+ia, eht+iä, pyyhk+iä */
/* 24 */ 18, NO_GRADATION+LAST_OF_STEM, /* analyso+ida, na+ida */
/* 25 */ 30, NO_GRADATION+LAST_OF_STEM, /* epärö+ida, luenno+ida */
/* 26 */ 19, NO_GRADATION+LAST_OF_STEM, /* saa+da (NSS 19), myy+dä (20) */
/* juo+da (21), vie+dä (22) */
/* 27 */ 23, NO_GRADATION+ALWAYS_FRONT, /* kä+ydä */
/* 28 */ 44, GRADATION +USE_BACKHARMOP, /* anta+utua, ehe+ytyä */
/* 29 */ 0, 0,
/* 30 */ 33, GRADATION +ALWAYS_FRONT, /* nä+hdä, te+hdä */
/* 31 */ 0, 0,
/* 32 */ 0, 0,
/* 33 */ 41 /* WAS 24 ! */, GRADATION +ALWAYS_BACK, /* rangai+sta */
/* 34 */ 24, NO_GRADATION+ALWAYS_BACK, /* hai+sta, huri+sta */
/* 35 */ 45, NO_GRADATION+ALWAYS_FRONT, /* seis+tä (defective verb) */
/* 36 */ 24, NO_GRADATION+ALWAYS_FRONT, /* aivopes+tä, heli+stä */
/* 37 */ 25, NO_GRADATION+LAST_OF_STEM, /* kuu+lla, nie+llä */
/* 38 */ 26, NO_GRADATION+LAST_OF_STEM, /* pu+rra, su+rra */
/* 39 */ 27, NO_GRADATION+LAST_OF_STEM, /* me+nnä, pa+nna */
/* 40 */ 28, NO_GRADATION+ALWAYS_BACK, /* aavist+ella, aj+ella */
/* 41 */ 28, GRADATION +ALWAYS_BACK, /* ajat+ella */
/* 42 */ 28, NO_GRADATION+ALWAYS_FRONT, /* el+ellä, elvist+ellä */
/* 43 */ 28, GRADATION +ALWAYS_FRONT, /* esit+ellä */
/* 44 */ 29, NO_GRADATION+ALWAYS_BACK, /* halke+illa */
/* 45 */ 29, NO_GRADATION+ALWAYS_FRONT, /* ente+illä, varjonyrkke+illä */
/* 46 */ 31, NO_GRADATION+USE_BACKHARMOP, /* ansa+ita, ilo+ita */
/* 47 */ 32, NO_GRADATION+LAST_OF_STEM, /* juo+sta, pie+stä, syö+stä */
/* 48 */ 34, GRADATION +USE_BACKHARMOP, /* aue+ta, hapa+ta, ilje+tä */
/* 49 */ 34, NO_GRADATION+USE_BACKHARMOP, /* ale+ta, ene+tä */
/* 50 */ 35, GRADATION +LAST_OF_STEM, /* ahda+ta, evä+tä (Also NSS 40) */
/* 51 */ 35, NO_GRADATION+LAST_OF_STEM, /* arva+ta, herä+tä (Also NSS 40)*/
/* 52 */ 36, GRADATION +USE_BACKHARMOP, /* au+eta, ilj+etä */
/* 53 */ 36, NO_GRADATION+USE_BACKHARMOP, /* hirv+etä, katk+eta */
/* 54 */ 37, GRADATION +USE_BACKHARMOP, /* lämm+itä */
/* 55 */ 37, NO_GRADATION+USE_BACKHARMOP, /* häv+itä, lev+itä */
/* 56 */ 38, GRADATION +LAST_OF_STEM, /* hio+ta, koo+ta */
/* 57 */ 38, NO_GRADATION+LAST_OF_STEM, /* ero+ta, löhö+tä */
/* 58 */ 39, GRADATION +LAST_OF_STEM, /* kavu+ta, ryöpy+tä */
/* 59 */ 39, NO_GRADATION+LAST_OF_STEM, /* halu+ta, äly+tä */
/* 60 */ 46, NO_GRADATION+ALWAYS_BACK, /* o+lla (special case of NSS25) */
/* 61 */ 0, 0,
/* 62 */ 0, 0,
/* 63 */ 0, 0
};
/* For words like lukema and raivaaja. With plural forms change
last 'a' to 'i' (except with NOMINATIVE just add 't'.) */
static Uchar *CASE_SUFFIXES[] =
{
toUstr(""), // NOMINATIVE raivaaja raivaajat
toUstr("n"), // GENITIVE raivaajan raivaajien (note the 'e')
toUstr("A"), // PARTITIVE raivaajaa raivaajia
toUstr(""), // ACCUSATIVE raivaaja(n) raivaajat
toUstr("ksi"), // TRANSLATIVE raivaajaksi raivaajiksi
toUstr("nA"), // ESSIVE raivaajana raivaajina
toUstr("ssA"), // INESSIVE raivaajassa raivaajissa
toUstr("stA"), // ELATIVE raivaajasta raivaajista
toUstr("@n"), // ILLATIVE raivaajaan raivaajiin
toUstr("llA"), // ADESSIVE raivaajalla raivaajilla
toUstr("ltA"), // ABLATIVE raivaajalta raivaajilta
toUstr("lle"), // ALLATIVE raivaajalle raivaajille
toUstr("ttA"), // ABESSIVE raivaajatta raivaajitta
toUstr("n"), // INSTRUCTIVE raivaajin
toUstr("ne"), // COMITATIVE raivaajine/ni/si/en/mme/nne
toUstr("tse") // PROLATIVE
// maitse, meritse, ilmateitse, postitse, raivaajitse?
};
static Uchar *POSS_SUFFIXES[] = /* Possessive suffixes. */
{ toUstr("ni"), toUstr("mme"), toUstr("si"), toUstr("nne"), toUstr("@n"),
toUstr("@n")
};
/* @ stands for: duplicate last vowel. */
static Uchar *NEG_AUXILIARIES[] =
{ toUstr("en"), toUstr("emme"), toUstr("et"), toUstr("ette"), toUstr("ei"),
toUstr("eivät")
};
static Uchar *NEG_IMPERATIVES[] =
{ toUstr("-"), toUstr("älkäämme"), toUstr("älä"), toUstr("älkää"),
toUstr("älköön"), toUstr("älkööt")
};
/*
Sixth (and seventh) element is used with negatives:
Except with conditionals, the seventh element (oltaisiin) is used for passive
*/
static Uchar *OLLA_PRESENTS[] =
{ toUstr("olen"), toUstr("olemme"), toUstr("olet"), toUstr("olette"),
toUstr("on"), toUstr("ovat"), toUstr("ole")
};
static Uchar *OLLA_IMPERFECTS[] =
{ toUstr("olin"), toUstr("olimme"), toUstr("olit"), toUstr("olitte"),
toUstr("oli"), toUstr("olivat"), toUstr("ollut"), toUstr("olleet")
};
static Uchar *OLLA_CONDITIONALS[] =
{ toUstr("olisin"), toUstr("olisimme"), toUstr("olisit"), toUstr("olisitte"),
toUstr("olisi"), toUstr("olisivat"), toUstr("olisi"), toUstr("oltaisiin")
};
static Uchar *OLLA_IMPERATIVES[] =
{ toUstr("-"), toUstr("-"), toUstr("-"), toUstr("-"), toUstr("olkoon"),
toUstr("olkoot"), toUstr("olko")
};
static Uchar *OLLA_POTENTIALS[] =
{ toUstr("lienen"), toUstr("lienemme"), toUstr("lienet"), toUstr("lienette"),
toUstr("lienee"), toUstr("lienevät"), toUstr("liene")
};
Uchar *Rp; /* Result Pointer */
Uchar *Result;
Uchar Otype,NSS_Class;
Uint Flags;
Uchar Backf;
Uchar A,O,U;
Uchar *VOWELS = toUstr("aeiouyäö");
#define SEP1 (' ') /* Separator 1 is blank. */
#define strequ(s,t) !strcmp((s),(t))
#define contains_a_char(S,C) (strchr(toStr(S),C))
#define isvowelp(c) (contains_a_char(VOWELS,(c)))
#define addchar(c) (*++Rp = ((Uchar) (c)))
#define firstchar() (*Result)
#define lastchar() (*Rp)
#define penultchar() (*(Rp-1))
#define changelastchar(c) (lastchar() = (c))
#define changepenultchar(c) (penultchar() = (c))
#define deletelastchar() (*Rp-- = '\0')
#define duplastchar() ((*(Rp+1)=*Rp),(*++Rp)) /* addchar(lastchar()) */
/* Set the Rp to beginning, and replace the whole Result with s: */
#define replacestring(s) ((Rp = (Result-1)),addstring(toUstr(s)))
/* We have to add the terminating zero before we use front1harmop: */
#define frontharmop() ((*(Rp+1)='\0'),front1harmop(Result))
#define invalid_combination() { replacestring("-"); return; }
/* If no quantitative gradation occurs (i.e. weak2strong returns 0 or 1)
then decrement Rp back to the last character:
*/
#define Weak2Strong() { addchar('\0'); Rp -= (weak2strong(Result)!=2); }
/* If quantitative gradation occurs (i.e. strong2weak returns 2)
then decrement Rp by two characters. (Otherwise only by one character,
so that it again points to the last character of Result, after
addchar('\0') incremented it by one.)
*/
#define Strong2Weak() { addchar('\0'); Rp -= ((strong2weak(Result)==2)+1); }
#define get_syllable_count() (*(Rp+1) = '\0',count_syllables(Result))
/* String s can contain 'variables' @, A, O, or U. @ means that the last
character should be duplicated. A, O and U stand for a, o and u or
ä, ö and y (corresponding 'dotted' vowels), depending from whether
the stem is back or front harmonizing.
*/
void addstring(Uchar *s)
{
while(*s)
{
if(*s == '@') { duplastchar(); }
else if(*s == 'A') { addchar(A); }
else if(*s == 'O') { addchar(O); }
else if(*s == 'U') { addchar(U); }
else { addchar(*s); }
s++;
}
}
/*
; Duplicate last vowel, but only if it's not the second vowel of
; diphthong or long vowel.
; In this case all the other vowel combinations except those which
; have a or ä as the second vowel are treated as "diphthongs".
*/
void duplastvow(void)
{
if((lastchar() != penultchar()) &&
((lastchar() == A) || !isvowelp(penultchar())))
{ duplastchar(); }
}
int back1harmop(Uchar *s)
{ /* Check whether the string s contains a, o or u: */
return(!!(contains_a_char(s,'a') || contains_a_char(s,'o')
|| contains_a_char(s,'u')));
}
int back2harmop(Uchar *s)
{
/* If the last letter is a, o or u, then it's backharmonizing:
(but not with e, i, y, ä and ö) */
return(!!contains_a_char(toUstr("aou"),*(s+strlen(toStr(s))-1)));
}
int front1harmop(Uchar *s)
{ /* Check whether the string s contains ä, ö or y: */
return(!!(contains_a_char(s,'ä') || contains_a_char(s,'ö')
|| contains_a_char(s,'y')));
}
/* =========== SOME MISC. FUNCTIONS FOR STRING MANIPULATION ========== */
int f_isvowelp(Uchar c)
{
return(!!isvowelp(c));
}
int f_isspace(Uchar c)
{ return(isascii(c) && isspace(c)); }
/* Gets pointer to first character in s which, when applied to testfun,
returns non-zero. For example fun_index(buf,f_isdigit)
returns pointer to first digit in buf, NULL if there is
no digits at all in buf.
*/
Uchar *fun_index_gen(Uchar *s,PFI testfun,Uint negate_flag)
{
while(*s)
{
if(negate_flag ^ (!!((*testfun)(*s)))) { return(s); }
s++;
}
return(NULL);
}
/* This is like previous, but start searching from the end. */
Uchar *fun_rindex_gen(Uchar *s,PFI testfun,Uint negate_flag)
{
Uchar *orig_s;
/* if(!s) { return(s); } */ /* If s is NULL, return NULL immediately */
if(!*s) { return(NULL); } /* Nope ! If s is empty, then return NULL */
orig_s = s; /* Save the beginning of s */
s += (strlen(toStr(s))-1); /* Get pointer to last character */
while(1)
{
if(negate_flag ^ (!!((*testfun)(*s)))) { return(s); }
if(s == orig_s) { break; }
--s;
}
return(NULL);
}
Uchar *strip_blankos(Uchar *s)
{
Uchar *t;
/* Get pointer to last non white space char: */
t = fun_rindex_gen(s,f_isspace,((Uint)1));
/* If there were nothing else than white spaces (blanks, tabs, newlines) then
change s to empty string. Otherwise cut after last non white space char: */
if(!t) { *s = '\0'; } else { *(t+1) = '\0'; }
return(s);
}
/* ================ STUFF FOR CONSONANT GRADATION, ETC. =============== */
int is_first_vowel_a(Uchar *s)
{
return((s = fun_index_gen(s,f_isvowelp,((Uint)0))) && (*s == 'a'));
}
int is_long_or_diftong(Uchar c1,Uchar c2,int count)
{
if(c1 == c2) { return(1); } /* Long vowel. */
if(c2 == 'i') { return(1); }
if((c2 == 'u') && contains_a_char("aeio",c1)) { return(1); }
if((c2 == 'y') && contains_a_char("eiäö",c1)) { return(1); }
if(!count) /* These are diftongs only in first syllable: */
{
if((c1 == 'i') && (c2 == 'e')) { return(1); }
if((c1 == 'u') && (c2 == 'o')) { return(1); }
if((c1 == 'y') && (c2 == 'ö')) { return(1); }
}
return(0);
}
int count_syllables(Uchar *s)
{
int count;
Uchar c1;
count=0;
while(*s)
{
if(isvowelp(*s))
{
c1 = *s++;
if(is_long_or_diftong(c1,*s,count))
{ s++; }
count++;
}
else { s++; } /* Skip consonants. */
}
return(count);
}
/* Get pointer to pointing to the last consonant or vowel combination
which is not long nor diftong, whichever is met first.
*/
Uchar *getposition(Uchar *s)
{
Uchar *orig_s;
orig_s = s;
s = (s+strlen(toStr(s))-1); /* Point to last character. */
while(s > orig_s)
{
if(!isvowelp(*s)) { return(s); } /* Last 'consonant'. */
if(*(s+1) && !is_long_or_diftong(*s,*(s+1),1)) { return(s); }
--s;
}
return(NULL); /* Didn't find any sensible position. */
}
/* Returns
0 if no changes.
1 if qualitative gradation (i.e. length doesn't change.)
2 if quantitative gradation (i.e. length grows.)
s should be positioned to the last consonant or to last vowel boundary ???
Note that this doesn't gradate double vowels like "maa" or "koo".
*/
int aux_weak2strong(Uchar *s,Uchar next)
{
Uchar prev,isvowelf;
prev = *(s-1);
isvowelf = !!isvowelp(prev);
/* if((prev == 's') || (prev == 't')) { return(0); } */ /* No gradation. */
if((prev == 'n') && (*s == 'g')) { *s = 'k'; return(1); } /* ng -> nk */
if(*s != prev) /* Not geminaatta already... */
{
if((((*s == 'b') || (*s == 'p')) &&
(isvowelf || contains_a_char("lmr",prev)))
||
(contains_a_char("gkt",*s) &&
(isvowelf || contains_a_char("lnr",prev))))
{
*(s+1) = *s; /* Duplicate the consonant. */
return(2);
}
}
if((*s == 'v') && (isvowelf || (prev == 'l') || (prev == 'r')))
{ *s = 'p'; return(1); } /* v -> p, lv -> lp, rv -> rp */
if((*s == 'm') && (prev == *s)) { *s = 'p'; return(1); } /* mm -> mp */
if((*s == 'd') && ((prev == 'h') || isvowelf)) /* d -> t, hd -> ht */
{ *s = 't'; return(1); }
if((*s == prev) && contains_a_char("lnr",prev))
{ *s = 't'; return(1); } /* ll -> lt, nn -> nt, rr -> rt */
if((prev == 'u') && (*s == '\'') && (next == 'u')) /* u'u -> uku */
{ *s = 'k'; return(1); }
if(contains_a_char("hlr",*s) && isvowelf) /* h -> hk, l -> lk, r -> rk */
{ *(s+1) = 'k'; return(2); }
if(contains_a_char("hlr",prev) && (*s == 'j') && (next == 'e'))
{ *s = 'k'; return(1); } /* lje -> lke, rje -> rke, hje -> hke */
if(isvowelp(*s) && isvowelp(next) && !is_long_or_diftong(*s,next,1))
{
*(s+1) = 'k'; return(2); /* 0 -> k (lue -> luke) */
}
return(0); /* No gradation. */
}
/* Returns
0 if no changes.
1 if qualitative gradation (i.e. length doesn't change.)
2 if quantitative gradation (i.e. length lessens.)
s should be positioned to the last consonant or to last vowel boundary ???
*/
int aux_strong2weak(Uchar *s,Uchar next)
{
Uchar prev,isvowelf;
prev = *(s-1);
isvowelf = !!isvowelp(prev);
if(contains_a_char("bgkpt",*s) && (*s == prev))
{ /* If bb, gg, kk, pp, or tt */
return(2); /* This indicates that the other one should be deleted. */
}
if(*s == 'p')
{
if(isvowelf || (prev == 'l') || (prev == 'r'))
{ *s = 'v'; } /* p -> v, lp -> lv, rp -> rv */
else if(prev == 'm') { *s = 'm'; } /* mp -> mm */
return(1);
}
if(*s == 't')
{
if((prev == 'h') || isvowelf) /* t -> d, ht -> hd */
{ *s = 'd'; }
else if(contains_a_char("lnr",prev))
{ *s = prev; } /* lt -> ll, nt -> nn, rt -> rr */
return(1);
}
if((prev == 'u') && (*s == 'k') && (next == 'u')) /* uku -> u'u */
{ *s = '\''; return(1); }
if(contains_a_char("hlr",prev) && (*s == 'k') && (next == 'e'))
{ *s = 'j'; return(1); } /* lke -> lje, rke -> rje, hke -> hje */
if(*s == 'k')
{ /* k -> -, hk -> h, lk -> l, rk -> r */
if(contains_a_char("hlr",prev) || isvowelf)
{ return(2); }
else if(prev == 'n') { *s = 'g'; return(1); } /* nk -> ng */
}
return(0); /* No gradation. */
}
/*
Routines weak2strong and strong2weak to do the consonant gradation.
*/
int weak2strong(Uchar *s)
{
Uchar next,nextnext;
int z;
if(!(s = getposition(s))) { return(0); }
else
{
next = *(s+1);
z = aux_weak2strong(s,next);
if(z == 2)
{ /* One character is inserted between, move the remaining ones
one step to right: */
for(s += 2; next; s++)
{
nextnext = *s;
*s = next;
next = nextnext;
}
*s = '\0';
}
return(z);
}
}
int strong2weak(Uchar *s)
{
Uchar next;
int z;
if(!(s = getposition(s))) { return(0); }
else
{
next = *(s+1);
z = aux_strong2weak(s,next);
if(z == 2) { strcpy(toStr(s),toStr((s+1))); } /* Delete one char. */
return(z);
}
}
/* ===================== VERB CLASS DEFINITIONS ======================= */
class FVC /* Finnish Verb Class */
{
public:
virtual Uchar *get_negative(void);
virtual Uchar *get_olla_verb(void);
virtual void get_auxiliaries(void);
virtual void add_pers_ending(void);
virtual void add_poss_suffix(void);
virtual void inflect_nominal(void);
virtual void conj_passive(void);
virtual void conj_present_indicative(void);
virtual void conj_imperfect_indicative(void);
virtual void conj_present_imperative(void);
virtual void conj_present_conditional(void);
virtual void conj_present_potential(void);
virtual void conj_infinitive1(void);
virtual void conj_infinitive2(void);
virtual void conj_infinitive3(void);
virtual void conj_infinitive4(void);
virtual void conj_infinitive5(void);
virtual void conj_part1act(void);
virtual void conj_part1pas(void);
virtual void conj_part2act(void);
virtual void conj_part2pas(void);
virtual void conj_agential_noun(void);
virtual void conj_negative_adj(void);
virtual void conj_abstract_noun(void); // Not functional yet?
virtual void add1missing_letters() { } // Added before cons. gradation.
virtual void add2missing_letters() { } // Added after cons. gradation.
virtual void get0infstem() = 0;
virtual void get1infstem() { this->get0infstem(); } // By default.
virtual void get2infstem()
{ this->get1infstem(); if(lastchar() == 'e') { changelastchar('i'); } }
virtual void get3infstem() // Used for Third Infinitive
{ this->get_svs(); addchar('m'); addchar(A); } // punoma, sukima, pakkaama
virtual void get4infstem()
{ this->get_svs(); addstring(toUstr("minen")); } // sukiminen
virtual void get_svs() = 0;
virtual void get_wvs() { this->get_svs(); }
virtual void get_vs() { this->get_svs(); }
virtual void get_cs() { this->get_svs(); addstring(toUstr("isi")); }
virtual void get_sis() { this->get_svs(); changelastchar('i'); }
virtual void get_wis() { this->get_wvs(); changelastchar('i'); }
virtual void get_is() { this->get_sis(); }
virtual void get_wps() { this->get1infstem(); }
virtual void get_sps() { this->get_wps(); Weak2Strong(); }
virtual void get_part2actstem(void);
virtual void get_potstem() { this->get_part2actstem(); addchar('e'); }
virtual void get_part1act() // Present Active Participle (sukiva)
{ this->get_svs(); addchar('v'); addchar(A); }
virtual void get_part1pas() // Present Passive Participle (suittava)
{ this->get_sps(); addstring(toUstr("AvA")); }
virtual void get_part2act() // Past Active Participle. (sukinut/sukineet)
{
if(plurpersp()) { this->get_part2act_pl(); }
else { this->get_part2act_sg(); }
}
virtual void get_part2act_sg()
{ this->get_part2actstem(); addchar(U); addchar('t'); }
virtual void get_part2act_pl()
{ this->get_part2actstem(); addstring(toUstr("eet")); }
virtual void get_part2pas() // Past Passive Participle (suittu)
{ this->get_sps(); addchar(U); }
virtual void get_agential_noun() = 0;
// For cases which have not been implemented yet:
virtual void get_abstract_noun() { invalid_combination(); }
virtual Uchar isLongAgentPluralp() { return(0); } // By default short.
};
/*
; Get appropriate negative auxiliary:
*/
Uchar *FVC::get_negative(void)
{
int n;
n = (get_person_number() - 2);
if(n == -2) { n = 4; } /* Kludge for passive mode (PERSON_NUMBER == 0) */
return((imperativep()?NEG_IMPERATIVES:NEG_AUXILIARIES)[n]);
}
/*
; Get appropriate affirmative auxiliary for secondary tenses:
*/
Uchar *FVC::get_olla_verb(void)
{
int n;
Uchar **pp;
n = (get_person_number() - 2);
/*
Kludge for passive mode (PERSON_NUMBER == 0), and Passive Perfect Conditional:
*/
if(n == -2) { n = (conditionalp() ? 7 : 4); }
if(negativep()) /* Kludge for negatives. */
{
if(pluperfectp() && plurpersp()) { n = 7; } /* olleet */
else { n = 6; } /* ole, ollut, olisi, liene */
}
if(conditionalp()) { pp = OLLA_CONDITIONALS; } /* Perf. Cond. */
else if(potentialp()) { pp = OLLA_POTENTIALS; } /* Perf. Pot. */
else if(imperativep()) /* Perfect Imperative */
{ /* If not valid combination, then mark the result as invalid: */
if(!thirdpersp() && !passivep()) { return(toUstr("-")); }
else { pp = OLLA_IMPERATIVES; }
}
else if(pluperfectp() || imperfectp()) /* Pluperf. || Imperf. Indic. */
{ pp = OLLA_IMPERFECTS; }
else { pp = OLLA_PRESENTS; } /* Present or Perf. Indic. */
return(pp[n]);
}
/*
; This copies the necessary negative-auxiliary and/or olla-auxiliary into
; result, if any of them is needed.
*/
void FVC::get_auxiliaries(void)
{
if(negativep())
{
addstring(this->get_negative());
if(lastchar() == '-') { invalid_combination(); }
addchar(SEP1);
}
if(sectensep())
{
addstring(this->get_olla_verb());
if(lastchar() == '-') { invalid_combination(); }
addchar(SEP1);
}
}
void FVC::add_poss_suffix(void)
{
int n;
n = get_poss_suffix();
if(n) // Add nothing if poss_suffix bits are zero.
{
if(translativep()) { changelastchar('e'); } // -ksi -> -kse-
if(!isvowelp(lastchar())) { deletelastchar(); }
// lukeakseen (not lukeaksensa), nauroivat nauramistaan (not nauramistansa)
// and saamaisillaan (not saamaisillansa)
// However, nähtensä (second infinitive instructive + third pers. poss suffix)
if(thirdpersp() && !infinitive1p()&& !infinitive4p()&& !infinitive5p()
&&((get_nominal_case() <= ACCUSATIVE) ||illativep() || instructivep()))
{ addstring(toUstr("nsA")); } // Instead of default @n
// What about partitive plural? raivaajiaan or raivaajiansa ?
else { addstring(POSS_SUFFIXES[n-2]); }
}
}
void FVC::inflect_nominal(void)
{
int i;
i = get_case_index();
if(plurcasep())
{
if(nominativep() || accusativep()) { addchar('t'); }
else if(agential_nounp() && this->isLongAgentPluralp())
{
changelastchar(O); // lukijoi
addchar('i');
if(genitivep()) { addstring(toUstr("de")); } // lukijoiden
else if(partitivep()) { addchar('t'); } // lukijoita
else if(illativep()) // lukijoihin
{ addstring(toUstr("hin")); this->add_poss_suffix(); return; }
}
else
{
changelastchar('i');
if(genitivep()) { addchar('e'); }
}
}
else // singular
{
// COMITATIVE (lukijoineen) and PROLATIVE (lukijoitse) can be applied
// only in the plural. However, let INSTRUCTIVE work also with singular,
// e.g. LUKEMAN (third infinitive instructive) or JALAN (some future addition?)
if(get_nominal_case() > INSTRUCTIVE) { invalid_combination(); }
}
addstring(CASE_SUFFIXES[i]);
this->add_poss_suffix();
}
void FVC::add_pers_ending(void)
{
if(affirmativep()) /* Do nothing if negative. */
{
if(singpersp())
{
if(firstpersp()) { addchar('n'); }
else if(secondpersp()) { addchar('t'); }
else /* thirdpersp() */
{
/* If present indicative or potential, then lengthen the last vowel: */
if(presindicp() || potentialp()) { duplastvow(); }
}
}
else /* Else it's plural person. */
{
if(firstpersp()) { addstring(toUstr("mme")); }
else if(secondpersp()) { addstring(toUstr("tte")); }
else /* thirdpersp() */
{
addstring(toUstr("vAt"));
}
}
}
}
void FVC::conj_passive(void)
{
/* If secondary tense or negative imperfect, then this is enough: */
if(sectensep() || (negativep() && imperfectp())) { this->get_part2pas(); }
else
{
if(presindicp()) { this->get_wps(); } else { this->get_sps(); }
if(imperfectp()) { addchar('i'); }
else
{
addchar(A);
if(imperativep()) { addchar('k'); addchar(O); }
else if(conditionalp()) { addstring(toUstr("isi")); }
else if(potentialp()) { addstring(toUstr("ne")); }
/* Else it's Present Indicative, do nothing for that. */
}
if(affirmativep()) /* If negative, do nothing, but if affirmative */
{ /* then duplicate the last character and add 'n', so we get: */
duplastchar();
addchar('n'); /* juodaan, juotiin, juotakoon, juotaisiin, juotaneen */
}
}
}
void FVC::conj_present_indicative(void)
{
this->get_vs();
this->add_pers_ending();
}
void FVC::conj_imperfect_indicative(void)
{
if(negativep()) { this->get_part2act(); }
else
{
this->get_is();
this->add_pers_ending();
}
}
/* Active Present Imperative goes like this:
--- onkikaamme --- älkäämme onkiko
ongi onkikaa älä ongi älkää onkiko
onkikoon onkikoot älk||n onkiko älk||t onkiko
*/
void FVC::conj_present_imperative(void)
{
/* Use Weak Vovel Stem when 2nd person singular: */
if(singpersp() && !thirdpersp())
{
if(firstpersp()) { invalid_combination(); }
else /* if(secondpersp()) */ { this->get_wvs(); }
}
else
{
this->get0infstem(); /* Else use infinitive stem. */
addchar('k'); /* Plus -ko, -koon, -kaamme, -kaa or -koot */
addchar((negativep() || thirdpersp()) ? O : A);
if(affirmativep())
{
duplastchar();
if(thirdpersp())
{ addchar((singpersp() ? 'n' : 't')); }
else if(firstpersp()) { addstring(toUstr("mme")); }
}
}
}
void FVC::conj_present_conditional()
{
this->get_cs(); /* Get Conditional Stem. */
this->add_pers_ending(); /* Add Personal Ending if needed. */
}
void FVC::conj_present_potential()
{
this->get_potstem(); /* Get Potential Stem. */
this->add_pers_ending(); /* Add Personal Ending if needed. */
}
void FVC::conj_infinitive1(void)
{
this->get1infstem();
addchar(A);
// If possessive suffix specified, then return the long form:
if(get_poss_suffix())
{ addstring(toUstr("kse")); this->add_poss_suffix(); }
}
void FVC::conj_infinitive2(void)
{ /* If no case defined, give an inessive passive (luettaessa) to user: */
if(nominativep()) { this->get_sps(); addstring(toUstr("AessA")); }
else if(inessivep())