Skip to content

Commit

Permalink
Five senses in English have been reduced.
Browse files Browse the repository at this point in the history
  • Loading branch information
fluffy-melli committed Jan 15, 2025
1 parent 98ebd75 commit 977fb00
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 211 deletions.
19 changes: 18 additions & 1 deletion cache/regexp.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,21 @@ package cache

import "regexp"

var URL = regexp.MustCompile(`https?://[^\s]+|www\.[^\s]+`)
var KRinitial = map[string]string{
"r": "ㄱ", "R": "ㄲ", "s": "ㄴ", "e": "ㄷ", "E": "ㄸ", "f": "ㄹ", "a": "ㅁ", "q": "ㅂ", "Q": "ㅃ",
"t": "ㅅ", "T": "ㅆ", "d": "ㅇ", "w": "ㅈ", "W": "ㅉ", "c": "ㅊ", "z": "ㅋ", "x": "ㅌ", "v": "ㅍ", "g": "ㅎ",
}

var KRmedial = map[string]string{
"k": "ㅏ", "o": "ㅐ", "i": "ㅑ", "I": "ㅒ", "j": "ㅓ", "p": "ㅔ", "u": "ㅕ", "P": "ㅖ", "h": "ㅗ", "y": "ㅛ",
"n": "ㅜ", "b": "ㅠ", "m": "ㅡ", "l": "ㅣ",
}

var KRfinal = map[string]string{
"r": "ㄱ", "s": "ㄴ", "e": "ㄷ", "f": "ㄹ", "a": "ㅁ", "q": "ㅂ", "t": "ㅅ", "d": "ㅇ", "w": "ㅈ", "c": "ㅊ",
"z": "ㅋ", "x": "ㅌ", "v": "ㅍ", "g": "ㅎ",
}

