word

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2019 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

This package defines a Word struct that is used to encapsulate most of the "state" variables we must track when stemming a word. The Word struct also has a few methods common to stemming in a variety of languages.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Word

type Word struct {

	// A slice of runes
	RS []rune

	// The index in RS where the R1 region begins
	R1start int

	// The index in RS where the R2 region begins
	R2start int

	// The index in RS where the RV region begins
	RVstart int
}

Word represents a word that is going to be stemmed.

func New

func New(in string) (word *Word)

Create a new Word struct

func (*Word) DebugString

func (w *Word) DebugString() string

func (*Word) FirstPrefix

func (w *Word) FirstPrefix(prefixes ...string) (foundPrefix string, foundPrefixRunes []rune)

Return the first prefix found or the empty string.

func (*Word) FirstSuffix

func (w *Word) FirstSuffix(suffixes ...string) (suffix string, suffixRunes []rune)

Return the first suffix found or the empty string.

func (*Word) FirstSuffixIfIn

func (w *Word) FirstSuffixIfIn(startPos, endPos int, suffixes ...string) (suffix string, suffixRunes []rune)

Find the first suffix that ends at `endPos` in the word among those provided; then, check to see if it begins after startPos. If it does, return it, else return the empty string and empty rune slice. This may seem a counterintuitive manner to do this. However, it matches what is required most of the time by the Snowball stemmer steps.

func (*Word) FirstSuffixIn

func (w *Word) FirstSuffixIn(startPos, endPos int, suffixes ...string) (suffix string, suffixRunes []rune)

func (*Word) FitsInR1

func (w *Word) FitsInR1(x int) bool

Returns true if `x` runes would fit into R1.

func (*Word) FitsInR2

func (w *Word) FitsInR2(x int) bool

Returns true if `x` runes would fit into R2.

func (*Word) FitsInRV

func (w *Word) FitsInRV(x int) bool

Returns true if `x` runes would fit into RV.

func (*Word) HasSuffixRunes

func (w *Word) HasSuffixRunes(suffixRunes []rune) bool

Return true if `w` ends with `suffixRunes`

func (*Word) HasSuffixRunesIn

func (w *Word) HasSuffixRunesIn(startPos, endPos int, suffixRunes []rune) bool

Return true if `w.RS[startPos:endPos]` ends with runes from `suffixRunes`. That is, the slice of runes between startPos and endPos have a suffix of suffixRunes.

func (*Word) R1

func (w *Word) R1() []rune

Return the R1 region as a slice of runes

func (*Word) R1String

func (w *Word) R1String() string

Return the R1 region as a string

func (*Word) R2

func (w *Word) R2() []rune

Return the R2 region as a slice of runes

func (*Word) R2String

func (w *Word) R2String() string

Return the R2 region as a string

func (*Word) RV

func (w *Word) RV() []rune

Return the RV region as a slice of runes

func (*Word) RVString

func (w *Word) RVString() string

Return the RV region as a string

func (*Word) RemoveFirstSuffix

func (w *Word) RemoveFirstSuffix(suffixes ...string) (suffix string, suffixRunes []rune)

Removes the first suffix found

func (*Word) RemoveFirstSuffixIfIn

func (w *Word) RemoveFirstSuffixIfIn(startPos int, suffixes ...string) (suffix string, suffixRunes []rune)

Find the first suffix in the word among those provided; then, check to see if it begins after startPos. If it does, remove it.

func (*Word) RemoveFirstSuffixIn

func (w *Word) RemoveFirstSuffixIn(startPos int, suffixes ...string) (suffix string, suffixRunes []rune)

Removes the first suffix found that is in `word.RS[startPos:len(word.RS)]`

func (*Word) RemoveLastNRunes

func (w *Word) RemoveLastNRunes(n int)

Remove the last `n` runes from the Word.

func (*Word) ReplaceSuffix

func (w *Word) ReplaceSuffix(suffix, replacement string, force bool) bool

Replace a suffix and adjust R1start and R2start as needed. If `force` is false, check to make sure the suffix exists first.

func (*Word) ReplaceSuffixRunes

func (w *Word) ReplaceSuffixRunes(suffixRunes []rune, replacementRunes []rune, force bool) bool

Replace a suffix and adjust R1start and R2start as needed. If `force` is false, check to make sure the suffix exists first.

func (*Word) String

func (w *Word) String() string

Return the Word as a string

Jump to

Keyboard shortcuts

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