icanhazwordz

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2025 License: MIT Imports: 3 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

icanhazwordz

does this string contain words?

package main

import (
	"fmt"

	"github.com/zricethezav/icanhazwordz"
)

func main() {
	searcher := icanhazwordz.NewSearcher(icanhazwordz.Filter{
		MinLength: 3,
		MaxLength: 4,
	})
	result := searcher.Find("The quick brown fox jumps over the lazy dog")
	for _, m := range result.Matches {
		fmt.Println(m.Word)
	}

    fmt.Println("---")
    seracher.Filter =
	searcher := icanhazwordz.NewSearcher(icanhazwordz.Filter{
		MinLength: 3,
		MaxLength: 4,
        PreferLongestNonOverlapping: true,
	})
	result := searcher.Find("The quick brown fox jumps over the lazy dog")
	for _, m := range result.Matches {
		fmt.Println(m.Word)
	}
}

Output:

the
brow
row
own
fox
jump
ump
over
the
laz
lazy
dog
---
the
brow
fox
jump
over
the
lazy
dog

Shoutout to the 🐐, github.com/BobuSumisu/aho-corasick


Folks, it's MIT

a2l827

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultFilter = Filter{MinLength: 2, MaxLength: 0, PreferLongestNonOverlapping: false}

Default filter ignores single character words. If you want to include them, set MinLength to 1.

Functions

This section is empty.

Types

type Filter

type Filter struct {
	MinLength                   int  // Minimum word length (inclusive)
	MaxLength                   int  // Maximum word length (inclusive, 0 means no limit)
	ExactLength                 int  // Exact word length (0 means no exact match required)
	PreferLongestNonOverlapping bool // Prefer longest non-overlapping matches. e.g. "hello" vs "hell"
}

Filter defines criteria for filtering words

type Match

type Match struct {
	Word     string `json:"word"`
	StartPos int    `json:"start_pos"`
	EndPos   int    `json:"end_pos"`
}

Match represents a found word match

type Result

type Result struct {
	WordCount   int      `json:"word_count"`
	UniqueWords []string `json:"unique_words"`
	Matches     []Match  `json:"matches"`
}

Result represents the result of English word detection

type Searcher

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

Searcher provides nltk English word detection with configurable filters

func NewSearcher

func NewSearcher(filter Filter) *Searcher

NewSearcher creates a new searcher with the specified word filters

func (*Searcher) Find

func (s *Searcher) Find(text string) Result

Find analyzes text using this searcher's word list

func (*Searcher) GetWordCount

func (s *Searcher) GetWordCount() int

GetWordCount returns the number of words in this searcher's dictionary

func (*Searcher) GetWords

func (s *Searcher) GetWords() []string

GetWords returns all words in this searcher's dictionary

Jump to

Keyboard shortcuts

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