feat(input): upgrade graph personalization, english morphology detection, and atomic SendInput replacement
This commit is contained in:
parent
52eef21bab
commit
cd4a452148
21 changed files with 1098 additions and 110 deletions
|
|
@ -4,12 +4,16 @@
|
|||
import { describe, expect, it } from 'vitest'
|
||||
import {
|
||||
SHARES_TERMS_MIN_SIMILARITY,
|
||||
buildQueryTerms,
|
||||
buildSequenceEdges,
|
||||
continuationsFrom,
|
||||
extractTerms,
|
||||
jaccard,
|
||||
rankRelated,
|
||||
splitSentences
|
||||
rankTwoHopGraphTargets,
|
||||
scoreCandidatePersonalization,
|
||||
splitSentences,
|
||||
stemContinuationsFrom
|
||||
} from '../src/personal-graph'
|
||||
|
||||
describe('extractTerms', () => {
|
||||
|
|
@ -136,4 +140,50 @@ describe('rankRelated', () => {
|
|||
expect(SHARES_TERMS_MIN_SIMILARITY).toBeGreaterThan(0)
|
||||
expect(SHARES_TERMS_MIN_SIMILARITY).toBeLessThan(1)
|
||||
})
|
||||
})
|
||||
|
||||
describe('stemContinuationsFrom · 2-hop 그래프 · 개인화 후보 재정렬', () => {
|
||||
it('조사가 달라도 어간 열이 일치하면 그 뒤의 이어쓰기를 추출한다', () => {
|
||||
const out = stemContinuationsFrom(
|
||||
['회의록 정리해서 내일 오전까지 공유드리겠습니다'],
|
||||
'이번 주간 회의록을 정리해서'
|
||||
)
|
||||
expect(out).toEqual(['내일 오전까지 공유드리겠습니다'])
|
||||
})
|
||||
|
||||
it('2-hop 경로(shares_terms -> follows)로 유사 문장 뒤에 실제로 썼던 후속 문장을 찾는다', () => {
|
||||
const queryTerms = buildQueryTerms([{ text: '금요일 배포 준비 끝났습니다', weight: 2 }])
|
||||
const targets = rankTwoHopGraphTargets({
|
||||
firstHopEdges: [
|
||||
{
|
||||
from: '금요일 배포 준비 완료했습니다',
|
||||
to: '스테이징 배포 점검 끝났습니다',
|
||||
kind: 'shares_terms',
|
||||
weight: 2
|
||||
}
|
||||
],
|
||||
secondHopFollowEdges: [
|
||||
{
|
||||
from: '스테이징 배포 점검 끝났습니다',
|
||||
to: '모니터링 대시보드 링크 공유드립니다',
|
||||
kind: 'follows',
|
||||
weight: 3
|
||||
}
|
||||
],
|
||||
queryTerms
|
||||
})
|
||||
expect(targets).toEqual(['모니터링 대시보드 링크 공유드립니다'])
|
||||
})
|
||||
|
||||
it('개인 그래프 힌트 및 어투와 일치하는 후보에 더 높은 개인화 점수를 준다', () => {
|
||||
const context = {
|
||||
prefix: '오늘 배포 일정 공유드립니다. ',
|
||||
followUpHints: ['모니터링 대시보드 확인 부탁드립니다'],
|
||||
relatedHints: ['릴리즈 노트 정리해서 올렸습니다']
|
||||
}
|
||||
const matchedScore = scoreCandidatePersonalization('모니터링 대시보드 확인 부탁드립니다.', context)
|
||||
const mismatchedRegisterScore = scoreCandidatePersonalization('그냥 빨리 해봐.', context)
|
||||
expect(matchedScore).toBeGreaterThan(4)
|
||||
expect(matchedScore).toBeGreaterThan(mismatchedRegisterScore)
|
||||
})
|
||||
})
|
||||
|
|
@ -51,4 +51,10 @@ describe('PersonalNgramModel', () => {
|
|||
const m = model('하나 둘 셋 넷 다섯', '하나 둘 셋 넷 다섯')
|
||||
expect(m.predict('하나 ', { maxWords: 2 })?.text).toBe('둘 셋')
|
||||
})
|
||||
|
||||
it('한국어 어절의 조사가 달라져도 어간 보조 바이그램으로 다음 어절을 예측한다', () => {
|
||||
const m = new PersonalNgramModel()
|
||||
m.addText('회의록은 내일 공유드릴게요', 3)
|
||||
expect(m.predict('이번 회의록을 ')).toMatchObject({ text: '내일 공유드릴게요', joint: 'separate' })
|
||||
})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -13,12 +13,14 @@ import {
|
|||
fixByVocabulary,
|
||||
fixKnownMisspelling,
|
||||
hasSuspiciousTypo,
|
||||
isCommonEnglishWord,
|
||||
mergeTypoCorrections,
|
||||
hangulToLatin,
|
||||
isPlausibleTypoFix,
|
||||
latinToHangul,
|
||||
parseModelTypoPairs,
|
||||
planTypoReplacement,
|
||||
rebaseTypoReplacementPlan,
|
||||
alignCorrectionToPrefix,
|
||||
typoRegionStart,
|
||||
validateModelCorrections
|
||||
|
|
@ -663,4 +665,50 @@ describe('Araso 급 한/영 자동 전환 · 합성어 · 잔류 Shift · URL
|
|||
deleteCount: 'dkssudgktpdy '.length
|
||||
})
|
||||
})
|
||||
|
||||
it('생산적 영어 접미사·접두사 파생형과 문장 첫머리의 구문 호응(to be, to the, for the, and the)을 복원한다', () => {
|
||||
expect(isCommonEnglishWord('implementation')).toBe(true)
|
||||
expect(isCommonEnglishWord('personalization')).toBe(true)
|
||||
expect(isCommonEnglishWord('unhappy')).toBe(true)
|
||||
expect(isCommonEnglishWord('restart')).toBe(true)
|
||||
expect(isCommonEnglishWord('disconnect')).toBe(true)
|
||||
expect(isCommonEnglishWord('effectively')).toBe(true)
|
||||
expect(isCommonEnglishWord('subagents')).toBe(true)
|
||||
|
||||
expect(applyAll('ㅑㅡㅔㅣ드둣ㅁ샤ㅐㅜ ')).toBe('implementation ')
|
||||
expect(applyAll('ㅔㄷㄱ내ㅜ미ㅑㅋㅁ샤ㅐㅜ ')).toBe('personalization ')
|
||||
expect(applyAll('ㅕㅜㅗ메ㅔㅛ ')).toBe('unhappy ')
|
||||
expect(applyAll('ㄱㄷㄴㅅㅁㄱㅅ ')).toBe('restart ')
|
||||
expect(applyAll('녀ㅠㅁㅎ둣ㄴ ')).toBe('subagents ')
|
||||
|
||||
// 문장 맨 앞에서도 "새 ㅠㄷ", "새 솓", "새 애 this", "랙 솓", "뭉 솓" 구문 호응을 복원한다
|
||||
expect(applyAll('새 ㅠㄷ honest ')).toBe('to be honest ')
|
||||
expect(applyAll('새 솓 point ')).toBe('to the point ')
|
||||
expect(applyAll('새 애 this ')).toBe('to do this ')
|
||||
expect(applyAll('랙 솓 team ')).toBe('for the team ')
|
||||
expect(applyAll('뭉 솓 result ')).toBe('and the result ')
|
||||
expect(applyAll('좨 ㅑㄴ there ')).toBe('who is there ')
|
||||
|
||||
// 한국어 오타 사전 확장 (괜찬아, 있읍니다, 없읍니다, 했읍니다, 금새)
|
||||
expect(fixKnownMisspelling('괜찬아요')).toBe('괜찮아요')
|
||||
expect(fixKnownMisspelling('있읍니다')).toBe('있습니다')
|
||||
expect(fixKnownMisspelling('없읍니다')).toBe('없습니다')
|
||||
expect(fixKnownMisspelling('했읍니다')).toBe('했습니다')
|
||||
expect(fixKnownMisspelling('금새')).toBe('금세')
|
||||
})
|
||||
|
||||
it('rebaseTypoReplacementPlan 은 비동기 모델 검사 중 덧붙은 짧은 꼬리 위로 교정 계획을 안전하게 리베이스한다', () => {
|
||||
const base = planTypoReplacement('ㅡㅁ가둥', [
|
||||
{ start: 0, end: 4, from: 'ㅡㅁ가둥', to: 'markdown', source: 'model' }
|
||||
])
|
||||
expect(base).not.toBeNull()
|
||||
const rebased = rebaseTypoReplacementPlan(base!, 'ㅡㅁ가둥', 'ㅡㅁ가둥 문서 ', 18)
|
||||
expect(rebased).toEqual({
|
||||
deleteCount: 'ㅡㅁ가둥 문서 '.length,
|
||||
insertText: 'markdown 문서 ',
|
||||
originalText: 'ㅡㅁ가둥 문서 ',
|
||||
corrections: base!.corrections
|
||||
})
|
||||
expect(rebaseTypoReplacementPlan(base!, 'ㅡㅁ가둥', '전혀다른문장', 18)).toBeNull()
|
||||
})
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue