Minor improvements on automata for Korean 3set-like IMEs

This commit is contained in:
minjaesong
2021-11-16 09:29:58 +09:00
parent 9344faa878
commit bbb7a4d7be
4 changed files with 49 additions and 29 deletions

View File

@@ -369,6 +369,8 @@ let bufAssemble = (normalise) => {
else
return states.buf.join('')
}
let isBufferEmpty = (buf) => buf[0] === undefined && buf[1] === undefined && buf[2] === undefined
let isBufferNotEmpty = (buf) => buf[0] !== undefined || buf[1] !== undefined || buf[2] !== undefined
let bufDebugStringify = (buf) => [0,1,2].map(i => (buf[i] == undefined) ? "·" : `\\u${buf[i].codePointAt(0).toString(16).toUpperCase()}`).join(' ')
return Object.freeze({"n":"세벌식 3-90","v":"one","c":"CuriousTo\uA75Bvald","m":"rewrite",
"t":states.keylayouts.map(it => [it[0],it[1]]),
@@ -413,22 +415,24 @@ return Object.freeze({"n":"세벌식 3-90","v":"one","c":"CuriousTo\uA75Bvald","
else if (2 == bufIndex && "\u11B8" == states.buf[2] && isJongseongDigraphB(s)) {
states.buf[2] = jongseongDigraphsB[s]
}
// key inputs that bufIndex collides (end compose and accept incoming char as a new char state)
// sending out assembled syllable and accepting new hangul character
else if (states.buf[bufIndex] !== undefined) {
let oldstr = bufAssemble(1)
reset()
states.buf[bufIndex] = s
// console.log(`sending bufout: 1,${oldstr} ${bufDebugStringify(states.buf)}`)
return ["1", oldstr + bufAssemble()]
return ["1", oldstr + bufAssemble(1)]
}
else {
let bufferEmpty = (!states.buf[0] && !states.buf[1] && !states.buf[2])
let bufferEmpty = isBufferEmpty(states.buf)
states.buf[bufIndex] = s
// head of the word after the non-hangul
if (bufferEmpty) {
// console.log(`assem0: ${bufDebugStringify(states.buf)} -> 0,${bufAssemble()}`)
return ["0", bufAssemble()]
return ["0", bufAssemble(1)]
}
// not head of the word
else {
// console.log(`assem1: ${bufDebugStringify(states.buf)} -> 1,${bufAssemble()}`)
return ["1", bufAssemble()]
@@ -436,14 +440,16 @@ return Object.freeze({"n":"세벌식 3-90","v":"one","c":"CuriousTo\uA75Bvald","
}
// console.log(`assem-digraph: ${bufDebugStringify(states.buf)} -> 1,${bufAssemble()}`)
return ["1", bufAssemble()]
return ["1", bufAssemble(1)]
}
else if (states.buf[0]) {
// sending out assembled syllable and accepting new non-hangul character
else if (isBufferNotEmpty(states.buf)) {
let oldstr = bufAssemble(1)
reset()
// console.log(`sending1 out: 1,${oldstr}${s}`)
return ["1", oldstr + s]
}
// non-hangul
else {
// console.log(`sending0 out: 0,${s}`)
return ["0", s]
@@ -469,13 +475,13 @@ return Object.freeze({"n":"세벌식 3-90","v":"one","c":"CuriousTo\uA75Bvald","
if (states.buf.length == 0) reset()
// let newbufstr = bufDebugStringify(states.buf)
// console.log(`popping assembly: ${oldbufstr} -> ${newbufstr}`)
// console.log(`popping assembly: ${oldbufstr} -> 1,${newbufstr}`)
return bufAssemble()
return bufAssemble(1)
},
"end":()=>{
// console.log(`end composing`)
let ret = bufAssemble()
let ret = bufAssemble(1)
reset()
return ret
},

View File

@@ -73,7 +73,7 @@ let states = {"keylayouts":[[""],[undefined],
[":","\\"],
["\u1107","4"],
["\u1110",'·'],
["\u1169","?"],
["\u1169","!"],
[undefined],
[undefined],
[undefined],
@@ -369,6 +369,8 @@ let bufAssemble = (normalise) => {
else
return states.buf.join('')
}
let isBufferEmpty = (buf) => buf[0] === undefined && buf[1] === undefined && buf[2] === undefined
let isBufferNotEmpty = (buf) => buf[0] !== undefined || buf[1] !== undefined || buf[2] !== undefined
let bufDebugStringify = (buf) => [0,1,2].map(i => (buf[i] == undefined) ? "·" : `\\u${buf[i].codePointAt(0).toString(16).toUpperCase()}`).join(' ')
return Object.freeze({"n":"세벌식 공자판","v":"one","c":"CuriousTo\uA75Bvald","m":"rewrite",
"t":states.keylayouts.map(it => [it[0],it[1]]),
@@ -413,22 +415,24 @@ return Object.freeze({"n":"세벌식 공자판","v":"one","c":"CuriousTo\uA75Bva
else if (2 == bufIndex && "\u11B8" == states.buf[2] && isJongseongDigraphB(s)) {
states.buf[2] = jongseongDigraphsB[s]
}
// key inputs that bufIndex collides (end compose and accept incoming char as a new char state)
// sending out assembled syllable and accepting new hangul character
else if (states.buf[bufIndex] !== undefined) {
let oldstr = bufAssemble(1)
reset()
states.buf[bufIndex] = s
// console.log(`sending bufout: 1,${oldstr} ${bufDebugStringify(states.buf)}`)
return ["1", oldstr + bufAssemble()]
return ["1", oldstr + bufAssemble(1)]
}
else {
let bufferEmpty = (!states.buf[0] && !states.buf[1] && !states.buf[2])
let bufferEmpty = isBufferEmpty(states.buf)
states.buf[bufIndex] = s
// head of the word after the non-hangul
if (bufferEmpty) {
// console.log(`assem0: ${bufDebugStringify(states.buf)} -> 0,${bufAssemble()}`)
return ["0", bufAssemble()]
return ["0", bufAssemble(1)]
}
// not head of the word
else {
// console.log(`assem1: ${bufDebugStringify(states.buf)} -> 1,${bufAssemble()}`)
return ["1", bufAssemble()]
@@ -436,14 +440,16 @@ return Object.freeze({"n":"세벌식 공자판","v":"one","c":"CuriousTo\uA75Bva
}
// console.log(`assem-digraph: ${bufDebugStringify(states.buf)} -> 1,${bufAssemble()}`)
return ["1", bufAssemble()]
return ["1", bufAssemble(1)]
}
else if (states.buf[0]) {
// sending out assembled syllable and accepting new non-hangul character
else if (isBufferNotEmpty(states.buf)) {
let oldstr = bufAssemble(1)
reset()
// console.log(`sending1 out: 1,${oldstr}${s}`)
return ["1", oldstr + s]
}
// non-hangul
else {
// console.log(`sending0 out: 0,${s}`)
return ["0", s]
@@ -469,13 +475,13 @@ return Object.freeze({"n":"세벌식 공자판","v":"one","c":"CuriousTo\uA75Bva
if (states.buf.length == 0) reset()
// let newbufstr = bufDebugStringify(states.buf)
// console.log(`popping assembly: ${oldbufstr} -> ${newbufstr}`)
// console.log(`popping assembly: ${oldbufstr} -> 1,${newbufstr}`)
return bufAssemble()
return bufAssemble(1)
},
"end":()=>{
// console.log(`end composing`)
let ret = bufAssemble()
let ret = bufAssemble(1)
reset()
return ret
},

View File

@@ -454,22 +454,24 @@ return Object.freeze({"n":"신세벌식 03","v":"one","c":"CuriousTo\uA75Bval
else if (2 == bufIndex && "\u11B8" == states.buf[2] && isJongseongDigraphB(s)) {
states.buf[2] = jongseongDigraphsB[s]
}
// key inputs that bufIndex collides (end compose and accept incoming char as a new char state)
// sending out assembled syllable and accepting new hangul character
else if (states.buf[bufIndex] !== undefined) {
let oldstr = bufAssemble(1)
reset()
states.buf[bufIndex] = s
// console.log(`sending bufout: 1,${oldstr} ${bufDebugStringify(states.buf)}`)
return ["1", oldstr + bufAssemble()]
return ["1", oldstr + bufAssemble(1)]
}
else {
let bufferEmpty = isBufferEmpty(states.buf)
states.buf[bufIndex] = s
// head of the word after the non-hangul
if (bufferEmpty) {
// console.log(`assem0: ${bufDebugStringify(states.buf)} -> 0,${bufAssemble()}`)
return ["0", bufAssemble()]
return ["0", bufAssemble(1)]
}
// not head of the word
else {
// console.log(`assem1: ${bufDebugStringify(states.buf)} -> 1,${bufAssemble()}`)
return ["1", bufAssemble()]
@@ -477,14 +479,16 @@ return Object.freeze({"n":"신세벌식 03","v":"one","c":"CuriousTo\uA75Bval
}
// console.log(`assem-digraph: ${bufDebugStringify(states.buf)} -> 1,${bufAssemble()}`)
return ["1", bufAssemble()]
return ["1", bufAssemble(1)]
}
// sending out assembled syllable and accepting new non-hangul character
else if (isBufferNotEmpty(states.buf)) {
let oldstr = bufAssemble(1)
reset()
// console.log(`sending1 out: 1,${oldstr}${s}`)
return ["1", oldstr + s]
}
// non-hangul
else {
// console.log(`sending0 out: 0,${s}`)
return ["0", s]
@@ -512,7 +516,7 @@ return Object.freeze({"n":"신세벌식 03","v":"one","c":"CuriousTo\uA75Bval
// let newbufstr = bufDebugStringify(states.buf)
// console.log(`popping assembly: ${oldbufstr} -> 1,${newbufstr}`)
return bufAssemble()
return bufAssemble(1)
},
"end":()=>{
// console.log(`end composing`)

View File

@@ -454,22 +454,24 @@ return Object.freeze({"n":"신세벌식 P2","v":"one","c":"CuriousTo\uA75Bvald",
else if (2 == bufIndex && "\u11B8" == states.buf[2] && isJongseongDigraphB(s)) {
states.buf[2] = jongseongDigraphsB[s]
}
// key inputs that bufIndex collides (end compose and accept incoming char as a new char state)
// sending out assembled syllable and accepting new hangul character
else if (states.buf[bufIndex] !== undefined) {
let oldstr = bufAssemble(1)
reset()
states.buf[bufIndex] = s
// console.log(`sending bufout: 1,${oldstr} ${bufDebugStringify(states.buf)}`)
return ["1", oldstr + bufAssemble()]
return ["1", oldstr + bufAssemble(1)]
}
else {
let bufferEmpty = isBufferEmpty(states.buf)
states.buf[bufIndex] = s
// head of the word after the non-hangul
if (bufferEmpty) {
// console.log(`assem0: ${bufDebugStringify(states.buf)} -> 0,${bufAssemble()}`)
return ["0", bufAssemble()]
return ["0", bufAssemble(1)]
}
// not head of the word
else {
// console.log(`assem1: ${bufDebugStringify(states.buf)} -> 1,${bufAssemble()}`)
return ["1", bufAssemble()]
@@ -477,14 +479,16 @@ return Object.freeze({"n":"신세벌식 P2","v":"one","c":"CuriousTo\uA75Bvald",
}
// console.log(`assem-digraph: ${bufDebugStringify(states.buf)} -> 1,${bufAssemble()}`)
return ["1", bufAssemble()]
return ["1", bufAssemble(1)]
}
// sending out assembled syllable and accepting new non-hangul character
else if (isBufferNotEmpty(states.buf)) {
let oldstr = bufAssemble(1)
reset()
// console.log(`sending1 out: 1,${oldstr}${s}`)
return ["1", oldstr + s]
}
// non-hangul
else {
// console.log(`sending0 out: 0,${s}`)
return ["0", s]
@@ -512,7 +516,7 @@ return Object.freeze({"n":"신세벌식 P2","v":"one","c":"CuriousTo\uA75Bvald",
// let newbufstr = bufDebugStringify(states.buf)
// console.log(`popping assembly: ${oldbufstr} -> 1,${newbufstr}`)
return bufAssemble()
return bufAssemble(1)
},
"end":()=>{
// console.log(`end composing`)