Toggle navigation
Toggle navigation
This project
Loading...
Sign in
2020-2-capstone-design2
/
2015104216
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
장준영
2020-12-12 01:42:05 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
1c0b33aa9b886c8b0209daf7976da71cad6696e9
1c0b33aa
1 parent
617b7a17
feat-표준화 service 추가
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
131 additions
and
0 deletions
server/service/calcDistance.js
server/service/standardization.js
server/service/calcDistance.js
0 → 100644
View file @
1c0b33a
File mode changed
server/service/standardization.js
0 → 100644
View file @
1c0b33a
/* eslint-disable no-use-before-define */
/* eslint-disable no-restricted-syntax */
const
Hangul
=
require
(
'hangul-js'
);
const
standardize
=
(
word
)
=>
{
let
result
=
''
;
let
newLetter
=
''
;
const
disassembledWord
=
Hangul
.
disassemble
(
word
);
for
(
const
[
index
,
letter
]
of
disassembledWord
.
entries
())
{
if
(
isKorean
(
letter
))
{
newLetter
=
Hangul
.
isConsonant
(
letter
)
?
standardizeConsonent
(
letter
)
:
standardizeVowel
(
letter
);
}
else
{
const
preLetter
=
index
===
1
?
''
:
disassembledWord
[
index
-
1
];
const
nextLetter
=
index
===
disassembledWord
.
length
-
1
?
''
:
disassembledWord
[
index
+
1
];
newLetter
=
isVowelSpecial
(
preLetter
,
letter
,
nextLetter
)
?
standardizeSpecialVowel
(
letter
)
:
standardizeSpecialConsonent
(
letter
);
}
result
+=
newLetter
;
}
return
result
;
};
const
isKorean
=
(
word
)
=>
{
const
numCheck
=
/
[
0-9
]
/
;
// 숫자
const
engCheck
=
/
[
a-zA-Z
]
/
;
// 문자
const
specialCheck
=
/
[
~!@#$%^&*()_+|<>?:{}
]
/
;
// 특수문자
if
(
!
numCheck
.
test
(
word
)
&&
!
engCheck
.
test
(
word
)
&&
!
specialCheck
.
test
(
word
))
{
return
true
;
}
return
false
;
};
const
standardizeConsonent
=
(
letter
)
=>
{
switch
(
letter
)
{
case
(
'ㄱ'
,
'ㄲ'
,
'ㅋ'
):
return
'ㄱ'
;
case
(
'ㄷ'
,
'ㄸ'
,
'ㅌ'
):
return
'ㄷ'
;
case
(
'ㅂ'
,
'ㅃ'
,
'ㅍ'
):
return
'ㅂ'
;
case
(
'ㅅ'
,
'ㅆ'
):
return
'ㅅ'
;
case
(
'ㅈ'
,
'ㅉ'
,
'ㅊ'
):
return
'ㅈ'
;
default
:
return
letter
;
}
};
const
standardizeVowel
=
(
letter
)
=>
{
switch
(
letter
)
{
case
(
'ㅏ'
,
'ㅑ'
):
return
'ㅏ'
;
case
(
'ㅗ'
,
'ㅛ'
):
return
'ㅗ'
;
case
(
'ㅐ'
,
'ㅒ'
,
'ㅔ'
,
'ㅖ'
,
'ㅙ'
,
'ㅚ'
,
'ㅝ'
,
'ㅞ'
):
return
'ㅐ'
;
case
(
'ㅜ'
,
'ㅠ'
):
return
'ㅜ'
;
case
(
'ㅓ'
,
'ㅕ'
):
return
'ㅓ'
;
case
(
'ㅟ'
,
'ㅢ'
,
'ㅣ'
):
return
'ㅣ'
;
default
:
return
letter
;
}
};
const
isVowelSpecial
=
(
preLetter
,
letter
,
nextLetter
)
=>
{
if
(
preLetter
!==
''
)
{
if
(
nextLetter
===
''
)
{
if
(
isKorean
(
preLetter
))
{
if
(
Hangul
.
isConsonant
(
preLetter
))
{
return
true
;
}
}
}
else
if
(
isKorean
(
preLetter
)
&&
isKorean
(
nextLetter
))
{
if
(
Hangul
.
isConsonant
(
preLetter
)
&&
Hangul
.
isConsonant
(
nextLetter
))
{
return
true
;
}
}
}
return
false
;
};
const
standardizeSpecialConsonent
=
(
letter
)
=>
{
switch
(
letter
)
{
case
(
'g'
,
'ㅑ'
):
return
'ㅏ'
;
case
(
'ㅗ'
,
'ㅛ'
):
return
'ㅗ'
;
case
(
'ㅐ'
,
'ㅒ'
,
'ㅔ'
,
'ㅖ'
,
'ㅙ'
,
'ㅚ'
,
'ㅝ'
,
'ㅞ'
):
return
'ㅐ'
;
case
(
'ㅜ'
,
'ㅠ'
):
return
'ㅜ'
;
case
(
'ㅓ'
,
'ㅕ'
):
return
'ㅓ'
;
case
(
'ㅟ'
,
'ㅢ'
,
'ㅣ'
):
return
'ㅣ'
;
default
:
return
letter
;
}
};
const
standardizeSpecialVowel
=
(
letter
)
=>
{
switch
(
letter
)
{
case
(
'g'
,
'ㅑ'
):
return
'ㅏ'
;
case
(
'ㅗ'
,
'ㅛ'
):
return
'ㅗ'
;
case
(
'ㅐ'
,
'ㅒ'
,
'ㅔ'
,
'ㅖ'
,
'ㅙ'
,
'ㅚ'
,
'ㅝ'
,
'ㅞ'
):
return
'ㅐ'
;
case
(
'ㅜ'
,
'ㅠ'
):
return
'ㅜ'
;
case
(
'ㅓ'
,
'ㅕ'
):
return
'ㅓ'
;
case
(
'ㅟ'
,
'ㅢ'
,
'ㅣ'
):
return
'ㅣ'
;
default
:
return
letter
;
}
};
module
.
exports
=
{
standardize
};
Please
register
or
login
to post a comment