Class KoreanTextMatcher

Object
io.github.bangjunyoung.KoreanTextMatcher

public final class KoreanTextMatcher extends Object
한글 음절 근사 매칭 클래스.

이 클래스는 문자 수준에서의 음절 근사 매칭 API를 포함하고 있는 KoreanCharApproxMatcher의 상위 서비스로 문자열 수준에서의 음절 근사 매칭 API를 포함하고 있다.

한글 음절 근사 매칭은 두 개의 한글 음절을 비교할 때 음절을 이루는 자모의 일부만 일치해도 두 음절이 같은 것으로 간주하는 매칭 방법이다. 예를 들어 일반적인 문자 비교에서 '밝''ㅂ', '바', '발'과 다른 문자로 간주되지만 음절 근사 매칭에서는 '밝''ㅂ', '바', '발'이 모두 부합하는 것으로 간주한다.

단, 여기서 주의할 점은 자모의 개수가 다른 두 음절간 비교시 교환성이 성립하지 않는다는 것이다. 예를 들어 '발''밝'에 부합하지만 '밝''발'에 부합하지 않는다. 즉, 자모의 개수가 더 많은 음절에 대해 자모의 개수가 더 적은 음절을 비교하는 쪽으로 매칭이 이루어져야 한다는 뜻이다.

매칭에 사용할 자모로 Unicode Hangul Jamo와 Hangul Compatibility Jamo를 모두 지원한다.

  • Constructor Details

    • KoreanTextMatcher

      public KoreanTextMatcher(String pattern)
      KoreanTextMatcher 클래스의 새 인스턴스를 초기화한다. 정규식 앵커 ^$를 사용하여 pattern의 위치를 검색 대상 문자열의 시작과 끝으로 한정할 수 있다.
      Parameters:
      pattern - 검색할 패턴
      Throws:
      IllegalArgumentException - patternnull일 때.
  • Method Details

    • match

      public KoreanTextMatch match(String text)
      주어진 text에 대해 KoreanTextMatcher(String)에서 지정해 둔 pattern의 첫번째 출현을 찾는다. text 내 검색 시작 위치를 지정하려면 match(String, int)를 사용한다.
      Parameters:
      text - 검색 대상 문자열
      Returns:
      검색 결과를 담은 KoreanTextMatch 인스턴스. KoreanTextMatch.success()true일 때만 유효하다. 검색이 실패하면 KoreanTextMatch.EMPTY를 리턴한다.
      Throws:
      IllegalArgumentException - textnull일 때.
    • match

      public KoreanTextMatch match(String text, int startIndex)
      주어진 text에 대해 KoreanTextMatcher(String)에서 지정해 둔 pattern의 첫번째 출현을 찾는다.
      Parameters:
      text - 검색 대상 문자열
      startIndex - 검색을 시작할 text 내 위치
      Returns:
      검색 결과를 담은 KoreanTextMatch 인스턴스. KoreanTextMatch.success()true일 때만 유효하다. 검색이 실패하면 KoreanTextMatch.EMPTY를 리턴한다.
      Throws:
      IllegalArgumentException - textnull일 때, 또는 startIndex0보다 작거나 text.length()보다 클 때.
    • matches

      public Iterable<KoreanTextMatch> matches(String text)
      주어진 text에 대해 KoreanTextMatcher(String)에서 지정해 둔 pattern의 모든 출현을 찾는다. text 내 검색 시작 위치를 지정하려면 matches(String, int)를 사용한다.
      Parameters:
      text - 검색 대상 문자열
      Returns:
      검색 결과를 담은 Iterable<KoreanTextMatch> 인스턴스. 찾은 것이 없으면 빈 리스트를 리턴한다.
      Throws:
      IllegalArgumentException - textnull일 때.
    • matches

      public Iterable<KoreanTextMatch> matches(String text, int startIndex)
      주어진 text에 대해 KoreanTextMatcher(String)에서 지정해 둔 pattern의 모든 출현을 찾는다.
      Parameters:
      text - 검색 대상 문자열
      startIndex - 검색을 시작할 text 내 위치
      Returns:
      검색 결과를 담은 Iterable<KoreanTextMatch> 인스턴스.
      Throws:
      IllegalArgumentException - textnull일 때, 또는 startIndex0보다 작거나 text.length()보다 클 때.
    • isMatch

      public static boolean isMatch(String text, String pattern)
      주어진 text 내에 주어진 pattern이 존재하는지 여부를 조사한다. 정규식 앵커 ^$를 사용하여 pattern의 위치를 검색 대상 문자열의 시작과 끝으로 한정할 수 있다.
      Parameters:
      text - 검색 대상 문자열
      pattern - 검색할 패턴
      Returns:
      text 내에 pattern이 존재하면 true, 그렇지 않으면 false.
      Throws:
      IllegalArgumentException - text 또는 patternnull일 때.
    • match

      public static KoreanTextMatch match(String text, String pattern)
      주어진 text 내에서 주어진 pattern의 첫번째 출현을 찾는다. 모든 출현을 찾으려면 matches(String, String)를 사용한다. 정규식 앵커 ^$를 사용하여 pattern의 위치를 검색 대상 문자열의 시작과 끝으로 한정할 수 있다.
      Parameters:
      text - 검색 대상 문자열
      pattern - 검색할 패턴
      Returns:
      검색 결과를 담은 KoreanTextMatch 인스턴스. KoreanTextMatch.success()true일 때만 유효하다. 검색이 실패하면 KoreanTextMatch.EMPTY를 리턴한다.
      Throws:
      IllegalArgumentException - text 또는 patternnull일 때.
    • matches

      public static Iterable<KoreanTextMatch> matches(String text, String pattern)
      주어진 text 내에서 주어진 pattern의 모든 출현을 찾는다. 첫번째 출현만 찾으려면 match(String, String)를 사용한다. 정규식 앵커 ^$를 사용하여 pattern의 위치를 검색 대상 문자열의 시작과 끝으로 한정할 수 있다.
      Parameters:
      text - 검색 대상 문자열
      pattern - 검색할 패턴
      Returns:
      검색 결과를 담은 Iterable<KoreanTextMatch> 인스턴스.
      Throws:
      IllegalArgumentException - text 또는 patternnull일 때.