Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add vietnamese #14

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea/
coverage.out
/nbproject/private/
/nbproject/
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ It uses a curated list of the most frequent words used in these languages:
* Swedish
* Thai
* Turkish
* Vietnamese

If the function is used with an unsupported language, it doesn't fail, but will apply english filter to the content.

Expand Down
61 changes: 33 additions & 28 deletions custom.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
func LoadStopWordsFromFile(filePath string, langCode string, sep string) {
b, err := ioutil.ReadFile(filePath)
if err != nil {
panic(err)
panic(err)
}
LoadStopWordsFromString(string(b), langCode, sep)
}
Expand All @@ -41,137 +41,142 @@ func LoadStopWordsFromString(wordsList string, langCode string, sep string) {
case "ar":
arabic = make(map[string]string)
for _, word := range words {
arabic[word] = ""
arabic[word] = ""
}
case "bg":
bulgarian = make(map[string]string)
for _, word := range words {
bulgarian[word] = ""
bulgarian[word] = ""
}
case "cs":
czech = make(map[string]string)
for _, word := range words {
czech[word] = ""
czech[word] = ""
}
case "da":
danish = make(map[string]string)
for _, word := range words {
danish[word] = ""
danish[word] = ""
}
case "de":
german = make(map[string]string)
for _, word := range words {
german[word] = ""
german[word] = ""
}
case "el":
greek = make(map[string]string)
for _, word := range words {
greek[word] = ""
greek[word] = ""
}
case "en":
english = make(map[string]string)
for _, word := range words {
english[word] = ""
english[word] = ""
}
case "es":
spanish = make(map[string]string)
for _, word := range words {
spanish[word] = ""
spanish[word] = ""
}
case "fa":
persian = make(map[string]string)
for _, word := range words {
persian[word] = ""
persian[word] = ""
}
case "fr":
french = make(map[string]string)
for _, word := range words {
french[word] = ""
french[word] = ""
}
case "fi":
finnish = make(map[string]string)
for _, word := range words {
finnish[word] = ""
finnish[word] = ""
}
case "hu":
hungarian = make(map[string]string)
for _, word := range words {
hungarian[word] = ""
hungarian[word] = ""
}
case "id":
indonesian = make(map[string]string)
for _, word := range words {
indonesian[word] = ""
indonesian[word] = ""
}
case "it":
italian = make(map[string]string)
for _, word := range words {
italian[word] = ""
italian[word] = ""
}
case "ja":
japanese = make(map[string]string)
for _, word := range words {
japanese[word] = ""
japanese[word] = ""
}
case "km":
khmer = make(map[string]string)
for _, word := range words {
khmer[word] = ""
khmer[word] = ""
}
case "lv":
latvian = make(map[string]string)
for _, word := range words {
latvian[word] = ""
latvian[word] = ""
}
case "nl":
dutch = make(map[string]string)
for _, word := range words {
dutch[word] = ""
dutch[word] = ""
}
case "no":
norwegian = make(map[string]string)
for _, word := range words {
norwegian[word] = ""
norwegian[word] = ""
}
case "pl":
polish = make(map[string]string)
for _, word := range words {
polish[word] = ""
polish[word] = ""
}
case "pt":
portuguese = make(map[string]string)
for _, word := range words {
portuguese[word] = ""
portuguese[word] = ""
}
case "ro":
romanian = make(map[string]string)
for _, word := range words {
romanian[word] = ""
romanian[word] = ""
}
case "ru":
russian = make(map[string]string)
for _, word := range words {
russian[word] = ""
russian[word] = ""
}
case "sk":
slovak = make(map[string]string)
for _, word := range words {
slovak[word] = ""
slovak[word] = ""
}
case "sv":
swedish = make(map[string]string)
for _, word := range words {
swedish[word] = ""
swedish[word] = ""
}
case "th":
thai = make(map[string]string)
for _, word := range words {
thai[word] = ""
thai[word] = ""
}
case "tr":
turkish = make(map[string]string)
for _, word := range words {
turkish[word] = ""
turkish[word] = ""
}
case "vi":
vietnamese = make(map[string]string)
for _, word := range words {
vietnamese[word] = ""
}
}
}
2 changes: 2 additions & 0 deletions simhash.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ func Simhash(content []byte, langCode string, cleanHTML bool) uint64 {
hash = removeStopWordsAndHash(content, thai)
case "tr":
hash = removeStopWordsAndHash(content, turkish)
case "vi":
hash = removeStopWordsAndHash(content, vietnamese)
}

return hash
Expand Down
9 changes: 6 additions & 3 deletions stopwords.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
//
// arabic, bulgarian, czech, danish, english, finnish, french, german,
// hungarian, italian, japanese, latvian, norwegian, persian, polish,
// portuguese, romanian, russian, slovak, spanish, swedish, turkish
// portuguese, romanian, russian, slovak, spanish, swedish, turkish,
// vietnamese

// Package stopwords contains various algorithms of text comparison (Simhash, Levenshtein)
package stopwords
Expand All @@ -23,8 +24,8 @@ import (
)

var (
remTags = regexp.MustCompile(`<[^>]*>`)
oneSpace = regexp.MustCompile(`\s{2,}`)
remTags = regexp.MustCompile(`<[^>]*>`)
oneSpace = regexp.MustCompile(`\s{2,}`)
wordSegmenter = regexp.MustCompile(`[\pL\p{Mc}\p{Mn}-_']+`)
)

Expand Down Expand Up @@ -118,6 +119,8 @@ func Clean(content []byte, langCode string, cleanHTML bool) []byte {
content = removeStopWords(content, thai)
case "tr":
content = removeStopWords(content, turkish)
case "vi":
content = removeStopWords(content, vietnamese)
}

//Remove duplicated space characters
Expand Down
Loading