scanner

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: May 2, 2025 License: MIT Imports: 6 Imported by: 0

README

Text Scanners

Text Scanners compatible with bufio.Scanner.

  • Identity consumes entire reader as output.
  • Slicer splits the input reader by fixed delimiter.
  • Sentencer splits the input reader by punctuations, forming sentences.
  • Chunker builds chunks of appoximately equal size.

Documentation

Index

Constants

View Source
const EndOfSentence = ".!?"

Default end of sentence

Variables

This section is empty.

Functions

func NewSentencer

func NewSentencer(eos string, r io.Reader) *bufio.Scanner

Create a scanner that slices input stream by end of sentence

func NewSlicer

func NewSlicer(delim string, r io.Reader) *bufio.Scanner

Create a scanner that slices input stream by fixed delimiter

Types

type Chunker

type Chunker struct {
	Scanner
	// contains filtered or unexported fields
}

func NewChunker

func NewChunker(size int, s Scanner) *Chunker

func (*Chunker) Scan

func (s *Chunker) Scan() bool

func (*Chunker) Text

func (s *Chunker) Text() string

type Identity

type Identity struct {
	io.Reader
	// contains filtered or unexported fields
}

func NewIdentity

func NewIdentity(r io.Reader) *Identity

func (*Identity) Err

func (r *Identity) Err() error

func (*Identity) Scan

func (r *Identity) Scan() bool

func (*Identity) Text

func (r *Identity) Text() string

type Scanner

type Scanner interface {
	Scan() bool
	Text() string
	Err() error
}

Scanner is an interface similar to bufio.Scanner. It defines core functionality defined by this library.

type Sentencer

type Sentencer []byte

func (Sentencer) Split

func (s Sentencer) Split(data []byte, atEOF bool) (advance int, token []byte, err error)

bufio.SplitFunc for sentence.

type Slicer

type Slicer []byte

func (Slicer) Split

func (s Slicer) Split(data []byte, atEOF bool) (advance int, token []byte, err error)

bufio.SplitFunc for fixed delimiter.

Jump to

Keyboard shortcuts

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