-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinput.js
More file actions
368 lines (300 loc) · 14.6 KB
/
Copy pathinput.js
File metadata and controls
368 lines (300 loc) · 14.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
import Hangul from 'hangul-js'
import Bias from './bias'
import readline from 'readline'
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
})
class InputProcess{
constructor(){
// 수정하고자 하는 패키지명
this.packageName = null
// 지금 추가하고자 하는 단어명
this.word = null
// 글자별 옵션
this.charsOption = {}
}
process(input){
// 수정하고자 하는 패키지명
if(this.packageName === null){
if(input.length == 0){
console.log(`패키지명을 입력해주세요. (예: kr-badwords)`)
return
}else{
// TODO 폴더 존재여부 확인
// 없으면 폴더 별개 생성 요청
this.packageName = input
console.log(`패키지명이 입력되었습니다. (${this.packageName})`)
input = ''
}
}
// 지금 추가하고자 하는 단어
if(this.word === null){
if(input.length == 0){
console.log(`추가하고자 하는 단어를 입력해주세요. (예: 바보)`)
return
}else{
this.word = input.split('')
console.log(`단어추가가 시작되었습니다. (${input})`)
input = ''
}
}
// 단어별 파싱 시작
for(let char of this.word){
// 단어 데이터가 구성 안 된 경우 초기화
if(typeof this.charsOption[char] === 'undefined'){
this.charsOption[char] = {
// 초성만으로 존재가능한지
onsetIndependent: null,
// 중성에서 수직모음이 들어갈 수 있는지
nucleusVerticality: null,
// 중성에서 수평모음이 들어갈 수 있는지
nucleusHorizontal: null,
// 중성에서 복합모음이 들어갈 수 있는지
nucleusComplex: null,
// 종성에서 받침이 없는 경우도 허용되는지
codaEmptyAllow: null,
// 종성에서 받침이 있는 경우도 허용되는지
codaExistAllow: null,
// 모든 구성진행이 완료되었는지ㅣ
isFinished: false
}
}
// 단어 옵션
let charOption = this.charsOption[char]
// 단어 구성이 다 끝난 경우 다음글자로 넘어가기
if(charOption.isFinished)
continue
// 아래서부터 옵션별 체크시작
// 예 또는 아니요가 아닌 경우 다시입력 요구
let answer = null
let answerCheck = (onlyBoolean = true)=>{
if(input.length !== 0){
switch(String(input).toLowerCase()){
case 'y':
case 'yes':
case '예':
case '네':
answer = true
break
case 'n':
case 'no':
case '아니요':
case '아뇨':
answer = false
break
default:
if(onlyBoolean){
console.log('잘못된 입력입니다. Y 또는 N 을 입력해주세요.')
return
}
}
}
}
// 글자 파싱
let parsed = Bias.hangulParse(char)
// PROCESS 1
// 초성만으로 탐지가 가능한지
if(parsed.initialConsonant.length === 0){
// 입력된 글자에 초성이 없을때
// 초성만으로 탐지 여부는 false
charOption.onsetIndependent = false
}else{
// 입력된 글자에 초성이 존재할때
// 초성만으로 탐지가 가능한지
if(charOption.onsetIndependent === null){
if(answer === null){
console.log(`글자 '${char}' 가 초성만 있어도 사람이 해당 단어를 인지 가능합니까? [Y/N]`)
console.log(`예: ${parsed.initialConsonant}`)
return
}else{
charOption.onsetIndependent = answer
answer = null
}
}
}
// PROCESS 2
// 중성에서 수직모음이 들어갈 수 있는지
if(parsed.initialConsonant.length == 0 &&
parsed.horizonVowel.length == 0){
// 초성 또는 수평모음 둘 다 존재하지 않을때
// 만능 수직모음 사용 여부는 false
charOption.nucleusVerticality = false
}else{
// 초성 또는 수평모음 둘중하나라도 존재할 경우
// 중성에서 수직모음이 들어갈 수 있는지
if(charOption.nucleusVerticality === null){
if(answer === null){
console.log(`글자 '${char}' 의 중성에 수직모음이 들어갈 수 있습니까? [Y/N]`)
let exDef = []
if(parsed.initialConsonant.length != 0)
exDef.push(parsed.initialConsonant)
if(parsed.horizonVowel.length != 0)
exDef.push(parsed.horizonVowel)
let exDefAfter = []
if(parsed.finalConsonant.length != 0)
exDefAfter.push(parsed.finalConsonant)
let exA = Hangul.assemble([...exDef, 'ㅣ', ...exDefAfter])
let exB = Hangul.assemble([...exDef, 'ㅑ', ...exDefAfter])
let exC = Hangul.assemble([...exDef, 'ㅓ', ...exDefAfter])
let exD = Hangul.assemble([...exDef, 'ㅖ', ...exDefAfter])
console.log(`예: ${exA}, ${exB}, ${exC}, ${exD}... 등등`)
return
}else{
charOption.nucleusVerticality = answer
answer = null
}
}
}
// PROCESS 3
// 중성에서 수평모음이 들어갈 수 있는지
if(parsed.initialConsonant.length == 0 &&
parsed.verticalVowel.length == 0){
// 초성 또는 수직모음 둘 다 존재하지 않을때
// 만능 수평모음 사용 여부는 false
charOption.nucleusHorizontal = false
}else{
// 초성 또는 수직모음 둘중하나라도 존재할 경우
// 중성에서 수평모음이 들어갈 수 있는지
if(charOption.nucleusHorizontal === null){
if(answer === null){
console.log(`글자 '${char}' 의 중성에 수평모음이 들어갈 수 있습니까? [Y/N]`)
let exDef = []
if(parsed.initialConsonant.length != 0)
exDef.push(parsed.initialConsonant)
let exDefAfter = []
if(parsed.finalConsonant.length != 0)
exDefAfter.push(parsed.finalConsonant)
let exHorizontalNucleus = [
"ㅗ",
"ㅛ",
"ㅜ",
"ㅠ",
"ㅡ"
]
let exHorizontalNucleusStr = ''
for(let exHorizontalChar of exHorizontalNucleus){
let isFirst = (exHorizontalNucleusStr.length == 0) ? true : false
if(!isFirst) exHorizontalNucleusStr += ', '
exHorizontalNucleusStr += Hangul.assemble([...exDef, exHorizontalChar, ...exDefAfter])
}
/**
* @TODO
* 수평모음 전체예를 보여준 후,
* y 또는 n 을 입력하게 하거나,
* 필요한 수평모음 일부를 , 로 구분해서 입력하게 할 수 있도록
*/
// 수평모음 전체를 보여주기
console.log(`전체 수평모음 목록의 적용결과 다음과 같습니다.`)
console.log(`만약 y를 입력하시면 아래의 모든 모음이 사용처리 됩니다.`)
console.log(`수평모음 적용 예: ${exHorizontalNucleusStr}... 등등\n`)
console.log(`그러나 위 모음 중 일부만 사용하고 싶은 경우,`)
console.log(`사용할 모음들만 모아서 아래처럼 입력해주세요.`)
console.log(`입력 예: ㅗ,ㅛ,ㅜ,ㅠ,ㅡ`)
return
}else{
charOption.nucleusHorizontal = answer
answer = null
}
}
}
// PROCESS 4
// 중성에서 복합모음이 들어갈 수 있는지
if(parsed.initialConsonant.length === 0){
// 입력된 글자에 초성이 없을때
// 만능 복합모음 사용 여부는 false
charOption.nucleusComplex = false
}else{
// 입력된 글자에 초성이 존재할때
// 초성만으로 탐지가 가능한지
if(charOption.nucleusComplex === null){
if(answer === null){
console.log(`글자 '${char}' 의 중성에 복합모음이 사용될 수 있습니까? [Y/N]`)
let exDef = []
if(parsed.initialConsonant.length != 0)
exDef.push(parsed.initialConsonant)
let exDefAfter = []
if(parsed.finalConsonant.length != 0)
exDefAfter.push(parsed.finalConsonant)
let exA = Hangul.assemble([...exDef, 'ㅡ', 'ㅣ', ...exDefAfter])
let exB = Hangul.assemble([...exDef, 'ㅗ', 'ㅐ', ...exDefAfter])
let exC = Hangul.assemble([...exDef, 'ㅜ', 'ㅔ', ...exDefAfter])
let exD = Hangul.assemble([...exDef, 'ㅜ', 'ㅣ', ...exDefAfter])
console.log(`예: ${exA}, ${exB}, ${exC}, ${exD}... 등등`)
return
}else{
charOption.nucleusComplex = answer
answer = null
}
}
}
// PROCESS 5
// 종성에서 받침이 없는 경우도 허용되는지
if(parsed.initialConsonant.length === 0){
// 입력된 글자에 초성이 없을때
// 비어있는 받침표현 사용 여부는 false
charOption.codaEmptyAllow = false
}else{
// 입력된 글자에 초성이 존재할때
// 종성에서 받침이 없는 경우도 허용되는지
if(charOption.codaEmptyAllow === null){
if(answer === null){
console.log(`글자 '${char}' 의 종성에 받침이 없는 경우도 사람이 해당 단어를 인지 가능합니까? [Y/N]`)
let exDef = []
if(parsed.initialConsonant.length != 0)
exDef.push(parsed.initialConsonant)
let exA = Hangul.assemble([...exDef, 'ㅡ', 'ㅣ'])
let exB = Hangul.assemble([...exDef, 'ㅗ', 'ㅐ'])
let exC = Hangul.assemble([...exDef, 'ㅜ', 'ㅔ'])
let exD = Hangul.assemble([...exDef, 'ㅜ', 'ㅣ'])
console.log(`예: ${exA}, ${exB}, ${exC}, ${exD}... 등등`)
return
}else{
charOption.codaEmptyAllow = answer
answer = null
}
}
}
// PROCESS 6
// 종성에서 받침이 있는 경우도 허용되는지
if(parsed.initialConsonant.length === 0){
// 입력된 글자에 초성이 없을때
// 비어있는 받침표현 사용 여부는 false
charOption.codaExistAllow = false
}else{
// 입력된 글자에 초성이 존재할때
// 종성에서 받침이 있는 경우도 허용되는지
if(charOption.codaExistAllow === null){
if(answer === null){
console.log(`글자 '${char}' 의 종성에 받침이 있는 경우도 단어로 사람이 해당 단어를 인지 가능합니까? [Y/N]`)
let exDef = []
if(parsed.initialConsonant.length != 0)
exDef.push(parsed.initialConsonant)
let exA = Hangul.assemble([...exDef, 'ㅡ', 'ㅣ', 'ㄱ'])
let exB = Hangul.assemble([...exDef, 'ㅗ', 'ㅐ', 'ㅋ'])
let exC = Hangul.assemble([...exDef, 'ㅜ', 'ㅔ', 'ㄹ'])
let exD = Hangul.assemble([...exDef, 'ㅜ', 'ㅣ', 'ㅂ'])
console.log(`예: ${exA}, ${exB}, ${exC}, ${exD}... 등등`)
return
}else{
charOption.codaExistAllow = answer
charOption.isFinished = true
answer = null
}
}
}
}
// 모든 구성이 완료된 경우
console.log('모든 구성 완료')
console.log(charsOption)
/**
* @TODO
* 실제 JSON 옵션 구성 후 저장
*/
}
}
var inputProcess = new InputProcess()
inputProcess.process('')
rl.on('line', (input) => {
inputProcess.process(input)
})