-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstemmer.go
62 lines (53 loc) · 1.63 KB
/
stemmer.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
// This file is part of GoIRS.
//
// GoIRS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// GoIRS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with GoIRS. If not, see <http://www.gnu.org/licenses/>.
package goirs
import (
"os"
"github.com/kljensen/snowball/spanish"
)
func stemmer(input <-chan string, output chan string) {
defer close(output)
for currstr := range input {
output <- spanish.Stem(currstr, false)
}
}
//StemmerIterator recorre el iterador y devuelve
func (tokens StringIterator) StemmerIterator() StringIterator {
out := make(chan string, BUFFERSIZE)
go stemmer(tokens, out)
return out
}
//StemmerWriterIterator escribe los tokens pasados por el stemmer
func (tokens StringIterator) StemmerWriterIterator(dostem bool, file string, writeStem bool) StringIterator {
if dostem {
if writeStem {
towrite, err := os.Create(file)
defer towrite.Close()
if err != nil {
panic(err)
}
out := make(chan string, BUFFERSIZE)
in := tokens.StemmerIterator()
dest, err := os.Create(file)
if err != nil {
panic(err)
}
go tokenWrite(dest, in, out)
return out
}
return tokens.StemmerIterator()
}
return tokens
}