-
Notifications
You must be signed in to change notification settings - Fork 25
/
custom.go
177 lines (169 loc) · 4.04 KB
/
custom.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
// Copyright 2015 Benjamin BALET. All rights reserved.
// Use of this source code is governed by the BSD license
// license that can be found in the LICENSE file.
// Package stopwords allows you to customize the list of stopwords
package stopwords
import (
"io/ioutil"
"strings"
"golang.org/x/text/language"
)
// LoadStopWordsFromFile loads a list of stop words from a file
// filePath is the full path to the file to be loaded
// langCode is a BCP 47 or ISO 639-1 language code (e.g. "en" for English).
// sep is the string separator (e.g. "\n" for newline)
func LoadStopWordsFromFile(filePath string, langCode string, sep string) {
b, err := ioutil.ReadFile(filePath)
if err != nil {
panic(err)
}
LoadStopWordsFromString(string(b), langCode, sep)
}
// LoadStopWordsFromString loads a list of stop words from a string
// filePath is the full path to the file to be loaded
// langCode is a BCP 47 or ISO 639-1 language code (e.g. "en" for English).
// sep is the string separator (e.g. "\n" for newline)
func LoadStopWordsFromString(wordsList string, langCode string, sep string) {
//Parse language
tag := language.Make(langCode)
base, _ := tag.Base()
langCode = base.String()
words := strings.Split(strings.ToLower(wordsList), sep)
switch langCode {
case "ar":
arabic = make(map[string]string)
for _, word := range words {
arabic[word] = ""
}
case "bg":
bulgarian = make(map[string]string)
for _, word := range words {
bulgarian[word] = ""
}
case "cs":
czech = make(map[string]string)
for _, word := range words {
czech[word] = ""
}
case "da":
danish = make(map[string]string)
for _, word := range words {
danish[word] = ""
}
case "de":
german = make(map[string]string)
for _, word := range words {
german[word] = ""
}
case "el":
greek = make(map[string]string)
for _, word := range words {
greek[word] = ""
}
case "en":
english = make(map[string]string)
for _, word := range words {
english[word] = ""
}
case "es":
spanish = make(map[string]string)
for _, word := range words {
spanish[word] = ""
}
case "fa":
persian = make(map[string]string)
for _, word := range words {
persian[word] = ""
}
case "fr":
french = make(map[string]string)
for _, word := range words {
french[word] = ""
}
case "fi":
finnish = make(map[string]string)
for _, word := range words {
finnish[word] = ""
}
case "hu":
hungarian = make(map[string]string)
for _, word := range words {
hungarian[word] = ""
}
case "id":
indonesian = make(map[string]string)
for _, word := range words {
indonesian[word] = ""
}
case "it":
italian = make(map[string]string)
for _, word := range words {
italian[word] = ""
}
case "ja":
japanese = make(map[string]string)
for _, word := range words {
japanese[word] = ""
}
case "km":
khmer = make(map[string]string)
for _, word := range words {
khmer[word] = ""
}
case "lv":
latvian = make(map[string]string)
for _, word := range words {
latvian[word] = ""
}
case "nl":
dutch = make(map[string]string)
for _, word := range words {
dutch[word] = ""
}
case "no":
norwegian = make(map[string]string)
for _, word := range words {
norwegian[word] = ""
}
case "pl":
polish = make(map[string]string)
for _, word := range words {
polish[word] = ""
}
case "pt":
portuguese = make(map[string]string)
for _, word := range words {
portuguese[word] = ""
}
case "ro":
romanian = make(map[string]string)
for _, word := range words {
romanian[word] = ""
}
case "ru":
russian = make(map[string]string)
for _, word := range words {
russian[word] = ""
}
case "sk":
slovak = make(map[string]string)
for _, word := range words {
slovak[word] = ""
}
case "sv":
swedish = make(map[string]string)
for _, word := range words {
swedish[word] = ""
}
case "th":
thai = make(map[string]string)
for _, word := range words {
thai[word] = ""
}
case "tr":
turkish = make(map[string]string)
for _, word := range words {
turkish[word] = ""
}
}
}