Skip to content

Commit

Permalink
Resolved the issue of undetected English words
Browse files Browse the repository at this point in the history
  • Loading branch information
fluffy-melli committed Jan 16, 2025
1 parent 4eff944 commit 84a0212
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 40 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ module github.com/fluffy-melli/korcen-go

go 1.22.2

require github.com/gyarang/gohangul v0.1.3 // indirect
require github.com/gyarang/gohangul v0.1.3
8 changes: 5 additions & 3 deletions korcen.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ func CList(list []string, types int, input string, continues bool) (bool, []Inde
}
}
item = KoToEnglish(item)
if len(item) <= 1 {
continue
}
in = strings.Index(input, item)
if in != -1 {
indexs = append(indexs, IndexOF{
Expand Down Expand Up @@ -184,13 +187,12 @@ func Politics(input string, continues bool) (bool, []IndexOF) {
// bool: 비속어가 포함된 경우 true, 그렇지 않으면 false.
// string: 감지된 비속어가 있으면 해당 비속어를, 없으면 빈 문자열("")을 반환.
func English(input string, continues bool) (bool, []IndexOF) {
newtext := ChangeUnicode(input)
prof := NewProfanity(cache.English)
df, pr := prof.Censor(newtext)
df, pr := prof.Censor(input)
if !df {
return false, make([]IndexOF, 0)
}
in := strings.Index(newtext, pr)
in := strings.Index(input, pr)
return true, []IndexOF{
{
Swear: pr,
Expand Down
59 changes: 24 additions & 35 deletions replace.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

func ChangeUnicode(unicode string) string {
//unicode = strings.ToLower(unicode)
unicode = RemoveDomain(unicode)
unicode = strings.ReplaceAll(unicode, "ㅿ", "ㅅ")
unicode = strings.ReplaceAll(unicode, "^", "ㅅ")
unicode = strings.ReplaceAll(unicode, "^", "ㅅ")
Expand Down Expand Up @@ -118,10 +119,10 @@ func ChangeUnicode(unicode string) string {
unicode = strings.ReplaceAll(unicode, "b", "ㅂ")
unicode = strings.ReplaceAll(unicode, "u", "ㅂ")
unicode = strings.ReplaceAll(unicode, "v", "ㅂ")
unicode = RemoveDomain(unicode)
unicode = RemoveDuplicate(unicode)
unicode = RemoveNumber(unicode)
unicode = RemoveEnglish(unicode)
unicode = After(unicode)
dism := gohangul.Disassemble(unicode)
unicode = gohangul.Assemble(dism)
unicode = PreGeneral(unicode)
Expand All @@ -130,7 +131,6 @@ func ChangeUnicode(unicode string) string {
unicode = PreBelittle(unicode)
unicode = PrePolitics(unicode)
unicode = RemoveJ(unicode)
unicode = After(unicode)
return unicode
}

Expand Down Expand Up @@ -187,6 +187,7 @@ func RemoveDomain(input string) string {
input = strings.ReplaceAll(input, ".me", "")
input = strings.ReplaceAll(input, ".xyz", "")
input = strings.ReplaceAll(input, ".online", "")
input = strings.ReplaceAll(input, "?v=", "")
return input
}

Expand Down Expand Up @@ -226,44 +227,32 @@ func RemoveJ(input string) string {
}

func RemoveEnglish(input string) string {
input = strings.ReplaceAll(input, "ha", "")
input = strings.ReplaceAll(input, "hi", "")
input = strings.ReplaceAll(input, "hag", "")
input = strings.ReplaceAll(input, "ham", "")
input = strings.ReplaceAll(input, "hat", "")
input = strings.ReplaceAll(input, "hem", "")
input = strings.ReplaceAll(input, "her", "")
input = strings.ReplaceAll(input, "hex", "")
input = strings.ReplaceAll(input, "hic", "")
input = strings.ReplaceAll(input, "him", "")
input = strings.ReplaceAll(input, "his", "")
input = strings.ReplaceAll(input, "hiv", "")
input = strings.ReplaceAll(input, "hmo", "")
input = strings.ReplaceAll(input, "hod", "")
input = strings.ReplaceAll(input, "hog", "")
input = strings.ReplaceAll(input, "hot", "")
input = strings.ReplaceAll(input, "hub", "")
input = strings.ReplaceAll(input, "hug", "")
input = strings.ReplaceAll(input, "hum", "")
input = strings.ReplaceAll(input, "ssh", "")
input = strings.ReplaceAll(input, "cat", "")
input = strings.ReplaceAll(input, "watch", "")
input = strings.ReplaceAll(input, "status", "")
return input
}

//func EnglishToKo(input string) string {
// var result strings.Builder
// runes := []rune(input)
// i := 0
// for i < len(runes) {
// ch := runes[i]
// if isEnglishLetter(ch) {
// if cache.Regexinitial.MatchString(string(ch)) {
// initial := cache.KRinitial[string(ch)]
// i++
// if i < len(runes) && cache.Regexmedial.MatchString(string(runes[i])) {
// medial := cache.KRmedial[string(runes[i])]
// i++
// if i < len(runes) && cache.Regexfinal.MatchString(string(runes[i])) {
// final := cache.KRfinal[string(runes[i])]
// result.WriteString(initial + medial + final)
// i++
// } else {
// result.WriteString(initial + medial)
// }
// } else {
// result.WriteString(string(runes[i-1]))
// }
// }
// } else {
// result.WriteString(string(ch))
// i++
// }
// }
//
// return result.String()
//}

func KoToEnglish(input string) string {
dism := gohangul.Disassemble(input)
input = string(dism)
Expand Down
2 changes: 1 addition & 1 deletion test/speed_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ func Benchmark0(b *testing.B) {
}

func Test0(t *testing.T) {
fmt.Println(korcen.Check("gpdmdmd"))
fmt.Println(korcen.Check(""))
}

0 comments on commit 84a0212

Please sign in to comment.