liveBook · Manning

Tokenization

As explained in Just Use Postgres!

Tokenization is the process of splitting text into discrete tokens for linguistic or computational processing.

Tokenization splits a document into discrete tokens before full-text search. In PostgreSQL, the sentence “5 explorers are traveling” becomes “5,” “explorers,” “are,” and “traveling.” Normalization then converts tokens into lexemes, while storage and indexing prepare them for queries. section 6.1

PostgreSQL’s parser identifies token types before dictionaries normalize them:

  • Numbers such as “5” become numeric tokens and remain {5}. section 6.1.1
  • Words such as “explorers” and “traveling” are normalized by English stemming to {explor} and {travel}. section 6.1 section 6.1.1
  • Stop words such as “are,” “to,” and “a” produce no lexemes. section 6.1

Inspect tokens with ts_debug

Run SELECT token, description, lexemes, dictionary FROM ts_debug('5 explorers are traveling to a distant galaxy'); to inspect each token, its type, resulting lexeme, and dictionary. PostgreSQL uses the default built-in parser unless another configuration is selected.

How Just Use Postgres! covers it

How deep it goes
Explains parsing, token types, dictionaries, stemming, and stop-word removal, then stops short of query ranking internals.
Examples
Uses movie-search text, ts_debug output, numeric and word token types, and English stemming examples.
What it assumes
Assumes PostgreSQL full-text search context and basic SQL ability, while demonstrating token processing from a sentence.
What you can do after
Diagnose tokenization and normalization with PostgreSQL’s ts_debug function and interpret its parser output.
How it connects
Connects tokenization with normalization, lexemes, tsvector, dictionaries, stemming, stop words, and full-text search.

Also explained in

Compare how 25 books explain tokenization →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Just Use Postgres!. The section links point to the parts of the book it draws on.