fix(suggestion): place overlay in DIPs, size it to content, and harden suggestion sessions
This commit is contained in:
parent
75e053d72f
commit
9e5b94ced2
18 changed files with 2178 additions and 558 deletions
|
|
@ -8,8 +8,8 @@
|
|||
//
|
||||
// 전부 순수 함수로 두어 LLM/DB 없이 검증 가능하게 한다.
|
||||
|
||||
import { countWords } from './input-intelligence'
|
||||
import type { PhraseSource } from './input-intelligence'
|
||||
import { countLexicalWords, getWordSegmenter } from './text-segmentation'
|
||||
|
||||
// 렌더러/프리로드도 같은 계약을 쓴다 (main 모듈을 import 할 수 없다).
|
||||
export type { PhraseSource }
|
||||
|
|
@ -104,18 +104,6 @@ const TERM_SEPARATOR = /[^\p{L}\p{N}\p{M}]+/u
|
|||
/** 띄어쓰기 없이 쓰는 문자 체계 — 경계 분리만으로는 문장 전체가 한 토큰이 된다. */
|
||||
const UNSPACED_SCRIPT = /[\p{Script=Thai}\p{Script=Lao}\p{Script=Khmer}\p{Script=Myanmar}]/u
|
||||
|
||||
let wordSegmenter: Intl.Segmenter | null | undefined
|
||||
|
||||
/** 런타임이 지원할 때만 단어 분할기를 만든다 (Hermes 등에는 없을 수 있다). */
|
||||
function getWordSegmenter(): Intl.Segmenter | null {
|
||||
if (wordSegmenter !== undefined) return wordSegmenter
|
||||
wordSegmenter =
|
||||
typeof Intl !== 'undefined' && typeof Intl.Segmenter === 'function'
|
||||
? new Intl.Segmenter(undefined, { granularity: 'word' })
|
||||
: null
|
||||
return wordSegmenter
|
||||
}
|
||||
|
||||
/** 띄어쓰기 없는 문자 체계의 토큰을 사전 기반 단어로 나눈다. 분할기가 없으면 그대로 둔다. */
|
||||
function segmentUnspacedToken(token: string): string[] {
|
||||
if (!UNSPACED_SCRIPT.test(token)) return [token]
|
||||
|
|
@ -164,12 +152,17 @@ export function extractTerms(text: string, limit = 8): string[] {
|
|||
.map(([token]) => token)
|
||||
}
|
||||
|
||||
/** 문장 단위로 쪼갠다 (종결 부호 + 개행). 2단어 이상만 남긴다. */
|
||||
/**
|
||||
* 문장 단위로 쪼갠다 (종결 부호 + 개행). 2단어 이상만 남긴다.
|
||||
*
|
||||
* 단어 수는 countLexicalWords 로 센다 — 공백으로만 세면 띄어쓰기 없는 중국어·일본어·태국어
|
||||
* 문장이 모두 1단어가 되어 그 언어 사용자의 문장이 하나도 학습되지 않는다.
|
||||
*/
|
||||
export function splitSentences(text: string): string[] {
|
||||
return text
|
||||
.split(/[.!?。!?…\n]+/u)
|
||||
.map((segment) => segment.replace(/\s+/gu, ' ').trim())
|
||||
.filter((segment) => segment.length >= 4 && countWords(segment) >= 2)
|
||||
.filter((segment) => segment.length >= 4 && countLexicalWords(segment) >= 2)
|
||||
}
|
||||
|
||||
/** 한 텍스트 안에서 인접한 문장 쌍 (follows 엣지의 근거). */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue