Skip to content

feat(postagger): DictionaryProtocol 추상 인터페이스 정의 - #246

Merged
lovit merged 1 commit into
refactor-2026-postaggerfrom
feature/237
Mar 9, 2026
Merged

feat(postagger): DictionaryProtocol 추상 인터페이스 정의#246
lovit merged 1 commit into
refactor-2026-postaggerfrom
feature/237

Conversation

@lovit

@lovit lovit commented Mar 9, 2026

Copy link
Copy Markdown
Owner

관련 이슈

closes #237

변경 내용

커스텀 사전 주입을 위한 DictionaryProtocol을 정의한다.

DictionaryProtocol

class DictionaryProtocol(Protocol):
    max_length: int
    def get_pos(self, word: str) -> list[str]: ...
    def word_is_tag(self, word: str, tag: str) -> bool: ...

커스텀 사전 주입 예시

class MyMedicalDictionary:
    max_length = 10
    def get_pos(self, word: str) -> list[str]:
        return ["Noun"] if word in {"암", "세포"} else []
    def word_is_tag(self, word: str, tag: str) -> bool:
        return tag == "Noun" and word in {"암", "세포"}

matcher = EojeolTemplateMatcher(MyMedicalDictionary())

변경 범위

  • Dictionary 구현 클래스는 변경 없음 — 기존 코드 호환성 유지
  • EojeolTemplateMatcher, LRTemplateMatcher 생성자 타입 힌트를 DictionaryProtocol로 변경
  • DictionaryProtocol 공개 export 추가

🤖 Generated with Claude Code

- dictionary.py: DictionaryProtocol(Protocol) 추가
  - get_pos(), word_is_tag(), max_length 인터페이스 정의
  - 커스텀 사전 주입 예시 docstring 포함
- template.py: BaseTemplateMatcher, EojeolTemplateMatcher, LRTemplateMatcher
  dictionary 타입 힌트를 DictionaryProtocol로 변경
- __init__.py: DictionaryProtocol export 추가
- test_postagger.py: Protocol 준수 및 커스텀 사전 주입 테스트 추가

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@lovit
lovit merged commit 35787e3 into refactor-2026-postagger Mar 9, 2026
2 checks passed
@lovit
lovit deleted the feature/237 branch March 10, 2026 13:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant