lextoken

package
v1.28.0 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package lextoken provides the canonical query tokenizer and identifier splitter for go-code. It is a leaf package (stdlib-only, no internal imports) consumed by both internal/analyze and internal/embeddings.

Three previously divergent sites are collapsed here:

  • splitIdentifier/splitCamelCase (analyze/context.go) → SplitIdentifier/SplitCamelCase
  • extractQueryTerms (analyze/context.go) → Tokenize
  • extractKeywordsForBoost (analyze/rank.go) and ExtractQueryKeywords (embeddings/store_keyword.go) — byte-identical logic → KeywordTokenize

Stopword decision: analyze/rank.go and embeddings/store_keyword.go had byte-identical stopword sets. They are unified into one canonical set here. coupling/symbols.go:stopTokens is a different domain (HTTP-literal dedup) and is NOT touched by this package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FilterStopwords

func FilterStopwords(terms []string) []string

FilterStopwords returns a copy of terms with stopwords removed. Returns nil when input is nil (preserves nil-vs-empty distinction).

func IsStopword

func IsStopword(word string) bool

IsStopword reports whether word is in the canonical stopword set.

func KeywordTokenize

func KeywordTokenize(query string) []string

KeywordTokenize splits a natural-language query into meaningful search terms by:

  1. Lowercasing and splitting on non-alphanumeric characters.
  2. Keeping terms ≥ 3 characters.
  3. Filtering canonical stopwords (IsStopword).
  4. Deduplicating.

It does NOT perform identifier splitting (use Tokenize for that). Mirrors the byte-identical logic from analyze/rank.go:286 (extractKeywordsForBoost) and embeddings/store_keyword.go:76 (ExtractQueryKeywords).

func SplitCamelCase

func SplitCamelCase(s string) []string

SplitCamelCase splits a camelCase or PascalCase identifier into lowercase subwords. Subwords shorter than 2 characters are dropped. Mirrors analyze/context.go:138 (splitCamelCase).

func SplitIdentifier

func SplitIdentifier(s string) []string

SplitIdentifier splits an identifier on underscores, then splits each part by camelCase. Empty parts (from leading/trailing/double underscores) are skipped. Mirrors analyze/context.go:186 (splitIdentifier).

func Tokenize

func Tokenize(query string) []string

Tokenize splits a natural-language or identifier query into lowercase alphanumeric terms for symbol matching. It:

  1. Lowercases and strips non-alphanumeric characters from each word.
  2. Keeps terms ≥ 3 characters.
  3. Also runs identifier splitting (SplitIdentifier) on each word, adding the resulting subwords as additional terms.
  4. Deduplicates across both passes.

NOTE: Tokenize does NOT filter stopwords — it is used in analyze/context.go where stopwords are intentional query signals (e.g. "what", "are"). Use KeywordTokenize for stopword-filtered keyword extraction.

Mirrors analyze/context.go:202 (extractQueryTerms).

Types

This section is empty.

Jump to

Keyboard shortcuts

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