@@ -323,59 +323,63 @@ def just_asking(text):
323
323
324
324
# add affixes to words based on their vowel harmony
325
325
def inverse (word ,affix ):
326
+ word = lara .nlp .trim (word )
326
327
if not word :
327
328
return ''
328
329
vh = lara .nlp .vowel_harmony (word )
329
330
result = word
330
331
if affix in ('ra' ,'re' ):
332
+ if word [- 1 ].lower () in ('a' ,'e' ):
333
+ result = result [:- 1 ]+ result [- 1 ].replace ('a' ,'á' ).replace ('e' ,'é' )
331
334
if vh == 'magas' :
332
- return result + 'ra'
333
- else :
334
335
return result + 're'
335
- if affix == 't' :
336
- if lara .nlp .is_vowel (word [- 1 ]):
337
- if word [- 1 ].lower () in ('a' ,'e' ):
338
- result = result [:- 1 ]+ result [- 1 ].replace ('a' ,'á' ).replace ('e' ,'é' )
339
- return result + 't'
340
- elif vh == 'magas' :
341
- return result + 'et'
342
336
else :
343
- return result + 'at '
344
- if affix == 'k' :
337
+ return result + 'ra '
338
+ if affix in ( 'k' , 's' , 't' ) :
345
339
if lara .nlp .is_vowel (word [- 1 ]):
346
340
if word [- 1 ].lower () in ('a' ,'e' ):
347
341
result = result [:- 1 ]+ result [- 1 ].replace ('a' ,'á' ).replace ('e' ,'é' )
348
- return result + 'k'
349
- elif vh == 'magas' :
350
- return result + 'ek'
342
+ if len (result )== 2 :
343
+ if word .lower ()== "fű" :
344
+ return result [0 ]+ "üve" + affix
345
+ elif word .lower ()== "tó" :
346
+ return result [0 ]+ "ava" + affix
347
+ elif word .lower ()== "ló" :
348
+ return result [0 ]+ "ova" + affix
349
+ return result + affix
350
+ test = _inverse_only_o (result ) # exceptions
351
+ if test :
352
+ test2 = sum ([lara .nlp .is_vowel (char ) for char in result ]) # more exceptions
353
+ if test2 < 2 :
354
+ return result + test + affix
355
+ return result [:- 2 ]+ result [- 1 ]+ test + affix
356
+ if vh == 'magas' :
357
+ return result + 'e' + affix
358
+ elif vh == 'vegyes' :
359
+ return result + 'o' + affix
351
360
else :
352
- return result + 'ak'
361
+ return result + 'a' + affix
353
362
if affix == 'i' :
363
+ if len (result )== 2 :
364
+ if word .lower ()== "fű" :
365
+ return result [0 ]+ "üvi"
366
+ elif word .lower ()== "tó" :
367
+ return result [0 ]+ "avi"
368
+ elif word .lower ()== "ló" :
369
+ return result [0 ]+ "ovi"
354
370
if word [- 1 ]== 'i' :
355
371
return result
356
372
return result + 'i'
357
- if affix in ('bol' ,'ból' ,'böl' ,'ből' ):
358
- if word [- 1 ].lower () in ('a' ,'e' ):
359
- result = result [:- 1 ]+ result [- 1 ].replace ('a' ,'á' ).replace ('e' ,'é' )
360
- if vh in ('magas' ,'vegye' ):
361
- return result + 'ből'
362
- return result + 'ból'
363
- if affix in ('rol' ,'ról' ,'röl' ,'ről' ):
364
- if word [- 1 ].lower () in ('a' ,'e' ):
365
- result = result [:- 1 ]+ result [- 1 ].replace ('a' ,'á' ).replace ('e' ,'é' )
366
- if vh in ('magas' ,'vegyes' ):
367
- return result + 'ről'
368
- return result + 'ról'
369
- if affix in ('tol' ,'tól' ,'töl' ,'től' ):
373
+ if affix in ('bol' ,'ból' ,'böl' ,'ből' ,'rol' ,'ról' ,'röl' ,'ről' ,'tol' ,'tól' ,'töl' ,'től' ):
370
374
if word [- 1 ].lower () in ('a' ,'e' ):
371
375
result = result [:- 1 ]+ result [- 1 ].replace ('a' ,'á' ).replace ('e' ,'é' )
372
- if vh in ( 'magas' , 'vegyes' ) :
373
- return result + 'től '
374
- return result + 'tól '
376
+ if vh == 'magas' :
377
+ return result + affix [ 0 ] + 'ől '
378
+ return result + affix [ 0 ] + 'ól '
375
379
if affix in ('nak' ,'nek' ):
376
380
if word [- 1 ].lower () in ('a' ,'e' ):
377
381
result = result [:- 1 ]+ result [- 1 ].replace ('a' ,'á' ).replace ('e' ,'é' )
378
- if vh in ( 'magas' , 'vegyes' ) :
382
+ if vh == 'magas' :
379
383
return result + 'nek'
380
384
return result + 'nak'
381
385
if affix in ('val' ,'vel' ):
@@ -394,15 +398,33 @@ def inverse(word,affix):
394
398
else :
395
399
if len (word )> 1 :
396
400
if word [- 2 :].lower () in ('cs' ,'gy' ,'ly' ,'ny' ,'sz' ,'ty' ,'zs' ):
397
- result = result [:- 2 ]+ result [- 2 ]+ result [- 2 ]+ result [- 1 ]
401
+ if word [- 3 ].lower ()!= word [- 2 ].lower ():
402
+ result = result [:- 2 ]+ result [- 2 ]+ result [- 2 ]+ result [- 1 ]
403
+ else :
404
+ result = result [:- 2 ]+ result [- 2 ]+ result [- 1 ]
398
405
if vh == 'magas' :
399
406
return result + 'el'
400
407
else :
401
408
return result + 'al'
402
- if vh == 'magas' :
403
- return result + result [- 1 ]+ 'el'
409
+ if word [- 2 ].lower ()!= word [- 1 ].lower ():
410
+ if vh == 'magas' :
411
+ return result + result [- 1 ]+ 'el'
412
+ else :
413
+ return result + result [- 1 ]+ 'al'
404
414
else :
405
- return result + result [- 1 ]+ 'al'
415
+ if vh == 'magas' :
416
+ return result + 'el'
417
+ else :
418
+ return result + 'al'
406
419
raise ValueError ('Unsupported affix' ,affix )
407
420
408
-
421
+ def _inverse_only_o (word ):
422
+ vowel = ''
423
+ for char in word :
424
+ if lara .nlp .is_vowel (char ):
425
+ if char not in ('o' ,'O' ,'ó' ,'Ó' ,'ö' ,'Ö' ,'ő' ,'Ő' ):
426
+ return False
427
+ else :
428
+ vowel = char
429
+ return vowel .lower ()
430
+
0 commit comments