subword

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2023 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package subword implements a word replacement with a level.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Builder

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

Builder is a buffer to build a []Subword array.

func NewBuilder

func NewBuilder(subwords []Subword) *Builder

NewBuilder creates a Builder from subwords.

func (*Builder) Reset

func (b *Builder) Reset()

Reset discards the underlying subwords.

func (*Builder) String

func (b *Builder) String() string

String() concatenates buffered subwords to assemble the full word.

func (*Builder) Subwords

func (b *Builder) Subwords() []Subword

Subwords builds the buffered subwords into a []Subword array. It merges adjoin subwords if they share the same level.

func (*Builder) Write

func (b *Builder) Write(subwords ...Subword)

Write extends the underlying subwords by the given ones.

type Replacement

type Replacement struct {
	Start int
	Stop  int
	Word  string
}

Replacement is a deferred sw Replacement.

func NewReplacement

func NewReplacement(start, stop int, word string) Replacement

NewReplacement creates a Replacement.

func (Replacement) String

func (r Replacement) String() string

type Replacer

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

Replacer remembers replacements in a buffer. Finally, it applies the replacements and splits the result in several subwords.

func NewReplacer

func NewReplacer(word string, prevLevel, nextLevel int) *Replacer

NewReplacer creates a SubwordReplacer for a word.

func (*Replacer) Replace

func (r *Replacer) Replace(start, stop int, word string)

Replace buffers a replacement.

func (*Replacer) ReplaceBy

func (r *Replacer) ReplaceBy(repls ...Replacement)

ReplaceBy buffers multiple replacements.

func (*Replacer) String

func (r *Replacer) String() string

String applies the buffered replacements and returns the replaced full word.

func (*Replacer) Subwords

func (r *Replacer) Subwords() []Subword

Subwords applies the buffered replacements and returns the replaced word as a []Subword array.

type Subword

type Subword struct {
	Word  string
	Level int
}

Subword is a chunk of a word with a level number. The level indicates which step in the procedure generated this sw.

func New

func New(word string, level int) Subword

New creates a Subword.

Jump to

Keyboard shortcuts

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