• Stars
    star
    253
  • Rank 160,776 (Top 4 %)
  • Language
    Go
  • License
    MIT License
  • Created over 11 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Go implementation of the Snowball stemmers

Snowball

A Go (golang) implementation of the Snowball stemmer for natural language processing.

Status
Latest release v0.9.0 (2023-11-14)
Latest build status Build
Languages available English, Spanish (español), French (le français), Russian (ру́сский язы́к), Swedish (svenska), Norwegian (norsk), Hungarian (magyar)
License MIT

Usage

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"
	}
}

Organization & Implementation

The code is organized as follows:

  • The top-level snowball package has a single exported function snowball.Stem, which is defined in snowball/snowball.go.
  • The stemmer for each language is defined in a "sub-package", e.g snowball/spanish.
  • Each language exports a Stem function: e.g. spanish.Stem, which is defined in snowball/spanish/stem.go.
  • Code that is common to multiple languages may go in a separate package, e.g. the small romance package.

Some notes about the implementation:

  • In order to ensure the code is easily extended to non-English languages, I avoided using bytes and byte arrays, and instead perform all operations on runes. See snowball/snowballword/snowballword.go and the SnowballWord struct.
  • In order to avoid casting strings into slices of runes numerous times, this implementation uses a single slice of runes stored in the SnowballWord struct for each word that needs to be stemmed.
  • In spite of the foregoing, readability requires that some strings be kept around and repeatedly cast into slices of runes. For example, in the Spanish stemmer, one step requires removing suffixes with accute accents such as "ución", "logía", and "logías". If I were to hard-code those suffices as slices of runes, the code would be substantially less readable.
  • Instead of carrying around the word regions R1, R2, & RV as separate strings (or slices or runes, or whatever), we carry around the index where each of these regions begins. These are stored as R1start, R2start, & RVstart on the SnowballWord struct. I believe this is a relatively efficient way of storing R1 and R2.
  • The code does not use any maps or regular expressions 1) for kicks, and 2) because I thought they'd negatively impact the performance. (But, mostly for #1; I realize #2 is silly.)
  • I end up refactoring the snowballword package a bit every time I implement a new language.
  • Clearly, the Go implentation of these stemmers is verbose relative to the Snowball language. However, it is much better than the Java version and others.

Testing

To run the tests, do go test ./... in the top-level directory.

Future work

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.)

Related work

I know of a few other stemmers availble in Go:

Contributors

License (MIT)

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.

More Repositories

1

golang-html5-sse-example

HTML5 Server Sent Events with Go
Go
316
star
2

async-flask-sqlalchemy-example

Non-blocking Flask, SQLAlchemy, Psygopg2, Postgresql, Gevent & Gunicorn Example
Python
264
star
3

mit-phd-thesis

MIT Ph.D. Thesis in LaTeX
PostScript
62
star
4

node-sse-example

JavaScript
31
star
5

golang-chat

A minimal Go TCP chat example
Go
30
star
6

go-is-awesome

Presentation about Golang
HTML
19
star
7

Gemoda

A generic motif discovery algorithm for sequential data
C
9
star
8

py-reqcache

Caching for Python's Request Package
Python
7
star
9

shell-interval-training-timer

shell-interval-workout-timer
Shell
6
star
10

semiuniq

A uniq-like tool for removing nearby repeated lines in a file"
Rust
4
star
11

viff

Fork of http://viff.dk/
Python
4
star
12

biogrep

A multi–threaded pattern matcher for large pattern sets
C
3
star
13

docker-actix-postgres-redis-todo

A version of the Actix todo example, dockerized with redis for session storage
Rust
3
star
14

ctbiomed

Analyzes biomedical research trends in Connecticut
Python
2
star
15

example-attackable-web-app

A web app vulnerable to SQL injection, XSS, and CSRF.
Python
2
star
16

yale-class-chat

Chat, Q&A, voting, and attendance-taking platform for use in Yale classes
Elixir
2
star
17

meteor-coursera

Coursera OAuth flow for Meteor
JavaScript
1
star
18

hollablog

Blog for Kyle and Gilman. Woot.
1
star
19

homebrew-tap

Homebrew tap for code from Kyle Jensen (kljensen)
Ruby
1
star
20

binomp

P-value for binomial distribution
C
1
star
21

cleanup-heroku

A portable, POSIX-compliant shell script to delete old, unused Heroku applications
Shell
1
star
22

basement-motion-lights

Code for my motion-activated basement lighting
C++
1
star
23

borkedbuild

Make custom build badges for you software projects
Go
1
star
24

kljensen

1
star
25

pgtap-results-approx-eq

Compare the results of two PostgreSQL queries to determine if they are "approximately" the same
PLpgSQL
1
star
26

j2tex

Code I use to create templated LaTeX documents
Python
1
star
27

easy-in-class-quiz

A 1-page in-class multiple choice quiz in Markdown/LaTeX. Easy to write with AI and compile/print/grade.
TeX
1
star