A Go (golang) implementation of the Snowball stemmer for natural language processing.
Status | |
---|---|
Latest release | v0.10.0 (2024-08-13) |
Latest build status | |
Languages available | English, Spanish (español), French (le français), Russian (ру́сский язы́к), Swedish (svenska), Norwegian (norsk), Hungarian (magyar) |
License | MIT |
Here is a minimal Go program that uses this package in order to stem a single word.
package main
import (
"fmt"
"github.com/kljensen/snowball"
)
func main(){
stemmed, err := snowball.Stem("Accumulations", "english", true)
if err == nil{
fmt.Println(stemmed) // Prints "accumul"
}
}
The code is organized as follows:
snowball
package has a single exported function snowball.Stem
,
which is defined in snowball/snowball.go
.snowball/spanish
.Stem
function: e.g. spanish.Stem
,
which is defined in snowball/spanish/stem.go
.romance
package.Some notes about the implementation:
snowball/snowballword/snowballword.go
and the
SnowballWord
struct.SnowballWord
struct for each word that needs to be stemmed.R1start
, R2start
, & RVstart
on the SnowballWord
struct. I believe this is a relatively efficient way of
storing R1 and R2.snowballword
package a bit every time I implement a
new language.To run the tests, do go test ./...
in the top-level directory.
I'd like to implement the Snowball stemmer in more languages. If you can help, I would greatly appreciate it: please fork the project and send a pull request!
(Also, if you are interested in creating a larger NLP project for Go, please get in touch.)
I know of a few other stemmers availble in Go:
Copyright (c) the Contributors (see above)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.