Watch
1
0
Fork
You've already forked golang-github-clipperhouse-uax29
0
No description
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Daniel Baumann 7e608b313c
Releasing fastforward version 2.7.0-4~ffwd13+u1.
Signed-off-by: Daniel Baumann <daniel@debian.org>
2026-07-17 10:07:03 +02:00
.github/workflows Adding upstream version 2.7.0. 2026-07-08 16:30:36 +02:00
debian Releasing fastforward version 2.7.0-4~ffwd13+u1. 2026-07-17 10:07:03 +02:00
graphemes Adding upstream version 2.7.0. 2026-07-08 16:30:36 +02:00
internal Adding upstream version 2.7.0. 2026-07-08 16:30:36 +02:00
phrases Adding upstream version 2.7.0. 2026-07-08 16:30:36 +02:00
sentences Adding upstream version 2.7.0. 2026-07-08 16:30:36 +02:00
testdata Adding upstream version 2.7.0. 2026-07-08 16:30:36 +02:00
words Adding upstream version 2.7.0. 2026-07-08 16:30:36 +02:00
.gitignore Adding upstream version 2.7.0. 2026-07-08 16:30:36 +02:00
AGENTS.md Adding upstream version 2.7.0. 2026-07-08 16:30:36 +02:00
doc.go Adding upstream version 2.7.0. 2026-07-08 16:30:36 +02:00
gen.go Adding upstream version 2.7.0. 2026-07-08 16:30:36 +02:00
go.mod Adding upstream version 2.7.0. 2026-07-08 16:30:36 +02:00
go.sum Adding upstream version 2.7.0. 2026-07-08 16:30:36 +02:00
LICENSE Adding upstream version 2.7.0. 2026-07-08 16:30:36 +02:00
README.md Adding upstream version 2.7.0. 2026-07-08 16:30:36 +02:00

This package tokenizes (splits) words, sentences and graphemes, based on Unicode text segmentation (UAX #29), for Unicode 17. Details and usage are in the respective packages:

uax29/graphemes

uax29/words

uax29/phrases

uax29/sentences

Why tokenize?

Any time our code operates on individual words, we are tokenizing. Often, we do it ad hoc, such as splitting on spaces, which gives inconsistent results. The Unicode standard is better: it is multi-lingual, and handles punctuation, special characters, etc.

Uses

The uax29 module has 4 tokenizers. In decreasing granularity: sentences → phrases → words → graphemes. Words and graphemes are the most common uses.

You might use words for inverted indexes, full-text search, TF-IDF, BM25, embeddings, etc.

If you're doing embeddings, the definition of “meaningful unit” will depend on your application. You might choose sentences, phrases, words, or a combination.

Conformance

We use the official Unicode test suites. Status:

Go

Quick start

go get "github.com/clipperhouse/uax29/v2/words"
import "github.com/clipperhouse/uax29/v2/words"

text := "Hello, 世界. Nice dog! 👍🐶"

tokens := words.FromString(text)

for tokens.Next() {                     // Next() returns true until end of data
	fmt.Println(tokens.Value())         // Do something with the current token
}

See also

jargon, a text pipelines package for CLI and Go, which consumes this package.

Prior art

blevesearch/segment

rivo/uniseg

Other language implementations

C# (also by me)

JavaScript

Rust

Java

Python