Skip to content

feat: add POS tag sync workflow with C++ upstream (closes #40) - #46

Merged
kkweon merged 2 commits into
mainfrom
feat/pos-tag-sync-workflow
Aug 12, 2026
Merged

feat: add POS tag sync workflow with C++ upstream (closes #40)#46
kkweon merged 2 commits into
mainfrom
feat/pos-tag-sync-workflow

Conversation

@mrchypark

Copy link
Copy Markdown
Member

POS Tag Sync Workflow Implementation

C++ Kiwi 원본 저장소의 POS 태그 정의와 Go 코드를 자동으로 동기화하는 워크플로우를 구현합니다.

Changes

1. 추출 스크립트

  • 파일: scripts/extract_postags.py
  • 기술: tree-sitter C++ 파서
  • 기능: C++ Types.h에서 POSTag enum 자동 추출, Go 코드 생성

2. GitHub Actions 워크플로우

  • 파일: .github/workflows/sync-postypes.yaml
  • 트리거: 주간 자동 실행 (매주 월요일 9시 UTC) + 수동 실행
  • 기능:
    • 최신 Kiwi 릴리즈 감지
    • POS 태그 추출 및 비교
    • 변경사항 있을 시 자동 PR 생성

3. Makefile 타겟

make sync-postypes    # 태그 추출 및 비교
make check-postypes   # 동기화 상태 확인 (CI용)

4. postype.go 업데이트

  • C++ v0.23.2 기준으로 태그 동기화
  • 새 태그 추가: POS_P, POS_PV, POS_PA, POS_PV_I, POS_PA_I
  • 불필요 태그 제거: POS_V, POS_VV_R, POS_VA_R, POS_VX_R, POS_XSA_R
  • 이름 변경: POS_USER_0POS_USER0

Verification

  • 워크플로우 실행 성공 확인
  • PR 자동 생성 테스트 완료
  • .venv 파일 제외 확인

Closes #40

@mrchypark
mrchypark requested a review from kkweon August 11, 2026 23:08
@mrchypark

Copy link
Copy Markdown
Member Author

@kkweon 넵 부탁드리겠습니다!

kkweon added 2 commits August 11, 2026 17:30
The generated postype.go did not compile: POS_P, POS_PV and POS_PA were
all emitted as "P", which produced duplicate cases in the isValid switch.

Rewrite the generator to evaluate POSTag enum initializers the way the
C++ compiler does and to transcribe tagToString/tagRToString, instead of
relying on hardcoded special cases and an "ends with i" heuristic. That
corrects three mappings that never matched upstream:

  - pa = p + 1 == max, so tagToString returns "@", not "P"
  - pvi/pai fall through the irregular switch default, so both are "@",
    not "PV-I"/"PA-I"
  - the -R variants are reachable only through tagRToString, which is
    what kiwi_res_tag calls; dropping them made ParsePOSType fail on
    ordinary sentences such as "편지를 받았다", re-introducing #39

Deduplicate the isValid switch by value so aliases can no longer break
the build, keep POS_USER_0..4 as deprecated aliases so the rename does
not break downstream code, and add a regression test covering both the
-R tags and a regular conjugation through Analyze.

Verify the generated code inside the sync workflow: pull requests opened
with GITHUB_TOKEN do not trigger CI, so nothing was checking it.
ParsePOSType is the Go counterpart of upstream's toPOSTag, so derive the
accepted strings from that function instead of inventing them.

The previous commit mapped POS_PA, POS_PV_I and POS_PA_I to "@". That
string is not something upstream ever converts to or from: tagToString
guards its table with assert(t < POSTag::max) and pa == max, so reading
"@" only happens in an NDEBUG build past the assertion, and toPOSTag has
no entry for "@" at all. Drop the three constants rather than exposing a
sentinel as a tag.

Restore POS_V and add the remaining strings toPOSTag accepts but Kiwi
never emits: A (POSTag::p), NF, NV, NA and UNK (POSTag::unknown), and ^
(POSTag::unknown, spelled POS_CARET). POS_V had been removed on the
grounds that Kiwi never returns "V", which is true of tagToString but
irrelevant to a parser -- toPOSTag accepts it.

kiwigo now accepts exactly toPOSTag's 75 strings plus "P", which
tagToString can return for POSTag::p even though toPOSTag does not
accept it. Emit the two groups as separate blocks so the generated
alignment matches gofmt.
@kkweon
kkweon force-pushed the feat/pos-tag-sync-workflow branch from 49deb8b to 6c5f289 Compare August 12, 2026 00:33

@kkweon kkweon left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

원래 커밋은 main 에 이미 반영되어 있어서(0ff8d45), 중복을 제거하고 이 브랜치에는 후속 수정만 남겼습니다.

수정 내용:

  • 생성기가 POSTag enum 값을 직접 평가하고 tagToString / tagRToString / toPOSTag 를 그대로 전사하도록 변경
  • isValid 를 값 기준으로 중복 제거 (duplicate case 빌드 실패 해소)
  • -R 태그 복구 (#39 재발 방지) + 회귀 테스트 추가
  • 동기화 워크플로에 빌드/테스트 게이트 추가 — GITHUB_TOKEN 으로 생성된 PR 은 CI 가 돌지 않아 검증 공백이 있었습니다

CI 통과했습니다. 머지하면 현재 실패 중인 main 도 함께 복구됩니다.

@kkweon
kkweon merged commit ba165a3 into main Aug 12, 2026
2 checks passed
@kkweon
kkweon deleted the feat/pos-tag-sync-workflow branch August 12, 2026 00:40
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.

C++ Kiwi POS 태그 정의와 Go 코드 자동 동기화 방안 제안 ✨

2 participants