var Regexinitial = regexp.MustCompile(`[rRsseEfFaqQtTdDwWcxyzv]`)
var Regexmedial = regexp.MustCompile(`[koijphyunbl]`)
var Regexfinal = regexp.MustCompile(`[rswacxzv]`)
75 changes: 9 additions & 66 deletions korcen.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,7 @@ func Special(input string, continues bool) (bool, []IndexOF) {
func Check(input string) CheckInfo {
var detect bool
var swear []IndexOF
input = ChangeUnicode(input)
detect, swear = General(input, false)
detect, swear = English(input, false)
if detect {
return CheckInfo{
Detect: true,
Expand All @@ -255,7 +254,8 @@ func Check(input string) CheckInfo {
}
}

detect, swear = Minor(input, false)
input = ChangeUnicode(input)
detect, swear = General(input, false)
if detect {
return CheckInfo{
Detect: true,
Expand All @@ -264,7 +264,7 @@ func Check(input string) CheckInfo {
}
}

detect, swear = Sexual(input, false)
detect, swear = Minor(input, false)
if detect {
return CheckInfo{
Detect: true,
Expand All @@ -273,7 +273,7 @@ func Check(input string) CheckInfo {
}
}

detect, swear = Belittle(input, false)
detect, swear = Sexual(input, false)
if detect {
return CheckInfo{
Detect: true,
Expand All @@ -282,7 +282,7 @@ func Check(input string) CheckInfo {
}
}

detect, swear = Race(input, false)
detect, swear = Belittle(input, false)
if detect {
return CheckInfo{
Detect: true,
Expand All @@ -291,7 +291,7 @@ func Check(input string) CheckInfo {
}
}

detect, swear = Parent(input, false)
detect, swear = Race(input, false)
if detect {
return CheckInfo{
Detect: true,
Expand All @@ -300,7 +300,7 @@ func Check(input string) CheckInfo {
}
}

detect, swear = Politics(input, false)
detect, swear = Parent(input, false)
if detect {
return CheckInfo{
Detect: true,
Expand All @@ -309,7 +309,7 @@ func Check(input string) CheckInfo {
}
}

detect, swear = English(input, false)
detect, swear = Politics(input, false)
if detect {
return CheckInfo{
Detect: true,
Expand Down Expand Up @@ -351,60 +351,3 @@ func Check(input string) CheckInfo {
Swear: make([]IndexOF, 0),
}
}

// ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 비속어 감지 및 결과 반환 함수
// 입력:
//
// input: 비속어가 포함될 수 있는 문자열.
//
// 출력:
//
// CheckInfo: struct {
// Detect bool // 비속어 감지 여부
// Swear string // 감지된 비속어
// Type int // 비속어의 유형
// }
func AllCheck(input string) CheckInfo {
var swear []IndexOF
var respond []IndexOF
input = ChangeUnicode(input)
_, swear = General(input, true)
respond = append(respond, swear...)

_, swear = Minor(input, true)
respond = append(respond, swear...)

_, swear = Sexual(input, true)
respond = append(respond, swear...)

_, swear = Belittle(input, true)
respond = append(respond, swear...)

_, swear = Race(input, true)
respond = append(respond, swear...)

_, swear = Parent(input, true)
respond = append(respond, swear...)

_, swear = Politics(input, true)
respond = append(respond, swear...)

_, swear = English(input, true)
respond = append(respond, swear...)

_, swear = Japanese(input, true)
respond = append(respond, swear...)

_, swear = Chinese(input, true)
respond = append(respond, swear...)

_, swear = Special(input, true)
respond = append(respond, swear...)

return CheckInfo{
Detect: len(respond) != 0,
NewText: input,
Swear: respond,
}
}
218 changes: 75 additions & 143 deletions replace.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,10 @@ func ChangeUnicode(unicode string) string {
unicode = strings.ReplaceAll(unicode, "b", "ㅂ")
unicode = strings.ReplaceAll(unicode, "u", "ㅂ")
unicode = strings.ReplaceAll(unicode, "v", "ㅂㅂ")
unicode = cache.URL.ReplaceAllString(unicode, "")
unicode = EnglishToKo(unicode)
unicode = RemoveDomain(unicode)
unicode = RemoveDuplicate(unicode)
unicode = RemoveNumber(unicode)
unicode = EnglishToKo(unicode)
dism := gohangul.Disassemble(unicode)
unicode = gohangul.Assemble(dism)
unicode = PreGeneral(unicode)
Expand All @@ -144,6 +144,53 @@ func After(input string) string {
return input
}

func RemoveDomain(input string) string {
input = strings.ReplaceAll(input, "http://", "")
input = strings.ReplaceAll(input, "https://", "")
input = strings.ReplaceAll(input, "youtu.be", "")
input = strings.ReplaceAll(input, "youtube.com", "")
input = strings.ReplaceAll(input, "google.com", "")
input = strings.ReplaceAll(input, "facebook.com", "")
input = strings.ReplaceAll(input, "amazon.com", "")
input = strings.ReplaceAll(input, "apple.com", "")
input = strings.ReplaceAll(input, "microsoft.com", "")
input = strings.ReplaceAll(input, "twitter.com", "")
input = strings.ReplaceAll(input, "instagram.com", "")
input = strings.ReplaceAll(input, "wikipedia.org", "")
input = strings.ReplaceAll(input, "yahoo.com", "")
input = strings.ReplaceAll(input, "linkedin.com", "")
input = strings.ReplaceAll(input, ".us", "")
input = strings.ReplaceAll(input, ".uk", "")
input = strings.ReplaceAll(input, ".ca", "")
input = strings.ReplaceAll(input, ".de", "")
input = strings.ReplaceAll(input, ".fr", "")
input = strings.ReplaceAll(input, ".jp", "")
input = strings.ReplaceAll(input, ".kr", "")
input = strings.ReplaceAll(input, ".co.kr", "")
input = strings.ReplaceAll(input, ".cn", "")
input = strings.ReplaceAll(input, ".in", "")
input = strings.ReplaceAll(input, ".au", "")
input = strings.ReplaceAll(input, ".com", "")
input = strings.ReplaceAll(input, ".org", "")
input = strings.ReplaceAll(input, ".net", "")
input = strings.ReplaceAll(input, ".edu", "")
input = strings.ReplaceAll(input, ".gov", "")
input = strings.ReplaceAll(input, ".mil", "")
input = strings.ReplaceAll(input, ".co", "")
input = strings.ReplaceAll(input, ".int", "")
input = strings.ReplaceAll(input, ".tech", "")
input = strings.ReplaceAll(input, ".ai", "")
input = strings.ReplaceAll(input, ".io", "")
input = strings.ReplaceAll(input, ".app", "")
input = strings.ReplaceAll(input, ".tv", "")
input = strings.ReplaceAll(input, ".store", "")
input = strings.ReplaceAll(input, ".club", "")
input = strings.ReplaceAll(input, ".me", "")
input = strings.ReplaceAll(input, ".xyz", "")
input = strings.ReplaceAll(input, ".online", "")
return input
}

func RemoveDuplicate(input string) string {
var result strings.Builder
var prevRune rune
Expand Down Expand Up @@ -180,147 +227,32 @@ func RemoveJ(input string) string {
}

func EnglishToKo(input string) string {
input = strings.ReplaceAll(input, "rk", "가")
input = strings.ReplaceAll(input, "ri", "갸")
input = strings.ReplaceAll(input, "rj", "거")
input = strings.ReplaceAll(input, "ru", "겨")
input = strings.ReplaceAll(input, "rh", "고")
input = strings.ReplaceAll(input, "ry", "교")
input = strings.ReplaceAll(input, "rn", "구")
input = strings.ReplaceAll(input, "rb", "규")
input = strings.ReplaceAll(input, "rm", "그")
input = strings.ReplaceAll(input, "rl", "기")
input = strings.ReplaceAll(input, "sk", "나")
input = strings.ReplaceAll(input, "si", "냐")
input = strings.ReplaceAll(input, "sj", "거")
input = strings.ReplaceAll(input, "su", "겨")
input = strings.ReplaceAll(input, "sh", "노")
input = strings.ReplaceAll(input, "sy", "뇨")
input = strings.ReplaceAll(input, "sn", "누")
input = strings.ReplaceAll(input, "sb", "뉴")
input = strings.ReplaceAll(input, "sm", "느")
input = strings.ReplaceAll(input, "sl", "니")
input = strings.ReplaceAll(input, "ek", "다")
input = strings.ReplaceAll(input, "ei", "댜")
input = strings.ReplaceAll(input, "ej", "더")
input = strings.ReplaceAll(input, "eu", "뎌")
input = strings.ReplaceAll(input, "eh", "도")
input = strings.ReplaceAll(input, "ey", "됴")
input = strings.ReplaceAll(input, "en", "두")
input = strings.ReplaceAll(input, "eb", "듀")
input = strings.ReplaceAll(input, "em", "드")
input = strings.ReplaceAll(input, "el", "디")
input = strings.ReplaceAll(input, "fk", "라")
input = strings.ReplaceAll(input, "fi", "랴")
input = strings.ReplaceAll(input, "fj", "러")
input = strings.ReplaceAll(input, "fu", "려")
input = strings.ReplaceAll(input, "fh", "로")
input = strings.ReplaceAll(input, "fy", "료")
input = strings.ReplaceAll(input, "fn", "루")
input = strings.ReplaceAll(input, "fb", "류")
input = strings.ReplaceAll(input, "fm", "르")
input = strings.ReplaceAll(input, "fl", "리")
input = strings.ReplaceAll(input, "ak", "마")
input = strings.ReplaceAll(input, "ai", "먀")
input = strings.ReplaceAll(input, "aj", "머")
input = strings.ReplaceAll(input, "au", "며")
input = strings.ReplaceAll(input, "ah", "모")
input = strings.ReplaceAll(input, "ay", "묘")
input = strings.ReplaceAll(input, "an", "무")
input = strings.ReplaceAll(input, "ab", "뮤")
input = strings.ReplaceAll(input, "am", "므")
input = strings.ReplaceAll(input, "al", "미")
input = strings.ReplaceAll(input, "qk", "바")
input = strings.ReplaceAll(input, "qi", "뱌")
input = strings.ReplaceAll(input, "qj", "버")
input = strings.ReplaceAll(input, "qu", "벼")
input = strings.ReplaceAll(input, "qh", "보")
input = strings.ReplaceAll(input, "qy", "뵤")
input = strings.ReplaceAll(input, "qn", "부")
input = strings.ReplaceAll(input, "qb", "뷰")
input = strings.ReplaceAll(input, "qm", "브")
input = strings.ReplaceAll(input, "ql", "비")
input = strings.ReplaceAll(input, "tk", "사")
input = strings.ReplaceAll(input, "ti", "샤")
input = strings.ReplaceAll(input, "tj", "서")
input = strings.ReplaceAll(input, "tu", "셔")
input = strings.ReplaceAll(input, "th", "소")
input = strings.ReplaceAll(input, "ty", "쇼")
input = strings.ReplaceAll(input, "tn", "수")
input = strings.ReplaceAll(input, "tb", "슈")
input = strings.ReplaceAll(input, "tm", "스")
input = strings.ReplaceAll(input, "tl", "시")
input = strings.ReplaceAll(input, "dk", "아")
input = strings.ReplaceAll(input, "di", "야")
input = strings.ReplaceAll(input, "dj", "어")
input = strings.ReplaceAll(input, "du", "여")
input = strings.ReplaceAll(input, "dh", "오")
input = strings.ReplaceAll(input, "dy", "요")
input = strings.ReplaceAll(input, "dn", "우")
input = strings.ReplaceAll(input, "db", "유")
input = strings.ReplaceAll(input, "dm", "으")
input = strings.ReplaceAll(input, "dl", "이")
input = strings.ReplaceAll(input, "wk", "자")
input = strings.ReplaceAll(input, "wi", "쟈")
input = strings.ReplaceAll(input, "wj", "저")
input = strings.ReplaceAll(input, "wu", "져")
input = strings.ReplaceAll(input, "wh", "조")
input = strings.ReplaceAll(input, "wy", "죠")
input = strings.ReplaceAll(input, "wn", "주")
input = strings.ReplaceAll(input, "wb", "쥬")
input = strings.ReplaceAll(input, "wm", "즈")
input = strings.ReplaceAll(input, "wl", "지")
input = strings.ReplaceAll(input, "ck", "차")
input = strings.ReplaceAll(input, "ci", "챠")
input = strings.ReplaceAll(input, "cj", "처")
input = strings.ReplaceAll(input, "cu", "쳐")
input = strings.ReplaceAll(input, "ch", "초")
input = strings.ReplaceAll(input, "cy", "쵸")
input = strings.ReplaceAll(input, "cn", "추")
input = strings.ReplaceAll(input, "cb", "츄")
input = strings.ReplaceAll(input, "cm", "츠")
input = strings.ReplaceAll(input, "cl", "치")
input = strings.ReplaceAll(input, "zk", "카")
input = strings.ReplaceAll(input, "zi", "캬")
input = strings.ReplaceAll(input, "zj", "커")
input = strings.ReplaceAll(input, "zu", "켜")
input = strings.ReplaceAll(input, "zh", "코")
input = strings.ReplaceAll(input, "zy", "쿄")
input = strings.ReplaceAll(input, "zn", "쿠")
input = strings.ReplaceAll(input, "zb", "큐")
input = strings.ReplaceAll(input, "zm", "크")
input = strings.ReplaceAll(input, "zl", "키")
input = strings.ReplaceAll(input, "xk", "타")
input = strings.ReplaceAll(input, "xi", "탸")
input = strings.ReplaceAll(input, "xj", "터")
input = strings.ReplaceAll(input, "xu", "텨")
input = strings.ReplaceAll(input, "xh", "토")
input = strings.ReplaceAll(input, "xy", "툐")
input = strings.ReplaceAll(input, "xn", "투")
input = strings.ReplaceAll(input, "xb", "튜")
input = strings.ReplaceAll(input, "xm", "트")
input = strings.ReplaceAll(input, "xl", "티")
input = strings.ReplaceAll(input, "vk", "파")
input = strings.ReplaceAll(input, "vi", "퍄")
input = strings.ReplaceAll(input, "vj", "퍼")
input = strings.ReplaceAll(input, "vu", "펴")
input = strings.ReplaceAll(input, "vh", "포")
input = strings.ReplaceAll(input, "vy", "표")
input = strings.ReplaceAll(input, "vn", "푸")
input = strings.ReplaceAll(input, "vb", "퓨")
input = strings.ReplaceAll(input, "vm", "프")
input = strings.ReplaceAll(input, "vl", "피")
input = strings.ReplaceAll(input, "gk", "하")
input = strings.ReplaceAll(input, "gi", "햐")
input = strings.ReplaceAll(input, "gj", "허")
input = strings.ReplaceAll(input, "gu", "혀")
input = strings.ReplaceAll(input, "gh", "호")
input = strings.ReplaceAll(input, "gy", "효")
input = strings.ReplaceAll(input, "gn", "후")
input = strings.ReplaceAll(input, "gb", "휴")
input = strings.ReplaceAll(input, "gm", "흐")
input = strings.ReplaceAll(input, "gl", "히")
return input
var result strings.Builder
i := 0
for i < len(input) {
if cache.Regexinitial.MatchString(string(input[i])) {
initial := cache.KRinitial[string(input[i])]
i++
if i < len(input) && cache.Regexmedial.MatchString(string(input[i])) {
medial := cache.KRmedial[string(input[i])]
i++
if i < len(input) && cache.Regexfinal.MatchString(string(input[i])) {
final := cache.KRfinal[string(input[i])]
result.WriteString(initial + medial + final)
i++
} else {
result.WriteString(initial + medial)
}
} else {
result.WriteString(string(input[i-1]))
}
} else {
result.WriteString(string(input[i]))
i++
}
}

return result.String()
}

func RemoveNumber(input string) string {
Expand Down
Loading

0 comments on commit 977fb00

Please sign in to comment.