Created
October 5, 2011 05:41
-
-
Save complex857/1263737 to your computer and use it in GitHub Desktop.
-val, -vel rag generálása szóhoz
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function addWithTermination(word) { | |
var vowels = [ | |
'a', 'á', | |
'e', 'é', | |
'i', 'í', | |
'o', 'ó', | |
'ö', 'ő', | |
'u', 'ú', | |
'ü', 'ű' | |
], | |
terminations = { | |
'val': ['a', 'ae', 'aé', 'ai', 'aí', 'á', 'ái', 'áí', 'o', 'oi', 'ó', 'u', 'ú'], | |
'vel': ['e', 'ei', 'é', 'i', 'í', 'ö', 'ő', 'ü', 'ű'] | |
}, | |
exceptions = { | |
'val': ['íj','híd','díj'], | |
'vel': [] | |
}, | |
lastCharIndex = word.length - 1, | |
lastChar = word[lastCharIndex], | |
vowelsAsString = vowels.join(''), | |
vowelsPattern = new RegExp('[' + vowelsAsString + ']', 'ig'), | |
vowelsMatch = word.match(vowelsPattern), | |
lastTwoVowels = [], | |
lastTwoVowelsAsString, termination; | |
if (exceptions.val.indexOf(word) !== -1) { | |
termination = 'val'; | |
} | |
else if (exceptions.vel.indexOf(word) !== -1) { | |
termination = 'vel'; | |
} | |
else if (vowelsMatch.length > 1) { /* Több magánhagzó van a szóban */ | |
lastTwoVowels.push(vowelsMatch[vowelsMatch.length - 2]); | |
lastTwoVowels.push(vowelsMatch[vowelsMatch.length - 1]); | |
lastTwoVowelsAsString = lastTwoVowels.join(''); | |
if (terminations.val.indexOf(lastTwoVowelsAsString) === -1 && terminations.vel.indexOf(lastTwoVowelsAsString) === -1) { /* A magánhagzó pár nem egy speciális pár */ | |
termination = terminations.val.indexOf(lastTwoVowels[1]) === -1 ? 'vel' : 'val'; | |
} | |
else { /* A magánhagzó pár egy speciális pár */ | |
termination = terminations.val.indexOf(lastTwoVowelsAsString) === -1 ? 'vel' : 'val'; | |
} | |
} | |
else if (vowelsMatch.length === 1) { /* Csak egy magánhangzó van a szóban */ | |
termination = terminations.val.indexOf(vowelsMatch[vowelsMatch.length - 1]) === -1 ? 'vel' : 'val'; | |
} | |
else { /* Ilyen szó nincs */ | |
return word; | |
} | |
if (vowels.indexOf(lastChar) !== -1) { | |
if (vowels.indexOf(lastChar) % 2 === 0) { | |
/* | |
* Az utolsó karakter magánhangzó és ha | |
* nem ékezetes, akkor ékezetessé kell tenni | |
*/ | |
word = word.substring(0, lastCharIndex) + vowels[vowels.indexOf(lastChar) + 1]; | |
} | |
} | |
else { | |
if (word[lastCharIndex - 1] !== word[lastCharIndex]) { | |
/* | |
* Az utolsó karakter mássalhangzó, így | |
* ha nem kettős mássalhangzó alapból, | |
* akkor megkell kettőzni | |
*/ | |
word += word[lastCharIndex]; | |
} | |
/* | |
* Mássalhangzóra végződés esetén mindenképp | |
* törölni kell a -val, -vel ragból a v-t | |
*/ | |
termination = termination.substring(1); | |
} | |
word += termination; | |
return word; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Csinaltam helyet a kiveteleknek. (itt most velaris i okozta dolgok vannak A magyar nyelvből kiveszett hangok)