Help us shape the future of Go! Take the 2026 Go Developer Survey

snowball

package module
v0.8.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 10, 2025 License: MIT Imports: 4 Imported by: 81

README

Snowball Stemmer for Go

Go Reference Test

Usage

package snowball_test

import (
	"fmt"

	"github.com/tebeka/snowball"
)

func Example() {
	stemmer, err := snowball.New("english")
	if err != nil {
		fmt.Println("error", err)
		return
	}
	defer stemmer.Close()

    for _, word := []string{"worked", "working", "works"} {
        fmt.Println(stemmer.Stem(word))
    }

	// Output:
	// work
	// work
	// work
}

This project was mostly a learning exercise for me, I don't consider it production quality.

Installing

go get github.com/tebeka/snowball@latest

You will need a C compiler on your machine.

Development

If you want to update the underlying C library, run update-c.sh. Make sure to run the tests after.

Documentation

Overview

Package snowball implements a stemmer

Example
package main

import (
	"fmt"

	"github.com/tebeka/snowball"
)

func main() {
	stemmer, err := snowball.New("english")
	if err != nil {
		fmt.Println("error", err)
		return
	}
	defer stemmer.Close()

	fmt.Println(stemmer.Stem("working"))
	fmt.Println(stemmer.Stem("works"))
	fmt.Println(stemmer.Stem("worked"))
}
Output:
work
work
work

Index

Examples

Constants

View Source
const (
	// Version is the library version
	Version = "0.8.0"
)

Variables

View Source
var (
	//go:embed "lib-version.txt"
	SnowballVersion string
)

Functions

func LangList

func LangList() []string

LangList returns the list of languages supported by snowball. DEPRECATED: Use Languages

func Languages added in v0.6.0

func Languages() []string

Languages returns the list of languages supported by snowball.

Types

type Stemmer

type Stemmer struct {
	// contains filtered or unexported fields
}

Stemmer structure. Warning: Stemmers are not goroutine safe, create a stemmer per goroutine or use a pool (such as sync.Pool) to ensure safety.

func New

func New(lang string) (*Stemmer, error)

New creates a new stemmer for lang.

func (*Stemmer) Close added in v0.7.0

func (stmr *Stemmer) Close() error

Close closes the stemmer and frees the underlying C memory.

func (*Stemmer) Lang

func (stmr *Stemmer) Lang() string

Lang return the stemmer language.

func (*Stemmer) Stem

func (stmr *Stemmer) Stem(word string) string

Stem returns them stem of word (e.g. running -> run).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL