Skip to content

Instantly share code, notes, and snippets.

@benelog
Created August 27, 2012 09:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benelog/3486793 to your computer and use it in GitHub Desktop.
Save benelog/3486793 to your computer and use it in GitHub Desktop.
Korean lanauge Utils
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