/**
*
* 한글문서 판별
*
*/
public class KorString {
//한글 유니코드 범위 (0xAC00~0xD7A3)
private boolean isKoreanChar(char ch) {
if ((ch < 0xAC00) || (ch > 0xD7A3))
return false;
return true;
}
public boolean isKorean(String str) {
for(char ch: str.toCharArray()) {
if(isKoreanChar(ch))
return true;
}
return false;
}
public static void main(String[] args) {
KorString check = new KorString();
/**
* 테스트
*/
System.out.println(check.isKorean("한글입니다.")); // true
System.out.println(check.isKorean("abcdef")); // false
System.out.println(check.isKorean("abcd한글ef123.")); //true
/**
* 장문 테스트
*/
StringBuffer sb = new StringBuffer();
sb.append("love /lv/ (loves, loving, loved)");
sb.append("1. VERB");
sb.append("If you love someone, you feel romantically or sexually attracted to them, and they are very important to you.");
sb.append(" Oh, Amy, I love you.");
sb.append(" We love each other. We want to spend our lives together.");
sb.append("2. N-UNCOUNT");
sb.append("Love is a very strong feeling of affection towards someone who you are romantically or sexually attracted to.");
sb.append(" Our love for each other has been increased by what we’ve been through together.");
sb.append(" a old fashioned love story.");
sb.append(" an album of love songs.");
sb.append("3. VERB");
sb.append("You say that you love someone when their happiness is very important to you, so that you behave in a kind and caring way towards them.");
sb.append(" You’ll never love anyone the way you love your baby.");
sb.append("4. N-UNCOUNT");
sb.append("Love is the feeling that a person’s happiness is very important to you, and the way you show this feeling in your behaviour towards them.");
sb.append(" My love for all my children is unconditional.");
sb.append(" She’s got a great capacity for love.");
sb.append("5. VERB");
sb.append("If you love something, you like it very much.");
sb.append(" We loved the food so much, especially the fish dishes.");
sb.append(" I loved reading.");
sb.append(" one of these people that loves to be in the outdoors.");
sb.append(" I love it when I hear you laugh.");
sb.append("6. VERB");
sb.append("You can say that you love something when you consider that it is important and want to protect or support it.");
sb.append(" I love my country as you love yours.");
sb.append("7. N-UNCOUNT : oft N of n");
sb.append("Love is a strong liking for something, or a belief that it is important.");
sb.append(" The French are known for their love of their language.");
sb.append("8. N-COUNT : usu with poss");
sb.append("Your love is someone or something that you love.");
sb.append(" `She is the love of my life,’ he said.");
sb.append(" Music’s one of my great loves.");
sb.append("9. VERB");
sb.append("If you would love to have or do something, you very much want to have it or do it.");
sb.append(" I would love to play for England again.");
sb.append(" I would love a hot bath and clean clothes.");
sb.append(" His wife would love him to give up his job.");
sb.append("10. N-VOC");
sb.append("Some people use love as an affectionate way of addressing someone.[ BRIT, INFORMAL ]");
sb.append(" Well, I’ll take your word for it then, love.");
sb.append(" Don’t cry, my love.");
sb.append(" dear, darling ");
sb.append("11. NUM");
sb.append("In tennis, love is a score of zero.");
sb.append(" He beat Thomas Muster of Austria three sets to love.");
sb.append("12. CONVENTION");
sb.append("You can use expressions such as `love’, `love from’, and `all my love’, followed by your name, as an informal way of ending a letter to a friend or relation.");
sb.append(" with love from Grandma and Grandpa.");
sb.append("13. N-UNCOUNT : poss N");
sb.append("If you send someone your love, you ask another person, who will soon be speaking or writing to them, to tell them that you are thinking about them with affection.");
sb.append(" Please give her my love.");
sb.append("14. see also -loved, loving, free love, peace-loving, tug-of-love");
sb.append("15. PHRASE : V inflects, oft PHR with n");
sb.append("If you fall in love with someone, you start to be in love with them.");
sb.append(" I fell in love with him because of his kind nature.");
sb.append(" We fell madly in love.");
sb.append("16. PHRASE : V inflects, usu PHR with n");
sb.append("If you fall in love with something, you start to like it very much.");
sb.append(" Working with Ford closely, I fell in love with the cinema.");
sb.append("17. PHRASE : V inflects, oft PHR with n");
sb.append("If you are in love with someone, you feel romantically or sexually attracted to them, and they are very important to you.");
sb.append(" Laura had never before been in love.");
sb.append(" I’ve never really been in love with anyone.");
sb.append(" We were madly in love for about two years.");
sb.append("18. PHRASE : V inflects, usu PHR with n");
sb.append("If you are in love with something, you like it very much.");
sb.append(" He had always been in love with the enchanted landscape of the West.");
sb.append("19. PHRASE : V inflects, oft pl-n PHR, PHR to/with n");
sb.append("When two people make love, they have sex.");
sb.append(" Have you ever made love to a girl before?.");
// TickObject tick = new TickObject(); // 시간측정
// tick.start();
System.out.println(check.isKorean(sb.toString())); // false
// tick.printlab(); // responsed time : 0 ms. mem: 245,232 (alloc: 245,232 free: 1,786,384) // 0초걸렸어;
}
}
요렇게 영어로 된문장은 아예접근을 못하게 하는것도 방법인것 같네요~;
(영어로된 사이트에 들어가서 한글이 없으면 익스플로어 닫는것처럼...^^;)
밥먹고 소화시키면서 해봤습니다.
(단점이라면 한글유니코드 안에 들어오는 스펨글<중국, 일본 타이완> 은 못막네요;^^;)
게시판에 성격이안맞으면 삭제해주세요~