feat(desktop): typo auto-correct and context-aware sentence prediction
Some checks failed
ci / 정본·보안·린트·타입·테스트 (push) Has been cancelled
deploy-site / deploy (push) Has been cancelled
ci / 워크스페이스 빌드 검증 (push) Has been cancelled
ci / 모바일 린트·타입·Jest (push) Has been cancelled
ci / Supabase Edge Functions + Cloudflare Worker (push) Has been cancelled
ci / .NET API 서버 테스트 (push) Has been cancelled
Some checks failed
ci / 정본·보안·린트·타입·테스트 (push) Has been cancelled
deploy-site / deploy (push) Has been cancelled
ci / 워크스페이스 빌드 검증 (push) Has been cancelled
ci / 모바일 린트·타입·Jest (push) Has been cancelled
ci / Supabase Edge Functions + Cloudflare Worker (push) Has been cancelled
ci / .NET API 서버 테스트 (push) Has been cancelled
Typo auto-correct (INPUT-19) - TypoCorrectionService + core typo-correction: 2-set Korean layout mistypes both ways, always-wrong spellings, near-misses of the user's frequent words, optional model check re-validated in core; applied by backspace N + paste and cancelled on new keys or window change. Prediction quality (INPUT-20/21) - gemma models are sent raw with the user's unfinished sentence pre-filled into the model turn, so the model truly continues the text (mid-word joins and spacing exact). Other models keep the instruction prompt. - Context: text before the caret (opening lines and a fact list of names, dates, amounts outside the 400-char window), messages just sent in the same chat window (memory only, 30 min), personal-graph follow-ups and IDF-ranked related sentences with Korean stemming. - Guards: first sentence only, restated-prefix stripping (also fixes the instruction path), repeat drop, no invented dates/names/numbers (one retry), plain -다 register, no emoji unless the user uses them, search-box keywords. Fill loop mixes instruction prompts for variety. - Opt-in real-model probe: tests/integration/suggestion-quality.ollama.test.ts Suggestions now actually show up - Terminal (Claude Code): caret trust from the input line, not the whole screen (status line below the box blocked every keystroke); Korean composition counts as typing at the end; a grey placeholder filling the empty box at once is not user text. - Chrome: UIA focus flicker while typing no longer resets "edited". - KakaoTalk/RichEdit: trailing paragraph mark ignored for edit position and stripped so accepted text keeps its separating space. - While the overlay is visible the suggestion shortcuts are captured so Ctrl+Alt+Enter no longer also types a newline; released when hidden. - nut-js preloaded after boot (first accept waited 4.8 s).
This commit is contained in:
parent
5ca3709b32
commit
3cac14f668
56 changed files with 4700 additions and 258 deletions
|
|
@ -56,6 +56,11 @@ export interface GraphContext {
|
|||
continuations: string[]
|
||||
/** 관계로 끌어온 관련 문장 (follows 우선, 그다음 용어 공유) */
|
||||
related: string[]
|
||||
/**
|
||||
* 직전 완결 문장(또는 그와 거의 같은 문장) 뒤에 사용자가 실제로 이어 쓴 문장 — follows 엣지.
|
||||
* "다음 문장" 을 고를 때 가장 강한 근거다. 없으면 생략될 수 있다(호환).
|
||||
*/
|
||||
followUps?: string[]
|
||||
}
|
||||
|
||||
/** 용어 추출에서 제외할 불용어 (한/영 최소 집합). */
|
||||
|
|
@ -131,13 +136,39 @@ export function tokenizeTerms(text: string): string[] {
|
|||
.flatMap(segmentUnspacedToken)
|
||||
}
|
||||
|
||||
/**
|
||||
* 한국어 어절 끝의 조사·흔한 '하다' 활용을 떼어 낸 어간.
|
||||
*
|
||||
* 왜: "회의에서" 와 "회의는" 이 다른 용어로 잡히면 같은 주제의 문장끼리 겹치는 용어가 거의 없어
|
||||
* 그래프가 관련 문장을 못 찾는다(한국어는 거의 모든 명사에 조사가 붙는다). 남는 어간이 2자 미만이면
|
||||
* 떼지 않는다 — "회의"(의), "결과"(과) 같은 단어 끝 글자를 조사로 오인하지 않게.
|
||||
*/
|
||||
const KOREAN_SUFFIXES: readonly string[] = [
|
||||
'했습니다', '하겠습니다', '드립니다', '합니다', '했어요', '해요', '했다', '하는', '하고', '해서', '하면', '하기',
|
||||
'에서는', '에서도', '에서의', '에게서', '으로부터', '로부터', '으로는', '으로도', '이라는', '이라고', '에게는',
|
||||
'한테서', '에서', '에게', '한테', '으로', '까지', '부터', '처럼', '보다', '만큼', '이나', '이랑', '과는', '와는',
|
||||
'에는', '에도', '들은', '들이', '들을', '들의',
|
||||
'은', '는', '이', '가', '을', '를', '에', '의', '도', '로', '만', '와', '과', '랑', '들', '한', '할'
|
||||
].slice().sort((a, b) => b.length - a.length)
|
||||
|
||||
const HANGUL_WORD = /^[가-힣]+$/u
|
||||
|
||||
export function stemTerm(token: string): string {
|
||||
if (!HANGUL_WORD.test(token)) return token
|
||||
for (const suffix of KOREAN_SUFFIXES) {
|
||||
if (token.endsWith(suffix) && token.length - suffix.length >= 2) return token.slice(0, -suffix.length)
|
||||
}
|
||||
return token
|
||||
}
|
||||
|
||||
/**
|
||||
* 문장에서 비교용 용어를 뽑는다.
|
||||
*
|
||||
* 토큰화 → 불용어/짧은 토큰 제거 → 빈도 순.
|
||||
* 토큰화 → 한국어 어간화 → 불용어/짧은 토큰 제거 → 빈도 순.
|
||||
*/
|
||||
export function extractTerms(text: string, limit = 8): string[] {
|
||||
const tokens = tokenizeTerms(text)
|
||||
.map(stemTerm)
|
||||
.filter((token) => token.length >= MIN_TERM_CHARS)
|
||||
.filter((token) => !STOPWORDS.has(token))
|
||||
|
||||
|
|
@ -260,4 +291,102 @@ export function rankRelated(
|
|||
if (out.length >= limit) break
|
||||
}
|
||||
return out
|
||||
}
|
||||
}
|
||||
// ============================================================
|
||||
// 관련 문장 점수 (IDF 가중 용어 겹침)
|
||||
// ============================================================
|
||||
|
||||
/** 관련 문장 후보 노드 — 저장소에서 읽은 그대로(용어는 어간화 전일 수 있다). */
|
||||
export interface GraphNodeSample {
|
||||
text: string
|
||||
terms: readonly string[]
|
||||
count: number
|
||||
lastUsedAt: number | null
|
||||
appName: string | null
|
||||
}
|
||||
|
||||
export interface RelatedNodeQuery {
|
||||
/** 질의 용어 → 가중치 (지금 문장 용어를 앞 문맥보다 무겁게) */
|
||||
terms: ReadonlyMap<string, number>
|
||||
appName?: string | null
|
||||
now?: number
|
||||
/** 이미 접두에 들어 있는 문장 등 제외할 텍스트 */
|
||||
exclude?: (text: string) => boolean
|
||||
}
|
||||
|
||||
export interface ScoredNode {
|
||||
text: string
|
||||
score: number
|
||||
sharedTerms: number
|
||||
}
|
||||
|
||||
/**
|
||||
* 질의 용어와 노드 용어의 겹침을 IDF 로 가중해 순위를 매긴다.
|
||||
*
|
||||
* 자카드는 긴 문장일수록 점수가 희석되고, "합니다" 같은 흔한 어절과 "배포" 같은 주제어를 같게
|
||||
* 센다. 여기서는 훑은 노드 집합에서 드문 용어일수록 무겁게, 노드 길이는 제곱근으로만 나눈다.
|
||||
* 같은 앱에서 쓴 문장, 최근 문장, 자주 쓴 문장에 가산점을 준다.
|
||||
*/
|
||||
export function scoreRelatedNodes(
|
||||
query: RelatedNodeQuery,
|
||||
nodes: readonly GraphNodeSample[],
|
||||
limit = 6
|
||||
): ScoredNode[] {
|
||||
if (query.terms.size === 0 || nodes.length === 0) return []
|
||||
const now = query.now ?? Date.now()
|
||||
const nodeTerms = nodes.map((node) => new Set(node.terms.map(stemTerm)))
|
||||
|
||||
const documentFrequency = new Map<string, number>()
|
||||
for (const terms of nodeTerms) {
|
||||
for (const term of terms) documentFrequency.set(term, (documentFrequency.get(term) ?? 0) + 1)
|
||||
}
|
||||
const total = nodes.length
|
||||
const idf = (term: string): number => Math.log(1 + total / (1 + (documentFrequency.get(term) ?? 0)))
|
||||
const requestedApp = query.appName?.trim().toLowerCase() || null
|
||||
|
||||
const scored: ScoredNode[] = []
|
||||
nodes.forEach((node, index) => {
|
||||
if (query.exclude?.(node.text)) return
|
||||
const terms = nodeTerms[index]
|
||||
if (terms.size === 0) return
|
||||
let overlap = 0
|
||||
let shared = 0
|
||||
for (const [term, weight] of query.terms) {
|
||||
if (!terms.has(term)) continue
|
||||
overlap += weight * idf(term)
|
||||
shared += 1
|
||||
}
|
||||
if (shared === 0) return
|
||||
const recency = node.lastUsedAt ? Math.max(0, 1 - (now - node.lastUsedAt) / (14 * 86400000)) : 0
|
||||
const sameApp = requestedApp !== null && node.appName?.trim().toLowerCase() === requestedApp
|
||||
const score =
|
||||
(overlap / Math.sqrt(terms.size)) * (sameApp ? 1.3 : 1) +
|
||||
recency * 0.3 +
|
||||
Math.log2(1 + Math.max(0, node.count)) * 0.1
|
||||
scored.push({ text: node.text, score, sharedTerms: shared })
|
||||
})
|
||||
|
||||
scored.sort((a, b) => b.score - a.score || b.sharedTerms - a.sharedTerms)
|
||||
const out: ScoredNode[] = []
|
||||
for (const item of scored) {
|
||||
if (out.some((existing) => existing.text === item.text)) continue
|
||||
out.push(item)
|
||||
if (out.length >= limit) break
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
/**
|
||||
* 질의 용어 가중치 — 지금 쓰는 문장 2, 직전 문장 1.5, 앞 문맥 1.
|
||||
* 같은 용어가 여러 곳에 나오면 가장 큰 가중치를 쓴다.
|
||||
*/
|
||||
export function buildQueryTerms(parts: ReadonlyArray<{ text: string; weight: number }>): Map<string, number> {
|
||||
const terms = new Map<string, number>()
|
||||
for (const part of parts) {
|
||||
if (!part.text) continue
|
||||
for (const term of extractTerms(part.text, 12)) {
|
||||
terms.set(term, Math.max(terms.get(term) ?? 0, part.weight))
|
||||
}
|
||||
}
|
||||
return terms
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue