Created
August 27, 2012 09:01
-
-
Save benelog/3486793 to your computer and use it in GitHub Desktop.
Korean lanauge Utils
This file contains 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
public class InitialConsonantExtractor { | |
private static final char[] INITIAL_CONSONANT = | |
{'ㄱ', 'ㄲ', 'ㄴ', 'ㄷ', 'ㄸ', 'ㄹ', 'ㅁ', 'ㅂ', 'ㅃ', 'ㅅ', 'ㅆ', 'ㅇ', 'ㅈ', 'ㅉ', 'ㅊ', 'ㅋ', 'ㅌ', 'ㅍ', 'ㅎ'}; | |
public static final int NUMBER_OF_FINAL_CONSONANT = 28; | |
public static final int NUMBER_OF_VOWEL = 21; | |
public static boolean isKorean(char ch) { | |
return (ch >= '가' && ch <= '힣'); | |
} | |
public static char extract(String word) { | |
char initialCharacter = word.charAt(0); | |
if (isKorean(initialCharacter)) { | |
int indexOfFirstConsonant = ((initialCharacter - '가') / (NUMBER_OF_VOWEL * NUMBER_OF_FINAL_CONSONANT)); | |
return INITIAL_CONSONANT[indexOfFirstConsonant]; | |
} | |
return initialCharacter; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment