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-13 21:17:03 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
833af7e7728c730323e81c8aa463a09cd1ce44f2
833af7e7
1 parent
faaaf7f0
feat : calcDistance 구현
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
100 additions
and
26 deletions
server/controller/calcDistance.js
server/model/db.js
server/routes/index.js
server/service/calcDistance.js
server/service/query.js
server/service/standardization.js
server/controller/calcDistance.js
0 → 100644
View file @
833af7e
const
e
=
require
(
'express'
);
const
levenshtein
=
require
(
'js-levenshtein'
);
const
db
=
require
(
'../model/db'
);
const
{
calcDistance
}
=
require
(
'../service/calcDistance'
);
const
{
getProfanity
}
=
require
(
'../service/query'
);
const
{
standardize
,
removeSpecial
}
=
require
(
'../service/standardization'
);
exports
.
calcDistance
=
async
(
req
,
res
,
next
)
=>
{
const
{
word
}
=
req
.
body
;
const
profanityList
=
await
getProfanity
();
let
specialRemoved
=
removeSpecial
(
word
);
let
specialNotRemoved
=
word
;
specialRemoved
=
standardize
(
specialRemoved
);
specialNotRemoved
=
standardize
(
specialNotRemoved
);
const
rareResult
=
calcDistance
(
word
,
profanityList
);
const
specialRemovedResult
=
calcDistance
(
specialRemoved
,
profanityList
);
const
specialNotRemovedResult
=
calcDistance
(
specialNotRemoved
,
profanityList
);
const
minResult
=
Math
.
min
(
rareResult
,
specialRemovedResult
,
specialNotRemovedResult
);
if
(
minResult
<=
1
){
res
.
status
(
200
).
json
({
success
:
true
,
isProfanity
:
"YES"
});
}
else
{
res
.
status
(
200
).
json
({
success
:
true
,
isProfanity
:
"NO"
});
}
};
\ No newline at end of file
server/model/db.js
View file @
833af7e
...
...
@@ -2,16 +2,15 @@ const mysql = require('mysql2/promise');
const
dotenv
=
require
(
'dotenv'
);
const
path
=
require
(
'path'
);
dotenv
.
config
({
path
:
path
.
join
(
__dirname
,
"../.env"
)
});
dotenv
.
config
({
path
:
path
.
join
(
__dirname
,
'../.env'
)
});
const
db
=
mysql
.
createPool
({
host
:
process
.
env
.
DB_HOST
,
user
:
process
.
env
.
DB_USER
,
port
:
process
.
env
.
DB_PORT
,
password
:
process
.
env
.
DB_PASSWORD
,
database
:
process
.
env
.
DB_DATABASE
,
connectionLimit
:
10
,
});
const
db
=
mysql
.
createPool
({
host
:
process
.
env
.
DB_HOST
,
user
:
process
.
env
.
DB_USER
,
port
:
process
.
env
.
DB_PORT
,
password
:
process
.
env
.
DB_PASSWORD
,
database
:
process
.
env
.
DB_DATABASE
,
connectionLimit
:
10
,
});
module
.
exports
=
db
;
...
...
server/routes/index.js
View file @
833af7e
...
...
@@ -2,9 +2,9 @@ const express = require('express');
const
router
=
express
.
Router
();
const
{
calcDistance
}
=
require
(
'../controller/calcDistance'
);
/* GET home page. */
router
.
post
(
'/checkProfanity'
,
(
req
,
res
)
=>
{
res
.
send
(
'hello'
);
});
router
.
post
(
'/checkProfanity'
,
calcDistance
);
module
.
exports
=
router
;
...
...
server/service/calcDistance.js
View file @
833af7e
/* eslint-disable no-restricted-syntax */
const
levenshtein
=
require
(
'js-levenshtein'
);
const
Hangul
=
require
(
'hangul-js'
);
const
calcDistance
=
()
=>
{
const
result
=
levenshtein
(
'개새끼'
,
'ㄱHsㅐㄲ!'
);
console
.
log
(
result
);
};
exports
.
calcDistance
=
(
word
,
profanityList
)
=>
{
let
leastLevenshtein
=
1000
;
for
(
const
profanity
of
profanityList
[
0
])
{
let
compareWord
=
Hangul
.
disassemble
(
profanity
.
content
);
compareWord
=
compareWord
.
join
(
''
);
if
(
leastLevenshtein
>
levenshtein
(
word
,
compareWord
))
{
leastLevenshtein
=
levenshtein
(
word
,
compareWord
);
}
}
calcDistance
();
return
leastLevenshtein
;
};
...
...
server/service/query.js
0 → 100644
View file @
833af7e
const
db
=
require
(
'../model/db'
);
exports
.
getProfanity
=
async
()
=>
{
const
selectResult
=
await
db
.
query
(
"SELECT DISTINCT content from profanity"
);
return
selectResult
;
};
server/service/standardization.js
View file @
833af7e
/* eslint-disable no-use-before-define */
/* eslint-disable no-restricted-syntax */
const
{
config
}
=
require
(
'dotenv'
);
const
Hangul
=
require
(
'hangul-js'
);
const
standardize
=
(
word
)
=>
{
...
...
@@ -12,7 +13,7 @@ const standardize = (word) => {
?
standardizeConsonent
(
letter
)
:
standardizeVowel
(
letter
);
}
else
{
const
preLetter
=
index
===
1
?
''
:
disassembledWord
[
index
-
1
];
const
preLetter
=
index
===
0
?
''
:
disassembledWord
[
index
-
1
];
const
nextLetter
=
index
===
disassembledWord
.
length
-
1
?
''
:
disassembledWord
[
index
+
1
];
newLetter
=
isVowelSpecial
(
preLetter
,
letter
,
nextLetter
)
?
standardizeSpecialVowel
(
letter
)
...
...
@@ -120,18 +121,44 @@ const standardizeSpecialConsonent = (letter) => {
};
const
standardizeSpecialVowel
=
(
letter
)
=>
{
let
result
=
''
;
switch
(
letter
)
{
case
(
'a'
,
'A'
):
return
'ㅏ'
;
result
=
'ㅏ'
;
break
;
case
(
'u'
,
'U'
):
return
'ㅓ'
;
result
=
'ㅓ'
;
break
;
case
(
'@'
,
'H'
):
return
'ㅐ'
;
case
(
'l'
,
'1'
,
'i'
,
'I'
,
'!'
):
return
'ㅣ'
;
result
=
'ㅐ'
;
break
;
case
(
'l'
,
'i'
,
'I'
,
'!'
,
1
):
result
=
'ㅣ'
;
break
;
case
'1'
:
result
=
'ㅣ'
;
break
;
default
:
return
letter
;
result
=
letter
;
break
;
}
return
result
;
};
const
removeSpecial
=
(
word
)
=>
{
const
numCheck
=
/
[
0-9
]
/g
;
// 숫자
const
engCheck
=
/
[
a-zA-Z
]
/g
;
// 문자
const
specialCheck
=
/
[
~!@#$%^&*()_+|<>?:{}
]
/g
;
// 특수문자
let
result
=
word
.
replace
(
numCheck
,
''
);
result
=
result
.
replace
(
engCheck
,
''
);
result
=
result
.
replace
(
specialCheck
,
''
);
return
result
;
};
module
.
exports
=
{
standardize
};
module
.
exports
=
{
standardize
,
removeSpecial
};
...
...
Please
register
or
login
to post a comment