calcDistance.js
1.11 KB
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 : "욕설"});
}else{
res.status(200).json({success : true, isProfanity : "정상"});
}
};